@@ -35,6 +35,7 @@ CONFIG_FLOAT(max_accel_, "max_acceleration");
3535CONFIG_FLOAT (max_decel_, " max_deceleration" );
3636CONFIG_FLOAT (turbo_speed_, " joystick_turbo_speed" );
3737CONFIG_FLOAT (normal_speed_, " joystick_normal_speed" );
38+ CONFIG_STRING (joystick_mode_, " joystick_mode" );
3839CONFIG_STRING (serial_port_, " serial_port" );
3940
4041DEFINE_string (config_dir, " /home/orin/roboracer_ws/src/ut_automata/config" ,
@@ -71,7 +72,8 @@ VescDriver::VescDriver(rclcpp::Node::SharedPtr nh,
7172 // Load config.
7273 config_reader::ConfigReader reader ({
7374 FLAGS_config_dir + " /car.lua" ,
74- FLAGS_config_dir + " /vesc.lua"
75+ FLAGS_config_dir + " /vesc.lua" ,
76+ FLAGS_config_dir + " /joystick.lua"
7577 });
7678 }
7779 state_msg_.header .frame_id = " base_link" ;
@@ -227,16 +229,51 @@ void VescDriver::joystickCallback(const sensor_msgs::msg::Joy::SharedPtr msg) {
227229 mux_steering_angle_ = 0 ;
228230 }
229231 if (drive_mode_ == kJoystickDrive ) {
230- if (msg->axes .size () < 5 ) return ;
231- const float steer_joystick = -msg->axes [0 ];
232- const float drive_joystick = -msg->axes [4 ];
232+ // Check minimum axes requirement based on mode
233+ size_t min_axes = 5 ; // Default for "both" mode (needs axes 0 and 4)
234+ if (joystick_mode_ == " left" ) {
235+ min_axes = 2 ; // Needs axes 0 and 1
236+ } else if (joystick_mode_ == " right" ) {
237+ min_axes = 5 ; // Needs axes 3 and 4
238+ }
239+
240+ if (msg->axes .size () < min_axes) {
241+ if (kDebug ) printf (" Insufficient axes for joystick mode '%s': need %zu, have %zu\n " ,
242+ joystick_mode_.c_str (), min_axes, msg->axes .size ());
243+ return ;
244+ }
245+
246+ float steer_joystick = 0.0 ;
247+ float drive_joystick = 0.0 ;
248+
249+ // Parse joystick mode configuration
250+ if (joystick_mode_ == " both" ) {
251+ // Default mode: left stick for steering, right stick for drive
252+ steer_joystick = -msg->axes [0 ]; // Left stick horizontal
253+ drive_joystick = -msg->axes [4 ]; // Right stick vertical
254+ } else if (joystick_mode_ == " left" ) {
255+ // Left stick only: horizontal for steering, vertical for drive
256+ steer_joystick = -msg->axes [0 ]; // Left stick horizontal
257+ drive_joystick = -msg->axes [1 ]; // Left stick vertical
258+ } else if (joystick_mode_ == " right" ) {
259+ // Right stick only: horizontal for steering, vertical for drive
260+ steer_joystick = -msg->axes [3 ]; // Right stick horizontal
261+ drive_joystick = -msg->axes [4 ]; // Right stick vertical
262+ } else {
263+ // Default to both mode if invalid configuration
264+ if (kDebug ) printf (" Invalid joystick_mode '%s', using default 'both'\n " , joystick_mode_.c_str ());
265+ steer_joystick = -msg->axes [0 ]; // Left stick horizontal
266+ drive_joystick = -msg->axes [4 ]; // Right stick vertical
267+ }
268+
233269 const bool turbo_mode = (msg->axes [2 ] >= 0.9 );
234270 const float max_speed = (turbo_mode ? turbo_speed_ : normal_speed_);
235271 float speed = drive_joystick * max_speed;
236272 float steering_angle = steer_joystick * kMaxTurnRate ;
237273 mux_drive_speed_ = speed;
238274 mux_steering_angle_ = steering_angle;
239- if (kDebug ) printf (" %7.2f %.1f\u00b0\n " , speed, math_util::RadToDeg (steering_angle));
275+ if (kDebug ) printf (" Mode: %s, Speed: %7.2f, Steering: %.1f\u00b0\n " ,
276+ joystick_mode_.c_str (), speed, math_util::RadToDeg (steering_angle));
240277 }
241278
242279 if (drive_mode_ == kAutonomousDrive ||
0 commit comments