This is the program to be run on the competitors JackBords for the juniors robot wars competition on the 3rd Dec 2020 at Paraparaumu College.
The claw servo is connected to pin a3 and is used to open and close the claw when the user presses the u1 button on the drive page or the u2 button.
This program assumes there are two bumpers on the robot connected to pins A1 & A2. These are the triggers. There is also an RGB LED attached to pins C1 to C3 on port C in the following manner:
C1 = RED
C2 = GREEN
C3 = BLUE
When the program starts the LED will flash green several times.
The robot will start with a health of 10.
When a bumper is triggered a random value between -6 and 6 will be generated and added to the robots health. Thus if the value is negative the health will go down and if positive it will go up. The RGB LED will flash a color ONCE if the health was positive and TWICE if negative. The health colors will be:
End of the Round:
If the number of triggers is 10 then the robot died and the LED will show RED.
If the robot ran out of health it will show BLUE.
Robot Death Cause:
BLUE Health <= 0
Note: Make sure you set the program to run at boot with the setboot command.
eg if its in program slot 2 use setboot 2
Junior Robot Wars Program
3 Dec 2020
repeat 10 -> tg c2|d100
-- Setup the bumper pins A1 & A2
btp a1 do_boom
btp a2 do_boom
btp u1 svp a3 120
btp u2 svp a3 0
any /health <= 0 ->
"XXXXXX WE DIED XXXXX"
inc /died 2
repeat 10 -> tg c1|d50
-- Exit if many hits
any /hits >= 10 -> inc /died|exitnow
The mine is triggered work out the health or damage.
-- Get a new random number between -6 and 6.
rand -6 6 -> /hit_result
-- Update the health var
add /health /hit_result -> /health
-- Flash for neg /hit_result ie deduct health
any /hit_result < 0 -> /flashes 2
-- Count no of hits
print "T /hits TR /hit_result H /health F /flashes"
-- Display hit result on RGB LED
show_hit_color /hit_result /flashes
show_hit_color /hit_color 0 /hit_flashes 0 =
-- All c off
-- Get abs version of color
abs /hit_color -> /hit_color
repeat /hit_flashes ->
-- Set the color on Port C
ant /hit_color ->
= 1 -> c1 1
= 2 -> c2 1
= 3 -> c3 1
= 4 -> c2 1|c3 1
= 5 -> c1 1|c3 1
= 6 -> c1 1|c2 1
-> c1 1|c2 1|c3 1
RED = Died from Hits
BLUE = Died from Health
ant /died ->
= 1 -> "Died Hits"|c1 1
= 2 -> "Died Health"|c3 1
-> c2 1
-- clear the buttons