Rosanswers logo

Hi, I want to subscribe some data which is published from rosserial_arduino in cpp

I coded like this in sketch

std_msgs::Float64 vx_msg; 

ros::Publisher vx_pub("vx_msg", &vx_msg);

void setup() {

  nh.getHardware() -> setBaud(57600); 




void loop() {


  vx_msg.data = 1; // publish linear velocity

  vx_pub.publish (&vx_msg);


This is for calculating odometry . As I can't use encoder, I have to publish constant velocity which I compute.

I can check that the message is published well because I can watch the data with ' $ rostopic echo'

so I coded with global function in .cpp file

##Like this

double vel_x;

void vx_odom (const vx_pub::vx_msg &vx_msg)


    vel_x = vx_msg.vx.msg.data;


There are tutorials about how to subscribe string message . But, I don't have idea if It is Float64 type.

What is the form of subsribing float 64 type data ?

Originally posted by Ros_junior on ROS Answers with karma: 1 on 2015-09-11

Post score: 0


1 Answer 1


Rosanswers logo

Please check again the Subscriber Tutorial and try to understand it. Especially read carefully the the paragraph where the commands are described.

Instead of what you did here:

void vx_odom (const vx_pub::vx_msg &vx_msg)

you have to put in the respective message type into the callback function. So for you it would be:

void vx_odom (const std_msgs::Float64::ConstPtr& vx_msg)

Originally posted by mgruhler with karma: 12390 on 2015-09-17

This answer was ACCEPTED on the original site

Post score: 1


Your Answer

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