ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Publishing Odometry using Rosserial

asked 2021-11-05 17:02:48 -0600

Nabil Miri gravatar image

What type of message should I use to publish encoder value which is read by an Arduino? Should I use Twist, Odometry or tfMessage message type?

edit retag flag offensive close merge delete


Take a look at this tutorial as reference:

I’ll summarize it and add it as an answer a little later

osilva gravatar image osilva  ( 2021-11-06 17:05:25 -0600 )edit

1 Answer

Sort by » oldest newest most voted

answered 2021-11-07 07:54:32 -0600

osilva gravatar image

Please refer to this tutorial for further info:

#include <ArduinoHardware.h>
#include <ros.h>
#include <geometry_msgs/Twist.h>

ros::NodeHandle nh;

geometry_msgs::Twist msg;

ros::Publisher pub("husky/cmd_vel", &msg);

void setup()
} void loop()

else if (digitalRead(4)==1)

else if (digitalRead(8)==0 && digitalRead(4)==0)


As you can see a Twist message is published to the cmd_vel topic. Twist message is composed of Linear and Angular velocities as can be seen here:

image description

Once code loaded in Arduino and publishing velocity commands, we can pass these messages along into our ROS environment through rosserial

edit flag offensive delete link more


@osilva It's not clear to me what kind of sensor data the user is gathering. If it's wheel encoder values, I think it's confusing to put that in a Twist message.

Mike Scheutzow gravatar image Mike Scheutzow  ( 2021-11-07 08:45:41 -0600 )edit

That’s true. It’s not clear what kind of sensor data but it’s not the only way for sure just an example.

osilva gravatar image osilva  ( 2021-11-07 08:58:01 -0600 )edit

This is a bit of a strange answer @osilva. The title of the question is rather clear:

Publishing Odometry using Rosserial

we have a message type which is almost always used for this, being nav_msgs/Odometry. Could you clarify why you're showing how to publish a geometry_msgs/Twist instead? Conceptual reuse is not easy for someone just starting out, so I would probably recommend to stick to examples implementing what the OP asked, instead of some other message.

gvdhoorn gravatar image gvdhoorn  ( 2021-11-07 13:23:59 -0600 )edit

I appreciate the feedback @Mike Scheutzow and @gvdhoorn. The reason I used this example is that some new users find it easier to grasp the concept of Twist msg but I can see how this can be confusing as the request is for publishing Odometry. I opted for the part of the question that said what should be used :

Should I use **Twist**, Odometry or tfMessage message type?
osilva gravatar image osilva  ( 2021-11-07 13:49:06 -0600 )edit

Question Tools

1 follower


Asked: 2021-11-05 17:02:48 -0600

Seen: 315 times

Last updated: Nov 07 '21