By Preston Ohta

# Write-Up

The car analyzes its environment using a single line scan to detect the road and incoming obstacles. It uses the same proportional algorithm for road tracking as in Part 1, but now uses an additional algorithm to avoid barrels on the road.

When obstacles near the car, the linescan uses the left and right boundaries of the obstacles to determine the widths of the gaps through which the car could potentially pass through. It then compares these widths to find the largest one, and sets its target to be the midpoint of that gap. However, the previous road-following algorithm was not agile enough to navigate through the smaller gaps, so I implemented a "swerve path" following the function:

y = x^4 * tan(x) + x

To achieve this path by controlling only steering, the steering angle is controlled by the derivative of this function, or:

y' = x^4 * sec(x)^2 + 4x^3 * tan(x) + 1

Where the change in the x value is inversely proportional to the distance between the detour midpoint and the center of the image while -1.3 <= x <= 1. However, since a steering angle of 0 is represented as a vertical line, the actual steering function follows:

theta = 1/y'

The car resumes its previous road-following algorithm once the cubic path is completed.

## Benefits of this Method

- Scalable: works with any number of obstacles or road size

- Robust: is not affected by mis-alignment

- Computationally economical: computes evasive trajectory using a single row from an image and a single algorithm

## Drawbacks

- Linescan must be close to front of car to not affect road tracking, so evasive trajectory is rather late and sharp, sometimes causing the car to tilt

- While the car does not completely crash, the back of the car occasionally clips barrels

View source code here