RC indoor air combat using 08M2's


New Member
Our local model airplane club flies outdoor when weather allows. During autum and winter we rent an indoor gym, and fly indoor.
With very light depron and EPP airplanes.
Since the indoor environment challenges with it's stone walls (that cause damage to the plane when you hit them) it is exciting for a while, but then begins to repeat itself in the small circles possible...it becomes boring.

To bring excitement back I designed small modules (tags) that emit IR signals, and can receive them. These tags can be used to play airplane combat.
The design is simple, the code also. All you need is an airplane with a free PWM channel to fire the IR gun on the tag.
When the IR hits someone, their tag registers the hit.
There are challenges in reloading when ammunition runs out, and you can get lethal dammage (you can't shoot anymore).
Every plane needs a tage, with a different unique number.

The 08M2 supports SONY 12 bit code. And so does the Maximite Colour computer. I have a maximite and 24" monitor connected to a target that can be used for practise. It registers the shots from the 08M2 tags, and shows a highscore list. This same setup can be used to "read" the history from the tags, so you know who killed you...

If there is interest I can put some photo's, and a schematics of the circuit.

For now only the software listing. Simple.
'------------------------------------------IR COMBAT ---------------------------------------

'it is a progam for IR combat with RC planes (indoor). Needed is a free channel on the receiver,
'that can be controlled from a FIRE button on the transmitter (i.e. the GEAR switch)

'Each plane has a IR tag, that fires IR pulses under command of the FIRE button, and an IR receiver,
'that senses competitors gun fire. Each plane has XX bullets to fire and can handle YY hits before
'it is destroyed. Each plane has a unique ID.

'Refil of ammunition can happen in 2 ways.
'1/ landing, and keeping throttle at minimum for 5 successive seconds. The tag must be connected
'with the throttle channel.
'2/ continue flying for 30 seconds, and then ammo is refilled. This is the case when throttle is
'not connected to the tag.

'Lethal damage to the plane is visible through a LED that is lit constantly, and firing is
'inhibitted. The only way to repair is to power down the complete plane, and power UP again.

'Hardware PICAXE 08M2
'   pin   IO
'    8    GND
'    7    0=IR output LED (high = on)
'    6    1=throttle channel from receiver, res to gnd if not used
'    5    2=status LED (high=ON, shared with programming TX pin)
'    4    3=FIRE chanel from receiver
'    3    4=IR input sensor
'    2    5=gnd (programming RX pin)
'    1    +5V

'Versions ------------------------------------------------------------------------------------------
'    0.1    Throttle connected everything works.
'           Known problem: you cannot be hit while ammo is empty. Need to add gameplay when
'           no throttle signal (time out on pulsin).
'    0.2    implement "no throttle", needs pull down at throttle pin to prevent noise
'    0.3    added comments for better understanding.
'    0.4    changes from playing with it and score board -2020- version
'    0.4p    pinout change for breadboard soldering, LED inverted
'    0.5/0.5p    added dump of hits after code 127 received

'Game Play -----------------------------------------------------------------------------------------
symbol AMMO = 100        'guns bullets
symbol SHLD = 10         'lethal damage level
symbol ME = 3            'unque tag number 0...127
symbol GROUNDED = 25     '25 x 200msec loops to refil ammo
symbol REPLENISH = 30    '30 seconds brute force wait for new ammo

'IO pins -------------------------------------------------------------------------------------------
symbol LED = 0    '0 old, 2 new
symbol FIRE = 2   '2 old, 3 new
symbol THR = 1
symbol IRI = 3    '3 old, 4 new
symbol IRO = 4    '4 old, 0 new

'memory variables ----------------------------------------------------------------------------------
symbol TMP = w0             'b0/b1 for measuring PWM pulse width
symbol THR_IDLE = w1        'b2/b3 PWM pulse width when trhottle = idle
symbol CNTR = b4            'counts 200msec loops for ammo refil
symbol BULLETS = b5         'number of bullets left
symbol HEALTH = b6          'life counter, 0 = dead           
symbol OPPONENT = b7        'unique ID of TAG of opponent that hit you

'----------------------------------------- INIT the TAG --------------------------------------------
    'wait 1 Sec for the 2.4GHz receiver to lock, and stabilize
    high LED
    pause 1000
    low LED
    'life at maximum, no way to restore except repower

    'first check if there is a throttle pulse at all.
    'this has a double function. It checks if the tag has THR attached. And if it has, it
    'uses that value THR_IDLE as a reference for motor_off.
    pulsin THR,1,THR_IDLE         'if no pulse, time out after 1 second, value 0 returned
    if THR_IDLE = 0 then main2    'else value in 10uSec ticks (120 = 1200uSec = 1.2mSec)

    'real value: this value is used later to determine that the airplane is on the ground.
    'throttle values between 1.0msec and 1.2msec are assumed valid.
    if THR_IDLE > 120 then start
    if THR_IDLE < 100 then start
    'add a small offset to cope with jitter
    goto main2 'force 30sec immunity during takeoff

'------------------------------------------ COMBAT PHASE ---------------------------------------------
'here we check if we must fire and do the firing (total time around 100ms), if not we listen to the
'IR sensor (100ms) to see if we are hit. This loops forever. In each loop there is a test for
'ammo and health. Both cases we escape the loop.

    'measure FIRE input pulse width in 10uSec ticks and store in w0
    'this value jitters +/-1. For this application jitter is unimportant.
    pulsin FIRE,1,TMP
    'check is pulse shows FIRE is active (<1.5mSec)
    if TMP < 150 then    'less than 1.5msec
        if BULLETS > 0 then
            'fire the (IR) gun, this takes some 20-30msec
            irout IRO,1,ME
            'lower ammo
            BULLETS = BULLETS - 1
            'flash led to see that we have fired
            high LED
            pause 40
            toggle LED
            pause 30
        end if   
        'check if we are hit during 100msec
        irin [100,nohit] , IRI, OPPONENT
        'if hit then register hit
        ' here we store hits in eeprom and read later into computer for ratings.
        write HEALTH,OPPONENT
        HEALTH  = HEALTH  - 1

nohit:      'not hit

        '  debug - costs 150 msec ***********************
        '  debug end ************ ***********************

    'check for ammo and refil routine if so
    if BULLETS  = 0 then main2
    'check for health, and stop forever all if we are dead. only repower can revive us.
    if HEALTH  = 0 then
        high LED
        'stop    '-or- infinitely wait for dump command, then dump hit list

'this section needs testing first
        'check for the pulses from the dump remote control       
        irin [100,readout] , IRI, OPPONENT
        if OPPONENT = 127 then
            'dump EEPROM content for all hits
            for CNTR=0 to SHLD
                toggle LED
                read CNTR,TMP
                pause 100
                irout IRO,1,TMP
                toggle LED
                pause 500
            next CNTR   
        end if
        goto readout
    end if
    'we are in good shape, go for next loop
    goto main1

'------------------------------------------ REFIL AMMO -----------------------------------------
' refilling ammo either through waiting, or checking if the plane has been grounded for 5 seconds.
    'check if there is throttle channel connected, is there a pulse at all
    if THR_IDLE = 0 then wait30
    'measure the throttle input pulse for 5 seconds, and make sure we stay on the ground
    'if we repeat this test every 200mSec, we need 25 iterations for 5 seconds
    'until condition met, toggle the led 5x per second (fast)
    for CNTR = 0 to GROUNDED
        pulsin THR,1,TMP
        if TMP > THR_IDLE then
        end if
        toggle LED
        pause 10
        toggle LED
        pause 180
    next CNTR
    'we have been grounded for 5 seconds, restore ammo, damage remains
    goto main1
    'throttle not connected, do a brute force wait 30 seconds
    'LED blinks short short wait
    for CNTR = 0 to REPLENISH         '30x1000msec = 30 sec
        high LED
        pause 10
        toggle LED
        pause 180
        toggle LED
        pause 10
        toggle LED
        pause 800
    next CNTR   
    goto main1