Commit d144676c authored by Stefan Dähling's avatar Stefan Dähling

evaluate mqtt message for substation

parent 919752b3
......@@ -437,6 +437,7 @@ void Ensure_prosumer_behavior::apply_control_values()
IO->log_info("\tApplying control values\n\t\tP_ctrl: " + std::to_string(prosumer_data->P_ctrl) +
"W Q_ctrl: " + std::to_string(prosumer_data->Q_ctrl) + "var");
return;
}
......
......@@ -58,23 +58,9 @@ void Ensure_substation_behavior::execute_agent_behavior()
void Ensure_substation_behavior::process_ensure_msg(Ensure_msg &msg)
{
// ensure test behavior receives a ping from the cloud platform and replies with a pong
double v = sqrt(substation_data->v2_re * substation_data->v2_re +
substation_data->v2_im * substation_data->v2_im) / (substation_data->Vnom2 / sqrt(3));
Ensure_msg new_msg;
int counter = (int) *msg.n;
counter ++;
new_msg.time_sec = t_next;
*(new_msg.agent_id) = id;
*(new_msg.performative) = *msg.performative;
*(new_msg.P) = *msg.P;
*(new_msg.Q) = *msg.Q;
*(new_msg.n) = counter;
*(new_msg.v) = v;
*(new_msg.SOC) = *msg.SOC;
*(new_msg.connected) = *msg.connected;
IO->log_info("\tSend message: " + new_msg.get_message_output());
send_villas_msg(new_msg);
knowledge.set_t_recv(t_next);
knowledge.set_n_ctrl(*(msg.n));
return;
}
void Ensure_substation_behavior::send_measurement_message()
......@@ -104,40 +90,9 @@ void Ensure_substation_behavior::send_measurement_message()
* */
void Ensure_substation_behavior::apply_control_values()
{
/* adjust tap position according to voltage of secondary node */
double v = sqrt(substation_data->v2_re * substation_data->v2_re +
substation_data->v2_im * substation_data->v2_im) / (substation_data->Vnom2 / sqrt(3));
// Define reasonable minimal interval for oltc switching, now 60 sek
if (t_next >= substation_data->t_last_action + 60) {
if (fabs(v) > 0.001) {
if (v < 1) {
/* voltage is smaller than 1 pu -> decrease tap position */
double delta = ((1 - v) * 100) / (substation_data->range / substation_data->N);
/* threshold for tap changing in order to avoid oscillations */
if (delta > 0.7) {
substation_data->n_ctrl = substation_data->n - round(delta);
}
if (substation_data->n_ctrl < -substation_data->N) {
substation_data->n_ctrl = -substation_data->N;
}
} else {
/* voltage is greater than 1 pu -> increase tap position */
double delta = ((v - 1) * 100) / (substation_data->range / substation_data->N);
/* threshold for tap changing in order to avoid oscillations */
if (delta > 0.7) {
substation_data->n_ctrl = substation_data->n + round(delta);
}
if (substation_data->n_ctrl > substation_data->N) {
substation_data->n_ctrl = substation_data->N;
}
}
}
if (substation_data->n_ctrl != substation_data->n) {
substation_data->t_last_action = t_next;
}
}
substation_data->n_ctrl = knowledge.get_n_ctrl();
IO->log_info("\tApplying control values\n\t\tn_ctrl: " +
std::to_string(substation_data->n_ctrl));
return;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment