Create Gap Following Package

To set up your gap following package within the driver stack container follow these steps:

1️⃣ Create the Gap Follow Package

Inside the driver stack container, navigate to your ROS 2 workspace ~/f1tenth_ws/src and create a new package:

cd ~/f1tenth_ws/src
ros2 pkg create gap_follow --build-type ament_python --dependencies rclpy sensor_msgs std_msgs ackermann_msgs

Note

Dependencies:

  • rclpy (ROS Client Library for Python)

  • sensor_msgs (Standard Sensor Messages)

  • std_msgs (Standard ROS Messages)

  • ackermann_msgs (Ackermann Drive Messages)

2️⃣ Modify package.xml

Ensure package.xml includes dependencies such as rclpy, sensor_msgs, std_msgs, and ackermann_msgs. Open package.xml and verify:

<depend>rclpy</depend>
<depend>sensor_msgs</depend>
<depend>std_msgs</depend>
<depend>ackermann_msgs</depend>

If you’re using C++ instead of Python, also ensure you have:

<depend>rclcpp</depend>
<depend>tf2_ros</depend>
<depend>geometry_msgs</depend>

3️⃣ Modify CMakeLists.txt (If Using C++)

If you’re using C++, modify CMakeLists.txt to include:

find_package(rclcpp REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(std_msgs REQUIRED)
find_package(ackermann_msgs REQUIRED)

Ensure the add_executable or ament_target_dependencies includes these necessary dependencies.

4️⃣ Install Dependencies Using rosdep

Run the following to install missing dependencies:

cd ~/f1tenth_ws
rosdep install --from-paths src --ignore-src -r -y

5️⃣ Implement the Gap Follow Node

You’ll create a gap follow node that processes LiDAR data (/scan) to find the largest gap and publishes steering commands to navigate through it.

Example: Python Gap Follow Node (gap_follow_node.py)

Create a file inside gap_follow/gap_follow_node.py:

6️⃣ Make It Executable

Modify setup.py inside gap_follow:

entry_points={
    'console_scripts': [
        'gap_follow_node = gap_follow.gap_follow_node:main',
    ],
},

7️⃣ Build & Run

Run the following:

cd ~/f1tenth_ws
colcon build --packages-select gap_follow
source install/setup.bash
ros2 run gap_follow gap_follow_node

C++ Alternative Implementation

If you prefer to implement the Gap Follow node in C++, you can use the following starter code:

Note: When using C++, ensure your package is created with --build-type ament_cmake and that your CMakeLists.txt includes the necessary dependencies (rclcpp, sensor_msgs, ackermann_msgs, etc.).