The code is a very simple state machine. I shall post a flow diagram if I can figure out an appropriate CAD tool.
Can (should?) middle school kids be asked to deal with the uncertainties of the real world? I think this TOY level car demonstrates that ambiguity in an appealing and dramatic fashion.
The code consists of a set of hardware related constants which need not be changed.
11 Variable definitions and the following four car behavior constants.
frontdanger - 12 inches
stopreversing - 26 inches
frontfree - 72 inches
desiredtrack - 36 inches
A routine that triggers the SONARS and puts the code in a tight loop when the radio transmitter has been turned on.
Six IF statements. These are each state machines. They evaluate the SENSOR data and tell the wheels what to do. Their labels are:
CheckIfInDanger
TryLeftTurn
TooCloseToWall
TooFarFromWall
ReverseOutOfTrouble
Keepreversing
At one level all the students need to modify are the constants. At another level they can modify these six IF statements. An advanced student could add more states.
Ken
Bookmarks