Skip to content

Aswin0305/hw2_vfh

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HW2 VFH

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.

Installation

  • 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

Dependencies

ROS2 Packages

  • ROS2 Humble or later
  • rclpy
  • geometry_msgs
  • sensor_msgs
  • nav_msgs
  • tf2_ros
  • tf2_geometry_msgs
  • visualization_msgs
  • std_msgs

Python Packages

  • scipy
  • numpy

Install Python dependencies:

pip3 install scipy numpy --break-system-packages

Robot Platform

  • TurtleBot3 (burger, waffle, or waffle_pi)
  • Stage simulator (for simulation)
  • Any robot with LaserScan and odometry capabilities

Usage

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.

Launching the World and VFH Controller

ros2 launch hw2_vfh vfh_stage_nodes.launch.py world:=open_world

Available Worlds:

  • open_world - Open environment with minimal obstacles
  • building_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

Running on Real TurtleBot3

# 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

Parameters

Launch File Parameters

Parameter Type Options Description
world string {open_world, building_world} Selects which Stage world to load

VFH Controller Parameters

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)

Setting Controller Parameters at Launch

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

Topics

Subscribed Topics

Topic Type Description
/odom nav_msgs/Odometry Robot odometry information
/base_scan sensor_msgs/LaserScan Laser scan data for obstacle detection

Published Topics

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

Visualization with RViz

Launch RViz to visualize the robot's navigation:

rviz2

Add the following displays:

  • LaserScan → Topic: /base_scan or /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.

Configuring Waypoints

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.

Algorithm Overview

The Vector Field Histogram (VFH) algorithm works through the following steps:

  1. Histogram Construction: Laser scan data is divided into angular sectors, with each sector accumulating obstacle magnitude based on distance
  2. Valley Detection: Contiguous free sectors (below obstacle threshold) are identified as "valleys"
  3. Valley Selection: The best valley is chosen based on:
    • Proximity to target direction
    • Valley width (wider is better)
    • Obstacle density within the valley
  4. 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

Troubleshooting

Robot doesn't move

  • 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

Robot crashes into obstacles

  • Decrease max_linear_speed
  • Increase min_obstacle_distance
  • Decrease obstacle_threshold for more conservative behavior
  • Check laser scan range and field of view

Robot deviates from waypoints

  • Increase obstacle_threshold for less obstacle avoidance
  • Decrease sector_size_deg for finer angular resolution
  • Verify waypoints are reachable in the environment

Wrong topic names

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)

License

This package is licensed under the Apache 2.0 License.

Author

Aswin Arumugam
arumugaa@oregonstate.edu

References

Acknowledgments

This implementation is designed for the ROB599 HW2 assignment and builds upon classical VFH obstacle avoidance techniques adapted for Stage simulation environments.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published