[solved] How to publish multiple messages from single topic?
hai,
I have a problem in my code. i have to publish multiple messages from single topic, to display 2 voltages which is data type of Float64.
#include <ros.h>
#include <std_msgs/Float64.h>
ros::NodeHandle nh;
float voltage1 = 23.44, voltage2 = 74.43;
std_msgs::Float64 test;
ros::Publisher p("my_topic", &test);
void setup()
{
nh.initNode();
nh.advertise(p);
}
void loop()
{
test.data = voltage1;
test.data = voltage2;
p.publish( &test );
nh.spinOnce();
delay(10);
}
when i did this, i only getting
voltage2
value.how can i publish both?
melvin@melvin-HP-Notebook:~$ rosrun rosserial_arduino serial_node.py /dev/ttyACM0
[INFO] [1537962733.845694]: ROS Serial Python Node
[INFO] [1537962733.851536]: Connecting to /dev/ttyACM0 at 57600 baud
[INFO] [1537962735.962522]: Requesting topics...
[INFO] [1537962740.982019]: Packet Failed : Failed to read msg data
[INFO] [1537962740.983027]: expected msg length is 84
[WARN] [1537962740.984163]: Last read step: data
[WARN] [1537962740.985069]: Run loop error: Serial Port read failure: Returned short (expected 84 bytes, received 83 instead).
[INFO] [1537962740.985887]: Requesting topics...
I got this error while connecting through serial_node after add this line test.layout.dim_length = 2;