ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

Kinetic: turtlesim and teleop_key. Change keyboard key input?

asked 2018-02-28 04:45:11 -0600

cholopineco gravatar image

Hello everyone. I’m at the beginning with ROS. I installed the Kinetic on ubuntu 16.04 LTS.

I would like to understand how I can change the keys to control the turtlesim from the teleop_key (for example, instead of the arrows, the keys w, a, s, d). It can be done? Can someone help me? Thank you.

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted

answered 2018-02-28 09:01:25 -0600

In general, all you need is a node publishing a geometry_msgs/Twist message on the correct topic (likely turtle1/cmd_vel). There are many keyboard-based teleop nodes that could be used instead of the turtle_teleop_key. For example teleop_twist_keyboard or key_teleop. Running one of these nodes with the right remapping would allow you to control the turtlesim using whatever the keybindings of that node are. For example after running your turtlesim_node you could run

rosrun teleop_twist_keyboard cmd_vel:=turtle1/cmd_vel

And then you'd be using the keys described on the teleop_twist_keyboard page.

If you really want to change the keys used in the turtle_teleop_key node from the tutorial, then the only way to do that would be to have a copy of the source code for the turtlesim package in your workspace, edit the source code, and then recompile. The keys used for driving the turtle are defined here, and they are processed in this case statement. If you wanted to use "wsad", you could change the top defines to be:

#define KEYCODE_R 0x64
#define KEYCODE_L 0x61
#define KEYCODE_U 0x77
#define KEYCODE_D 0x73
#define KEYCODE_Q 0x71

To read more about why, in the original code, the arrow keys are the specific values they are (e.g. Right=0x43), you could read the following:

edit flag offensive delete link more


Thanks a lot jarvisschultz! The source code where should it be put? I thought about modifying the original one, but I could not find it.

cholopineco gravatar image cholopineco  ( 2018-02-28 12:06:29 -0600 )edit

You need to have the whole package's source code in a workspace. Likely the easiest way to do this is to cd into your workspace/src directory and then run git clone Now you'd have the whole ros_tutorials metapackage in your workspace.

jarvisschultz gravatar image jarvisschultz  ( 2018-03-01 08:07:28 -0600 )edit

After editing the code, you would need to re-compile the package with catkin_make.

jarvisschultz gravatar image jarvisschultz  ( 2018-03-01 08:07:53 -0600 )edit

Thanks a lot! I'll try to immediately follow your advice.

cholopineco gravatar image cholopineco  ( 2018-03-02 07:43:38 -0600 )edit

answered 2018-02-28 23:37:00 -0600

I will not claim to know much about this topic, but here is a reputable example of a keyboard teleop file from a book I am using to learn ROS if you would like to create your own!

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2018-02-28 04:45:11 -0600

Seen: 5,396 times

Last updated: Feb 28 '18