Skip to content

Commit f1f2d18

Browse files
authored
Merge pull request #190 from CWRUbotix/servo-positions
Add 3 servo positions
2 parents 70e1579 + 01a7134 commit f1f2d18

File tree

1 file changed

+26
-13
lines changed

1 file changed

+26
-13
lines changed

src/surface/flight_control/flight_control/mavlink_control_node.py

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@
5050
SERVO_MIN = 500
5151
SERVO_MAX = 2500
5252
SERVO_TURN_RATE = 500
53-
SERVO_PRESET_UP = 970
54-
SERVO_PRESET_DOWN = 1550
53+
SERVO_PRESET_UP = 770
54+
SERVO_PRESET_MIDDLE = 1200
55+
SERVO_PRESET_DOWN = 1650
5556
# If True each button corresponds to a preset
5657
# If false one button moves gradually up and one moves gradually down
5758
SERVO_USE_PRESETS = True
@@ -104,13 +105,13 @@ class ManipButton:
104105
class ControllerProfile:
105106
manip_left: int = L1
106107
manip_right: int = R1
107-
servo_up: int = TRI_BUTTON
108-
servo_down: int = SQUARE_BUTTON
108+
servo_up: int = DPAD_RIGHT
109+
servo_middle: int = DPAD_UP
110+
servo_down: int = DPAD_LEFT
109111
roll_left: int = X_BUTTON # positive roll
110112
roll_right: int = O_BUTTON # negative roll
111113
arm_button: int = MENU
112114
disarm_button: int = PAIRING_BUTTON
113-
cam_front_button: int = DPAD_UP
114115
cam_back_button: int = DPAD_DOWN
115116
lateral: int = LJOYX
116117
forward: int = LJOYY
@@ -181,6 +182,7 @@ def __init__(self) -> None:
181182
)
182183

183184
self.back_cam_mode = False
185+
self.switch_cam_button_was_pressed = False
184186

185187
self.servo_pwm = SERVO_PRESET_DOWN if SERVO_USE_PRESETS else SERVO_CENTER
186188

@@ -276,6 +278,8 @@ def send_mavlink_control(self, joy_state: JoystickState) -> None:
276278
if SERVO_USE_PRESETS:
277279
if buttons[self.profile.servo_up]:
278280
self.servo_pwm = SERVO_PRESET_UP
281+
elif buttons[self.profile.servo_middle]:
282+
self.servo_pwm = SERVO_PRESET_MIDDLE
279283
elif buttons[self.profile.servo_down]:
280284
self.servo_pwm = SERVO_PRESET_DOWN
281285
else:
@@ -405,14 +409,23 @@ def process_camera_buttons(self, joy_state: JoystickState) -> None:
405409
The state of the joystick buttons and axess
406410
"""
407411
# MARK: PROC CAM BUTTONS
408-
# Camera switching uses the DPAD, currently not remapable with the controller profile system
409-
# because DPADs are presented as axes not buttons and using any other axis is non-sensible
410-
if joy_state.buttons[self.profile.cam_front_button]:
411-
self.right_stream_switch_publisher.publish(VideoWidgetSwitch(relative=False, index=0))
412-
self.back_cam_mode = False
413-
elif joy_state.buttons[self.profile.cam_back_button]:
414-
self.right_stream_switch_publisher.publish(VideoWidgetSwitch(relative=False, index=1))
415-
self.back_cam_mode = True
412+
if (
413+
joy_state.buttons[self.profile.cam_back_button]
414+
and not self.switch_cam_button_was_pressed
415+
):
416+
# Toggle back cam
417+
self.back_cam_mode = not self.back_cam_mode
418+
self.get_logger().info(f'Back Cam Mode {self.back_cam_mode}')
419+
if self.back_cam_mode:
420+
self.right_stream_switch_publisher.publish(
421+
VideoWidgetSwitch(relative=False, index=1)
422+
)
423+
else:
424+
self.right_stream_switch_publisher.publish(
425+
VideoWidgetSwitch(relative=False, index=0)
426+
)
427+
428+
self.switch_cam_button_was_pressed = joy_state.buttons[self.profile.cam_back_button]
416429

417430
def poll_mavlink(self) -> None:
418431
"""Check for incoming mavlink messages from the vehicle and send state updates if

0 commit comments

Comments
 (0)