Skip to content

Commit

Permalink
fix(gripper): add stopped state (#816)
Browse files Browse the repository at this point in the history
* fix(motor-control): add a state to the motor control that maintains the difference between a never homed and a stopped gripper

* revert to the unhomed state during estop or collisions

* keep the older estop behavior
  • Loading branch information
ryanthecoder authored Nov 15, 2024
1 parent 9b4907f commit 7b650fc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ class BrushedMotorInterruptHandler {
can::ids::ErrorCode::collision_detected);
report_position(pulses);
error_handled = true;
hardware.set_motor_state(BrushedMotorState::UNHOMED);
}
} else if (motor_state != BrushedMotorState::UNHOMED) {
auto pulses = hardware.get_encoder_pulses();
Expand All @@ -166,6 +167,7 @@ class BrushedMotorInterruptHandler {
motor_state == BrushedMotorState::FORCE_CONTROLLING
? can::ids::ErrorCode::labware_dropped
: can::ids::ErrorCode::collision_detected;
hardware.set_motor_state(BrushedMotorState::UNHOMED);
cancel_and_clear_moves(err);
report_position(pulses);
error_handled = true;
Expand Down Expand Up @@ -198,8 +200,9 @@ class BrushedMotorInterruptHandler {
in_estop = true;
cancel_and_clear_moves(can::ids::ErrorCode::estop_detected);
} else if (hardware.has_cancel_request()) {
if (!hardware.get_stay_enabled()) {
hardware.set_motor_state(BrushedMotorState::UNHOMED);
if (!hardware.get_stay_enabled() &&
hardware.get_motor_state() != BrushedMotorState::UNHOMED) {
hardware.set_motor_state(BrushedMotorState::STOPPED);
}
cancel_and_clear_moves(can::ids::ErrorCode::stop_requested,
can::ids::ErrorSeverity::warning);
Expand Down
5 changes: 3 additions & 2 deletions include/motor-control/core/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,6 @@ enum class BrushedMotorState : uint8_t {
UNHOMED = 0x0,
FORCE_CONTROLLING_HOME = 0x1,
FORCE_CONTROLLING = 0x2,
POSITION_CONTROLLING = 0x3
};
POSITION_CONTROLLING = 0x3,
STOPPED = 0x4
};
8 changes: 4 additions & 4 deletions motor-control/tests/test_brushed_motor_interrupt_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,10 +526,10 @@ SCENARIO("handler recovers from error state") {
test_objs.hw.request_cancel();
test_objs.handler.run_interrupt();
THEN(
"motor state should become un-homed only if stay engaged is "
"falsy") {
"motor state should become stopped only if stay engaged is "
"false") {
REQUIRE(test_objs.hw.get_motor_state() ==
(!stay_engaged ? BrushedMotorState::UNHOMED
(!stay_engaged ? BrushedMotorState::STOPPED
: og_motor_state));
}
THEN("a stop requested warning is issued") {
Expand Down Expand Up @@ -560,4 +560,4 @@ SCENARIO("handler recovers from error state") {
}
}
}
}
}

0 comments on commit 7b650fc

Please sign in to comment.