Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

ugv-obstacle-avoidance

A C++ simulation of obstacle avoidance logic for an unmanned ground vehicle (UGV). The vehicle uses three simulated distance sensors (front, left, right) to detect obstacles and navigate around them autonomously.

Built to explore autonomous navigation concepts relevant to embedded and unmanned systems development.


What it simulates

The simulation runs a UGV through an obstacle course over a configurable number of timesteps. Each step:

  1. Three distance sensors take readings (with configurable Gaussian noise)
  2. The navigation controller decides what to do: continue, turn left, turn right, or stop
  3. The vehicle state machine updates position and heading accordingly
  4. All events are logged to a CSV file for analysis

The decision logic picks the turn direction with the most clearance when an obstacle is detected ahead. If all sides are blocked, the vehicle stops.


Project structure

src/
  sensor.h / sensor.cpp        - distance sensor simulation with noise
  vehicle.h / vehicle.cpp      - vehicle state machine (IDLE/MOVING/TURNING/STOPPED)
  navigation.h / navigation.cpp - obstacle avoidance decision logic
  logger.h / logger.cpp        - CSV event logger
  main.cpp                     - simulation entry point
tests/
  test_sensor.cpp
  test_vehicle.cpp
  test_navigation.cpp
CMakeLists.txt

Building and running

Requirements: CMake 3.14+, a C++17 compiler (GCC or Clang)

mkdir build && cd build
cmake ..
make
./ugv_sim           # run with default 200 steps
./ugv_sim 500       # run with custom step count

The simulation prints a timestamped log to the console and saves a full CSV report to logs/simulation.csv.


Running the tests

Tests use GoogleTest. Install it first:

# macOS
brew install googletest

# Ubuntu/Debian
sudo apt install libgtest-dev

Then build and run:

mkdir build && cd build
cmake ..
make
ctest --output-on-failure

Sample output

=== UGV Obstacle Avoidance Simulation ===
Steps: 200 | Timestep: 100ms

t=  2800ms |     TURN_RIGHT | F:  30.2cm L: 299.8cm R: 301.1cm | State=TURNING ...
t=  8000ms |     TURN_LEFT  | F:  19.8cm L:  24.3cm R: 300.5cm | State=TURNING ...
t= 19900ms |        STOP    | F:  15.1cm L:  17.9cm R:  18.2cm | State=STOPPED ...

=== Simulation Complete ===
Total steps:       200
Obstacles avoided: 3
Final position:    (142.3, 891.7) cm

What I learned building this

Writing this forced me to understand state machines properly — the vehicle cannot just "decide" to turn, it has to transition through states with defined rules. I also got a much better feel for why sensor noise matters in real systems: even 2cm of noise can change whether an obstacle is detected or not, which affects navigation decisions significantly.

The CSV logging was useful for visualizing what the vehicle actually did step-by-step, which is how I debugged the turn completion logic.


References

  • Siegwart, Nourbakhsh, Scaramuzza — Introduction to Autonomous Mobile Robots (MIT Press)
  • Fraunhofer IEM Advanced Mobility Systems research
  • HC-SR04 ultrasonic sensor datasheet (for realistic noise modeling)

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages