@@ -154,29 +154,29 @@ template <symmetry_tag current_sensor_symmetry_> class CurrentSensor : public Ge
154
154
CurrentSensorOutput<sym_calc> output{};
155
155
output.id = id ();
156
156
output.energized = 1 ; // current sensor is always energized
157
- auto i_output = i;
158
157
auto const i_calc_param = calc_param<sym_calc>();
159
158
auto const angle_measurement_type = i_calc_param.angle_measurement_type ;
160
159
auto const i_measured_complex = i_calc_param.measurement .value ();
161
- if (angle_measurement_type == AngleMeasurementType::local_angle) {
162
- // I_l = conj(I_g) * exp(i * u_angle)
163
- // Tranform back the output angle to the local angle frame of reference
164
- auto const u_angle = arg (u);
165
- i_output = conj (i_output) * (cos (u_angle) + 1i * sin (u_angle));
166
- }
160
+ ComplexValue<sym_calc> i_output = [&i, &u, &angle_measurement_type] {
161
+ switch (angle_measurement_type) {
162
+ case AngleMeasurementType::global_angle: {
163
+ return i;
164
+ }
165
+ case AngleMeasurementType::local_angle: {
166
+ // I_l = conj(I_g) * exp(i * u_angle)
167
+ // Tranform back the output angle to the local angle frame of reference
168
+ auto const u_angle = arg (u);
169
+ return ComplexValue<sym_calc>{conj (i) * (cos (u_angle) + 1i * sin (u_angle))};
170
+ }
171
+ default : {
172
+ throw MissingCaseForEnumError{" generic output angle measurement type" , angle_measurement_type};
173
+ }
174
+ }
175
+ }();
167
176
output.i_residual = (cabs (i_measured_complex) - cabs (i_output)) * base_current_;
168
177
// arg(e^i * u_angle) = u_angle in (-pi, pi]
169
178
auto const unbounded_i_angle_residual = arg (i_measured_complex) - arg (i_output);
170
- if constexpr (is_symmetric_v<sym_calc>) {
171
- output.i_angle_residual =
172
- arg (ComplexValue<sym_calc>{cos (unbounded_i_angle_residual), sin (unbounded_i_angle_residual)});
173
- } else {
174
- output.i_angle_residual = arg (ComplexValue<sym_calc>{
175
- cos (unbounded_i_angle_residual (0 )) + 1i * sin (unbounded_i_angle_residual (0 )),
176
- cos (unbounded_i_angle_residual (1 )) + 1i * sin (unbounded_i_angle_residual (1 )),
177
- cos (unbounded_i_angle_residual (2 )) + 1i * sin (unbounded_i_angle_residual (2 )),
178
- });
179
- }
179
+ output.i_angle_residual = arg (ComplexValue<sym_calc>{exp (1 .0i * unbounded_i_angle_residual)});
180
180
return output;
181
181
}
182
182
};
0 commit comments