Joe O'Reilly

Task Sheet 7

23 Jan 2012

7.1

Choice of Sensors

Sensor Advantages Disadvantages
Bump Sensor Instant binary feedback Not easy to tell direction of bump if using an arm
Ultrasonic Sensor We can respond according to how far we are from objets Only works well when parallel, sensor error is common
Light Sensor Can respond to dynamic changes in the environment Can easily become trapped in a dark place

We setup the robot with one forwards facing bump sensor and two sideways facing ultrasonic sensors. This allowed us to account for most of the situations that the robot might encounter, including but not limited to:

The Final Robot Configuration

Here are all the algorithms used excodessed in pseudo code.

Action loop

forever

    if bump = true
    do bump

    if correct = true
    do correct

    if turn = true
    do turn

    if corridor = true
    do corridor

    if wall = true
    do wall
loop

Subsumption loop

do setup

forever

let action = 0

if left > 27 
let action = 1

if right > 27
let action = 2

if (left < 7 | right < 7)
let action = 3

if action = 0
let corridor = true

elif action = 1
let wall = true

elif action = 2
let turn = true

else
correct = true

loop

Reading loop

forever

let left = reading left
let right = right reading

display "L :" + left
display "R :" + right

loop

Behaviour for Bump

to bump

display "bump"
backwards 6cm

if right + left < 22.5   
do escape
do choose 180 
backwards 10cm

else

if right + left > 40
    do choose 180

else
    if right < 10 
        backwards 10cm
        curveleft

let turn = false // codevents erroneous turn detection
let bump = false // stops this being called again

end bump

Behaviour for Correct

to correct

display "correcting"
backwards 7cm

if left < 7
do pointTurnRight 22.5°

else
do pointTurnLeft 22.5°

forwards 1cm

end correct

Behaviour for Turn

to turn

display "turning"

if left < 10
backwards 10cm
curveRight 90°
forwards 10cm

else
forwards 5cm
pointTurnRight 90°
forwards 25cm

if bumped
do setup
let bump = true

let turn = false

end turn

Behaviour for Corridor

to corridor

display "Corridoring"
let errorcodevious = right - left
move forwards .35 rotations // To create a small difference between initial errorNow and errorcodevious readings

while corridor = true

let errorNow = right - left

if errorNow > 0 

    if errorNow < errorcodevious
        forwards .35 rotations

    else
        steer towards left .35 rotations
        forwards .35 rotations

else

if errorNow > errorcodevious
    forwards .35 rotations

else
    steer towards right .35 rotations
    forwards .35 rotations

let errorcodevious = errorNow

if bumped
    do setup
    let bump = true

loop

end corridor

Behaviour for Wall Following

to wall

display "Wall Following"

let codev = right

move forwards .35 rotations // To create a small difference between initial codev and now readings

while wall = true

let now = right

if now > 12 // This is the target wall following distance

    if (now - codev) > 0
        steer towards left .35 rotations
        forwards .35 rotations

    else
        forwards .35 rotations

else

    if (now - codev) < 0
        steer towards right .35 rotations
        forwards .35 rotations

    else
        forwards .35 rotations

let codev = now

if bumped
    do setup
    let bump = true

loop    

end wall

Behaviour for Escaping

to escape

display "Escaping!"
let errorcodevious = left - right
backwards .35 rotations // To create a small difference between initial codev and now readings

while (right + left) < 22.5

let errorNow = left - right

if errorNow > 0

    if errorNow < errorcodevious
        backwards .35 rotations

    else
        backwards steer towards right .35 rotations
        backwards .35 rotations

else

    if errorNow > errorcodevious
        backwards .35 rotations

    else
        backwards steer towards left .35 rotations
        backwards .35 rotations

    let errorcodevious = errorNow

loop 

let codevious = left
backwards .35 rotations // To create a small difference between initial codev and now readings

repeat(2)

let now = left

if now > 17.5

    if (now - codevious) > 0
        backwards steer towards right .35 rotations
        backwards .35 rotations

    else
        backwards .35 rotations

else

    if (now - codevious) < 0
        backwards steer towards left .35 rotations
        backwards .35 rotations

    else
        backwards .35 rotations

let codevious = now

loop

end escape

Behaviour for Setup

to setup

let bump, correct, turn, corridor, wall, escape = false;

end setup

Miscellaneous Functions

Here are downloads of our maze solving files

Next

Professional Issues - Blog entry 1

Previous

AI - Task Sheet 6