In other tutorials, I showed how to get access to the joystick and how to code with that. In this tutorial, I’m going to show you how to do that without writing any line of code.
First, install the required packages:
1 |
sudo apt-get install ros-noetic-teleop-twist-joy ros-noetic-joy ros-noetic-joy-teleop |
Now call the following
1 |
rosrun joy joy_node dev:=/dev/input/js0 |
This will publish the topic “/joy_node” which is a type of “sensor_msgs/Joy”
Now you need to create your favorite message from that, for instance, if you want to move your robot you need to create “Twist” and publish that over /cmd_vel. To do that, create a yaml file and call it “joystick_param.yaml”, then put the following in the file and save it:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
teleop: walk: type: topic message_type: geometry_msgs/Twist topic_name: /turtle1/cmd_vel deadman_buttons: [4] axis_mappings: - axis: 1 target: linear.x scale: 0.5 offset: -0.03 - axis: 0 target: angular.z scale: 0.5 - axis: 2 target: linear.y scale: 0.3 hello: type: topic message_type: std_msgs/String topic_name: chatter deadman_buttons: [1] message_value: - target: data value: 'Hello' |
Now load it to ROS param:
1 |
rosparam load joystick_param.yaml |
Then you can call joy_teleop.py, so it will check the values that you set into teleop and publish
/chatter and /cmd_vel
1 |
rosrun joy_teleop joy_teleop.py |
Alternatively, you can just call the following which will do lines above at once:
1 |
roslaunch teleop_twist_joy teleop.launch |
read more:
joy, joy_teleop, teleop_twist_joy, teleop_example
I copied the joystick_param.yaml file, now where do I put it? When I type in
rosparam load joystick_param.yaml, I get this error:ERROR: file [joystick_param.yaml] does not exist
Dear Wone,, plce the yaml file there and then run rosparam load joystick_param.yaml
the yaml file should be next to the node file that you are running, for instance, if you in the terminal working directory is /home/
it works!