Skip to content

Commit 7b650fc

Browse files
authored
fix(gripper): add stopped state (#816)
* 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
1 parent 9b4907f commit 7b650fc

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

include/motor-control/core/brushed_motor/brushed_motor_interrupt_handler.hpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ class BrushedMotorInterruptHandler {
151151
can::ids::ErrorCode::collision_detected);
152152
report_position(pulses);
153153
error_handled = true;
154+
hardware.set_motor_state(BrushedMotorState::UNHOMED);
154155
}
155156
} else if (motor_state != BrushedMotorState::UNHOMED) {
156157
auto pulses = hardware.get_encoder_pulses();
@@ -166,6 +167,7 @@ class BrushedMotorInterruptHandler {
166167
motor_state == BrushedMotorState::FORCE_CONTROLLING
167168
? can::ids::ErrorCode::labware_dropped
168169
: can::ids::ErrorCode::collision_detected;
170+
hardware.set_motor_state(BrushedMotorState::UNHOMED);
169171
cancel_and_clear_moves(err);
170172
report_position(pulses);
171173
error_handled = true;
@@ -198,8 +200,9 @@ class BrushedMotorInterruptHandler {
198200
in_estop = true;
199201
cancel_and_clear_moves(can::ids::ErrorCode::estop_detected);
200202
} else if (hardware.has_cancel_request()) {
201-
if (!hardware.get_stay_enabled()) {
202-
hardware.set_motor_state(BrushedMotorState::UNHOMED);
203+
if (!hardware.get_stay_enabled() &&
204+
hardware.get_motor_state() != BrushedMotorState::UNHOMED) {
205+
hardware.set_motor_state(BrushedMotorState::STOPPED);
203206
}
204207
cancel_and_clear_moves(can::ids::ErrorCode::stop_requested,
205208
can::ids::ErrorSeverity::warning);

include/motor-control/core/types.hpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,6 @@ enum class BrushedMotorState : uint8_t {
4444
UNHOMED = 0x0,
4545
FORCE_CONTROLLING_HOME = 0x1,
4646
FORCE_CONTROLLING = 0x2,
47-
POSITION_CONTROLLING = 0x3
48-
};
47+
POSITION_CONTROLLING = 0x3,
48+
STOPPED = 0x4
49+
};

motor-control/tests/test_brushed_motor_interrupt_handler.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -526,10 +526,10 @@ SCENARIO("handler recovers from error state") {
526526
test_objs.hw.request_cancel();
527527
test_objs.handler.run_interrupt();
528528
THEN(
529-
"motor state should become un-homed only if stay engaged is "
530-
"falsy") {
529+
"motor state should become stopped only if stay engaged is "
530+
"false") {
531531
REQUIRE(test_objs.hw.get_motor_state() ==
532-
(!stay_engaged ? BrushedMotorState::UNHOMED
532+
(!stay_engaged ? BrushedMotorState::STOPPED
533533
: og_motor_state));
534534
}
535535
THEN("a stop requested warning is issued") {
@@ -560,4 +560,4 @@ SCENARIO("handler recovers from error state") {
560560
}
561561
}
562562
}
563-
}
563+
}

0 commit comments

Comments
 (0)