Why do I need to enter a loop to display a marker?
I followed the tutorial on publishing markers in Rviz, I am wondering why I need to enter a loop to publish a marker that has an infinite lifetime (ros::Duration
)
I would expect the following code to display the marker but it does not:
#include <ros/ros.h>
#include <visualization_msgs/Marker.h>
int main(int argc, char **argv)
{
ros::init(argc, argv, "ros_test");
ros::NodeHandle node;
ros::Rate r(1);
// Test marker
ros::Publisher marker_pub = node.advertise<visualization_msgs::Marker>("my_marker", 1);
visualization_msgs::Marker marker;
marker.header.frame_id = "/base_link";
marker.header.stamp = ros::Time::now();
marker.type = visualization_msgs::Marker::CUBE;
marker.action = visualization_msgs::Marker::ADD;
marker.lifetime = ros::Duration();
// Pose
marker.pose.position.x = 0.5;
marker.pose.position.y = 0;
marker.pose.position.z = 0;
marker.pose.orientation.x = 0;
marker.pose.orientation.y = 0;
marker.pose.orientation.z = 0;
marker.pose.orientation.w = 1;
// Scale
marker.scale.x = marker.scale.y = marker.scale.z = 0.1;
// Color
marker.color.r = marker.color.b = 0.2;
marker.color.g = 0.6f;
marker.color.a = 1.0;
marker_pub.publish(marker);
return 0;
}
Adding a loop enables to visualize the marker:
while (ros::ok())
{
marker_pub.publish(marker);
}
I don't want to loop; how to publish the marker once in Rviz?