From dcb900c92ffd5d5c8f54053d5a21fe11c4c6f4f3 Mon Sep 17 00:00:00 2001 From: Josh Pieper Date: Thu, 28 Jul 2022 14:11:24 -0400 Subject: [PATCH] Revert a60aab46018a456df7f3ab6c5661711e0e00878c I'm not sure what I was testing with, but all 5 motors I have tested with today limit to half of the power specified with this change. --- fw/bldc_servo.cc | 2 +- utils/dynamometer_drive.cc | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/fw/bldc_servo.cc b/fw/bldc_servo.cc index 2cca47b4..d4fcc458 100644 --- a/fw/bldc_servo.cc +++ b/fw/bldc_servo.cc @@ -1684,7 +1684,7 @@ class BldcServo::Impl { // This is conservative... we could use std::hypot(d, q), however // that would take more CPU cycles, and most of the time we'll // only be seeing q != 0. - const float max_V = 0.5f * adjusted_max_power_W_ / + const float max_V = adjusted_max_power_W_ / (std::abs(status_.d_A) + std::abs(status_.q_A)); if (!config_.voltage_mode_control) { diff --git a/utils/dynamometer_drive.cc b/utils/dynamometer_drive.cc index ecbd83a3..a522b75f 100644 --- a/utils/dynamometer_drive.cc +++ b/utils/dynamometer_drive.cc @@ -1898,11 +1898,13 @@ class Application { double expected_speed_Hz; } tests[] = { { 100.0, 4.04 }, - { 20.0, 2.20 }, - { 10.0, 1.35 }, - { 5.0, 1.00 }, + { 20.0, 3.12 }, + { 10.0, 2.14 }, + { 5.0, 1.43 }, }; + std::string errors; + for (const auto test : tests) { dut_pid.max_power_W = test.power_W; co_await dut_->ConfigurePid(dut_pid); @@ -1920,10 +1922,11 @@ class Application { fmt::print("Power {} / Speed {}\n", test.power_W, average_speed); if (RelativeError(average_speed, test.expected_speed_Hz) > 0.15) { - throw mjlib::base::system_error::einval( + if (!errors.empty()) { errors += "\n"; } + errors += fmt::format( "Speed {} != {} (within {}%)", - average_speed, test.expected_speed_Hz, 0.15 * 100)); + average_speed, test.expected_speed_Hz, 0.15 * 100); } co_await dut_->Command("d stop"); @@ -1934,6 +1937,10 @@ class Application { co_await dut_->Command("d stop"); co_await fixture_->Command("d stop"); + if (!errors.empty()) { + throw mjlib::base::system_error::einval(errors); + } + co_return; }