This is team MachFive's project report for IAP 2018 RACECAR.

### Team Members

- Alon Kosowsky-Sachs
- Danilo Roascio
- Jack Strang
- Antonio TerĂ¡n Espinoza

### Results

**Winners** of the 2018 IAP edition, with a record time of **32.724 seconds**. Our remaining timed laps were:

- 33.242 seconds
- 33.712 seconds
- 33.973 seconds
- 34.874 seconds

Here's a video of our runs:

### Approach

The idea behind our controller is to always navigate parallel to the wall at a given distance. In order to achieve this, we want to angle away from the wall when we are too close, parallel to the wall when at the appropriate distance, and towards the wall when we are too far; this behaviour is depicted in the image below.

We use a proportional controller to set our rotational velocity to meet the desired angle and set the desired angle proportional to the error in our desired distance from the wall. This control scheme allowed the car to drive without oscillating around the desired distance.

Additionally, for this controller to work, we need to know the robot's angle relative to the right wall and its distance from the right wall. To do this, we sweep the LiDAR on the right side (as shown in the image below) and compute a linear regression through the points. Using the slope and intercept of this line, the robot can estimate its distance and angle to the wall.

This control scheme lets us gracefully turn. At a left turn, the regression will cause the car to think that the right wall is where the dotted red line in the picture below is. This will cause the robot to turn to the left. As the robot turns, the top wall will dominate the sweep, causing the regression to match the top wall, thus forcing the robot to follow the top wall.

A similar mechanism occurs at a right turn; the regression cuts across the corner so the robot will turn across the corner, as is shown in the image below.