Skip to content

Commit 9718788

Browse files
authored
use stay_engaged to determine whether or not to stay enabled (#711)
1 parent 0ce7658 commit 9718788

File tree

5 files changed

+27
-12
lines changed

5 files changed

+27
-12
lines changed

include/can/core/messages.hpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -1005,26 +1005,34 @@ struct GripperGripRequest : BaseMessage<MessageId::gripper_grip_request> {
10051005
uint8_t seq_id;
10061006
brushed_timer_ticks duration;
10071007
uint32_t duty_cycle;
1008+
int32_t encoder_position_um;
1009+
uint8_t stay_engaged;
10081010

10091011
template <bit_utils::ByteIterator Input, typename Limit>
10101012
static auto parse(Input body, Limit limit) -> GripperGripRequest {
10111013
uint8_t group_id = 0;
10121014
uint8_t seq_id = 0;
10131015
brushed_timer_ticks duration = 0;
10141016
uint32_t duty_cycle = 0;
1017+
int32_t encoder_position_um = 0;
1018+
uint8_t stay_engaged = 0;
10151019
uint32_t msg_ind = 0;
10161020

10171021
body = bit_utils::bytes_to_int(body, limit, msg_ind);
10181022
body = bit_utils::bytes_to_int(body, limit, group_id);
10191023
body = bit_utils::bytes_to_int(body, limit, seq_id);
10201024
body = bit_utils::bytes_to_int(body, limit, duration);
10211025
body = bit_utils::bytes_to_int(body, limit, duty_cycle);
1026+
body = bit_utils::bytes_to_int(body, limit, encoder_position_um);
1027+
body = bit_utils::bytes_to_int(body, limit, stay_engaged);
10221028

10231029
return GripperGripRequest{.message_index = msg_ind,
10241030
.group_id = group_id,
10251031
.seq_id = seq_id,
10261032
.duration = duration,
1027-
.duty_cycle = duty_cycle};
1033+
.duty_cycle = duty_cycle,
1034+
.encoder_position_um = encoder_position_um,
1035+
.stay_engaged = stay_engaged};
10281036
}
10291037

10301038
auto operator==(const GripperGripRequest& other) const -> bool = default;

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

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class MotionController {
4848
.duty_cycle = can_msg.duty_cycle,
4949
.group_id = can_msg.group_id,
5050
.seq_id = can_msg.seq_id,
51+
.stay_engaged = can_msg.stay_engaged,
5152
.stop_condition = MoveStopCondition::none,
5253
.usage_key = hardware.get_usage_eeprom_config().get_distance_key()};
5354
if (!enabled) {

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

+2-11
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,8 @@ class BrushedMotorInterruptHandler {
251251
.seconds = uint16_t(
252252
hardware.get_stopwatch_pulses(true) / 2600)});
253253
}
254+
hardware.set_stay_enabled(
255+
static_cast<bool>(buffered_move.stay_engaged));
254256
motor_state = ControlState::ACTIVE;
255257
buffered_move.start_encoder_position =
256258
hardware.get_encoder_pulses();
@@ -260,7 +262,6 @@ class BrushedMotorInterruptHandler {
260262
}
261263
// clear the old states
262264
hardware.reset_control();
263-
hardware.set_stay_enabled(false);
264265
timeout_ticks = 0;
265266
switch (buffered_move.stop_condition) {
266267
case MoveStopCondition::limit_switch:
@@ -323,16 +324,6 @@ class BrushedMotorInterruptHandler {
323324
message_index = buffered_move.message_index;
324325
}
325326

326-
// if we think we dropped a labware we don't want the controller
327-
// to stop the motor in case we only slipped or collided and still
328-
// have the labware in the jaws
329-
// likewise if the estop is hit and the motor is gripping something
330-
if (err_code == can::ids::ErrorCode::labware_dropped ||
331-
(motor_state == ControlState::FORCE_CONTROLLING &&
332-
err_code == can::ids::ErrorCode::estop_detected)) {
333-
hardware.set_stay_enabled(true);
334-
}
335-
336327
status_queue_client.send_brushed_move_status_reporter_queue(
337328
can::messages::ErrorMessage{.message_index = message_index,
338329
.severity = severity,

include/motor-control/core/motor_messages.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ struct BrushedMove { // NOLINT(cppcoreguidelines-pro-type-member-init)
107107
uint8_t group_id;
108108
uint8_t seq_id;
109109
int32_t encoder_position;
110+
uint8_t stay_engaged = 0;
110111
MoveStopCondition stop_condition = MoveStopCondition::none;
111112
int32_t start_encoder_position;
112113
uint16_t usage_key;

motor-control/tests/test_brushed_motor_interrupt_handler.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ SCENARIO("Brushed motor interrupt handler handle move messages") {
3737
.duty_cycle = 50,
3838
.group_id = 0,
3939
.seq_id = 0,
40+
.stay_engaged = 0,
4041
.stop_condition = MoveStopCondition::limit_switch};
4142
test_objs.queue.try_write_isr(msg);
4243

@@ -49,6 +50,7 @@ SCENARIO("Brushed motor interrupt handler handle move messages") {
4950
THEN("The motor hardware proceeds to home") {
5051
/* motor shouldn't be gripping */
5152
REQUIRE(!test_objs.hw.get_is_gripping());
53+
REQUIRE(!test_objs.hw.get_stay_enabled());
5254
test_objs.hw.set_encoder_value(1000);
5355
test_objs.hw.set_limit_switch(true);
5456

@@ -67,6 +69,7 @@ SCENARIO("Brushed motor interrupt handler handle move messages") {
6769
REQUIRE(read_ack.ack_id ==
6870
AckMessageId::stopped_by_condition);
6971
REQUIRE(test_objs.handler.is_idle);
72+
REQUIRE(!test_objs.hw.get_stay_enabled());
7073
}
7174
}
7275
}
@@ -79,6 +82,7 @@ SCENARIO("Brushed motor interrupt handler handle move messages") {
7982
REQUIRE(test_objs.reporter.messages.size() == 1);
8083
Ack read_ack = std::get<Ack>(test_objs.reporter.messages.back());
8184
REQUIRE(read_ack.ack_id == AckMessageId::timeout);
85+
REQUIRE(!test_objs.hw.get_stay_enabled());
8286
}
8387
}
8488

@@ -87,6 +91,7 @@ SCENARIO("Brushed motor interrupt handler handle move messages") {
8791
.duty_cycle = 50,
8892
.group_id = 0,
8993
.seq_id = 0,
94+
.stay_engaged = 1,
9095
.stop_condition = MoveStopCondition::none};
9196
test_objs.queue.try_write_isr(msg);
9297

@@ -99,6 +104,7 @@ SCENARIO("Brushed motor interrupt handler handle move messages") {
99104
THEN("The motor hardware proceeds to grip") {
100105
/* motor should be gripping */
101106
REQUIRE(test_objs.hw.get_is_gripping());
107+
REQUIRE(test_objs.hw.get_stay_enabled());
102108
test_objs.hw.set_encoder_value(30000);
103109

104110
AND_WHEN("The encoder speed timer overflows") {
@@ -125,6 +131,7 @@ SCENARIO("Brushed motor interrupt handler handle move messages") {
125131
REQUIRE(read_ack.encoder_position == 30000);
126132
REQUIRE(read_ack.ack_id ==
127133
AckMessageId::complete_without_condition);
134+
REQUIRE(test_objs.hw.get_stay_enabled());
128135
}
129136
}
130137
}
@@ -140,6 +147,7 @@ SCENARIO("Brushed motor interrupt handler handle move messages") {
140147
REQUIRE(test_objs.reporter.messages.size() == 1);
141148
Ack read_ack = std::get<Ack>(test_objs.reporter.messages.back());
142149
REQUIRE(read_ack.ack_id == AckMessageId::timeout);
150+
REQUIRE(test_objs.hw.get_stay_enabled());
143151
}
144152
}
145153
GIVEN("A message to move") {
@@ -226,13 +234,15 @@ SCENARIO("estop pressed during Brushed motor interrupt handler") {
226234
.duty_cycle = 50,
227235
.group_id = 0,
228236
.seq_id = 0,
237+
.stay_engaged = 1,
229238
.stop_condition = MoveStopCondition::limit_switch};
230239
test_objs.queue.try_write_isr(msg);
231240
WHEN("Estop is pressed") {
232241
// Burn through the startup ticks
233242
for (uint32_t i = 0; i <= HOLDOFF_TICKS; i++) {
234243
test_objs.handler.run_interrupt();
235244
}
245+
REQUIRE(test_objs.hw.get_stay_enabled());
236246
test_objs.hw.set_estop_in(true);
237247
test_objs.handler.run_interrupt();
238248
THEN("Errors are sent") {
@@ -242,6 +252,7 @@ SCENARIO("estop pressed during Brushed motor interrupt handler") {
242252
std::get<can::messages::ErrorMessage>(
243253
test_objs.reporter.messages.front());
244254
REQUIRE(err.error_code == can::ids::ErrorCode::estop_detected);
255+
REQUIRE(test_objs.hw.get_stay_enabled());
245256
}
246257
}
247258
}
@@ -255,6 +266,7 @@ SCENARIO("labware dropped during grip move") {
255266
.duty_cycle = 50,
256267
.group_id = 0,
257268
.seq_id = 0,
269+
.stay_engaged = 1,
258270
.stop_condition = MoveStopCondition::none};
259271
test_objs.queue.try_write_isr(msg);
260272
WHEN("grip is complete") {
@@ -263,6 +275,7 @@ SCENARIO("labware dropped during grip move") {
263275
for (uint32_t i = 0; i <= 100; i++) {
264276
test_objs.handler.run_interrupt();
265277
}
278+
REQUIRE(test_objs.hw.get_stay_enabled());
266279
test_objs.handler.set_enc_idle_state(true);
267280
test_objs.handler.run_interrupt();
268281
THEN("Move complete message is sent") {
@@ -303,6 +316,7 @@ SCENARIO("collision while homed") {
303316
.duty_cycle = 50,
304317
.group_id = 0,
305318
.seq_id = 0,
319+
.stay_engaged = 0,
306320
.stop_condition = MoveStopCondition::limit_switch};
307321
test_objs.queue.try_write_isr(msg);
308322
WHEN("home is complete") {

0 commit comments

Comments
 (0)