Home    Worksheets    Subroutines   

Help sheet 111:
Straighten against a wall

This sheet shows you how to use a wall to straighten the  buggy's path

Suppose your buggy has just detected a wall and stopped.
You want to spin 180 degrees in order to come back in the other direction.

One way of doing it is to use the spin180L subroutine and make sure the pause value is exactly  right so that the buggy is facing in its new direction.

Another is to reverse back into the wall after turning, so that the bumper at the back is forced flat against the wall

1)  A simple example:
'---A simple state -------------

'------- run ahead to wall
        do until input1=1
          gosub fwd
'---- the front is now touching the wall -------
        gosub spin180
        gosub rev     ' reverse for 1/10 a second
'---- the back bumper is now touching the wall -

'   . . . .  go on your way 

'----------end of main program---
This program starts by running forwards till the wall is touched.



It then spins 180 degrees

It then reverses back into the wall to straighten up

It uses "gosub fwd" to run forwards. 
It uses
"until input1=1" to detect the wall. 
It uses "gosub rev" to reverse for 1/10 a second.  You'll find subroutine rev on the Subroutines page.

2)  Adjustment

You might find that a single " gosub rev " is not enough to straighten completely.
If so, use two or even three of them.


Content Scl Version 18/04/07