Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ahiuchingau committed Dec 11, 2023
1 parent 1b2a09c commit 80180c4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,10 @@ class BrushedMotorInterruptHandler {

auto has_active_move() -> bool { return _has_active_move.load(); }

[[nodiscard]] auto get_idle_holdoff_ticks() const -> uint32_t {
return error_conf.idle_holdoff_ticks;
}

std::atomic<bool> is_idle = true;
uint32_t tick = 0;
uint32_t timeout_ticks = 0;
Expand Down
31 changes: 21 additions & 10 deletions motor-control/tests/test_brushed_motor_interrupt_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ SCENARIO("Brushed motor interrupt handler handle move messages") {

WHEN("A brushed move message is received and loaded") {
// Burn through the startup ticks
for (uint32_t i = 0; i <= HOLDOFF_TICKS; i++) {
for (uint32_t i = 0;
i <= test_objs.handler.get_idle_holdoff_ticks(); i++) {
test_objs.handler.run_interrupt();
}

Expand All @@ -73,7 +74,8 @@ SCENARIO("Brushed motor interrupt handler handle move messages") {

AND_WHEN("The limit switch is hit") {
// Burn through the ticks since they reset with new move
for (uint32_t i = 0; i <= HOLDOFF_TICKS; i++) {
for (uint32_t i = 0;
i <= test_objs.handler.get_idle_holdoff_ticks(); i++) {
test_objs.handler.run_interrupt();
}

Expand Down Expand Up @@ -112,7 +114,8 @@ SCENARIO("Brushed motor interrupt handler handle move messages") {

WHEN("A brushed move message is received and loaded") {
// Burn through the startup ticks
for (uint32_t i = 0; i <= HOLDOFF_TICKS; i++) {
for (uint32_t i = 0;
i <= test_objs.handler.get_idle_holdoff_ticks(); i++) {
test_objs.handler.run_interrupt();
}

Expand All @@ -129,7 +132,9 @@ SCENARIO("Brushed motor interrupt handler handle move messages") {
THEN(
"Encoder speed tracker is holding off for a 1 ms (32 "
"ticks)") {
for (uint32_t i = 0; i < HOLDOFF_TICKS; i++) {
for (uint32_t i = 0;
i < test_objs.handler.get_idle_holdoff_ticks();
i++) {
REQUIRE(!test_objs.handler.is_sensing());
REQUIRE(test_objs.reporter.messages.size() == 0);
test_objs.handler.run_interrupt();
Expand Down Expand Up @@ -176,7 +181,8 @@ SCENARIO("Brushed motor interrupt handler handle move messages") {
test_objs.queue.try_write_isr(move_msg);
WHEN("A brushed move message is received and loaded") {
// Burn through the startup ticks
for (uint32_t i = 0; i <= HOLDOFF_TICKS; i++) {
for (uint32_t i = 0;
i <= test_objs.handler.get_idle_holdoff_ticks(); i++) {
test_objs.handler.run_interrupt();
}
THEN("The motor hardware proceeds to move") {
Expand Down Expand Up @@ -250,7 +256,8 @@ SCENARIO("estop pressed during Brushed motor interrupt handler") {
test_objs.queue.try_write_isr(grip_msg);
WHEN("Estop is pressed") {
// Burn through the startup ticks
for (uint32_t i = 0; i <= HOLDOFF_TICKS; i++) {
for (uint32_t i = 0;
i <= test_objs.handler.get_idle_holdoff_ticks(); i++) {
test_objs.handler.run_interrupt();
}
REQUIRE(!test_objs.handler.in_estop);
Expand Down Expand Up @@ -305,7 +312,8 @@ SCENARIO("labware dropped during grip move") {
test_objs.hw.set_encoder_value(40000);
test_objs.handler.set_enc_idle_state(false);
// Burn through the holdoff ticks
for (uint32_t i = 0; i <= HOLDOFF_TICKS; i++) {
for (uint32_t i = 0;
i <= test_objs.handler.get_idle_holdoff_ticks(); i++) {
test_objs.handler.run_interrupt();
}
// An error and increase error count is sent
Expand Down Expand Up @@ -355,7 +363,8 @@ SCENARIO("collision while homed") {
test_objs.hw.set_encoder_value(40000);
test_objs.handler.set_enc_idle_state(false);
// Burn through the holdoff ticks
for (uint32_t i = 0; i <= HOLDOFF_TICKS; i++) {
for (uint32_t i = 0;
i <= test_objs.handler.get_idle_holdoff_ticks(); i++) {
test_objs.handler.run_interrupt();
}
// An error and increase error count is sent
Expand Down Expand Up @@ -385,7 +394,8 @@ SCENARIO("A collision during position controlled move") {
test_objs.queue.try_write_isr(move_msg);
WHEN("A brushed move message is received and loaded") {
// Burn through the startup ticks
for (uint32_t i = 0; i <= HOLDOFF_TICKS; i++) {
for (uint32_t i = 0; i <= test_objs.handler.get_idle_holdoff_ticks();
i++) {
test_objs.handler.run_interrupt();
}
THEN("The motor hardware proceeds to move") {
Expand Down Expand Up @@ -439,7 +449,8 @@ SCENARIO("A collision during position controlled move") {
test_objs.hw.set_encoder_value(200000);
test_objs.handler.set_enc_idle_state(false);
// Burn through the 2 x holdoff ticks
for (uint32_t i = 0; i <= HOLDOFF_TICKS * 2; i++) {
for (uint32_t i = 0;
i <= test_objs.handler.get_idle_holdoff_ticks() * 2; i++) {
test_objs.handler.run_interrupt();
}
// An error and increase error count is sent
Expand Down

0 comments on commit 80180c4

Please sign in to comment.