Rosanswers logo

I'm trying to piece all of this together and have a couple questions. I am building a robot "Inga" who will run a pair of pittman motors through an Arduino Mega ADK with an Adafruit motor controller shield and a Robogaia encoder shield, ROS Hydro on 64 bit Toshiba Satellite running Ubuntu Precise. I'm getting comfortable with ROS but still at the shallow end of the learning curve. I know just enough C++ to not entirely helpless, am pretty good with python. I'm choosing to write most of my stuff in C++ to help me in my learning there. My ultimate goal is to employ the Nav stack using a Kinect and an XV-11 Lidar, plus some infrareds and sonars. In the process of learning how to do all of this I'm starting with just being able to move the bot around using a ps2 joystick and then build up to the Nav stack from there as my knowledge and time allows. I've read the appropriate tutorials for joy including creating a teleop node as well as all the Nav stack tutorials and ROS by Example.

Here's what I think I know:

  1. I need to write code for the Arduino that subscribes to gemoetry/Twist msgs to get cmd_vel and that publishes the encoder data. This is almost done.
  2. I need to create a base controller that subscribes to the joystick and publishes the cmd_vel messages the Arduino will read. This is what I'm working on now.

In order to create (2) I've copied the "Creating a Simple teleop node" code from [here] (http://wiki.ros.org/joy/Tutorials/WritingTeleopNode), renamed it inga_joy.cpp and modified it as follows:

#include <ros/ros.h>
#include <turtlesim/Velocity.h>
#include <sensor_msgs/Joy.h>

class TeleopInga

  void joyCallback(const sensor_msgs::Joy::ConstPtr& joy);
  ros::NodeHandle nh_;

  int linear_, angular_;
  double l_scale_, a_scale_;
  ros::Publisher vel_pub_;
  ros::Subscriber joy_sub_;


  nh_.param("axis_linear", linear_, linear_);
  nh_.param("axis_angular", angular_, angular_);
  nh_.param("scale_angular", a_scale_, a_scale_);
  nh_.param("scale_linear", l_scale_, l_scale_);

  vel_pub_ = nh_.advertise<inga::Velocity>("inga/command_velocity", 1);

  joy_sub_ = nh_.subscribe<sensor_msgs::Joy>("joy", 10, &TeleopInga::joyCallback, this);


void TeleopInga::joyCallback(const sensor_msgs::Joy::ConstPtr& joy)
  turtlesim::Velocity vel;
  vel.angular = a_scale_*joy->axes[angular_];
  vel.linear = l_scale_*joy->axes[linear_];

int main(int argc, char** argv)
  ros::init(argc, argv, "teleop_inga");
  TeleopInga teleop_inga;


Essentially what I've done so far is create a pkg in catkin_ws/src named inga_teleop with dependencies joy roscpp rospy and std_msgs


  1. On line 2: #include <turtlesim/Velocity.h> - since I'm not using turtlesim, where do I get the header to include for Velocity.h?

  2. On line 44: turtlesim::Velocity vel; - this will just be the package that I include for Velocity.h ?

  3. I see that I'm using sensor msgs, should I have included them in my initial package, or are these part of std_msgs?

  4. Once I'm done, does this get included in my launch file (I think I know it does) and how?

Originally posted by richkappler on ROS Answers with karma: 106 on 2014-06-08

Post score: 1


1 Answer 1


Rosanswers logo

  1. Since your base controller will subscribe to geometry_msgs/Twist messages on the cmd_vel topic, you should modify the teleop node to publish those messages. In particular, this means you should:

  2. Update the #include on line 2 to #include <geometry_msgs/Twist.h>

  3. Update line 35 so that it advertises geometry_msgs::Twist instead of turtlesim::Velocity

  4. Change the topic name on line 35 from turtle1/command_velocity to cmd_vel

  5. Update lines 44 to 47 so that they create a geometry_msgs::Twist vel and set vel.linear.x to your linear velocity, and vel.angular.z to your angular velocity.

  6. Since you're using messages from the sensor_msgs and geometry_msgs packages, you should depend on them in your package.xml and include them as components when you find_package catkin in your CMakeLists.txt.

  7. Yes, you can start this node from a launch file. The <node> tag for it would be:

     <node pkg="inga_teleop" type="inga_joy" name="inga_joy"/>

Originally posted by ahendrix with karma: 47576 on 2014-06-08

This answer was ACCEPTED on the original site

Post score: 3

Original comments

Comment by choog on 2014-06-11:
Hi I am kinda new to ROS and have only been working with it for about a week now. My question is; is there a way to read the position of the robot of lets say an xy cordinate plane and make the robot move based on those cordinates instead of using cmd_vel topic with twist messages?

Comment by ahendrix on 2014-06-12:
That gets complicated pretty quickly; you should probably ask it as a new question.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.