Skip to content

Commit

Permalink
Revert "Remove PWM compensation when using current mode control"
Browse files Browse the repository at this point in the history
This reverts commit 02d549e.

r4.8 boards (which have more exaggerated PWM compensation constants),
still benefit from this a lot.

Tweak the dyno cycle limit to pass.
  • Loading branch information
jpieper committed May 9, 2022
1 parent 0e41c5b commit 47756c5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 26 deletions.
25 changes: 4 additions & 21 deletions fw/bldc_servo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1708,12 +1708,11 @@ class BldcServo::Impl {
status_.pid_q.integral,
-max_current_integral, max_current_integral);

ISR_DoVoltageDQUncompensated(sin_cos, d_V, q_V);
ISR_DoVoltageDQ(sin_cos, d_V, q_V);
} else {
ISR_DoVoltageDQ(
sin_cos,
i_d_A * motor_.resistance_ohm,
i_q_A * motor_.resistance_ohm);
ISR_DoVoltageDQ(sin_cos,
i_d_A * motor_.resistance_ohm,
i_q_A * motor_.resistance_ohm);
}
}

Expand Down Expand Up @@ -1748,22 +1747,6 @@ class BldcServo::Impl {
return Vec3{idt.a, idt.b, idt.c};
}

void ISR_DoVoltageDQUncompensated(const SinCos& sin_cos, float d_V, float q_V) MOTEUS_CCM_ATTRIBUTE {
ISR_DoVoltageUncompensated(ISR_CalculatePhaseVoltage(sin_cos, d_V, q_V));
}

void ISR_DoVoltageUncompensated(const Vec3& voltage) MOTEUS_CCM_ATTRIBUTE {
const auto scale =
[&](float phase_voltage) {
return 0.5f + phase_voltage / status_.filt_bus_V;
};

ISR_DoPwmControl(Vec3{
scale(voltage.a),
scale(voltage.b),
scale(voltage.c)});
}

void ISR_DoVoltageDQ(const SinCos& sin_cos, float d_V, float q_V) MOTEUS_CCM_ATTRIBUTE {
ISR_DoBalancedVoltageControl(ISR_CalculatePhaseVoltage(sin_cos, d_V, q_V));
}
Expand Down
10 changes: 5 additions & 5 deletions utils/dynamometer_drive.cc
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ class ServoStatsReader {
// Here we verify that the final and total timer are always valid.
if (result.final_timer == 0 ||
result.total_timer == 0 ||
result.final_timer > 3100 ||
result.final_timer > 3220 ||
result.total_timer < 4250) {
throw mjlib::base::system_error::einval(
fmt::format("Invalid timer final={} total={}",
Expand Down Expand Up @@ -1341,16 +1341,16 @@ class Application {
co_await dut_->Command(
fmt::format("d pos {} 0 {}", position, options_.max_torque_Nm));

const double kDelayS = 2.0;
const double kDelayS = 1.0;
co_await Sleep(kDelayS);

const double expected_torque = kDelayS * pid.ki * position;

verify_position_mode();
if (std::abs(current_torque_Nm_ - expected_torque) > 0.24) {
if (std::abs(current_torque_Nm_ - expected_torque) > 0.16) {
throw mjlib::base::system_error::einval(
fmt::format("ki torque not as expected {} != {} (within {})",
current_torque_Nm_, expected_torque, 0.24));
current_torque_Nm_, expected_torque, 0.16));
}

// Stop the DUT to clear out the I term.
Expand Down Expand Up @@ -1903,7 +1903,7 @@ class Application {
{ 100.0, 4.04 },
{ 20.0, 3.0 },
{ 10.0, 2.09 },
{ 5.0, 1.3 },
{ 5.0, 1.55 },
};

for (const auto test : tests) {
Expand Down

0 comments on commit 47756c5

Please sign in to comment.