1515 */
1616#pragma once
1717
18+ // ============ Controller Selection ============
19+ // Set ONE of these as the active controller:
20+ #define CONTROLLER_PRO_CONTROLLER 1
21+ #define CONTROLLER_CYBORG_STICK 2
22+
23+ #define ACTIVE_CONTROLLER CONTROLLER_PRO_CONTROLLER
24+
1825#include < sensor_msgs/msg/joy.hpp>
1926#include < arm_hardware_interface/ArmSerialProtocol.h>
2027inline static constexpr int MAX_BUTTONS = 20 ; // can be decreased
@@ -216,9 +223,21 @@ namespace ArmControllerConfig { // Can make into a class later?
216223 case GameController::SWITCH_PRO_CONTROLLER:
217224 {
218225 using namespace switch_index ;
219- // TODO
226+ arm_control_msg.fk_axes [AXIS_2_INDEX] = joy_msg->axes [axes::LEFT_JOYSTICK_Y];
227+ arm_control_msg.fk_axes [AXIS_3_INDEX] = joy_msg->axes [axes::RIGHT_JOYSTICK_Y];
228+ arm_control_msg.fk_axes [AXIS_4_INDEX] = joy_msg->axes [axes::RIGHT_JOYSTICK_X];
229+ // dpad is buttons on Switch Pro and controls z axis
230+ arm_control_msg.fk_axes [AXIS_5_INDEX] = static_cast <float >(joy_msg->buttons [buttons::DPAD_UP] - joy_msg->buttons [buttons::DPAD_DOWN]);
231+ arm_control_msg.fk_axes [AXIS_6_INDEX] = static_cast <float >(joy_msg->buttons [buttons::DPAD_RIGHT] - joy_msg->buttons [buttons::DPAD_LEFT]);
220232
233+ arm_control_msg.ik_axes [IK_LIN_X_INDEX] = joy_msg->axes [axes::LEFT_JOYSTICK_Y];
234+ arm_control_msg.ik_axes [IK_LIN_Z_INDEX] = joy_msg->axes [axes::RIGHT_JOYSTICK_Y];
235+ arm_control_msg.ik_axes [IK_LIN_Y_INDEX] = joy_msg->axes [axes::LEFT_JOYSTICK_X];
236+ arm_control_msg.ik_axes [IK_ANG_X_INDEX] = static_cast <float >(joy_msg->buttons [buttons::DPAD_RIGHT] - joy_msg->buttons [buttons::DPAD_LEFT]);
237+ arm_control_msg.ik_axes [IK_ANG_Y_INDEX] = static_cast <float >(joy_msg->buttons [buttons::DPAD_UP] - joy_msg->buttons [buttons::DPAD_DOWN]);
221238
239+ arm_control_msg.end_effector = joy_msg->buttons [buttons::L1] - joy_msg->buttons [buttons::R1];
240+ arm_control_msg.kinematics_mode_switch = joy_msg->buttons [buttons::B];
222241 }
223242 break ;
224243 case GameController::CYBORG_JOYSTICK:
@@ -284,10 +303,12 @@ namespace ArmControllerConfig { // Can make into a class later?
284303namespace ControllerConfig {
285304
286305 // --- Face Buttons ---
287- constexpr int BTN_B = 0 ; // East
288- constexpr int BTN_A = 1 ; // South
289- constexpr int BTN_Y = 2 ; // North
290- constexpr int BTN_X = 3 ; // West
306+ constexpr int BTN_B = 0 ; // East (A)
307+ constexpr int BTN_A = 1 ; // South (B)
308+ constexpr int BTN_Y = 2 ; // North (X)
309+ constexpr int BTN_X = 3 ; // West (Y)
310+
311+ constexpr int BTN_HOME = 5 ; // Home
291312
292313 constexpr int BTN_UP = 12 ; // Left shoulder
293314 constexpr int BTN_DOWN = 13 ; // Right shoulder
@@ -321,9 +342,6 @@ namespace ControllerConfig {
321342 constexpr double CART_BUTTON_SPEED = 0.5 ; // unitless, range [0.0, 1.0]
322343 constexpr double ROT_STICK_SPEED = 0.6 ; // unitless, range [0.0, 1.0] for angular
323344
324- // --- Deadzone for analog axes (used later for joystick support) ---
325- constexpr double AXIS_DEADZONE = 0.15 ;
326-
327345 // --- Frame for Cartesian twist commands ---
328346 // "base_link" = world-fixed directions (forward is always forward)
329347 // "ee_base_link" = relative to end-effector orientation
@@ -343,8 +361,16 @@ namespace ControllerConfig {
343361
344362 // --- Gripper ---
345363 constexpr int BTN_GRIPPER_TOGGLE = 7 ; // ZR button — edge-triggered toggle
364+ constexpr int AXIS_GRIPPER_TOGGLE = 5 ; // ZR analog axis (rests at 1.0, pressed = -1.0)
365+ constexpr double AXIS_GRIPPER_PRESSED_THRESHOLD = 0.0 ; // trigger considered pressed below this
346366 constexpr double GRIPPER_OPEN_VALUE = 1.0 ;
347367 constexpr double GRIPPER_CLOSE_VALUE = 0.0 ;
368+
369+ // --- Gripper Sim Positions ---
370+ constexpr double GRIPPER_SIM_LEFT_OPEN_POS = 0.04 ;
371+ constexpr double GRIPPER_SIM_RIGHT_OPEN_POS = -0.04 ;
372+ constexpr double GRIPPER_SIM_LEFT_CLOSE_POS = 0.0 ;
373+ constexpr double GRIPPER_SIM_RIGHT_CLOSE_POS = 0.0 ;
348374}
349375
350376#elif ACTIVE_CONTROLLER == CONTROLLER_CYBORG_STICK
@@ -392,8 +418,28 @@ namespace ControllerConfig {
392418
393419 // --- Gripper ---
394420 constexpr int BTN_GRIPPER_TOGGLE = BTN_TRIGGER; // trigger = gripper toggle
421+ constexpr int AXIS_GRIPPER_TOGGLE = -1 ; // no analog trigger axis
422+ constexpr double AXIS_GRIPPER_PRESSED_THRESHOLD = 0.0 ;
395423 constexpr double GRIPPER_OPEN_VALUE = 1.0 ;
396424 constexpr double GRIPPER_CLOSE_VALUE = 0.0 ;
425+
426+ // --- Gripper Sim Positions ---
427+ constexpr double GRIPPER_SIM_LEFT_OPEN_POS = 0.04 ;
428+ constexpr double GRIPPER_SIM_RIGHT_OPEN_POS = -0.04 ;
429+ constexpr double GRIPPER_SIM_LEFT_CLOSE_POS = 0.0 ;
430+ constexpr double GRIPPER_SIM_RIGHT_CLOSE_POS = 0.0 ;
431+
432+ // --- Orientation ---
433+ constexpr double ROT_STICK_SPEED = 0.4 ;
434+ constexpr int AXIS_ROLL = AXIS_STICK_X; // stick X → roll
435+ constexpr int AXIS_PITCH = AXIS_STICK_Y; // stick Y → pitch
436+ constexpr int AXIS_YAW = AXIS_TWIST; // twist → yaw
437+ constexpr bool INVERT_ROLL = false ;
438+ constexpr bool INVERT_PITCH = false ;
439+ constexpr bool INVERT_YAW = false ;
440+
441+ // --- Misc ---
442+ constexpr int BTN_HOME = -1 ; // no home button on Cyborg stick
397443}
398444
399445#else
0 commit comments