Skip to content

Setting Up and Running a Roboclaw-Based ROS Node with Obstacle Avoidance

Setting Up and Running a Roboclaw-Based ROS Node with Obstacle Avoidance

This guide walks you through setting up and running a Roboclaw-based ROS node with obstacle avoidance functionality using LIDAR sensors. Follow these steps to configure and launch your robotics system efficiently.


Prerequisites

Before starting, ensure the following are set up on your system:

  1. ROS Installed: Ensure you have ROS Melodic or a compatible version installed on your system.
  2. Workspace Prepared: Your ROS workspace (e.g., ~/armpi_pro) is built and sourced.
  3. Packages Installed:
  4. roboclaw_ros for motor control.
  5. ldlidar_stl_ros for LIDAR sensor integration.
  6. Hardware Connections:
  7. Roboclaw is connected via /dev/ttyACM0.
  8. LIDAR sensor is operational and connected (e.g., /dev/ttyUSB0).

Launching the Required Nodes

To operate the system, you need to launch three components in sequence:

1. Start the ROS Core

Open a terminal and launch the ROS core:

roscore

Keep this terminal open as it provides the foundation for all ROS nodes.


2. Launch the Roboclaw Node

In a new terminal, navigate to your workspace and launch the Roboclaw node:

roslaunch roboclaw_node roboclaw.launch

This node handles motor control, publishing odometry, and subscribing to velocity commands (/cmd_vel).


3. Launch the LIDAR Node

In another terminal, launch the LIDAR node:

roslaunch ldlidar_stl_ros ld19.launch

This node processes LIDAR data and publishes it to the /scan topic.


Running the Obstacle Avoidance Node

Once the Roboclaw and LIDAR nodes are running, you can start the obstacle avoidance script. This script subscribes to /scan for LIDAR data and publishes velocity commands to /cmd_vel.

  1. Ensure the script is located at:

    ~/armpi_pro/src/roboclaw_ros/roboclaw_node/scripts/obstacle_avoidance.py
    

  2. Make the script executable:

    chmod +x ~/armpi_pro/src/roboclaw_ros/roboclaw_node/scripts/obstacle_avoidance.py
    

  3. Run the script using rosrun:

    rosrun roboclaw_node obstacle_avoidance.py
    


How It Works

  1. LIDAR Data Processing: The obstacle avoidance node processes data from /scan. It checks for obstacles within 6 inches (0.15 meters) in front of the robot.

  2. Motor Commands:

  3. If an obstacle is detected, the script sends a stop command to /cmd_vel.
  4. If the path is clear, the script commands the robot to move forward.

Example Workflow

Here’s how you would set up and run the entire system step-by-step:

  1. Open a terminal and start the ROS core:

    roscore
    

  2. In a second terminal, launch the Roboclaw node:

    roslaunch roboclaw_node roboclaw.launch
    

  3. In a third terminal, launch the LIDAR node:

    roslaunch ldlidar_stl_ros ld19.launch
    

  4. Finally, in a fourth terminal, run the obstacle avoidance script:

    rosrun roboclaw_node obstacle_avoidance.py
    


Troubleshooting

  1. Package Not Found: If you encounter errors like package 'roboclaw_node' not found, rebuild your workspace:

    cd ~/armpi_pro
    catkin_make
    source devel/setup.bash
    

  2. LIDAR or Roboclaw Not Responding:

  3. Verify device connections using ls /dev/tty* for correct port names.
  4. Update the respective .launch files to reflect the correct ports.

  5. Script Permissions: Ensure all scripts are executable using:

    chmod +x ~/armpi_pro/src/roboclaw_ros/roboclaw_node/scripts/*.py
    


Conclusion

With this setup, your robot is capable of autonomously navigating forward and stopping when obstacles are detected. The modular structure allows for easy debugging and future enhancements, such as adding new sensors or navigation strategies.

Mastering these steps ensures a reliable and robust robotic system ready for real-world applications.


Created 2025-01-22, Updated 2025-01-22
Authors: Harminder Singh Nijjar (1)

Comments