Skip to content

Commit 70e1579

Browse files
Merge pull request #189 from CWRUbotix/fix-manips
Stop spamming manip messages
2 parents 2765fde + 1f3fdf4 commit 70e1579

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

src/surface/flight_control/flight_control/mavlink_control_node.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -314,15 +314,21 @@ def manip_callback(self, joy_state: JoystickState) -> None:
314314
buttons = joy_state.buttons
315315
for button_id, manip_button in self.manip_buttons.items():
316316
just_pressed = buttons[button_id] == PRESSED
317-
318-
if MANIP_TOGGLE_MODE and manip_button.last_button_state is False and just_pressed:
319-
new_manip_state = not manip_button.is_active
320-
manip_button.is_active = new_manip_state
321-
elif not MANIP_TOGGLE_MODE and manip_button.last_button_state != just_pressed:
322-
manip_button.is_active = just_pressed
323-
324-
manip_msg = Manip(manip_id=manip_button.claw, activated=manip_button.is_active)
325-
self.manip_publisher.publish(manip_msg)
317+
was_active = manip_button.is_active
318+
319+
if MANIP_TOGGLE_MODE:
320+
if manip_button.last_button_state is False and just_pressed:
321+
new_manip_state = not manip_button.is_active
322+
manip_button.is_active = new_manip_state
323+
else:
324+
# For some reason you need to send activated: true to turn the relay board off and
325+
# activated: false to turn it on, but it's right before comp so instead of fixing
326+
# that I'm just inverting it here :)
327+
manip_button.is_active = not just_pressed
328+
329+
if was_active != manip_button.is_active:
330+
manip_msg = Manip(manip_id=manip_button.claw, activated=manip_button.is_active)
331+
self.manip_publisher.publish(manip_msg)
326332

327333
manip_button.last_button_state = just_pressed
328334

0 commit comments

Comments
 (0)