Simple Proportion Controller
Lesson Objectives:
- Students will build a simple LEGO car.
- Students will learn that a simple proportion controller relates two variables linearly.
- Students will learn how to program this on the EV3 IDE.
Materials:
- 2 motors
- EV3 brick with Wifi dongle and SD card (you should have access to the EV3 IDE)
- Ultrasonic Sensor
- Any other LEGO parts you need to build a car
What is a Simple Proportion Controller?
Let's say you are riding a bike when you see a wall in front of you and you decide that you want to stop 10 feet in front of the wall. If you were using a simple proportion controller, you would begin to slow down gradually as you approached the 10 feet mark rather than slam the brakes at once.
In theory, this works when moving backwards as well. If you ended up stopping 5 feet in front of the wall, you would pedal backwards fast and then slow down as you reached the 10 feet mark before finally coming to a stop.
When we build our LEGO car, we will program it so that it will maintain a certain distance in front of itself, and if there is an obstacle in front of it, it will either keep moving forward or backwards until it reaches its safe distance, or just stop if it is at the safe distance.
Let's say you are riding a bike when you see a wall in front of you and you decide that you want to stop 10 feet in front of the wall. If you were using a simple proportion controller, you would begin to slow down gradually as you approached the 10 feet mark rather than slam the brakes at once.
In theory, this works when moving backwards as well. If you ended up stopping 5 feet in front of the wall, you would pedal backwards fast and then slow down as you reached the 10 feet mark before finally coming to a stop.
When we build our LEGO car, we will program it so that it will maintain a certain distance in front of itself, and if there is an obstacle in front of it, it will either keep moving forward or backwards until it reaches its safe distance, or just stop if it is at the safe distance.
Let's Get Started!
Go ahead and make a car of your design that incorporates the EV3, ultrasonic sensor, and the two motors. Run IDE on the brick and load up the IDE on your computer by entering the IP number of the brick on a search tab.
First, we want to initialize the ultrasonic sensor and the motors we will be using. We also want to assign our safe distance to a variable so that this can be changed easily in the future, as well as a constant of proportionality (k), which determines how fast the car moves relative to the distance reading from the ultrasonic sensor.
Since we want the car to move faster when it is further away from the obstacle and slower as it gets closer, we must set the speed of the motors equal to the distance reading multiplied by the constant of proportionality (k). If we want the car to move faster in general, we can just increase the value of k.
All that is left is to tell the car when to move and when to stop. There are three different cases to consider:
An example of the code that was outlined above is shown here. Feel free to use this as a guide if you run into errors, but please try and write the code yourself with the help of the snippets provided on the IDE.
First, we want to initialize the ultrasonic sensor and the motors we will be using. We also want to assign our safe distance to a variable so that this can be changed easily in the future, as well as a constant of proportionality (k), which determines how fast the car moves relative to the distance reading from the ultrasonic sensor.
Since we want the car to move faster when it is further away from the obstacle and slower as it gets closer, we must set the speed of the motors equal to the distance reading multiplied by the constant of proportionality (k). If we want the car to move faster in general, we can just increase the value of k.
All that is left is to tell the car when to move and when to stop. There are three different cases to consider:
- If the obstacle is farther than the safe distance, keep moving forward at a constant speed.
- If the obstacle is closer than the safe distance, move backwards at a constant speed.
- Otherwise, just stay still.
An example of the code that was outlined above is shown here. Feel free to use this as a guide if you run into errors, but please try and write the code yourself with the help of the snippets provided on the IDE.