Skip to content

PS2 Gamepad Teleoperation

Chinese version

Hint

Operating environment and configuration:

  • OriginCar / OriginCar Pro
  • ROS 2 Humble (Foxy also works with the matching joy release)
  • PS2 gamepad + USB receiver
  • Base driver: origincar_base
  • Teleop package: ps2_teleop

This page explains how to drive OriginCar with a PS2 gamepad. After the receiver is plugged into a USB port on the main controller, Linux exposes it as /dev/input/js0. The joy package publishes the gamepad state on /joy, and ps2_teleop maps the left stick to velocity commands on /cmd_vel.

PS2 gamepad and USB receiver

Figure 1: PS2 gamepad and USB receiver

The control chain is:

PS2 gamepad → USB receiver → /dev/input/js0 → joy_node → /joy
                                                   ↓
                                          ps2_teleop_node
                                                   ↓
                                              /cmd_vel → base

1. Connect and Identify the Gamepad

Plug the gamepad's USB receiver into a USB port on the main controller (RDK X3 / X5 / S100), power on the gamepad, and check the device:

ls /dev/input/js*

If the output includes a device such as /dev/input/js0, the gamepad has been recognized.

If the gamepad is recognized but the sticks produce no data, press the MODE button on the gamepad to switch to analog mode. The indicator on the gamepad usually changes state.

If only js0 is present, the default device is fine for the commands below. If multiple gamepads are connected, list them with ros2 run joy joy_enumerate_devices, or specify the device when starting joy_node.

Device Permissions

The default OriginCar login is root, so no extra configuration is required. If you run as a regular user and get Permission denied, grant temporary access:

sudo chmod 666 /dev/input/js0

For a persistent rule:

echo 'KERNEL=="js[0-9]*", MODE="0666"' | sudo tee /etc/udev/rules.d/99-joystick.rules
sudo udevadm control --reload-rules
sudo udevadm trigger

Install the joy Driver

If joy_node is not available, install it first:

sudo apt update
sudo apt install -y ros-humble-joy

2. Install the ps2_teleop Package

Download the package:

Download ps2_teleop.zip

Upload the archive to the robot's ROS 2 workspace:

scp ps2_teleop.zip root@<ROBOT_IP>:/userdata/dev_ws/src/

Extract and build it on the robot:

cd /userdata/dev_ws/src
unzip ps2_teleop.zip

cd /userdata/dev_ws
colcon build --packages-select ps2_teleop --symlink-install
source install/setup.bash

Confirm that the node is installed:

ros2 pkg executables ps2_teleop

The expected output is:

ps2_teleop ps2_teleop_node

About --symlink-install

With --symlink-install, changes to config/ps2_teleop.yaml take effect after restarting the launch file; no rebuild is needed. Without this option, run colcon build again after editing the configuration.

3. Start Teleoperation

Terminal 1, start the base driver:

ros2 launch origincar_base origincar_bringup.launch.py

Terminal 2, start the gamepad node:

ros2 launch ps2_teleop ps2_teleop.launch.py

Once started, hold L1 and move the left stick to drive the car:

Input Action
Hold L1 + left stick up Forward
Hold L1 + left stick down Backward
Hold L1 + left stick left Turn left
Hold L1 + left stick right Turn right
Hold R1 + left stick Turbo mode
Release L1 or center the stick Stop

Ackermann steering

OriginCar Pro uses Ackermann steering. Steering while stationary will not turn the vehicle; add a small amount of forward or reverse speed at the same time.

4. Button Mapping

The default mapping follows a common PS2 USB receiver:

Gamepad input /joy index Function
Left stick vertical axes[1] Forward / backward (linear.x)
Left stick horizontal axes[0] Turn left / right (angular.z)
L1 buttons[4] Enable teleoperation
R1 buttons[5] Turbo mode

Different receiver batches may vary. Run the following command to inspect the stick and button indices:

ros2 topic echo /joy

For example, moving the left stick changes values in the axes array; pressing L1 / R1 changes the corresponding buttons entry from 0 to 1.

If the indices differ from the defaults, edit axis_linear, axis_angular, enable_button, and turbo_button in config/ps2_teleop.yaml.

5. Package Structure

ps2_teleop/
├── config/
│   └── ps2_teleop.yaml          # Axis, button, speed, and timeout parameters
├── launch/
│   └── ps2_teleop.launch.py     # Starts joy_node and the teleop node
├── ps2_teleop/
│   ├── __init__.py
│   └── ps2_teleop_node.py       # Gamepad-to-Twist mapping node
├── resource/
│   └── ps2_teleop
├── package.xml
├── setup.cfg
├── setup.py
└── README.md

The node logic is:

  1. Subscribe to /joy and store the latest axes and buttons.
  2. Publish /cmd_vel at 20 Hz.
  3. Publish zero velocity when no /joy message arrives within timeout.
  4. Publish zero velocity while enable_button is not held.
  5. Read the left stick vertical / horizontal axes, apply the dead zone, direction inversion, and speed limits, and produce linear.x and angular.z.
  6. Use turbo speed while turbo_button is held.

6. Safety Notes

  • For the first test, lift the wheels off the ground and verify forward, backward, steering, and stop-on-L1-release before driving on the floor.
  • Use low speeds during testing, keep bystanders clear, and prevent the car from driving off a table or hitting obstacles.
  • Releasing L1, centering the stick, or a /joy timeout makes the node publish zero velocity. However, a base-driver failure can still prevent stopping; be ready to switch off power.
  • Plug the receiver directly into the main controller's USB port when possible; avoid low-quality USB extension cables.
  • Turn off the gamepad when not in use to avoid draining its batteries.

Image 1