I am stuck at exercise 3.7 of the course “ROS2 Basics in 5 Days Humble (C++)”.
The task is:
Create a Publisher that writes into the /cmd_vel Topic to move the robot.
Create a Subscriber that reads from the /scan Topic. This is the Topic where the laser publishes its data.
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.
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.