Skip to content

Commit 32caf9c

Browse files
committed
cleaned up controller config
1 parent 5b3d781 commit 32caf9c

File tree

2 files changed

+1
-176
lines changed

2 files changed

+1
-176
lines changed

src/arm_control/include/controller_config.h

Lines changed: 0 additions & 173 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,6 @@
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-
2518
#include <sensor_msgs/msg/joy.hpp>
2619
#include <arm_hardware_interface/ArmSerialProtocol.h>
2720
inline static constexpr int MAX_BUTTONS = 20; // can be decreased
@@ -277,172 +270,6 @@ namespace ArmControllerConfig { // Can make into a class later?
277270
// }
278271
}
279272

280-
281-
282-
283-
// Button names (used):
284-
// 0 = BTN_EAST 1 = BTN_SOUTH
285-
// 2 = BTN_NORTH 3 = BTN_WEST
286-
// 12 = up
287-
// 13 = down
288-
// 14 = left
289-
// 15 = right
290-
//
291-
// Axes:
292-
// 0 = Left stick X 1 = Left stick Y
293-
// 2 = Right stick X 3 = Right stick Y
294-
// 4 = ZL analog (rests at 1.0)
295-
// 5 = ZR analog (rests at 1.0)
296-
//
297-
// NOTE: If your button indices differ, adjust the values below
298-
// and rebuild. Verify with: ros2 topic echo /joy
299-
// ============================================================
300-
301-
#if ACTIVE_CONTROLLER == CONTROLLER_PRO_CONTROLLER
302-
303-
namespace ControllerConfig {
304-
305-
// --- Face Buttons ---
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
312-
313-
constexpr int BTN_UP = 12; // Left shoulder
314-
constexpr int BTN_DOWN = 13; // Right shoulder
315-
316-
// --- Axes ---
317-
constexpr int AXIS_LEFT_X = 0;
318-
constexpr int AXIS_LEFT_Y = 1;
319-
constexpr int AXIS_RIGHT_X = 2;
320-
constexpr int AXIS_RIGHT_Y = 3;
321-
// axes[4], axes[5] = ZL/ZR triggers (rest at 1.0, pressed = -1.0) — avoid for motion
322-
323-
// --- Cartesian Button Mapping (6 buttons → 6 translation directions) ---
324-
// Face buttons control X/Y plane, shoulders control Z
325-
//
326-
// Y (+X forward)
327-
// X (+Y) B (-Y)
328-
// A (-X backward)
329-
//
330-
// R shoulder → +Z (up)
331-
// L shoulder → -Z (down)
332-
constexpr int BTN_CART_POS_X = BTN_Y; // North face → +X (forward)
333-
constexpr int BTN_CART_NEG_X = BTN_A; // South face → -X (backward)
334-
constexpr int BTN_CART_POS_Y = BTN_X; // West face → +Y (left)
335-
constexpr int BTN_CART_NEG_Y = BTN_B; // East face → -Y (right)
336-
constexpr int BTN_CART_POS_Z = BTN_UP; // R shoulder → +Z (up)
337-
constexpr int BTN_CART_NEG_Z = BTN_DOWN; // L shoulder → -Z (down)
338-
339-
// --- Twist Speed ---
340-
// command_in_type is "unitless" (-1 to 1), scaled by servo's linear/rotational params
341-
// 1.0 → full speed (0.5 m/s per servo config)
342-
constexpr double CART_BUTTON_SPEED = 0.5; // unitless, range [0.0, 1.0]
343-
constexpr double ROT_STICK_SPEED = 0.6; // unitless, range [0.0, 1.0] for angular
344-
constexpr double AXIS_DEADZONE = 0.15;
345-
346-
// --- Frame for Cartesian twist commands ---
347-
// "base_link" = world-fixed directions (forward is always forward)
348-
// "ee_base_link" = relative to end-effector orientation
349-
constexpr const char* CART_FRAME_ID = "base_link";
350-
351-
// --- EE Orientation Stick Mapping ---
352-
// Left stick → pitch (tilt forward/back) and yaw (rotate left/right)
353-
// Right stick → roll (tilt sideways)
354-
//
355-
// Servo angular.x = roll, angular.y = pitch, angular.z = yaw
356-
constexpr int AXIS_ROLL = AXIS_RIGHT_X; // right stick X → roll
357-
constexpr int AXIS_PITCH = AXIS_LEFT_Y; // left stick Y → pitch
358-
constexpr int AXIS_YAW = AXIS_LEFT_X; // left stick X → yaw
359-
constexpr bool INVERT_ROLL = false;
360-
constexpr bool INVERT_PITCH = false;
361-
constexpr bool INVERT_YAW = true; // typical: push left = positive yaw
362-
363-
// --- Gripper ---
364-
constexpr int BTN_GRIPPER_TOGGLE = 7; // ZR button — edge-triggered toggle
365-
constexpr int AXIS_GRIPPER_TOGGLE = 5; // ZR analog axis (rests at 1.0, pressed = -1.0)
366-
constexpr double AXIS_GRIPPER_PRESSED_THRESHOLD = 0.0; // trigger considered pressed below this
367-
constexpr double GRIPPER_OPEN_VALUE = 1.0;
368-
constexpr double GRIPPER_CLOSE_VALUE = 0.0;
369-
370-
// --- Gripper Sim Positions ---
371-
constexpr double GRIPPER_SIM_LEFT_OPEN_POS = 0.04;
372-
constexpr double GRIPPER_SIM_RIGHT_OPEN_POS = -0.04;
373-
constexpr double GRIPPER_SIM_LEFT_CLOSE_POS = 0.0;
374-
constexpr double GRIPPER_SIM_RIGHT_CLOSE_POS = 0.0;
375-
}
376-
377-
#elif ACTIVE_CONTROLLER == CONTROLLER_CYBORG_STICK
378-
379-
// ============================================================
380-
// Saitek Cyborg USB Stick
381-
// ============================================================
382-
// Axes:
383-
// 0 = Stick X (left/right)
384-
// 1 = Stick Y (forward/back)
385-
// 2 = Throttle slider (rests non-zero — DO NOT USE for motion)
386-
// 3 = Stick twist/rudder (rotation)
387-
// 4 = Hat X
388-
// 5 = Hat Y
389-
//
390-
// Buttons:
391-
// 0 = Trigger
392-
// ============================================================
393-
394-
namespace ControllerConfig {
395-
396-
// --- Axes ---
397-
constexpr int AXIS_STICK_X = 0;
398-
constexpr int AXIS_STICK_Y = 1;
399-
constexpr int AXIS_THROTTLE = 2; // rests non-zero — skip
400-
constexpr int AXIS_TWIST = 3; // rudder/twist
401-
constexpr int AXIS_HAT_X = 4;
402-
constexpr int AXIS_HAT_Y = 5;
403-
404-
// --- Buttons ---
405-
constexpr int BTN_TRIGGER = 0;
406-
407-
// --- Cartesian Button Mapping ---
408-
// Cyborg stick has no natural button-based Cartesian; set to -1 (disabled)
409-
constexpr int BTN_CART_POS_X = -1;
410-
constexpr int BTN_CART_NEG_X = -1;
411-
constexpr int BTN_CART_POS_Y = -1;
412-
constexpr int BTN_CART_NEG_Y = -1;
413-
constexpr int BTN_CART_POS_Z = -1;
414-
constexpr int BTN_CART_NEG_Z = -1;
415-
416-
constexpr double CART_BUTTON_SPEED = 0.3;
417-
constexpr double AXIS_DEADZONE = 0.15;
418-
constexpr const char* CART_FRAME_ID = "base_link";
419-
420-
// --- Gripper ---
421-
constexpr int BTN_GRIPPER_TOGGLE = BTN_TRIGGER; // trigger = gripper toggle
422-
constexpr int AXIS_GRIPPER_TOGGLE = -1; // no analog trigger axis
423-
constexpr double AXIS_GRIPPER_PRESSED_THRESHOLD = 0.0;
424-
constexpr double GRIPPER_OPEN_VALUE = 1.0;
425-
constexpr double GRIPPER_CLOSE_VALUE = 0.0;
426-
427-
// --- Gripper Sim Positions ---
428-
constexpr double GRIPPER_SIM_LEFT_OPEN_POS = 0.04;
429-
constexpr double GRIPPER_SIM_RIGHT_OPEN_POS = -0.04;
430-
constexpr double GRIPPER_SIM_LEFT_CLOSE_POS = 0.0;
431-
constexpr double GRIPPER_SIM_RIGHT_CLOSE_POS = 0.0;
432-
433-
// --- Orientation ---
434-
constexpr double ROT_STICK_SPEED = 0.4;
435-
constexpr int AXIS_ROLL = AXIS_STICK_X; // stick X → roll
436-
constexpr int AXIS_PITCH = AXIS_STICK_Y; // stick Y → pitch
437-
constexpr int AXIS_YAW = AXIS_TWIST; // twist → yaw
438-
constexpr bool INVERT_ROLL = false;
439-
constexpr bool INVERT_PITCH = false;
440-
constexpr bool INVERT_YAW = false;
441-
442-
// --- Misc ---
443-
constexpr int BTN_HOME = -1; // no home button on Cyborg stick
444-
}
445-
446273
#else
447274
#pragma warning "Warning: No valid ACTIVE_CONTROLLER defined in controller_config.h"
448275
#endif

src/arm_hardware_interface/src/moteus_CAN_interface/CommandCallback.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ void ArmCAN::CommandCallback(const rover_msgs::msg::ArmCommand::SharedPtr msg) {
1010

1111
switch (type) {
1212
case HOME_CMD:
13-
if (!SIMULATE) { sendHomeCmd(); }
13+
if (!SIMULATE) { sendHomeCmd(); }
1414
break;
1515
case COMM_CMD:
1616
if (!SIMULATE) { sendCommCmd(msg->cmd_value); }
@@ -35,9 +35,7 @@ void ArmCAN::CommandCallback(const rover_msgs::msg::ArmCommand::SharedPtr msg) {
3535
joint_states_.velocity[i] = firmToMoveitOffsetVel(current_velocity[i], i);
3636
}
3737
joint_states_.header.stamp = rclcpp::Clock().now();
38-
3938
joint_state_publisher_->publish(joint_states_); // sim! :)
40-
4139
} else {
4240
send_position_command(target_positions); // non-sim :(
4341
}

0 commit comments

Comments
 (0)