Junior Robot Wars 25 Nov 2020

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:

0 WHITE
1 RED
2 GREEN
3 BLUE
4 CYAN
5 PURPLE
6 YELLOW

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:
RED Hits
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

Program


---

Junior Robot Wars Program

3 Dec 2020

---


prog_vars =


d/hits 0

d/hit_result 0

d/health 10

d/flashes 0

d/died 0

prog_vars.


prog_start =


"Mine Start"

coff

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


prog_start.


prog_loop =

any /health <= 0 ->

-- Dead

"XXXXXX WE DIED XXXXX"

inc /died 2

repeat 10 -> tg c1|d50

exitnow

enda.


-- Exit if many hits

any /hits >= 10 -> inc /died|exitnow

prog_loop.




do_boom =

---

The mine is triggered work out the health or damage.

---

/flashes 0

-- 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

inc /hits

print "T /hits TR /hit_result H /health F /flashes"


-- Display hit result on RGB LED

show_hit_color /hit_result /flashes


do_boom.


show_hit_color /hit_color 0 /hit_flashes 0 =


-- All c off

coff

-- 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

ant.

d100

coff

repeat.


show_hit_color.

prog_stop =

---

RED = Died from Hits

BLUE = Died from Health

---

coff

ant /died ->

= 1 -> "Died Hits"|c1 1

= 2 -> "Died Health"|c3 1

-> c2 1

ant.

-- clear the buttons

rstb

prog_stop.