BERTIE

The basic maze-solving robot

This robot solves simple mazes by just keeping its 'hand' on the left wall


How does it work?

BERTIE senses the maze walls using infra-red sensors. It has three sensors measuring the distance to the left hand wall,
but they work like one sensor, giving a distance of:

TOO_NEAR
OK (between two and three centimetres)
TOO_FAR

or, if they can't detect a wall at all:
DISTANT

It tries to keep the distance to OK
It also has front sensors
If it detects a wall in front it turns right 90 degrees
If it detects open space it turns left 90 degrees
The program is technically a state-transition system
Basically, for each combination of the state of the sensors and the state of the robot an action sequence is defined.
Each action in the sequence is either to move forwards, turn, or set the robot state.
The initial state is 'Looking' (for the maze entrance), but subsequent states are just text and could be anything the programmer finds useful
Distance forwards is measured in millimetres. Distance to turn is measured in degrees.
So the first line means:
If:
FRONT_OFF - the front sensors detect nothing
LEFT_TOO_NEAR - the side sensors detect that the robot is too close to the left hand wall
STATE_Looking - the robot is looking for the start of the maze
Then:
STATE_Opening - the robot needs to open a bigger gap between itself and the wall
veerright_4 - turn right 4 degrees
forwards_10 - move forwards 10 millimetres

main_program1['FRONT_OFF LEFT_TOO_NEAR STATE_Looking'] = 'STATE_Opening veerright_4 forwards_10'
main_program1['FRONT_OFF LEFT_OK STATE_Looking'] = 'STATE_Running forwards_while'
main_program1['FRONT_OFF LEFT_TOO_FAR STATE_Looking'] = 'STATE_Closing veerleft_4 forwards_10'

main_program1['FRONT_OFF LEFT_TOO_NEAR STATE_Closing'] = 'STATE_Opening veerright_5 forwards_10'
main_program1['FRONT_OFF LEFT_OK STATE_Closing'] = 'STATE_Running veerright_3 forwards_10'
main_program1['FRONT_OFF LEFT_TOO_FAR STATE_Closing'] = 'veerleft_3 forwards_10'
main_program1['FRONT_ON LEFT_TOO_NEAR STATE_Closing'] = 'STATE_Running spinright_93 forwards_10'
main_program1['FRONT_ON LEFT_OK STATE_Closing'] = 'STATE_Running spinright_90 forwards_10'
main_program1['FRONT_ON LEFT_TOO_FAR STATE_Closing'] = 'STATE_Running spinright_87 forwards_10'

main_program1['FRONT_OFF LEFT_TOO_NEAR STATE_Running'] = 'STATE_Opening veerright_3 forwards_10'
main_program1['FRONT_OFF LEFT_OK STATE_Running'] = 'forwards_while'
main_program1['FRONT_OFF LEFT_TOO_FAR STATE_Running'] = 'STATE_Closing veerleft_3 forwards_10'
main_program1['FRONT_ON LEFT_TOO_NEAR STATE_Running'] = 'spinright_93 forwards_10'
main_program1['FRONT_ON LEFT_OK STATE_Running'] = 'spinright_90 forwards_10'
main_program1['FRONT_ON LEFT_TOO_FAR STATE_Running'] = 'spinright_87 forwards_10'
main_program1['FRONT_OFF LEFT_TOO_NEAR STATE_Opening'] = 'veerright_6 forwards_10'
main_program1['FRONT_OFF LEFT_OK STATE_Opening'] = 'STATE_Running veerleft_2 forwards_10'
main_program1['FRONT_OFF LEFT_TOO_FAR STATE_Opening'] = 'STATE_Closing veerleft_3 forwards_10'
main_program1['FRONT_ON LEFT_OK STATE_Opening'] = 'spinright_87 forwards_10'

main_program1['FRONT_OFF LEFT_DISTANT STATE_Closing'] = 'STATE_Turning forwards_195 spinleft_80 forwards_110'
main_program1['FRONT_OFF LEFT_DISTANT STATE_Running'] = 'STATE_Turning forwards_195 spinleft_85 forwards_110'
main_program1['FRONT_OFF LEFT_DISTANT STATE_Opening'] = 'STATE_Turning forwards_195 spinleft_90 forwards_110'

main_program1['FRONT_OFF LEFT_TOO_NEAR STATE_Turning'] = 'STATE_Opening veerright_4 forwards_10'
main_program1['FRONT_OFF LEFT_OK STATE_Turning'] = 'STATE_Running forwards_10'
main_program1['FRONT_OFF LEFT_TOO_FAR STATE_Turning'] = 'STATE_Closing veerleft_5 forwards_10'
main_program1['FRONT_OFF LEFT_DISTANT STATE_Turning'] = 'STATE_Turning_Again forwards_120 spinleft_90 forwards_80'

main_program1['FRONT_OFF LEFT_TOO_NEAR STATE_Turning_Again'] = 'STATE_Opening veerright_4 forwards_10'
main_program1['FRONT_OFF LEFT_OK STATE_Turning_Again'] = 'STATE_Running forwards_10'
main_program1['FRONT_OFF LEFT_TOO_FAR STATE_Turning_Again'] = 'STATE_Closing veerleft_4 forwards_10'

The program is in this compact form so you can easily create it by just copying the state from the diagnostics, and deciding what to do.