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

How to publish and subscribe float/double type value on a topic?

asked 2013-06-30 05:41:10 -0600

Bholms gravatar image

updated 2013-11-18 19:26:38 -0600

tfoote gravatar image

As far as I know, callback function used for the subscriber in the ROS tutorial are all string type, and callback functions are void type.

However, I need to use the subscribed values (e.g. velocities) for other purposes. Is there a way to pass and receive non-string type messages?

Thanks.


How do you modify the callback function prototype below?

void chatterCallback(const std_msgs::String::ConstPtr& msg)

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
1

answered 2013-06-30 07:56:04 -0600

allenh1 gravatar image

updated 2013-07-15 03:53:53 -0600

You could definitely decompose the sting messages with regular expressions.

Or, you could use a different message data type that has a float container.

Or, you could write your own message type.

Or, you could use the float message.

http://ros.org/doc/api/sensor_msgs/html/msg/ChannelFloat32.html


Have you done the ROS tutorials? If not, I recommend you do so. ROS is a complicated system, and you need to really grasp the concepts before you attempt coding. It is very important you understand what a Message is, and how to use them.

However, to answer your question, it depends on how you are modifying it. For the float message, you will need to add to the top of your code the following line.

#include <sensor_msgs/ChannelFloat32>

Now, you can change the function to read

void floatCallback(const sensor_msgs::ChannelFloat32::ConstPtr& float_msg)

and that should work.

edit flag offensive delete link more

Comments

Hmm... sensor_msgs/ChannelFloat32.msg isn't "the float message", std_msgs/Float32 (or Float64) is. And for velocities, geometry_msgs/Twist is the standard.

Martin Günther gravatar image Martin Günther  ( 2013-07-15 23:52:06 -0600 )edit
0

answered 2013-07-02 01:54:48 -0600

felix k gravatar image
edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-06-30 05:41:10 -0600

Seen: 21,265 times

Last updated: Jul 15 '13