|
|
Knightrous
Site Admin
Joined: 15 Jun 2004
Posts: 8511
Location: NSW
|
@Grotto: I've been working for a few months on my own picaxe relay on/off and PWM speed controller projects using the 08M PicAXE chip. I have one of my boards in a robot that is currently used for weapon switching. I haven't had any problems with power spikes or the like with my current setup, but it hasn't been in full combat yet. I did find that if you give the 08M too much work, it will get caught up in lag. I had a counting system in my failsafeing code and it caused a few issues I'm still trying to fix. It worked fine on the little test bed, counting and watching the input signals, but when we went to the real thing, it wouldn't failsafe till arond 3 seconds after you killed the TX. If you killed the RX it just stayed on...
I believe it's something to do with the way I've written my code as I've only had about 1 years of on/off self taught programming with the PicAXE chips. If you have MSN, I'd like to catch up with you on there and chat about PicAXE chips and coding. If your not an MSN user, we can just use the PM system on the forums
If your interested in a bit of my code, swing into the build threads and look for my build thread titled "Pulse 50 Speed Controllers - TDT - QLD". Flick to the last page, and you'll see my latest edition of code. _________________ https://www.halfdonethings.com/
|
Sat Jan 07, 2006 4:02 pm |
|
|
Spockie-Tech
Site Admin
Joined: 31 May 2004
Posts: 3160
Location: Melbourne, Australia
|
Here is the current version of the PRC code..
Note that this is presently set for use of opto-couplers on the Servo Inputs, which means it times an active *low* pulse (since Opto's invert the signal).
To use it without Opto's, change the second parameter on each of the pulsin caommands to a "1" (look for a 1 or high input). eg. pulsin 0,1,chan1 'get Radio Control Channel 1 pulsewidth.
Our present idea is to use small logic-level relays on the outputs which then switch the coils of the larger motor relays, and use a Receiver battery to completely isolate the PicAxe and Receiver from the Robots main power batteries which are subject to the big spikes when two relays, 2 or 4 motors start, and a 100+ amp load spike hits the power supply.
The next event should see how well this idea works..
Also, note the quadrant diagram comments (the messed up formatting bit - it works in a monospaced font), doesnt correspond to the code exactly, since Rick (Moth) changed the side-stick movements to only drive 1 motor at a time to make the side steering less twitchy..
code:
;--------------------------------
; PRC - Pic Relay Controller - v4.0x
; Copyright Nov 2004 Brett Paulin
; Oct04 - Hysteresis Bug Fix by Ajax
; Dec04 - Failsafe Trigger Points re-tuned
; May05 - Pulse-in inverted for Opto-isolaters
; May05 - Quadrant control adjusted to reduce main turn rate
; May05 - Channel_3 mask bug fixed by Moth
; written for PicAxe 18X micro
; www.robowars.org
;--------------------------------
setfreq m8
;-General Definitions
symbol failsafe_trig = 3
symbol failsafe_max = 12
;-RC Channel Definitions
symbol fail_low =60 ; (old 60) failsafe below here
symbol fail_high =240 ; (old 240) failsafe above here
symbol low_on =120 ; (old 120) low activate point
symbol low_off =135 ; (old 135) low deactivate point
symbol high_off =175 ; (old 175) high deactivate point
symbol high_on =180 ; (old 180) high acticate point
;--- Memory Register Usage Definitions
symbol failsafe_float=b0 ; current block error rate
symbol ch1mode=b1 ; channel 1 mode
symbol ch2mode=b2 ; channel 2 mode
symbol ch3mode=b3 ; channel 3 mode
symbol outpins=b4 ; output pins data
symbol start_flash=b5 ; startup led flash
symbol chan1 = w3 ; b7 + b6 - channel 1 timing word value
symbol chan2 = w4 ; b9 + b8 - channel 2 timing word value
symbol chan3 = w5 ; b10 + b11 - channel 3 timing word value
;--- I/O Pin Definitions
symbol ch1_fwd = %00000001 ; binary bit patterns to mix in
symbol ch1_mid = %00000000 ; to output pins for relay/led
symbol ch1_bck = %00000010 ; activation / deactivation
symbol ch2_fwd = %00000100
symbol ch2_mid = %00000000
symbol ch2_bck = %00001000
symbol ch3_fwd = %00100000
symbol ch3_mid = %00000000
symbol ch3_bck = %01000000
;- Mixing Mask Definitions
symbol ch1_mask = %11111100 ; which bits should be masked off
symbol ch2_mask = %11110011 ; for logical OR mixing process
symbol ch12_mask = %11110000
symbol ch3_mask = %10011111 ; Fixed potential bug here ---------
symbol failsafeout = %00010000
failsafe_float = 11
flash_led: ; Flash the fail safe Led at startup
for start_flash = 1 to 20
let pins = failsafeout
pause 400
let pins = ch1_mid
pause 400
next start_flash
;--------------------------------
main_loop:
setfreq m4 ; Reduce cpu speed as command has probs
pulsin 0,0,chan1 'get Radio Control Channel 1 pulsewidth
pulsin 1,0,chan2 'get Radio Control Channel 2 pulsewidth
pulsin 2,0,chan3 'get Radio Control Channel 3 pulsewidth
setfreq m8 ; Double cpu speed for rest of prog
if chan1 < fail_low or chan1 > fail_high then goto failsafe
if chan2 < fail_low or chan2 > fail_high then goto failsafe
if chan3 < fail_low or chan3 > fail_high then goto failsafe
failsafe_float = failsafe_float - 1 MIN 1
if failsafe_float > failsafe_trig then goto shutdown
if failsafe_float < failsafe_trig then goto chan1_test
goto shutdown
;**********
chan1_test:
if chan1 < low_on then chan1_low
if chan1 > low_off and chan1 < high_off then chan1_mid
if chan1 > high_on then chan1_high
if chan1 > high_off and ch1mode = 0 then chan1_mid
if chan1 > low_off and ch1mode = 255 then chan1_mid
goto chan2_test
chan1_low:
ch1mode=0 ; channel 1 is low (full back)
goto chan2_test
chan1_mid:
ch1mode=127 ; channel 1 is centered
goto chan2_test
chan1_high:
ch1mode=255 ; channel 1 is high (full forward)
goto chan2_test
;**********
chan2_test:
if chan2 < low_on then chan2_low
if chan2 > low_off and chan2 < high_off then chan2_mid
if chan2 > high_on then chan2_high
if chan2 > high_off and ch2mode = 0 then chan3_mid
if chan2 > low_off and ch2mode = 255 then chan3_mid
goto chan3_test
chan2_low:
ch2mode=0 ; channel 2 is low (full back)
goto chan3_test
chan2_mid:
ch2mode=127 ; channel 2 is centered
goto chan3_test
chan2_high:
ch2mode=255 ; channel 2 is high (full forward)
goto chan3_test
;**********
chan3_test:
if chan3 < low_on then chan3_low
if chan3 > low_off and chan3 < high_off then chan3_mid
if chan3 > high_on then chan3_high
if chan3 > high_off and ch3mode = ch3_bck then chan3_mid
if chan3 > low_off and ch3mode = ch3_fwd then chan3_mid
goto mixing
chan3_low:
ch3mode=ch3_bck
goto mixing
chan3_mid:
ch3mode=ch3_mid
goto mixing
chan3_high:
ch3mode=ch3_fwd
;******
mixing:
outpins = pins ; get current pins state
outpins = outpins & ch12_mask ; mask off current ch 1 + 2 output state
if ch1mode=0 and ch2mode=127 then bkwd ; check channel 1 and 2 modes
if ch1mode=127 and ch2mode=127 then stp ; and determine 9-point quadrant
if ch1mode=255 and ch2mode=127 then fwd ; position
if ch1mode=0 and ch2mode=255 then bkwd_right
if ch1mode=127 and ch2mode=255 then right
if ch1mode=255 and ch2mode=255 then fwd_right
if ch1mode=0 and ch2mode=0 then bkwd_left
if ch1mode=127 and ch2mode=0 then left
if ch1mode=255 and ch2mode=0 then fwd_left
;-------------------------------
fwd: ; mix in appropriate ouput state
outpins = outpins | ch1_fwd
outpins = outpins | ch2_fwd
goto mix_done
fwd_right:
outpins = outpins | ch1_fwd
outpins = outpins | ch2_mid
goto mix_done
; 1F & 2F
fwd_left: ; Fwd
outpins = outpins | ch1_mid ;1M & 2F 1F & 2M
outpins = outpins | ch2_fwd ;Fwd_left | Fwd_right
goto mix_done ; \ | /
; \ | /
stp: ;1B & 2F \|/ 1F & 2B
outpins = outpins | ch1_mid ;left ------|-----right
outpins = outpins | ch2_mid ; /|\
goto mix_done ; / | \
;1B & 2M / | \ 1M & 2B
;bkwd_left | bkwd_right
right: ;
outpins = outpins | ch1_fwd ; bkwd
outpins = outpins | ch2_mid ; 1B & 2B
goto mix_done ;
;
left: ;"full rate" turns removed from
outpins = outpins | ch1_mid ; left and right quadrents to
outpins = outpins | ch2_fwd ; improve driveability
goto mix_done
bkwd:
outpins = outpins | ch1_bck
outpins = outpins | ch2_bck
goto mix_done
bkwd_right:
outpins = outpins | ch1_fwd
outpins = outpins | ch2_bck
goto mix_done
bkwd_left:
outpins = outpins | ch1_bck
outpins = outpins | ch2_fwd
mix_done:
mix_aux:
outpins = outpins & ch3_mask ; mix in current weapon channel state
outpins = outpins | ch3mode
let pins = outpins
goto main_loop ; then loop around and do it all again
;--------------------------------------------------------------------------------------
;--------------------------------------------------------------------------------------
;What do if a failsafe occurs
failsafe:
failsafe_float = failsafe_float + 1 MAX failsafe_max
if failsafe_float > failsafe_trig then goto shutdown
goto main_loop
shutdown:
let pins = failsafeout
goto main_loop
_________________ Great minds discuss ideas. Average minds discuss events. Small minds discuss people
|
Sat Jan 07, 2006 4:32 pm |
|
|
|
Knightrous
Site Admin
Joined: 15 Jun 2004
Posts: 8511
Location: NSW
|
@Brett: Having just implimented the Min and Max functions into my code, it's seemed to have fixed the problem of the picaxe going into limbo counting pulses and it now failsafes Going to test out how the testbed works when running at 8Mhz. I'm sure glad there are some professional programmers around here, otherwise I'd still be swearing
I have a question for anyone who has been playing with picaxes. I'm currently looking at setting up a dead stop failsafe setup for my controllers. Having done some experimenting, I'm looking at switching the 08M on/off via the reciever. I was playing with my multi-meter checking the voltages that are given on the signal on the RX. I found that when you turn the transmitter off, the RX stops sending voltage/signals down the signal wire. So my idea is to use the low voltage on the signal lead to trigger a transistor, which turns the main power onto the 08M chip from the 5v regulator. So if the RX battery is unplugged or your TX is turned off, the whole board shuts down.
In my experimenting, I found my Hitec RX gives 1.80v at full forward, 2.45v at center stick, 3.08v at full backward and no voltage when the TX is turned off. Anyone see anything obviously wrong with my idea? I'm sure it will work, but peer review is really helpful sometimes.
Opps, Double Post _________________ https://www.halfdonethings.com/
|
Sat Jan 07, 2006 8:57 pm |
|
|
Grotto
Joined: 30 Aug 2005
Posts: 38
Location: Morisset NSW
|
Many many thanks for the code Mr Spock
I'll get around to checking it out when I get a chance.
TDT,
You can find the MIN % MAX functions in the "Mathematics"
section of the doco somewhere, thay are mathematical
functions not actual commands and so are listed in the cammand
list. Basically the functions work as follows
X + 1 MAX Y = X=X+1 but will be set to X=Y if X>Y
X - 1 MIN Y = X=X-1 but will be set to X=Y if X<Y
I hope this is understandable to you, its the way I think...
Also, the powering a picaxe (or anything) from the channels
as you suggest wont work (easily) as the voltage you are reading
is a PWM average. Its actually turning on & off really quick.
So your picaxe would be turned on&off at the same speed.
ie not terribly effective.
BUT, I am also a Hitec user too and I have one
channel on the RX that isnt used by the TX, Channel 7
on my Laser7 (6 channel) rig. It outputs a clean(checked with
an oscilloscope) and stable 4.8-5.0v voltage when the TX is on,
and 0v when its off. I use this for my Failsafe channel signal
to both to my pics and to the motors & weapon systems
(as a secondary level of redundance). I dont know how
much power(ma) it can supply, so I only use it as a
signal line (ie <1ma per device) .
Depending on your rig, you may have the same "spare"
channel.
Assuming you dont have access to an oscilloscope
you should be able to check with a multimeter that the
V+ wire is at EXACTLY the same voltage as the signal wire,
and IF your multimeter has a Frequency meter, the signal
wire should read 0.00hz.
[[if Spockie could verify my logic here, Ive had a CRO
for so long its hard to remember being without one ]]
If this pans out for you, you can use your transistor idea,
BUT I would suggest feeding the signal (directly) to an un-used
input of the picaxe and having a software failsafe, because
just powering the pic down may leave/activate weapons
by accident.
Let us know how you go...
Troll _________________ "The future is not set. There is no fate but what WE make."
........CEO Cyberdyne Systems
|
Sun Jan 08, 2006 4:39 am |
|
|
|
|
|
|
|
|
|
|
|
|