rviz doesn't visualize the Markers
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?