If you look at the documentation for std_msgs::Float64
, it shows that it contains a single data field, which is called data
and will be of type double
in C++.
So, in your code, you just do:
areaValue.data = Area
assuming that Area
is a double
.
I suggest that you take a look at the basic Writing a simple Publisher and Subscriber tutorial on the ROS wiki.
EDIT
If what is in the original post is the entirety of your code, then it's probably not going to do exactly what you think it does. If you use the default constructor for a publisher
, messages published
on them are emitted once immediately. Any nodes subscribed
to that topic at the moment of publishing will get the message, and then the topic will be clear. If you want any node that subscribes
to the topic to receive the last message published on it, do the following:
ros::Publisher Auc_pub = n.advertise<std_msgs::Float64>("/auc", 1000, true);
That last bool true
tells the publisher
that it should latch messages that are published.
But you have yet another problem, presuming this is all your code: You never spin, so your node starts up, advertises
its topic, publishes one message on it, and then shuts down, taking the topic with it (assuming nothing was subscribed
to the topic). You need to add the following before the end of your main
:
ros::spin();
This will keep the node active (and thus the topic alive) until ros::ok()
returns false
, I.E. until the node is killed.
Of course, your message is still only going to be published once, but the topic will at least stay alive. If you want the message to be broadcast periodically, use a ros::Timer
and put the pulish
call inside the timer's callback.
But seriously, please read the tutorials, they'll walk you through all of this stuff.