Publishing and subscribing to an array and store it (in the right order)
Hi Guys, the question is not so easy as it could sound.
In my program I have a class which has the following member function:
/* class #1 */
void Waypoint::updateWaypoints( const ros::TimerEvent& event ) {
/* publish the markers */
marker_pub.publish( marker_array );
ros::spinOnce();
}
where marker_array is a defined Array of markers and is going to be published at a given frequency (to make them visible on RViz), repeatedly.
In a separate class I have defined another function (see next function) which should read the same published array from the first element to the last only ONCE!!!. Now: since both classes are started in the main routine I cannot control how to PC will run them. So it could happen that the function defined in the second class could take, for istance, the 2nd value, read until the last and then read it again. This must not happen.)
/* class #2: different from #1 */
...
ros::Subscriber array_sub = subscribe ("marker_topic", 5, &function, this );
...
visualization_msgs::MarkerArray incoming_array;
...
void classname::function( const visualization_msgs::MarkerArray& msg ) {
if( !done ) {
incoming_array = msg; // <= ?!?!?!?!? Here I am not really sure
done = true; // Do it only once
}
}
EDIT: Here is the main routine. It calls both classes and let the them to run the code above:
#include "include/header_class1.h"
#include "include/header_class2.h"
int main( int argc, char **argv ) {
ros::init( argc, argv, "main_routine" );
ros::NodeHandle nh;
ros::NodeHandle nh_private( "~" );
/* publish the waypoints */
class1( nh, nh_private );
/* should read the wayoints from the previous class */
class2( nh, nh_private );
ros::spin();
return 0;
}
The problem is that I can do it whit normal vectors or other array but with not with markers. At last I am not really happy with the flag variable done that is going to be set once it has all data from the array. Im sure there are much better implementation of such a function. Any idea?!?
Regards
Can you edit your question to add the main function?