?How to interface basic stamp with servo output of r/c radio reciever?
mikea
Posts: 283
I'm new to microcontrollers and would like to find a way for the basic stamp 2 to sense the servo outputs of a 4 channel r/c reciever that i had from an airplane. In other words i don't want to run the servos from the reciever, just have the outputs sensed by the stamp and go from there. Maybe there is a command that would be useful in this? I know the stamp can run a servo directly as an output....so it seems it wouldnt be a giant hurdle to do the reverse and sense it as an input.The goal i guess is to have a "smart"platform for r/c projects. Thank you for any help. -mike
Comments
You should be able to do this with a BS but you will likely miss a lot of the signals. The stamp could only read one channel at a time. After it read the pulse of the first channel, it could then move on to the next. You could probably read all four channels about 12 times a second. I'm pretty sure you just use the PULSEIN command to read a pulse length instead of using PULSEOUT to send one.
Depending on your application a 12Hz read rate might be enough. Of course the 12Hz rate will get even slower if you need to perform calculations and other tasks between reading the pulses. This could be a problem depending on how "smart" you want to make your platform.
If you need to read all four channels at the normal 50Hz rate, you'll need to a different uC (such as a Prop). I'm currently working on a project where I'm reading in the pulses of six channels so I can use my RC radio to control a robot that doesn't use servos. The uC reads in the pulses from the receiver and calculates the PWM (the duty cycle kind) needed for each motor.
The BS could just listen in on the pulses that are driving the servos. The receiver would normally control the servos directly and the BS could use a relay to switch control to it when it wants to override the original signal.
Any advice would be appreciated. -mike
Hi Mike,
Sounds like a neat project and if you would post your code it will help to answer your questions.
' {$PBASIC 2.5}
channel0 VAR Word
channel1 VAR Word
'channel0 = 750
'channel1 = 750
main:
receiver:
PULSIN 0,1,channel0 'read output from receiver
PULSIN 1,1,channel1
DEBUG "channel0=",DEC ? channel0,CR 'display range+/- 550-950
'PAUSE 1000
DEBUG "channel1=", DEC ? channel1,CR
'PAUSE 1000
IF channel0>770 THEN 'fwd motor 1
GOSUB for1
ENDIF
IF channel0<700 THEN 'bwd motor 1
GOSUB back1
ENDIF
IF channel1<700 THEN 'bwd motor 2
GOSUB back2
ENDIF
IF channel1>770 THEN 'fwd motor 2
GOSUB for2
ENDIF
IF channel0<=770 THEN IF channel0 >= 700 THEN 'deadstick range center position
GOSUB nogo
ENDIF
GOTO main
'
for1:
LOW 8
HIGH 9
RETURN
back1:
LOW 9
HIGH 8
RETURN
back2:
LOW 7
HIGH 6
RETURN
for2:
LOW 6
HIGH 7
RETURN
nogo:
LOW 6
LOW 7
LOW 8
LOW 9
P.S. - I did not write this code, however I have used portions of it in my own demos.
You should use code tags when posting code or better yet, attach the original code as an attachment so the formatting is intact. It's very difficult to make out the code flow in what you have, but more importantly, if you look in the help files or BASIC STamp manual under DEBUG, you can see there are many comands to format the output including one to keep the text at the top of the screen (HOME). This will keep your debug values from running down the screen. My guess is you are getting jitter on the values coming in, however without being able to see the debug values when idle, it would be impossible to be sure. In a sense you do want the scrolling values initially so you can capture some data, PAUSE the display and scroll back and see if they are consistent when the controls are centered and not moving.
Phil made a tutorial on posting code.