"Peggy" the Wallfinder

For our first project in ME84 we were tasked with designing a motorized robot that could sense when it was approaching a wall and stop at a predefined distance from that wall. Specifically, we were tasked with programming the robot to execute two solutions: the bang-bang control and a simple proportional control. The difference between the two solutions lied only in the code, and the robot remained the same from start to finish.

The Design

Our robot is a rear wheel drive tricycle feature a front-facing ultrasonic sensor. The underbelly of the vehicle features a basic chassis which connects the two large motors in the rear to the EV3 computer on top. The front roller wheel is connect directly the front-bottom of the EV3 and the ultrasonic sensor is mounted on the side of the EV3.

Image Image

The following images display how the motors and sensors, respectively,are connected to the EV3 brain.

As you can see, the rear left motor is connected to terminal A and the right side motor is connected to terminal B.


The ultrasonic sensor is connected to terminal 1.


The Code

Bang Bang Control

Bang Bang control uses sensor data to determine whether the car should be either moving at full speed or coming to a sudden stop and then backing up a bit.


The bang bang controller utilizes a while loop that continually updates the robot's location and then decides, based on the location, whether the motors should be on or not. Once the desired distance is reached, Peggy backs up to account for unwanted coasting.

Our code begins by printing "Test" and finishes by printing "Hello wall". This was included to ensure that the loop breaks and the code runs all the way through. Additionally, we added "print(distanceCM)" as a quality assurance measure. This line asks Peggy to report her final distance.

Proportional Control

Proportional control uses sensor data to smoothly lower the speed of the car until it comes to a gentle stop 20 cm from the wall.


This code is similar to the bang bang controller but has different features in the while loop. Each time the loop runs, it calculates a new speed based on the current distance from the wall. A statement is included to ensure that the speed is set to 1000 if the calculation yields a speed beyond the max value. When the desired distance is reached, the motors should be at zero speed. Again, like in the bang bang code, Peggy greets her new friend and reports her relative location.

Peggy in Action

Look at her go.