Pseudo code help - Using Sections of code based on variables and sensors

Hi,

I am working on a project where the vehicle has to navigate a course. Here's a link to what I've done so far: - YouTube
That was all done off timing delays which was not very accurate.

I have added 4 infrared sensors (1 each side and 2 at the front) to allow the vehicle to know if it is going off the table and to know when to stop before dropping the bridge.

For the first leg (straight and turn right) I will use timing. Then after that I want to use the side sensor to make the left turn and carry on until the two front sensors reach the edge of the table. Then use timing to drop the bridge, drive across, winch up the bridge and make a left turn. Then use the sensor on the other side to prevent driving off the edge on the way to the finish.

I was thinking about using an arbitrary variable and then updating it based on conditions such as: if the first leg has been completed or if both front sensors are off the table etc. but I am not quite sure how to code it so some pseudo code would be great.

Pretty much i want to constantly check the sensors (for the sensing sections) then once its finished its leg, update the variable to start the next section. - If there's a better way code this course then any suggestions are appreciated

Any extra can be provided if need.

Thanks for your time.

You are describing a state machine which is a sensible way to approach the problem.

Each state has a finite start point and a finite end point and the system moves to the next state when some condition(s) become true. To program this it is handy to use the switch/case construction. Whilst in each state you perform any actions needed to take the system to the point where it moves to the next state and so on. Your main problem is probably going to be turning accurately as the sensors cannot help with this as they have no point of reference unless you can use them to measure the distance from the low walls to establish that the vehicle is at exactly 90 degrees to them. Depending on the layout of the course this may or may not be possible.

Good luck with your project.