Skip to content

Commit

Permalink
Add dyno test for servo.voltage_mode_control
Browse files Browse the repository at this point in the history
  • Loading branch information
jpieper committed Dec 3, 2021
1 parent 00d474b commit 501b886
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 13 deletions.
61 changes: 48 additions & 13 deletions utils/dynamometer_drive.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ struct Options {
bool validate_power_limit = false;
bool validate_max_velocity = false;
bool validate_rezero = false;
bool validate_voltage_mode_control = false;

template <typename Archive>
void Serialize(Archive* a) {
Expand Down Expand Up @@ -123,6 +124,7 @@ struct Options {
a->Visit(MJ_NVP(validate_power_limit));
a->Visit(MJ_NVP(validate_max_velocity));
a->Visit(MJ_NVP(validate_rezero));
a->Visit(MJ_NVP(validate_voltage_mode_control));
}
};

Expand Down Expand Up @@ -345,6 +347,8 @@ class Controller {
double max_position_slip = std::numeric_limits<double>::quiet_NaN();
double max_power_W = 450.0;
double max_velocity = 500.0;

bool voltage_mode_control = false;
};

boost::asio::awaitable<void> ConfigurePid(const PidConstants& pid) {
Expand Down Expand Up @@ -373,6 +377,9 @@ class Controller {
co_await Command(
fmt::format("conf set servo.max_velocity {}", pid.max_velocity));

co_await Command(
fmt::format("conf set servo.voltage_mode_control {}", pid.voltage_mode_control ? 1 : 0));

co_return;
}

Expand Down Expand Up @@ -613,6 +620,8 @@ class Application {
co_await ValidateMaxVelocity();
} else if (options_.validate_rezero) {
co_await ValidateRezero();
} else if (options_.validate_voltage_mode_control) {
co_await ValidateVoltageModeControl();
} else {
fmt::print("No cycle selected\n");
}
Expand Down Expand Up @@ -998,19 +1007,7 @@ class Application {
co_return;
}

boost::asio::awaitable<void> ValidatePositionBasic() {
co_await dut_->Command("d stop");
co_await fixture_->Command("d stop");
co_await fixture_->Command("d index 0");
co_await dut_->Command("d index 0");

// Set some constants that should work for basic position control.
Controller::PidConstants pid;
pid.kp = 1.0;
pid.ki = 0.0;
pid.kd = 0.05;
co_await dut_->ConfigurePid(pid);

boost::asio::awaitable<void> RunBasicPositionTest(Controller::PidConstants pid) {
// Move to a few different positions.
for (const double position : {0.0, -0.2, 0.3}) {
fmt::print("Moving to position {}\n", position);
Expand Down Expand Up @@ -1123,6 +1120,22 @@ class Application {

// Get back to our default config.
co_await dut_->ConfigurePid(pid);
}

boost::asio::awaitable<void> ValidatePositionBasic() {
co_await dut_->Command("d stop");
co_await fixture_->Command("d stop");
co_await fixture_->Command("d index 0");
co_await dut_->Command("d index 0");

// Set some constants that should work for basic position control.
Controller::PidConstants pid;
pid.kp = 1.0;
pid.ki = 0.0;
pid.kd = 0.05;
co_await dut_->ConfigurePid(pid);

co_await RunBasicPositionTest(pid);

// Now we'll do the basic tests with the fixture locked rigidly in
// place.
Expand Down Expand Up @@ -1959,6 +1972,7 @@ class Application {
}
}
}

boost::asio::awaitable<void> ValidateRezero() {
co_await fixture_->Command("d stop");
co_await dut_->Command("d stop");
Expand All @@ -1974,6 +1988,27 @@ class Application {
co_return;
}

boost::asio::awaitable<void> ValidateVoltageModeControl() {
co_await dut_->Command("d stop");
co_await fixture_->Command("d stop");
co_await fixture_->Command("d index 0");
co_await dut_->Command("d index 0");

Controller::PidConstants pid;
pid.voltage_mode_control = true;
pid.kp = 1.0;
pid.ki = 0.0;
pid.kd = 0.01;

co_await dut_->ConfigurePid(pid);

// With voltage mode control turned on, basic operation should
// work as before modulo different position PID values.
co_await RunBasicPositionTest(pid);

co_return;
}

boost::asio::awaitable<void> Sleep(double seconds) {
boost::asio::deadline_timer timer(executor_);
timer.expires_from_now(mjlib::base::ConvertSecondsToDuration(seconds));
Expand Down
3 changes: 3 additions & 0 deletions utils/firmware_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ def test_validate_max_velocity(self):
def test_rezero(self):
dyno('--validate_rezero', '1')

def test_voltage_mode_control(self):
dyno('--validate_voltage_mode_control', '1')


class TestDynoSlow(unittest.TestCase):
def test_torque_ripple(self):
Expand Down

0 comments on commit 501b886

Please sign in to comment.