0
$\begingroup$

Rosanswers logo

Hi all

I followed the rviz source code 2D Pose Estimate which is the below function to set initialpose for AMCL in my own code.

void InitialPoseTool::onPoseSet(double x, double y, double theta)

It worked in publishing a single message to the topic initialpose. However this was not able to set the pose of the robot, because in rviz the pose of the robot never changed to the new one and in the console there also had not been showing any message like "[ROS_INFO] setting the robot pose to ..." as usual when we used the rviz 2D Pose Estimate tool.

But I finally made it work by using the latched ros publisher rather than the normal publisher

ros::Publisher advertise(const std::string& topic, uint32_t queue_size, bool latch = true)

The question I want to raise here is why the normal publisher without latch could work in rviz while I have to use the latched version to publish the message to set the pose?

Thanks all.


Originally posted by dalishi on ROS Answers with karma: 89 on 2014-06-08

Post score: 1

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

I suspect you're creating the publisher and then immediately publishing a single message to set the robot pose.

This is the usual race condition many new users run into, where subscribers often don't receive the first message on a topic.

The reason that this happens is that subscribers don't connect immediately when a publisher starts; they have to receive a callback that a new publisher exists and establish a TCP connection, before they can receive messages. This takes a few milliseconds, and usually mean that existing subscribers will miss the first few messages on a new topic.

The reason that a latched topic works for this, is that new subscribers to a latched topic will immediately receive the most recent message on a topic, regardless of when it was published.


Originally posted by ahendrix with karma: 47576 on 2014-06-08

This answer was ACCEPTED on the original site

Post score: 4


Original comments

Comment by dalishi on 2014-06-08:
Hi ahendrix, thanks for the explanation. Now I am getting more clear about this. Thanks.

Comment by Manav_Poddar on 2018-07-03:
Hi, are you able to visualize the pose estimate(you sent through code) in rviz?

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.