Limiting Timeout on PULSIN for Radio Control Receiver
Zoot
Posts: 2,227
I'm using a radio control transmitter and receiver for my 'bot, and my code works fine, but I am looking to obviate the length of the timeout on the PULSIN (BS2p40).
In other words, on the BS2p the length of a timeout on PULSIN is 52.428 milliseconds. If I scan the RC channels for possible pulses (if pulses are present, then you are under radio control), I have timeouts that add up to nearly 100ms -- just waiting for something that might not be there.
I tried one trick that sort of worked -- I did a COUNT over a 25ms duration, and if it only counted 1 pulse, then the program presumed there was radio control, and would do two PULSINs for the 2 channels. The only problem there is that I have a pretty cheap transmitter/receiver (AM) and it is subject to unbelievable interference from the local radio station, so I would sometimes get false positives on the count. My PULSIN routines check for good values on pulses, so the bad pulses get thrown away, but that left me right back at waiting on possible timeouts up to 100ms.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
In other words, on the BS2p the length of a timeout on PULSIN is 52.428 milliseconds. If I scan the RC channels for possible pulses (if pulses are present, then you are under radio control), I have timeouts that add up to nearly 100ms -- just waiting for something that might not be there.
I tried one trick that sort of worked -- I did a COUNT over a 25ms duration, and if it only counted 1 pulse, then the program presumed there was radio control, and would do two PULSINs for the 2 channels. The only problem there is that I have a pretty cheap transmitter/receiver (AM) and it is subject to unbelievable interference from the local radio station, so I would sometimes get false positives on the count. My PULSIN routines check for good values on pulses, so the bad pulses get thrown away, but that left me right back at waiting on possible timeouts up to 100ms.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
Comments
Receiver:
·· 'Read the signals from the receiver and sends the values to the servo control board
·· 'the signals from the servo control board is then sent to the speed controllers.
·· 'Standard Teleoperated mode unless channnel2 variable changes
DO
··· PULSIN 0,1,channel0 'Measure receiver positive pulse pin p0
··· PULSIN 1,1,channel1 'Measure receiver positive pulse pin p1
··· PULSIN 2,1,channel2 'Measure receiver positive pulse pin p2
·· 'PULSIN 3,1,channel3 'Measure receiver positive pulse pin p3 'future use
·' check receiver to activate autonomus mode actually channel 5 on receiver
·· IF channel2 < 750 THEN motorstop 'failsafe robot for loss of radio signal
·· IF channel2· > 1000· THEN AutoEVA
·· pw = channel1
·· pw1 = channel0
SEROUT Sdat, Baud+$8000,[noparse][[/noparse]"!SC", ch, ra, pw.LOWBYTE, pw.HIGHBYTE, CR]
SEROUT Sdat, Baud+$8000,[noparse][[/noparse]"!SC", ch1, ra, pw1.LOWBYTE, pw1.HIGHBYTE, CR]
"show me what the heck is going on
·DEBUG "channel0 = ",DEC channel0 ,CR
·PAUSE 1000
·DEBUG "channel1 = ",DEC channel1 ,CR
·PAUSE 1000
·DEBUG "channel2 = ",DEC channel2 ,CR
·PAUSE 1000
LOOP
****************************
Basically I test the PWM signal between two exstream values of 750 uS (stick center)to 1000 uS (semi exstream stick movement from center.) if it's out of this range then I tell the robot to stop moving. I used the DEBUG statment to find the values in this test program.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Steven Kirk Nelson (slamer)
Team K.I.S.S
Build Safe, Build Mean, Build Strong!
My quasi "problem" is the timeouts on the PULSIN commands to begin with. On the BS2p, a PULSIN times out after 52ms or so -- obviously way longer than I need to check for a good pulse (<25ms in my case). This is a precious 104ms wasted in my main program loop while the 'bot checks for RC transmission.
Now, the reflex states in my 'bot "turn off" the PULSIN commands when they are executing, and turns them back on when it is done with any reflex behaviors (in other words, it only checks -- and wastes time -- on the PULSIN commands if it's not doing something really important like avoiding a wall).
As I wrote above, the only scenario I could come up with to shorten the wait time was to COUNT for 1 good pulse, then use that to check for PULSINs, e.g.
- COUNT for < 25ms. If there is ONLY ONE pulse during that time period, THEN
- PULSIN x, Y
Since I know I've got a good pulse from the COUNT, there won't be a timeout to wait for on the PULSINs. So that cuts the time for "good" checks to about 65-75ms, and cuts the time for "no RC" to 25ms. But naturally with the noisy RC, it doesn't work. I dunno, I may have to live with it, or get another RC package that isn't subject to so much interference.
Oh, one other check that I do that helps in eliminating bad counts is to check the state of the RC pin input for a "LOW" first -- if it isn't low, then the program skips the pulsins -- a high state would indicate a pulse "in progress". You still get a good pulsin (because pulsin waits for a complete 0-1-0 state change) but waiting to check when the pin is ready shortens the time required to read the pulse.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
His name is George Steiner at GSP products. He does a lot of the (72 Mhz (AIR) to (75 Mhz )(ground) for the combat robot folks. He does good work. I mention him on this web page
http://www.teamkiss.com/newkiss1220.html
75 Mhz FM radios·are a lot better and more predictable than AM. Browse around EBAY for a deal.
·The radios·I use·are the Futaba 9CAP and the Hitec Prizum 7x. Both are capable of PCM and programable failsafes and they have a lot of mixing functions as well. (of course these are sorta high end radio systems $350.00-$600.00)
But in EVA, I'm just using them in 75 Mhz PPM mode and talking to a Novak Xxtra 75 Mhz FM·tunable ·receiver without failsafe.
· I've found that even 75 mhz PPM FM is pretty stable and predictable.·I did had to add a line of code to take care of·the nonfailsafe function or PPM·limitation. But in the long run using a slightly better·75 Mhz FM radio·will save you a lot of Trial and Terror.
By the way thanks for the tip on checking for the negative part of the PWM receiver output I'll have to try that out.... Saving a bit of processing time is usually a good thing.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Steven Kirk Nelson (slamer)
Team K.I.S.S
Build Safe, Build Mean, Build Strong!
Post Edited (slamer) : 3/14/2007 1:02:30 AM GMT