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

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

Comments

Take a look at this tutorial as reference: https://www.clearpathrobotics.com/ass...

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
1

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

osilva gravatar image

Please refer to this tutorial for further info: https://www.clearpathrobotics.com/ass...

#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()
{
 nh.initNode();
 nh.advertise(pub);
} void loop()
{
 if(digitalRead(8)==1)
 msg.linear.x=-0.25;

else if (digitalRead(4)==1)
msg.linear.x=0.25;

else if (digitalRead(8)==0 && digitalRead(4)==0)
msg.linear.x=0;

pub.publish(&msg);
nh.spinOnce();
}

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

Comments

@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

Stats

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

Seen: 414 times

Last updated: Nov 07 '21