top of page
Search

Rethinking the Avoidance Logic: A Smarter, More Fluid Approach

  • Writer: Raffay Hassan
    Raffay Hassan
  • 7 days ago
  • 4 min read

The previous post documented getting everything off the bench and onto the car for the first time. The state machine worked in the sense that the car did reverse, turn, and escape. But there was a persistent problem: in anything tighter than a wide open space, the car got confused. It would reverse correctly, then get stuck trying to turn in one direction repeatedly. It would glide toward an obstacle and not stop in time.


The root cause was not a single bug. It was an architectural decision. The original controller used fixed timers for every state. TURNING ran for exactly 1.2 seconds regardless of what the sensors said. If the path was still blocked after 1.2 seconds, the car drove forward into it anyway. If the path cleared after 0.4 seconds, the car kept turning for another 0.8 seconds unnecessarily. The timers and the sensors were not connected.


This post covers the complete redesign of the motor controller, what changed, and why the system now handles tight spaces and narrow obstacles significantly better.


The Problem with Fixed Timers


Image 1 : Old fixed-timer state machine
Image 1 : Old fixed-timer state machine

The old controller had six states, each committed to a fixed duration before checking anything. TURNING for 1.2s. ESCAPING for 2.0s. STRAIGHTENING for 0.8s. The total manoeuvre time was always 7 seconds regardless of whether the obstacle was cleared in 2 seconds or never cleared at all.


There were two specific failure modes that appeared consistently in the field logs. First, TURNING would complete its full 1.2 seconds and transition to ESCAPING even when the front was still blocked, causing the car to drive directly into the obstacle during the escape phase. Second, when all three LiDAR zones were blocked simultaneously, the car would enter a confused loop of reversing and attempting to turn without ever actually changing its heading enough to find a clear path.


The New Reactive Approach


Image 2:  New sensor-driven reactive controller
Image 2:  New sensor-driven reactive controller

The new controller replaces timers with sensor-driven exits. The only state that still runs for a fixed duration is REVERSING, because the car needs guaranteed physical clearance before attempting a turn. Everything else exits as soon as the sensors confirm the correct condition.

Three structural changes define the new approach.


TURNING now exits when the front clears, not when a timer expires. The car turns at slow speed in the escape direction and checks the front centre distance every 50ms. The moment it reads above 1.0m, TURNING ends and ESCAPING begins. If the front stays blocked, TURNING continues until either the path opens or three consecutive failed attempts trigger the direction flip.


NORMAL now has three distance zones instead of a single stop threshold. Above 1.5m the car drives at full speed. Between 1.0m and 1.5m it slows and steers gently away from the obstacle. Between 0.6m and 1.0m it steers around the obstacle at slow speed without stopping at all. This is the glide-around range. Only when an obstacle is under 0.6m and both sides are also blocked does the car stop and reverse. A narrow object like a bottle in one zone while the sides are clear will never trigger a full reverse manoeuvre.


A stuck detection timer replaces the old confused retry loop. If the car has been continuously steering around an obstacle for more than 4 seconds without clearing the front, it declares stuck and triggers a fresh reverse. This cleanly handles the case where the car is trying to steer around something it physically cannot get past.


The Anti-Stuck Retry Strategy


The retry logic was redesigned to actually work. When TURNING fails three consecutive times because the front is still blocked on entry, the escape direction flips to the opposite side. After the flip, the car goes back through BRAKING and a full REVERSING before trying to turn again on the new heading. This means every three failed turns produces another full reverse on the opposite direction. The car keeps working to find a clear path rather than spinning in place.


Image 3: Full FSM showing retry loop and direction flip
Image 3: Full FSM showing retry loop and direction flip

LiDAR Zone Tuning


Two threshold changes were made based on evidence from the earlier log files.

The centre zone width was reduced from 19cm to 12cm total. A bottle is approximately 8cm wide. With the original zone width a bottle placed slightly off-centre would register in both FC and FL simultaneously, making the system believe the entire front was blocked when only one zone actually contained the obstacle. The narrower centre zone isolates thin objects to a single zone correctly.


The STOP threshold was raised from 0.35m to 0.6m to match real sensor readings. The LiDAR was consistently reading 0.44-0.48m when physically blocked at close range. With a threshold of 0.35m the reverse manoeuvre was never triggering because the readings never crossed the threshold.


Arduino Static IP


The Arduino Uno R4 WiFi is now configured with a static IP of 172.20.10.3. Previously it relied on DHCP which occasionally assigned a different address after a reboot, breaking the UDP connection from the Jetson. The static IP is set using WiFi.config before WiFi.begin so the address is consistent on every power cycle without any router configuration needed.



 
 
 

Comments


  • LinkedIn

The Burroughs, London

NW4 4BT

Autonomous Systems, Sensor Fusion, Digital Twins

 

© 2026 by Department of Science and Technology

 

bottom of page