STEAM DISCOVERY LAB
  • About
  • Tools
  • Projects
  • Resources
  • Product
  • About
  • Tools
  • Projects
  • Resources
  • Product
Search

Bang-Bang Controller


​Lesson Objectives:
  1. Students will build a simple LEGO car.
  2. Students will learn that a bang-bang controller switches abruptly between two states.
  3. 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 Bang-Bang 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 bang-bang controller, you would keep biking at the same speed and slam the brakes the second before you reached the 10 feet mark.

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 until you reached the 10 feet mark and then 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.

All that is left is to tell the car when to move and when to stop. There are three different cases to consider:
  1. If the obstacle is farther than the safe distance, keep moving forward at a constant speed.
  2. If the obstacle is closer than the safe distance, move backwards at a constant speed.
  3. 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.
Picture
Picture
200 Boston Ave, Medford, MA 02155
steamdiscoverylab@gmail.com
Center for Engineering Education and Outreach
​Tufts University
About
Tools
Projects
Resources
​
Contact
LEGO®, the LEGO® logo, the Brick, MINDSTORMS®, and the Minifigure are trademarks of ©The LEGO® Group. On some parts of this site  you will get access to so-called “developer software”, which offers documentation on different ways to operate the LEGO® Education SPIKE™ Prime Hub and technology. Whatever use you make of the developer software, bear in mind that the results are not experiences that the LEGO Group endorses, is with or will be liable for. No rights in or to trademarks of the LEGO Group are implied or given, and you may not apply to or register any protection anywhere in the world for intellectual property or industrial rights or similar in respect of any developer software, derivative or other result achieved through its use. The developer software is made available “as is” and, to the extent possible, no warranties or representations are implied or given in relation to it by the LEGO Group. It’s your responsibility to ensure all uses that you make and enable others to make comply with all applicable laws and best practices. By accessing the developer software, you acknowledge that the terms and conditions set out above and in LEGO Education’s terms of use for SPIKE Prime apply.
  • About
  • Tools
  • Projects
  • Resources
  • Product