How c++ subscribes float64 message published from rosserial
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 ?