0
$\begingroup$

Rosanswers logo

I am trying to create a home service robot using a turtlebot. In it the robot should start at origin at travel to point 1 where a marker has been displayed, stay there for 5 seconds and the marker will disappear indicating pick up and then travel to point 2 and stay there for 5 seconds after which marker would reappear indicating drop.

After launching my robot, I cannot view the marker at point 1, but my code for marker is functioning and the robot travels to point 1 and the terminal indicates me of a pickup and then it travels to point 2 where the terminal is indicating drop off and I can see then see the marker. Can someone please explain why am I not able to see the marker at point 1 as well?

The primary problem is in the add_markers.cpp file as it is the main file which is publishing the markers, on running a rostopic echo on /visualization_marker topic, I found that for the point A it is not publishing any information but it is doing so for point B which is perplexing me.

My workspace and add_markers.cpp code.


Originally posted by gentle_yeti on ROS Answers with karma: 3 on 2022-10-19

Post score: 0


Original comments

Comment by ravijoshi on 2022-10-21:
I suggest creating and sharing a minimal reproducible example.

Comment by ljaniec on 2022-10-21:
Maybe is it a problem of ROS spinning? Can you add a few ros::spinOnce(); and ros::Duration(1).sleep(); in the code? You should also wait to send the first point to travel until every publisher/subscriber is set up correctly

Comment by gentle_yeti on 2022-10-21:
@ljaniec , yes it worked!!! I understand the issue now. The add_marker was launching the first marker and then removing it before the set up could start, I put up a ros::Duration(1).sleep(); and it worked perfectly, thank you so much for the answer.

Comment by gentle_yeti on 2022-10-21:
@ravijoshi I apologize for not sharing in a easy to view way, I am still learning a lot of things and I will definitely keep this in mind the next time

Comment by ljaniec on 2022-10-21:
@gentle_yeti

  • I will move this to the answer, so you can upvote and accept it, so it will be marked as solved in the queue, ok? I will also link related question with it answers.

  • You gave us the whole workspace with packages, it worked for me as MWE (but there was quite a lot of additional stuff, to be honest - the less code there is to analyze for others, the better).

Comment by gentle_yeti on 2022-10-21:
@ljaniec okay, sure I'll do so. Okay, I understand, I'll keep it in mind to focus only on the required code and remove any additional stuff present, thanks for pointing that out, I didn't know about that.

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

As in the comment:

Maybe is it a problem of ROS spinning? Can you add a few ros::spinOnce(); and ros::Duration(1).sleep(); in the code? You should also wait to send the first point to travel until every publisher/subscriber is set up correctly.

It is connected with e.g. this question "What is first ? Publisher or Subscriber?"

Which among the following nodes should be started first? Publisher or Subscriber.

and its answers:

  • "In general it should not matter. You can start publishers and subscribers at any time. However, note that ROS is expecting messages as a constant message stream, e.g., like from a sensor. They are not buffered in some central instance. This explains why it misses receiving initial messages. It just wasn't there to listen."

  • "This is a common topic in IPC (interprocess communication). In general, the publish/subscribe model can be thought of like a radio broadcast where there is some time between initialization of a node and when it is functional. If you start the publisher first, then there will be a brief period of time when the node is broadcasting messages and the subscriber is not able to listen yet as it hasn't initialized fully. This can technically still happen with the subscriber starting first as the initialization time is not the same for publisher and subscribers (depends on implementation)."


Originally posted by ljaniec with karma: 3064 on 2022-10-21

This answer was ACCEPTED on the original site

Post score: 1

$\endgroup$

Your Answer

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