📦 Joy package for joystick_drivers repo
The joy package contains joy_node, a node that interfaces a generic joystick to ROS 2. This node publishes a “Joy” message, which contains the current state of each one of the joystick’s buttons and axes.
Published Topics
joy (sensor_msgs/msg/Joy): outputs the joystick state.
More Info
A /joy
message in ROS contains the state of the joystick’s axes and buttons and is typically published as a message of type sensor_msgs/Joy
. Example:
header:
seq: 123 # Sequence number of the message
stamp:
secs: 1626442826 # Time of message publication
nsecs: 123456789
frame_id: '' # Frame ID (often empty for /joy messages)
axes: [0.0, 1.0, -0.5, 0.0] # Array of axis positions (floats between -1.0 and 1.0)
buttons: [0, 0, 1, 0, 0, 1] # Array of button states (0 or 1 for each button)
Explanation of Fields
- header: Contains metadata, such as sequence number, timestamp, and frame ID.
- axes: An array representing the position of each joystick axis. Each entry is a float, usually between -1.0 and 1.0, where:
- Positive values indicate movement in one direction (e.g., right or up).
- Negative values indicate movement in the opposite direction (e.g., left or down).
- buttons: An array where each entry is an integer (0 or 1) indicating the state of each button:
0
means the button is not pressed.1
means the button is pressed.
Example with an Xbox Controller Layout
For an Xbox-style controller:
- axes might map as:
axes[0]
: Left thumbstick horizontal (left-right)axes[1]
: Left thumbstick vertical (up-down)axes[2]
: Right thumbstick horizontalaxes[3]
: Right thumbstick verticalaxes[4]
andaxes[5]
: Triggers (often -1 to 1, depending on the driver)
- buttons might map as:
buttons[0]
: A buttonbuttons[1]
: B buttonbuttons[2]
: X buttonbuttons[3]
: Y button- Additional entries for shoulder buttons, triggers, and other controller buttons.