Got stuck at exercise 3.7 - ROS2 Basics in 5 Days Humble (C++)

Hi there,

I am stuck at exercise 3.7 of the course “ROS2 Basics in 5 Days Humble (C++)”.

The task is:

  1. Create a Publisher that writes into the /cmd_vel Topic to move the robot.
  2. Create a Subscriber that reads from the /scan Topic. This is the Topic where the laser publishes its data.
  3. Depending on the readings you receive from the laser’s Topic, change the data you send to the /cmd_vel Topic, to avoid the sphere. This means using the values of the laser to decide.

When i have now the subscriber and the publisher, how can these two communicate with each other? Am I missing something that I should have already learned?

I would be grateful for getting some hints on how to solve this.

Thank you in advance :slight_smile:
Tim

Hi @TimSch

As far as I know, there are 2 ways to use publisher and subscriber together.

  • Inside scan_callback create a cmd_vel variable to send commands to move the robot accordingly to sensor values

  • create a timer and inside it use these themes, it would work similar to scan_callback

I hope this has resolved your question, if not, let me know.

3 Likes

Hi @TimSch

What I did was to have a topics_quiz_node containing both a subscriber and a publisher. When the callback associated to the subscriber event gets triggered, you do all your if statements and write accordingly to /cmd_vel.

It is not necessary to have two nodes, one for the subscriber and one for the writer. Use instead a single class/node which has both inside.

3 Likes

Thanks a lot @Voltedge and @Marco_Monforte for your help. I got it working :blush:

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.