ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

rviz doesn't visualize the Markers

asked 2016-01-26 09:06:20 -0500

updated 2016-01-26 09:08:25 -0500

Hello ! I am learning currently to use Point and Line Markers by the tutorials. And, I am confused what it is a mistake in my code, because there were not any errors in the compilation. My implementation should show points and line, but rviz could get the name of Fixed Frame only. The scene is empty without any markers.. The code is..

#include <ros/ros.h>
#include <visualization_msgs/Marker.h>
#include <iostream>
#include <ros/console.h>
#include <cmath>

int main(int argc, char** argv)
{
ros::init(argc, argv, "voronoi_2D_node"); 
ros::NodeHandle n;
ros::Publisher voronoi_pub = n.advertise<visualization_msgs::Marker>("visual_marker_pub", 10);
ros::Rate r(30);

while (ros::ok())
{
visualization_msgs::Marker line, point;
line.header.frame_id = point.header.frame_id = "/my_frame";
line.ns = point.ns = "voronoi_2D_node";
point.action = visualization_msgs::Marker::ADD;
line.action = visualization_msgs::Marker::ADD;
line.pose.orientation.w = point.pose.orientation.w = 1.0;
//line.header.stamp = point.header.stamp = ros::Time();
//line.lifetime = point.lifetime = ros::Duration();

point.id = 0;
line.id = 1;

point.type = visualization_msgs::Marker::POINTS;
line.type = visualization_msgs::Marker::LINE_STRIP;

point.scale.x = 0.2;
point.scale.y = 0.2;

line.scale.x = 0.1;

point.color.g = 1.0f;
point.color.a = 1.0;


line.color.b = 1.0;
line.color.a = 1.0; 

//point.pose.position.x = 0;
//point.pose.position.y = 0;
//point.pose.position.z = 0;

//line.pose.position.x = 0;
//line.pose.position.y = 1;
//line.pose.position.z = 0;

for (uint32_t i=0; i<2; ++i)
{
geometry_msgs::Point p;
p.x = i;
p.y = 0.5;
p.z = 0.5;

line.points.push_back(p);
point.points.push_back(p);


//ROS::INFO("The coordinates: x=[%d] , y=[%d] , z=[%d]", p.x, p.y, p.z);
std::cout<<"The coordinates: "<<p<<std::endl;

}
voronoi_pub.publish(point);
voronoi_pub.publish(line);

r.sleep();
}

}

The output is .. (in the terminal):

The coordinates: x: 0
y: 0.5
z: 0.5

The coordinates: x: 1
y: 0.5
z: 0.5

Do you know what kind of a reason can be if rviz doesn't illustrate the markers?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2016-01-26 10:21:04 -0500

Everything looked good to me. So I just tested your code and the markers popped up in rviz no problem. I'm guessing that your problem is most likely related to the Fixed Frame in rviz. If you are only running your node and rviz, then there are no nodes publishing on the /tf topic (via a tf broadcaster). Thus rviz has no way of knowing what frames are available. Try manually typing my_frame in for the Fixed Frame in rviz, and I'm guessing your markers will show up.

To see that this is the issue, try starting a static transform publisher. Then rviz will be able to correctly select a fixed frame. E.g.:

rosrun tf2_ros static_transform_publisher 0 0 0 0 0 0 world my_frame
edit flag offensive delete link more

Comments

Jarvis, I ran the static tf too ... But, there are no any markers in rviz. Thank you for testing my code. Now, I know that it works )

dyupleks gravatar image dyupleks  ( 2016-01-26 19:53:47 -0500 )edit

Did you add the markers on the correct topic (/visual_marker_pub) to the display?

jarvisschultz gravatar image jarvisschultz  ( 2016-01-26 22:59:29 -0500 )edit

That's right! I didnt add the Market Topic )) By default, there was /visualization_marker. When I clicked twice on the dropdownlist, my topic's name ( /visual_marker_pub ) popped up )) Thank you, Jarvis

dyupleks gravatar image dyupleks  ( 2016-01-27 06:00:46 -0500 )edit
2

answered 2018-02-06 07:20:57 -0500

Sarthak gravatar image

In case, the above-mentioned solutions do not work, just check whether you have selected the right frame-id on the screen of rviz. This was the error that I also faced, you will have to change it to the frame id that you have mentioned while creating markers. By default, I think it is set to /map.

edit flag offensive delete link more

Comments

Thank u for ur contribution :)

dyupleks gravatar image dyupleks  ( 2018-02-09 22:52:50 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2016-01-26 09:06:20 -0500

Seen: 5,382 times

Last updated: Jan 26 '16