Skip to content

Commit

Permalink
fix voltage sensor
Browse files Browse the repository at this point in the history
Signed-off-by: Martijn Govers <[email protected]>
  • Loading branch information
mgovers committed Jan 6, 2025
1 parent ca56ec8 commit 09d1dac
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,18 @@ template <symmetry_tag sym> class VoltageSensor : public GenericVoltageSensor {
explicit VoltageSensor(VoltageSensorInput<sym> const& voltage_sensor_input, double u_rated)
: GenericVoltageSensor{voltage_sensor_input},
u_rated_{u_rated},
u_sigma_{voltage_sensor_input.u_sigma / (u_rated_ * u_scale<sym>)},
u_measured_{voltage_sensor_input.u_measured / (u_rated_ * u_scale<sym>)},
u_sigma_{voltage_sensor_input.u_sigma * inv_u_norm()},
u_measured_{voltage_sensor_input.u_measured * inv_u_norm()},
u_angle_measured_{voltage_sensor_input.u_angle_measured} {};

UpdateChange update(VoltageSensorUpdate<sym> const& update_data) {
assert(update_data.id == this->id() || is_nan(update_data.id));
double const scalar = 1 / (u_rated_ * u_scale<sym>);

update_real_value<sym>(update_data.u_measured, u_measured_, scalar);
update_real_value<sym>(update_data.u_measured, u_measured_, inv_u_norm());
update_real_value<sym>(update_data.u_angle_measured, u_angle_measured_, 1.0);

if (!is_nan(update_data.u_sigma)) {
u_sigma_ = update_data.u_sigma * scalar;
u_sigma_ = update_data.u_sigma * inv_u_norm();
}

return {false, false};
Expand All @@ -110,6 +109,8 @@ template <symmetry_tag sym> class VoltageSensor : public GenericVoltageSensor {
RealValue<sym> u_measured_;
RealValue<sym> u_angle_measured_;

constexpr auto inv_u_norm() const { return 1.0 / (u_rated_ * u_scale<sym>); }

bool has_angle() const {
if constexpr (is_symmetric_v<sym>) {
return !is_nan(u_angle_measured_);
Expand Down
19 changes: 19 additions & 0 deletions tests/cpp_unit_tests/test_voltage_sensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,25 @@ TEST_CASE("Test voltage sensor") {
}
}

SUBCASE("Construction and update") {
VoltageSensorInput<symmetric_t> sym_voltage_sensor_input{
.id = 7, .measured_object = 3, .u_sigma = 1.0, .u_measured = 25000, .u_angle_measured = -0.2};
VoltageSensorUpdate<symmetric_t> sym_voltage_sensor_update{.id = 7,
.u_sigma = sym_voltage_sensor_input.u_sigma,
.u_measured = sym_voltage_sensor_input.u_measured,
.u_angle_measured =
sym_voltage_sensor_input.u_angle_measured};

SymVoltageSensor sym_voltage_sensor{sym_voltage_sensor_input, 31250};
auto const orig_calc_param = sym_voltage_sensor.calc_param<symmetric_t>();

sym_voltage_sensor.update(sym_voltage_sensor_update);
auto const updated_calc_param = sym_voltage_sensor.calc_param<symmetric_t>();

CHECK(orig_calc_param.value == updated_calc_param.value);
CHECK(orig_calc_param.variance == updated_calc_param.variance);
}

SUBCASE("Update inverse - sym") {
constexpr auto u_sigma = 1.0;
constexpr auto u_measured = 2.0;
Expand Down

0 comments on commit 09d1dac

Please sign in to comment.