;The code for the Senate Bus Borg!

 

global [count black]

 

to drive ; drives the bus around the track

initialize

determine-driver

end

 

to determine-driver ; randomly chooses which driver you get

ifelse random 2 [sobriety] [drunk-driver]

end

 

 

to drunk-driver ; the not-very-good driver

play-whatislove

go-straight

loop[

if (front-bumper)

[setcount (count + 1) print count backup-and-eject go-straight]

if (sees-black left-sensor) [turn-left]

if (sees-black right-sensor) [turn-right]

if (count = 4) [stop]

]

 

end

 

to sobriety ; the better driver

play-wheelsbus

go-straight

loop[

if (sees-black left-sensor)

[turn-left]

if (sees-black right-sensor)

[turn-right]

if (and (not sees-black left-sensor)

(not sees-black right-sensor) )

[go-straight]

if (front-bumper)

[setcount (count + 1) backup-and-eject]

if (count = 4) [stop]

]

 

end

 

to backup-and-eject ; to back up from building and eject the person

stop-motion

go-backwards

launch [repeat 5 [note 79 4 wait 3]]

wait 30

turn-right

wait 47

stop-motion

wait 20

eject

end

 

to play-wheelsbus

;Plays 'The Wheels on the Bus'

 

note 60 3 note 65 2 wait 1 repeat 3 [note 65 1 wait 1] wait 1 note 69 2 wait 1 note 72 2 wait 1 note 69 2 wait 1 note 65 4 wait 2 repeat 2 [note 67 2 wait 1] note 67 4 wait 2 note 64 2 wait 1 note 62 2 wait 1 note 60 3 wait 1 note 60 3 note 65 2 wait 1 repeat 3 [note 65 1 wait 1] wait 1 note 69 2 wait 1 note 72 2 wait 1 note 69 2 wait 1 note 65 5 wait 1 note 67 5 wait 1 note 60 5 wait 1 note 65 6 wait 2

 

end

 

to play-whatislove

; Plays "What is Love?" By Haddaway, arrangement by R.Bargoot

 

repeat 2 [note 64 3 note 67 3 note 69 5 wait 8 note 64 2 note 65 2 wait 1 note 64 2 wait 1 note 67 4 wait 1 note 64 3 wait 9 note 64 2 wait 1 note 67 4 wait 1 note 64 4 wait 8 note 64 2 wait 1 note 62 4 wait 12]

 

end

 

;SUB-PROCEDURES GOVERNING SENATE BUS MOTION

 

to go-straight ; to go straight

left-wheel on thisway

right-wheel on thatway

end

 

to go-backwards ; to go backwards

left-wheel on thatway

right-wheel on thisway

end

 

to turn-left ; to turn-left

right-wheel on thatway

left-wheel off

end

 

to turn-right ; to turn-right

left-wheel on thisway

right-wheel off

end

 

to eject ; to turn on conveyor belts and kick person out

convey-motor thatway onfor 45

kick-motor onfor 7

end

 

to stop-motion ; to stop the bus from moving

left-wheel off

right-wheel off

end

 

to initialize ; to initialize settings, including variables

setcount 0

setblack 135 ; default threshold

left-wheel setpower 8

right-wheel setpower 8

kick-motor setpower 8

convey-motor setpower 8

 

end

 

 

;MOTOR AND SENSOR ASSIGNMENTS

 

to sees-black :sensor-value ; denotes threshold where the sensor is reflecting black

output :sensor-value > black

 

end

 

to left-wheel ;left-wheel is motor a

a,

end

 

to right-wheel ; right-wheel is motor b

b,

end

 

to convey-motor ; conveyor motor is motor c

c,

end

 

to kick-motor ; kicking motor is motor d

d,

end

 

 

to left-sensor ; the left reflective sensor is in port 0

output sensor 0

end

 

to right-sensor ; the right reflective sensor is port 1

output sensor 1

end

 

to front-bumper ; the front switch is in port 7

output switch 7

end

 

Back to home