Lab 1.6: Extracting Data from ROS nodes


This lab is to analyze the topics published by nodes from other packages, and extract them to do further process.

Install Keyboard Teleoperation Package

First install the keyboard teleoperation package in Ubuntu using following command:

sudo apt-get install ros-indigo-teleop-twist-keyboard

We can use the package using following command, make sure you are running roscore.

rosrun teleop_twist_keyboard

Now lets look at the topic that is published by this teleop node:

rostopic echo /cmd_vel

Go back to the terminal window of teller node, then you can see the topic printed as following:

  x: 0.5
  y: 0.0
  z: 0.0
  x: 0.0
  y: 0.0
  z: 0.0

For more detail, lets look at the type of the topic using command:

rostopic type /cmd_vel

Where it will return:


Therefore, we now understand that the type is geometry_msgs/Twist, we can write a subscribe node that query Twist type message.

Use following command to understand what types of data in geometry_msgs/Twist.

rosmsg show geometry_msgs/Twist

You will see:

geometry_msgs/Vector3 linear
  float64 x
  float64 y
  float64 z
geometry_msgs/Vector3 angular
  float64 x
  float64 y
  float64 z

Now we know the keyboard values sent from teleop_twist_keyboard are actually float type.

Subscribe the keyboard messages and modify them

Use following script to extract the geometry_msgs/Twist message, note green text:

#include “ros/ros.h”
#include “std_msgs/String.h”
#include “geometry_msgs/Twist.h”

void cmdRCCallback(const geometry_msgs::Twist::ConstPtr& cmd_RC){
float m_straight=0;
float m_turn=0;

int main(int argc, char **argv)
ros::init(argc, argv, “tele”);
ros::NodeHandle n;
ros::Subscriber sub = n.subscribe(“cmd_vel”, 100, cmdRCCallback);
ros::Rate r(10);

while (ros::ok()){
return 0;

Since we use other message type, we have to include the dependency in manifest.xml file, find the manifest.xml  file in you package folder (in our case, it should be ~/dev/CIS623/my_ex1). The modified .xml file would be look like (note green text).

<description brief=”my_ex1″>


<review status=”unreviewed” notes=””/>
<depend package=”roscpp”/>
<depend package=”rospy”/>
<depend package=”std_msgs”/>
<depend package=”geometry_msgs”/>


Do not forget add the following line to compile the script as executable node in you CMakeLists.txt.

 rosbuild_add_executable(tele src/tele.cpp)

Now we all done, rosmake the package:

rosmake my_ex1

Test your node along with roscore and teleop_twist_keyboard node.


Get the Lab1.bag file from TA and use following command to use it, make sure your terminal is in the file folder:

rosbag play Lab1.bag

Now you can see there is a /scan topic has been published, please write a ROS node that subscribes the /scan data and modify the ranges data in the topic.

Hint: the /scan data is laser data, you can see example in the section of textbook called “Accessing the laser data and modifying it“.