Unable to publish Marker array.
Hi,
I am trying to publish Marker array of spheres. But when ever is tried
rostopic echo -n 1 /cir_visualization_marker.
The node is terminated giving an error
terminate called after throwing an instance of 'ros::serialization::StreamOverrunException'
what(): Buffer Overrun
Aborted (core dumped)
If i trying to visualize in rviz its not displaying any thing.
The standard output is printing put all the values and the message is being parsed properly into the callback
code:
#include <ros/ros.h>
#include <visualization_msgs/MarkerArray.h>
#include "test/Obstacles.h"
#include <cmath>
ros::Publisher line_marker_pub;
ros::Publisher cir_marker_pub;
void callback(const test::Obstacles::ConstPtr& msg);
int main( int argc, char** argv )
{
ros::init(argc, argv, "viz_obstacles");
ros::NodeHandle n;
cir_marker_pub = n.advertise<visualization_msgs::Marker>("cir_visualization_marker", 10);
ros::Subscriber sub = n.subscribe("/obstacle_extractor/raw_obstacles", 10, callback);
ros::spin();
return 0;
}
void callback(const test::Obstacles::ConstPtr& msg)
{
visualization_msgs::MarkerArray Markerarr;
int num_circ = msg->circles.size();
Markerarr.markers.resize(num_circ);
for ( int i = 0; i < num_circ; i++)
{
Markerarr.markers[i].header.frame_id = msg->header.frame_id;
Markerarr.markers[i].header.stamp = ros::Time::now();
Markerarr.markers[i].ns = "points_and_lines";
Markerarr.markers[i].id = i+10;
Markerarr.markers[i].action = visualization_msgs::Marker::ADD;
Markerarr.markers[i].type = visualization_msgs::Marker::SPHERE;
std::cout << "msg->circles[i].center.x: " << msg->circles[i].center.x << std::endl;
Markerarr.markers[i].pose.position.x = msg->circles[i].center.x;
Markerarr.markers[i].pose.position.y = msg->circles[i].center.y;
Markerarr.markers[i].pose.position.z = msg->circles[i].center.z;
Markerarr.markers[i].pose.orientation.x = 0.0;
Markerarr.markers[i].pose.orientation.y = 0.0;
Markerarr.markers[i].pose.orientation.z = 0.0;
Markerarr.markers[i].pose.orientation.w = 1.0;
std::cout << "msg->circles[i].radius " << msg->circles[i].radius << std::endl;
Markerarr.markers[i].scale.x = msg->circles[i].radius;
Markerarr.markers[i].scale.y = msg->circles[i].radius;
Markerarr.markers[i].scale.z = 0.1;
Markerarr.markers[i].color.a = 1.0;
Markerarr.markers[i].color.r = 0.0;
Markerarr.markers[i].color.g = 0.1;
Markerarr.markers[i].color.b = 0.0;
}
// for (auto& circ : msg->circles)
// {
// cir.pose.position.x = circ.center.x;
// cir.pose.position.y = circ.center.y;
//
// cir.scale.x = circ.radius;
// cir.scale.y = circ.radius;
//
// Markerarr.markers.push_back(cir);
// }
cir_marker_pub.publish(Markerarr);
}