how can i save rostopic in array?
Hi guys. I need help.
I want to make nodes that 'subscribe topic - save in array' and 'read array - publish topic'. (in my case it is geometry_msgs::Pointstamped) But there are no references and questions. Is it impossible?? If it`s possible. Could i get some advice or any reference link?
Thanks for reading :)
This is first node. : subscribe clicked_point and save in array. (not perfect yet. i`m still making.)
#include "ros/ros.h"
#include "geometry_msgs/Pointstamped.h"
int waypointList[10];
int i = 0;
void waypointCallback(const geometry_msgs::Pointstamped::ConstPtr& clicked_point)
int main(int argc, char **argv)
{
ros::init(argc, argv, "waypoint_saver");
ros::NodeHandle n;
//subscriber
ros::Subscriber waypoint_sub = n.subscribe("waypoint", 1, waypointCallback);
ros::Rate loop_rate(10);
while (ros::ok())
{
//waypoint_pub.header.stamp = ros::Time::now();
if (i < 10){}
waypointList[i]=clicked_point;
i += 1;
}
else{
ROS_INFO("Full waypoint(10 waypoints) %s")
return 0
}
ros::spinOnce();
loop_rate.sleep();
}
return 0
I would recommend you to use vector instead. Something like: std::vector<geometry_msgs::pointstamped>
could you tell me a reason? I don` know that what is good for this.