|
50 | 50 | SERVO_MIN = 500 |
51 | 51 | SERVO_MAX = 2500 |
52 | 52 | 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 |
55 | 56 | # If True each button corresponds to a preset |
56 | 57 | # If false one button moves gradually up and one moves gradually down |
57 | 58 | SERVO_USE_PRESETS = True |
@@ -104,13 +105,13 @@ class ManipButton: |
104 | 105 | class ControllerProfile: |
105 | 106 | manip_left: int = L1 |
106 | 107 | 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 |
109 | 111 | roll_left: int = X_BUTTON # positive roll |
110 | 112 | roll_right: int = O_BUTTON # negative roll |
111 | 113 | arm_button: int = MENU |
112 | 114 | disarm_button: int = PAIRING_BUTTON |
113 | | - cam_front_button: int = DPAD_UP |
114 | 115 | cam_back_button: int = DPAD_DOWN |
115 | 116 | lateral: int = LJOYX |
116 | 117 | forward: int = LJOYY |
@@ -181,6 +182,7 @@ def __init__(self) -> None: |
181 | 182 | ) |
182 | 183 |
|
183 | 184 | self.back_cam_mode = False |
| 185 | + self.switch_cam_button_was_pressed = False |
184 | 186 |
|
185 | 187 | self.servo_pwm = SERVO_PRESET_DOWN if SERVO_USE_PRESETS else SERVO_CENTER |
186 | 188 |
|
@@ -276,6 +278,8 @@ def send_mavlink_control(self, joy_state: JoystickState) -> None: |
276 | 278 | if SERVO_USE_PRESETS: |
277 | 279 | if buttons[self.profile.servo_up]: |
278 | 280 | self.servo_pwm = SERVO_PRESET_UP |
| 281 | + elif buttons[self.profile.servo_middle]: |
| 282 | + self.servo_pwm = SERVO_PRESET_MIDDLE |
279 | 283 | elif buttons[self.profile.servo_down]: |
280 | 284 | self.servo_pwm = SERVO_PRESET_DOWN |
281 | 285 | else: |
@@ -405,14 +409,23 @@ def process_camera_buttons(self, joy_state: JoystickState) -> None: |
405 | 409 | The state of the joystick buttons and axess |
406 | 410 | """ |
407 | 411 | # 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] |
416 | 429 |
|
417 | 430 | def poll_mavlink(self) -> None: |
418 | 431 | """Check for incoming mavlink messages from the vehicle and send state updates if |
|
0 commit comments