Tracking servos?
M. K. Borri
Posts: 279
I've started work on an enhanced autopilot thingy (let's call it navcom ai v2) and would like to know if anyone's already written the reverse of the servo pulse generator -- as in, something in assembly that takes in servo pulses on some pins and writes down in memory how long they were. If nobody's written one yet I will try to [noparse]:)[/noparse]
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
http://forums.parallax.com/showthread.php?p=650217
meow, i have my own topic now? (sorta)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
http://forums.parallax.com/showthread.php?p=650217
meow, i have my own topic now? (sorta)
Comments
This is not a runable code, but shows you the way.
Andy
In fact, I'm considering just reading the raw output from a receiver tuned to a R/C radio frequency (you know, bunch of servo-like pulses concatenated and separated by a longer pause), this way I can replace part of the RC radio altogether.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
http://forums.parallax.com/showthread.php?p=650217
meow, i have my own topic now? (sorta)
Post Edited (M. K. Borri) : 5/21/2007 2:26:54 AM GMT
The units for pulses are microseconds.
CON
· _clkmode = xtal1 + pll16x
· _xinfreq = 5_000_000
· rx1 = 1················ ' These are the I/O pins connected to R/C reciever channels r1..r4
· rx2 = 3
· rx3 = 5
· rx4 = 7
VAR
· long channels[noparse][[/noparse]4]
· long usec
PUB MAIN
' assumes and depends on pulse train order being 1-->2-->3-->4
> then eventually back to 1.
' rx1 through rx4 are Propeller I/O pins connected to R/C reciever, via 4.7k Ohm resistors and sharing common ground w/ Reciever.
' make sure pulse train from Rx is situated so that pins recieving signal is in order r1-->r2-->r3-->r4, otherwise
' sampling rate could drop as low as 12 Hz (not that that would necessarily be bad for certain data logging operations...
' GWS 'pico' 4 ch Rx has pulse sequence Rx channels 1-2-3-4. Other recievers may vary.
· usec := clkfreq / 1_000_000
· dira[noparse][[/noparse]rx1]~··························· ' set I/O to input
· dira[noparse][[/noparse]rx2]~··························· ' set I/O to input
· dira[noparse][[/noparse]rx3]~··························· ' set I/O to input
· dira[noparse][[/noparse]rx4]~··························· ' set I/O to input
· frqa := frqb := 1···················· ' enable the accumulations into PHSA and PHSB at 1 count unit per clock cycle
· repeat
··· repeat until ina[noparse][[/noparse]rx4] == 1········· ' wait for a high pulse to come by
··· repeat until ina[noparse][[/noparse]rx4] == 0········· ' and wait for I/O pin 3 to go low
··· CTRA := (%01000 << 26) + rx1
··· CTRB := (%01000 << 26) + rx2
··· PHSA := PHSB := 0
··· repeat until ina[noparse][[/noparse]rx2] == 1········· ' wait for a high pulse to start
··· repeat until ina[noparse][[/noparse]rx2] == 0········· ' and wait for I/O pin r2 pulse to finish
··· channels[noparse][[/noparse]0] := PHSA/usec··········· ' update ch_1 pulse length to RAM
··· channels[noparse][[/noparse]1] := PHSB/usec··········· ' update ch_2 pulse length to RAM
··· repeat until ina[noparse][[/noparse]rx1] == 1········· ' waits for channels 3 and 4 to pass once, otherwise about 800 clk cnts of ch3 get clipped
···
··· CTRA := (%01000 << 26) + rx3
··· CTRB := (%01000 << 26) + rx4
··· PHSA := PHSB := 0
··· repeat until ina[noparse][[/noparse]rx4] == 1········· ' wait for a high pulse to come by
··· repeat until ina[noparse][[/noparse]rx4] == 0········· ' and wait for I/O pin 3 to go low
··· channels[noparse][[/noparse]2] := PHSA/usec··········· ' update ch_3 pulse length to RAM
··· channels[noparse][[/noparse]3] := PHSB/usec··········· ' update ch_4 pulse length to RAM
This captures the incoming signal on P0 (in this case) and repeats it on P1. This allows monitoring, data logging and data manipulation.
I uploaded this example (Simple Radio Control Capture & Repeat to Servo) to the OBEX (obex.parallax.com/objects/401/).
I use also the PULSIN_uS(Pin,State)·from the·BS2_Functions,·but sometimes in my application there is no puls (RC off), so the software is waiting!. Is·it simple to add·a timeout,·the maximum amount of time to spend in the PULSIN·PUB, if there is no·puls within the timeout, than exit PUB.
idea >> PULSIN_uS(Pin,State, Timeout)
Thanks for any idea, Rob
{{ code from Travis_ }}
··DIRA[noparse][[/noparse]pin]~
··ctra·:=·0
··if·state·==·1
····ctra·:=·(%11010·<<·26·)·|·(%001·<<·23)·|·(0·<<·9)·|·(PIN)·'·set·up·counter,·A·level·count
··else
····ctra·:=·(%10101·<<·26·)·|·(%001·<<·23)·|·(0·<<·9)·|·(PIN)·'·set·up·counter,·!A·level·count
··frqa·:=·1
··waitpne(|<·Pin,·|<·Pin,·0)·························'·Wait·for·opposite·state·ready
··phsa:=0··················································'·Clear·count
··waitpeq(|<·Pin,·|<·Pin,·0)·························'·wait·for·pulse
··waitpne(|<·Pin,·|<·Pin,·0)·························'·Wait·for·pulse·to·end
··Duration·:=·phsa·········································'·Return·duration·as·counts
··ctra·:=0
·