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.