Can I use additional topics in ROS2 topics project

Hi,

I started the topic project in unit 3 from the course ROS2 in 5 days python, and the quiz was mentioned 2 topics /cmd_vel and /odom, but to get indication the wall has a opening is using reading from /scan.
Can I use /scan topic to pass the quiz ?

@sashag1991 Sure, you can use the /scan topic for detecting the opening in the wall.

Thanks, I have some issue with running the program, after few times I run my code I see the robot acting in different way and not as expected and even ros2 topic list didnt show ant topics. I assume it stuck on some state. I tried to reset all windows but the only thing that resolved it is to deleted the entire project and create it again from scratch. How can I avoid re-creating the project after some attempts of running it ?

Hi @sashag1991 ,

You do not have to delete the entire project and re-create it. Once you have checked if your project is working correctly and if it works wrong the next time, just clear the ros2 build directories and recompile.

# change directory to ros2_ws
cd ~/ros2_ws
# remove build, install and log folders
rm -rf ./build ./install ./log
# recompile from scratch and source
colcon build && source install/setup.bash
# launch your package
ros2 launch <your_pkg_name> <your_launch_file>.launch.py

That should fix your problem. Report back if you still have issues.

Regards,
Girish

Hello @sashag1991,
There are a several methods you could use to solve this error without having to re-create your project

  1. Clean up ROS2 nodes:
    following on @girishkumar.kannan 's suggestion, it is useful to always clear your nodes resources.
  2. ROS2 Lifecycle:
    consider using ROS2 lifecycle nodes if your nodes have a well-defined lifecycle (e.g., starting,
    configuring, activating, etc.). This can help in proper cleanup and initialization.
  3. ROS2 Logging:
    add more logging statements to your code to understand where it might be getting stuck. Use
    rclpy.loginfo() or other logging functions to print relevant information.

There are many other way to avoid such error like proper node shutdown, ROS2 environment reset and keeping tabs on all global variables or state that are held between runs unintentionally.

Hope this helps.