Skip to content
Permalink
Browse files

Smooth voltage used for flux braking

This creates a 1ms filtered bus voltage to use for flux braking.  The
unfiltered bus voltage resulted in a very noisy operation, as the
feedback loop was too tight.
  • Loading branch information...
jpieper committed Oct 29, 2019
1 parent bd35792 commit fbc19e1c8d966778b5baf486b6183f88c6c4e9c3
Showing with 18 additions and 10 deletions.
  1. +16 −10 moteus/bldc_servo.cc
  2. +2 −0 moteus/bldc_servo.h
@@ -673,13 +673,17 @@ class BldcServo::Impl {
status_.cur2_A = (status_.adc2_raw - status_.adc2_offset) * adc_scale_;
status_.bus_V = status_.adc3_raw * config_.v_scale_V;

if (!std::isfinite(status_.filt_bus_V)) {
status_.filt_bus_V = status_.bus_V;
} else {
constexpr float alpha = 1.0 / (kRateHz * 0.5f); // 0.5s
status_.filt_bus_V =
alpha * status_.bus_V + (1.0f - alpha) * status_.filt_bus_V;
}
auto update_filtered_bus_v = [&](float* filtered, float period_s) {
if (!std::isfinite(*filtered)) {
*filtered = status_.bus_V;
} else {
const float alpha = 1.0 / (kRateHz * period_s);
*filtered = alpha * status_.bus_V + (1.0f - alpha) * *filtered;
}
};

update_filtered_bus_v(&status_.filt_bus_V, 0.5f);
update_filtered_bus_v(&status_.filt_1ms_bus_V, 0.001f);

DqTransform dq{sin_cos,
status_.cur1_A,
@@ -1193,12 +1197,14 @@ class BldcServo::Impl {
return 0.0f;
}

if (status_.bus_V <= config_.flux_brake_min_voltage) {
const auto error = (
status_.filt_1ms_bus_V - config_.flux_brake_min_voltage);

if (error <= 0.0f) {
return 0.0f;
}

return ((status_.bus_V - config_.flux_brake_min_voltage) /
config_.flux_brake_resistance_ohm);
return (error / config_.flux_brake_resistance_ohm);
}();

ISR_DoCurrent(sin_cos, d_A, q_A);
@@ -277,6 +277,7 @@ class BldcServo {
float cur2_A = 0.0f;
float bus_V = 0.0f;
float filt_bus_V = std::numeric_limits<float>::quiet_NaN();
float filt_1ms_bus_V = std::numeric_limits<float>::quiet_NaN();
uint16_t position = 0;
float fet_temp_C = 0.0f;

@@ -316,6 +317,7 @@ class BldcServo {
a->Visit(MJ_NVP(cur2_A));
a->Visit(MJ_NVP(bus_V));
a->Visit(MJ_NVP(filt_bus_V));
a->Visit(MJ_NVP(filt_1ms_bus_V));
a->Visit(MJ_NVP(position));
a->Visit(MJ_NVP(fet_temp_C));
a->Visit(MJ_NVP(electrical_theta));

0 comments on commit fbc19e1

Please sign in to comment.
You can’t perform that action at this time.