Ask Your Question
0

How c++ subscribes float64 message published from rosserial

asked 2015-09-11 08:28:17 -0500

Ros_junior gravatar image

updated 2015-09-11 12:16:36 -0500

tfoote gravatar image

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); 

  nh.initNode();

  nh.advertise(vx_pub);

}

void loop() {

  nh.spinOnce();

  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 ?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2015-09-17 01:45:59 -0500

mgruhler gravatar image

Please check again the Subscriber Tutorial#roscpp_tutorials.2BAC8-Tutorials.2BAC8-WritingPublisherSubscriber.Writing_the_Subscriber_Node) 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)
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2015-09-11 08:28:17 -0500

Seen: 626 times

Last updated: Sep 17 '15