Ask Your Question
0

Unable to publish Marker array.

asked 2018-02-20 03:25:11 -0500

BhanuKiran.Chaluvadi gravatar image

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);
}
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2018-02-20 08:24:49 -0500

l4ncelot gravatar image

updated 2018-02-20 08:25:47 -0500

You're trying to publish visualization_msgs::MarkerArray while initializing here cir_marker_pub = n.advertise<visualization_msgs::Marker>("cir_visualization_marker", 10); that you will be publishing visualization_msgs::Marker.

edit flag offensive delete link more

Comments

@I4ncelot Thank you very much.

BhanuKiran.Chaluvadi gravatar imageBhanuKiran.Chaluvadi ( 2018-02-21 03:01:34 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2018-02-20 03:25:11 -0500

Seen: 1,102 times

Last updated: Feb 20 '18