Publisher only publishing two of my three variables
Hi,
I've been playing around with publishers and subscribers, challenging myself with modification on the tutorial pub/sub examples just to gain a foundation.
#include <ros/ros.h>
#include <std_msgs/Float64.h>
int main(int argc, char **argv)
{
ros::init(argc, argv, "project_one_publisher"); //publisher node name
ros::NodeHandle n;
ros::Publisher p_one_pub = n.advertise<std_msgs::Float64>("project_one", 1);
std_msgs::Float64 tens;
std_msgs::Float64 hundreds;
std_msgs::Float64 thousands;
ros::Rate naptime(1.0);
tens.data=0.0;
hundreds.data=0.0;
thousands.data=0.0;
while (ros::ok())
{
p_one_pub.publish(tens);
tens.data=tens.data + 10;
p_one_pub.publish(hundreds);
hundreds.data=hundreds.data + 100;
p_one_pub.publish(thousands);
thousands.data=thousands.data + 1000;
naptime.sleep();
}
}
I have no problems running my code however when I use rostopic echo <topic> it only prints the hundreds and thousands value, it doesn't display the tens value.
I also created a subscriber to subscribe to incoming data however that only reads the thousands value while randomly reading the hundreds value, ex:
[ INFO] [1579646242.765639960]: recieved value is: 264000.000000
[ INFO] [1579646243.804282174]: recieved value is: 265000.000000
[ INFO] [1579646244.774907455]: recieved value is: 266000.000000
[ INFO] [1579646245.809710083]: recieved value is: 2670.000000
[ INFO] [1579646245.809943092]: recieved value is: 267000.000000
[ INFO] [1579646246.763998267]: recieved value is: 268000.000000
[ INFO] [1579646247.766197402]: recieved value is: 269000.000000
So ya, my question is why on the echo topic, it's only showing the hundreds and thousands value but not the tens value and on the subscriber side, why it's mostly using the thousands value.
Thanks