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

Revision history [back]

click to hide/show revision 1
initial version

I m using ROS Noetic in Ubuntu 20.04. Please see following code which creates 2 lines in each message and publishes over ROS network. When one message is received the previous message's lines are deleted:

int main( int argc, char** argv )

{ ros::init(argc, argv, "points_and_lines");

ros::NodeHandle n;

ros::Publisher marker_pub = n.advertise<visualization_msgs::marker>("visualization_marker", 10);

ros::Rate r(1);

int count = 0;

visualization_msgs::Marker markerD; // Set the frame ID and timestamp. See the TF tutorials for information on these. markerD.header.frame_id = "map"; markerD.action = visualization_msgs::Marker::DELETEALL;

geometry_msgs::Point p;

while (ros::ok()) {

visualization_msgs::Marker line_list;
line_list.header.frame_id = "map";
line_list.ns = "points_and_lines";
line_list.action = visualization_msgs::Marker::ADD;
line_list.pose.orientation.w = 1.0;
line_list.type = visualization_msgs::Marker::LINE_LIST;
line_list.scale.x = 0.1;
line_list.header.stamp = ros::Time::now();
// Line list is red
line_list.color.r = 1.0;
line_list.color.a = 1.0;

marker_pub.publish(markerD);

line_list.id = count;

//Create end points of 1st line
p.x = count;
p.y = 0;
p.z = 0;
line_list.points.push_back(p);
p.z += 1.0;
line_list.points.push_back(p);

//Create end points of 2nd line
p.x = count;
p.y = 2;
p.z = 2;
line_list.points.push_back(p);
p.z += 1.0;
line_list.points.push_back(p);

count++;

marker_pub.publish(line_list);

r.sleep();

} }

I m using ROS Noetic in Ubuntu 20.04. Please see following code which creates 2 lines in each message and publishes over ROS network. When one message is received the previous message's lines are deleted:

int main( int argc, char** argv )

{ ros::init(argc, argv, "points_and_lines");

ros::NodeHandle n;

ros::Publisher marker_pub = n.advertise<visualization_msgs::marker>("visualization_marker", 10);

ros::Rate r(1);

int count = 0;

visualization_msgs::Marker markerD; // Set the frame ID and timestamp. See the TF tutorials for information on these. markerD.header.frame_id = "map"; markerD.action = visualization_msgs::Marker::DELETEALL;

geometry_msgs::Point p;

while (ros::ok()) {

visualization_msgs::Marker line_list;
line_list.header.frame_id = "map";
line_list.ns = "points_and_lines";
line_list.action = visualization_msgs::Marker::ADD;
line_list.pose.orientation.w = 1.0;
line_list.type = visualization_msgs::Marker::LINE_LIST;
line_list.scale.x = 0.1;
line_list.header.stamp = ros::Time::now();
// Line list is red
line_list.color.r = 1.0;
line_list.color.a = 1.0;

marker_pub.publish(markerD);

line_list.id = count;

//Create end points of 1st line
p.x = count;
p.y = 0;
p.z = 0;
line_list.points.push_back(p);
p.z += 1.0;
line_list.points.push_back(p);

//Create end points of 2nd line
p.x = count;
p.y = 2;
p.z = 2;
line_list.points.push_back(p);
p.z += 1.0;
line_list.points.push_back(p);

count++;

marker_pub.publish(line_list);

r.sleep();

} }

I m using ROS Noetic in Ubuntu 20.04. Please see following code which creates 2 lines in each message and publishes over ROS network. When one message is received the previous message's lines are deleted:deleted. Includes are <ros ros.h=""> and <visualization_msgs marker.h="">. (I m not able to add screen recording here to show how it is seen in RViz.)

int main( int argc, char** argv )

{ )

{

ros::init(argc, argv, "points_and_lines");

ros::NodeHandle n;

ros::Publisher marker_pub = n.advertise<visualization_msgs::marker>("visualization_marker", 10);

ros::Rate r(1);

int count = 0;

visualization_msgs::Marker markerD; markerD;

// Set the frame ID and timestamp. See the TF tutorials for information on these. these.

markerD.header.frame_id = "map"; "map";

markerD.action = visualization_msgs::Marker::DELETEALL;

geometry_msgs::Point p;

while (ros::ok()) {

visualization_msgs::Marker line_list;
line_list.header.frame_id = "map";
line_list.ns = "points_and_lines";
line_list.action = visualization_msgs::Marker::ADD;
line_list.pose.orientation.w = 1.0;
line_list.type = visualization_msgs::Marker::LINE_LIST;
line_list.scale.x = 0.1;
line_list.header.stamp = ros::Time::now();
// Line list is red
line_list.color.r = 1.0;
line_list.color.a = 1.0;

marker_pub.publish(markerD);

line_list.id = count;

//Create end points of 1st line
p.x = count;
p.y = 0;
p.z = 0;
line_list.points.push_back(p);
p.z += 1.0;
line_list.points.push_back(p);

//Create end points of 2nd line
p.x = count;
p.y = 2;
p.z = 2;
line_list.points.push_back(p);
p.z += 1.0;
line_list.points.push_back(p);

count++;

marker_pub.publish(line_list);

r.sleep();

} }

}

click to hide/show revision 4
No.4 Revision

I m using ROS Noetic in Ubuntu 20.04. Please see following code which creates 2 lines in each message and publishes over ROS network. When one message is received the previous message's lines are deleted. Includes are <ros ros.h=""> and <visualization_msgs marker.h="">. (I m not able to add screen recording here to show how it is seen in RViz.)

int main( int argc, char** argv ) 

{

{ ros::init(argc, argv, "points_and_lines");

"points_and_lines"); ros::NodeHandle n;

n; ros::Publisher marker_pub = n.advertise<visualization_msgs::marker>("visualization_marker", 10);

n.advertise<visualization_msgs::Marker>("visualization_marker", 10); ros::Rate r(1);

r(1); int count = 0;

0; visualization_msgs::Marker markerD;

markerD; // Set the frame ID and timestamp. See the TF tutorials for information on these.

these. markerD.header.frame_id = "map";

"map"; markerD.action = visualization_msgs::Marker::DELETEALL;

visualization_msgs::Marker::DELETEALL; geometry_msgs::Point p;

p; while (ros::ok()) {

{    
    visualization_msgs::Marker line_list;
 line_list.header.frame_id = "map";
 line_list.ns = "points_and_lines";
 line_list.action = visualization_msgs::Marker::ADD;
 line_list.pose.orientation.w = 1.0;
 line_list.type = visualization_msgs::Marker::LINE_LIST;
 line_list.scale.x = 0.1;
 line_list.header.stamp = ros::Time::now();
 // Line list is red
 line_list.color.r = 1.0;
 line_list.color.a = 1.0;

 marker_pub.publish(markerD);

 line_list.id = count;

 //Create end points of 1st line
 p.x = count;
 p.y = 0;
 p.z = 0;
 line_list.points.push_back(p);
 p.z += 1.0;
 line_list.points.push_back(p);

 //Create end points of 2nd line
 p.x = count;
 p.y = 2;
 p.z = 2;
 line_list.points.push_back(p);
 p.z += 1.0;
 line_list.points.push_back(p);

 count++;

 marker_pub.publish(line_list);

 r.sleep();
  }   
}

}

}