seeking clarity regarding visualization markers publishing
This is my main
function -
int main(int argc, char** argv) {
ros::init(argc, argv, "explore_node");
ros::NodeHandle nh("explore_node");
//ros::NodeHandle nh{};
tf2_ros::Buffer buffer(ros::Duration(10));
tf2_ros::TransformListener tf(buffer);
string global_frame, robot_base_frame;
nh.param("global_costmap/global_frame", global_frame, std::string("map"));
nh.param("global_costmap/robot_base_frame", robot_base_frame, std::string("base_link"));
costmap_2d::Costmap2DROS *global_costmap = new costmap_2d::Costmap2DROS("global_costmap", buffer);
costmap_2d::Costmap2DROS *local_costmap = new costmap_2d::Costmap2DROS("local_costmap", buffer);
costmap_2d::Costmap2D* global_costmap_ = temp_global_costmap_ = global_costmap->getCostmap();
unsigned char* global_og = global_costmap_->getCharMap();
geometry_msgs::PoseStamped global_pose;
bool flag = global_costmap->getRobotPose(global_pose);
if(flag) {cout << "global pose found successfully!" << endl;}
double wx = global_pose.pose.position.x , wy = global_pose.pose.position.y;
publish_markers(nh, global_costmap_, wx, wy); // publish markers function
return 0;
}
This is how publish_markers
function is defined -
void publish_markers(ros::NodeHandle &nh, costmap_2d::Costmap2D* &global_costmap_, double wx, double wy) {
visualization_msgs::Marker marker;
marker.header.frame_id = "map";
marker.header.stamp = ros::Time();
marker.ns = nh.getNamespace();
marker.id = 1;
marker.type = visualization_msgs::Marker::SPHERE;
marker.action = visualization_msgs::Marker::ADD;
marker.pose.position.x = wx + 1;
marker.pose.position.y = wy + 3;
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.lifetime = ros::Duration(5.0);
marker.scale.x = 1;
marker.scale.y = 1;
marker.scale.z = 1.0;
marker.color.a = 1.0; // Don't forget to set the alpha!
marker.color.r = 1.0;
marker.color.g = 0.0;
marker.color.b = 0.0;
ros::Time start = ros::Time::now();
ros::Duration del(30.0);
ros::Time end = start + del ;
while(ros::Time::now() < start + del) {
ros::Publisher vis_pub = nh.advertise<visualization_msgs::Marker>( "visualization_markers", 10 );
vis_pub.publish(marker);
}
}
Here's the problem -
The above program doesn't produce the desired marker
in Rviz
for all small values of del
and marker.lifetime
. If marker.lifetime
is small (say, less than 5
), then (roughly speaking) it only produces markers
in Rviz
for values of del > 20
. Why is this happening?
Asked by skpro19 on 2021-05-14 10:11:25 UTC
Comments
There is nothing special about the fact you're using markers here: your node is simply shutting down so fast, that RViz (and any other subscribers to the marker topic(s)) has no time to actually receive your messages.
This is the exact same problem as all other Q&As where the question is "why do my messages not reach my subscriber?" or "why does the first message always get lost?"
Asked by gvdhoorn on 2021-05-14 14:07:11 UTC
Are you saying that small values of
del
is responsible this? Why is that for small values ofdel
(10 < del < 15), if I increase the value ofmarker.lifetime
, it sometimes works?Asked by skpro19 on 2021-05-15 04:45:01 UTC