hw2_vfh is a ROS2 package that implements the Vector Field Histogram (VFH) algorithm for obstacle avoidance and waypoint navigation. The package provides a robust navigation controller that enables mobile robots to navigate through cluttered environments while avoiding obstacles in real-time.
- Clone the git repository to your ROS2 workspace source directory.
- Then navigate to the workspace root and build the package.
cd ~/ros2_ws/src
git clone <repository-url> hw2_vfh
cd ~/ros2_ws
colcon build --packages-select hw2_vfh
source install/setup.bash- ROS2 Humble or later
- rclpy
- geometry_msgs
- sensor_msgs
- nav_msgs
- tf2_ros
- tf2_geometry_msgs
- visualization_msgs
- std_msgs
- scipy
- numpy
Install Python dependencies:
pip3 install scipy numpy --break-system-packages- TurtleBot3 (burger, waffle, or waffle_pi)
- Stage simulator (for simulation)
- Any robot with LaserScan and odometry capabilities
This package contains a launch file that launches a Stage world with the VFH controller. The controller subscribes to laser scan and odometry data, then publishes velocity commands to navigate through a predefined set of waypoints while avoiding obstacles.
ros2 launch hw2_vfh vfh_stage_nodes.launch.py world:=open_worldAvailable Worlds:
open_world- Open environment with minimal obstaclesbuilding_world- Complex building environment with corridors and rooms
Example:
# Launch with open world
ros2 launch hw2_vfh vfh_stage_nodes.launch.py world:=open_world
# Launch with building world
ros2 launch hw2_vfh vfh_stage_nodes.launch.py world:=building_world# On TurtleBot (SSH):
ros2 launch turtlebot3_bringup robot.launch.py# On your PC:
source ~/ros2_ws/install/setup.bash
ros2 run hw2_vfh vfh_controller| Parameter | Type | Options | Description |
|---|---|---|---|
world |
string | {open_world, building_world} | Selects which Stage world to load |
The VFH controller supports the following runtime parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
target_tolerance |
double | 0.3 | Distance threshold (meters) to consider waypoint reached |
max_linear_speed |
double | 0.4 | Maximum forward velocity (m/s) |
max_angular_speed |
double | 1.5 | Maximum rotational velocity (rad/s) |
sector_size_deg |
int | 5 | Angular resolution of histogram sectors (degrees) |
obstacle_threshold |
double | 3.0 | Threshold for obstacle detection in histogram |
min_obstacle_distance |
double | 0.5 | Minimum safe distance from obstacles (meters) |
ros2 run hw2_vfh vfh_controller \
--ros-args \
-p target_tolerance:=0.5 \
-p max_linear_speed:=0.3 \
-p max_angular_speed:=1.0 \
-p obstacle_threshold:=2.5 \
-p min_obstacle_distance:=0.6| Topic | Type | Description |
|---|---|---|
/odom |
nav_msgs/Odometry | Robot odometry information |
/base_scan |
sensor_msgs/LaserScan | Laser scan data for obstacle detection |
| Topic | Type | Description |
|---|---|---|
/cmd_vel |
geometry_msgs/Twist | Velocity commands for robot motion |
/waypoint_markers |
visualization_msgs/MarkerArray | Visualization of waypoint path and status |
/current_goal |
visualization_msgs/Marker | Arrow pointing to current target waypoint |
Launch RViz to visualize the robot's navigation:
rviz2Add the following displays:
- LaserScan → Topic:
/base_scanor/scan - MarkerArray → Topic:
/waypoint_markers - Marker → Topic:
/current_goal - TF → Enable to see coordinate frames
- RobotModel → Display the robot model
Set the Fixed Frame to map or odom.
Waypoints are defined in the vfh_controller.py file. To modify the waypoint sequence, edit following lines:
self.waypoints = [(7.0, 4.5),
(7.0, -2.0),
(-2.0, -5.0),
(-7.0, -4.0),
(-5.0, 1.0),
(-1.0, 1.0),
(2.0, 5.0),
(5.0, 7.0)]Coordinates are in the map frame as (x, y) tuples in meters.
The Vector Field Histogram (VFH) algorithm works through the following steps:
- Histogram Construction: Laser scan data is divided into angular sectors, with each sector accumulating obstacle magnitude based on distance
- Valley Detection: Contiguous free sectors (below obstacle threshold) are identified as "valleys"
- Valley Selection: The best valley is chosen based on:
- Proximity to target direction
- Valley width (wider is better)
- Obstacle density within the valley
- Velocity Control:
- Angular velocity steers toward selected valley
- Linear velocity adapts to obstacle proximity and turning angle
- Emergency stop activates when obstacles are too close
- Check if laser scan topic is publishing:
ros2 topic echo /base_scan - Verify odometry is available:
ros2 topic echo /odom - Ensure TF transforms are available:
ros2 run tf2_ros tf2_echo map base_link
- Decrease
max_linear_speed - Increase
min_obstacle_distance - Decrease
obstacle_thresholdfor more conservative behavior - Check laser scan range and field of view
- Increase
obstacle_thresholdfor less obstacle avoidance - Decrease
sector_size_degfor finer angular resolution - Verify waypoints are reachable in the environment
If your robot uses different topic names, modify the subscriptions in the code:
# Change '/base_scan' to your laser topic (e.g., '/scan')
self.scan_sub = self.create_subscription(LaserScan, '/scan', self.scan_callback, 10)This package is licensed under the Apache 2.0 License.
Aswin Arumugam
arumugaa@oregonstate.edu
- Borenstein, J., & Koren, Y. (1991). "The vector field histogram-fast obstacle avoidance for mobile robots"
- ROS2 Documentation: https://docs.ros.org/
- TurtleBot3 e-Manual: https://emanual.robotis.com/docs/en/platform/turtlebot3/
This implementation is designed for the ROB599 HW2 assignment and builds upon classical VFH obstacle avoidance techniques adapted for Stage simulation environments.