0
$\begingroup$

Rosanswers logo

I am trying display marker array in rviz. The marker is published succesfully but is not visible in rviz. The code is below:

int
main (int argc, char** argv)
{

visualization_msgs::Marker marker;
visualization_msgs::MarkerArray marker_array_msg;

  // Initialize ROS
  ros::init (argc, argv, "pcl_tabletop");
  ros::NodeHandle nh;

  pub_marker = nh.advertise<visualization_msgs::MarkerArray>("normals_marker_array", 100);
//pub_marker1 = nh.advertise<visualization_msgs::Marker>("normals_marker", 0);
/*while(1)
{

marker.header.frame_id = "base_link";
marker.header.stamp = ros::Time();
marker.ns = "my_namespace";
marker.id = 120;
marker.type = visualization_msgs::Marker::SPHERE;
marker.action = visualization_msgs::Marker::ADD;
marker.pose.position.x = 1;
marker.pose.position.y = 1;
marker.pose.position.z = 1;
marker.pose.orientation.x = 0.0;
marker.pose.orientation.y = 0.0;
marker.pose.orientation.z = 0.0;
marker.pose.orientation.w = 1.0;
marker.scale.x = 1;
marker.scale.y = 0.1;
marker.scale.z = 0.1;
marker.color.a = 1.0;
marker.color.r = 1.0;
marker.color.g = 0.0;
marker.color.b = 0.0;

//pub_marker.publish(marker_array_msg);

pub_marker1.publish(marker);
}*/

marker_array_msg.markers.resize(5);//final->width * final->height);
for ( int i = 0; i < 5; i++)
{
    marker_array_msg.markers[i].header.frame_id = "base_link";
    marker_array_msg.markers[i].header.stamp = ros::Time();
    marker_array_msg.markers[i].ns = "my_namespace";
    marker_array_msg.markers[i].id = i;
    marker_array_msg.markers[i].type = visualization_msgs::Marker::SPHERE;
    marker_array_msg.markers[i].action = visualization_msgs::Marker::ADD;
    marker_array_msg.markers[i].pose.position.x = i+50;
    marker_array_msg.markers[i].pose.position.y = 50+i;
    marker_array_msg.markers[i].pose.position.z = 10+i;
    marker_array_msg.markers[i].pose.orientation.x = 0.0;
    marker_array_msg.markers[i].pose.orientation.y = 0.0;
    marker_array_msg.markers[i].pose.orientation.z = 0.0;
    marker_array_msg.markers[i].pose.orientation.w = 1.0;
    marker_array_msg.markers[i].scale.x = 1;
    marker_array_msg.markers[i].scale.y = 0.1;
    marker_array_msg.markers[i].scale.z = 0.1;
    marker_array_msg.markers[i].color.a = 1.0;
    marker_array_msg.markers[i].color.r = 0.0;
    if (i == 0)
    {
        marker_array_msg.markers[i].color.g = 0.1;
    }
    else
    {
        marker_array_msg.markers[i].color.g = i * 0.15;
    }
    marker_array_msg.markers[i].color.b = 0.0;

     //marker_array_msg.markers.push_back(mark);
}
while(1)
{
 pub_marker.publish(marker_array_msg);
}

  // Spin
  ros::spin ();
}

I tried both Marker and MarkerArray types but its not visible in rviz. Am i doing something wrong when assigning values to marker array ?? This was my first try with marker array further actually i want to display segmented pcl data as marker array.

Any idea what is wrong please :)


Originally posted by kk on ROS Answers with karma: 225 on 2013-07-16

Post score: 3


Original comments

Comment by micheal on 2013-08-13:
How can this work? There is no member markers in marker_array_msg array. This should constantly give you errors. I think you should make a vector<visualization_msg::Marker> markersarray; and then push_back every new marker you are making into it. Please correct me if I am wrong.

Comment by kk on 2013-08-15:
Its working fine. markers is present in visualization_msgs::MarkerArray type. basically i have fixed the size of the marker array and then populating them. The code is working fine but since the position values were too far they were not visible, once i zoomed out i was able to see the markers.

$\endgroup$

2 Answers 2

0
$\begingroup$

Rosanswers logo

I suspect this is a TF problem. There are a few things you can look at:

  • Is rivz subscribed to your marker topic?
  • In the rviz display for your markers, is the topic status OK?
  • Is the TF frame for your markers ("base_link") reachable from the fixed frame you have set in rviz?

You may want to try setting your fixed frame in rviz to "base_link".

Adding a screenshot of your rviz setup to the question will also help debug.

You're publishing to the "normals_marker_array" topic but subscribing to the "normals_marker" topic.

You're not calling ros::spin() or ros::spinOnce() in your publish loop to give the ROS library a chance to service the transmit and receive routines. Are you sure messages are being published properly?

Try rostopic echo normals_marker_array to see if messages are actually being published.


Originally posted by ahendrix with karma: 47576 on 2013-07-17

This answer was NOT ACCEPTED on the original site

Post score: 3


Original comments

Comment by kk on 2013-07-18:
Hi, Thank you for the reply. I think the problem is with the TF frame as you mentioned. It says does not exist.. Snapshots of the rviz attached in the link: https://www.dropbox.com/sh/sc0k50coh8wlv8b/yFynTDbeoF

Comment by kk on 2013-07-18:
Hi, Now i changed to /map as the topic for fixed frame(i am getting map data from morse) now it says OK. Even the marker topic are OK. But still cannot see the markers on rviz ?? Snapshots attached: https://www.dropbox.com/sh/qan3ki8orz9l7jz/xIt4y8Yogz

Comment by kk on 2013-07-18:
Hi actually i have subscribed correctly and i am able echo the message rostopic echo normals_marker_array. I found the issue. Its with the position values. Actually the markers were visible but at very higher position, I always had this doubt and now found the markers after zooming out in the rviz

Comment by kk on 2013-07-18:
But your other suggestions are also correct and would consider them in further code. Thank you very much ahendrix :)

$\endgroup$
0
$\begingroup$

Rosanswers logo

The main issue is with the position values i think. The markers were actually visible but not within the camera view. Once i zoomed out(honestly it was too far from the normal view ;-p) i was able to see the markers. Snapshot attached : https://www.dropbox.com/sh/6e41icc15lqrgvs/hJkxHx3AX8


Originally posted by kk with karma: 225 on 2013-07-18

This answer was ACCEPTED on the original site

Post score: 0

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.