Skip to content

Commit 34985a4

Browse files
committed
doing another refactor bruh
1 parent ccfa5b1 commit 34985a4

File tree

10 files changed

+763
-181
lines changed

10 files changed

+763
-181
lines changed

src/arm_control/include/controller_config.h

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@
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>
2027
inline 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?
284303
namespace 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

src/arm_hardware_interface/CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,12 @@ add_executable(
2626
serial_arm_driver src/ArmSerialInterface.cpp include/ArmSerialInterface.h
2727
include/arm_hardware_interface/ArmSerialProtocol.h)
2828
add_executable(
29-
moteus_arm_driver src/MoteusInterface.cpp include/ArmMoteusInterface.h
30-
include/arm_hardware_interface/ArmSerialProtocol.h include/axis_5_6_differential.h)
29+
moteus_arm_driver
30+
src/moteus_CAN_interface/MoteusMain.cpp
31+
src/moteus_CAN_interface/MoteusNode.cpp
32+
src/moteus_CAN_interface/CommandCallback.cpp
33+
src/moteus_CAN_interface/MoteusInterface.cpp
34+
src/moteus_CAN_interface/MoteusIO.cpp)
3135

3236
target_compile_definitions(moteus_arm_driver PRIVATE BUILDING_NEW_DRIVER=1) #??
3337

src/arm_hardware_interface/include/ArmMoteusInterface.h

Lines changed: 0 additions & 139 deletions
This file was deleted.

src/arm_hardware_interface/include/arm_hardware_interface/ArmSerialProtocol.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,13 @@ struct MotorConfig {
6262

6363
// Maximum velocity limit (revolutions/s)
6464
// Moteus Config: servo.velocity_limit (soft) or servo.max_velocity (hard limit)
65-
float max_velocity = 0.05f;
65+
float max_velocity = 0.3f;
6666

6767
// Position Limits (revolutions)
6868
// Moteus Config: servopos.position_min / servopos.position_max
6969
float position_min = -1.0f;
7070
float position_max = 1.0f;
71-
float position_warn_rev_padding = 0.01; // If position gets to within this amount to min or max, raise rover alert
71+
float position_warn_rev_padding = 0.02f;
7272

7373
// ---------------------------------------------------------
7474
// 2. Torque / Current Limits
Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
1-
/*
2-
Converts differential drive requests to motor outputs.
3-
Directions given from bird eye view and top down view of each motor.
4-
5-
ex. A5 = -5, A6 = -3 means spin A5 -5 R to L and A6 down by 3.
6-
This requires M5 to move 3 from L to R (positive direction) and M6 to move 3 from R to L (negative direction)
7-
from a top down view of each motor. The A5 spin also requires M5 to move 5 more in the positive direction.
8-
(We choose to move the motor to execute the spin as the one that can continue in the current direction of motion)
9-
10-
takes:
11-
axis5_input: Unitless input for axis 5
12-
axis6_input: Unitless input for axis 6
13-
returns:
14-
(motor5_output, motor6_output) Unitless values for motors 5 and 6
15-
*/
16-
void differential_drive(float axis5_input, float axis6_input, float &motor5_output, float &motor6_output) {
17-
18-
// If the inputs have the same sign, to continue in the same direction of motion, use axis 5 for rotation
19-
if((axis5_input > 0 && axis6_input > 0) || (axis5_input < 0 && axis6_input < 0)) {
20-
motor5_output = - axis5_input - axis6_input;
21-
motor6_output = motor5_output;
22-
}
23-
24-
// Else, use axis 6 for rotation
25-
else {
26-
motor5_output = - axis6_input;
27-
motor6_output = axis6_input;
28-
}
29-
30-
return;
1+
/*
2+
Converts differential drive requests to motor outputs.
3+
Directions given from bird eye view and top down view of each motor.
4+
5+
ex. A5 = -5, A6 = -3 means spin A5 -5 R to L and A6 down by 3.
6+
This requires M5 to move 3 from L to R (positive direction) and M6 to move 3 from R to L (negative direction)
7+
from a top down view of each motor. The A5 spin also requires M5 to move 5 more in the positive direction.
8+
(We choose to move the motor to execute the spin as the one that can continue in the current direction of motion)
9+
10+
takes:
11+
axis5_input: Unitless input for axis 5
12+
axis6_input: Unitless input for axis 6
13+
returns:
14+
(motor5_output, motor6_output) Unitless values for motors 5 and 6
15+
*/
16+
inline void differential_drive(float axis5_input, float axis6_input, float &motor5_output, float &motor6_output) {
17+
18+
// If the inputs have the same sign, to continue in the same direction of motion, use axis 5 for rotation
19+
if((axis5_input > 0 && axis6_input > 0) || (axis5_input < 0 && axis6_input < 0)) {
20+
motor5_output = - axis5_input - axis6_input;
21+
motor6_output = motor5_output;
22+
}
23+
24+
// Else, use axis 6 for rotation
25+
else {
26+
motor5_output = - axis6_input;
27+
motor6_output = axis6_input;
28+
}
29+
30+
return;
3131
}

0 commit comments

Comments
 (0)