Shop OBEX P1 Docs P2 Docs Learn Events
?How to interface basic stamp with servo output of r/c radio reciever? — Parallax Forums

?How to interface basic stamp with servo output of r/c radio reciever?

mikeamikea Posts: 283
edited 2012-03-01 10:19 in BASIC Stamp
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

  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-02-27 08:14
    mikea,

    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.
  • ercoerco Posts: 20,256
    edited 2012-02-27 08:41
    mikea: Per Duane, the BS2 can only do so much. If you plan to use it to read 4 different pulses from the receiver and also drive 4 servos, you may run out of headroom pretty quickly. It's likely OK to sample the pulsins at 12 hz, but the servos really need output pulses closer to 50 hz. You may need a pair of Servopals as servo drivers to offload that. Let us know how it goes, I'm a huge fan of pushing the Stamps as far as they can go! http://www.youtube.com/watch?v=OHxhki1zi_k
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-02-27 09:00
    erco wrote: »
    You may need a pair of Servopals as servo drivers to offload that.

    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.
  • mikeamikea Posts: 283
    edited 2012-02-29 07:03
    Thank you duane and erco for your your input, and sorry for the response delay. I'm very new to this stuff and get easily distracted in pursuing things i don't understand along the way. So far i've used the pulsin command with only a greater or less than threshhold for triggering stamp responses. This has worked well so far. I need to get some 3 pin headers i guess you call them to do more channels simultaneously, the one i am using was cut and borrowed from a servo. Thank you both for the info and ideas. -mike
  • mikeamikea Posts: 283
    edited 2012-02-29 12:54
    ..........Not sure on protocol if this should be a new thread or not. I have two questions related to the project in this thread. I have code and a circuit for receiving the output pulses from an r/c controller. It will do 4 actions using 2 channels like an r/c car ect. 4 i/o pins operate 2 red and 2 green leds to simulate motor. Motor 1 fwd/rev, and motor 2 fwd/rev. The two problems i'm having are (1) the "channel0 and 1" and their values scroll down the debug window at breakneck speeds.Any pause in the code(to have time to see the values) delays the performance. Parallax suggested lowering the baud rate which is currently 9600.I've tried doing this, but somehow im not doing it correctly, when the debug window pops up at program start it still shows 9600 and wont allow me to change it from there. It would be great if the "channel0..ect" were stationary and the value to the right of it changed.Problem (2) is i think in the code. green/red leds( for fwd/rev) representing the 2 motors act as they should, except for the red/green on pins 6,7. they flicker when applied singly and glow normal when on with either one of the other motor leds. Also the problem goes away when i comment the "nogo" subroutine, which keeps motors from latching when the joystick is in the center position.


    Any advice would be appreciated. -mike
  • Just JeffJust Jeff Posts: 36
    edited 2012-02-29 13:09
    mikea wrote: »
    ..........Not sure on protocol if this should be a new thread or not. I have two questions related to the project in this thread. I have code and a circuit for receiving the output pulses from an r/c controller. It will do 4 actions using 2 channels like an r/c car ect. 4 i/o pins operate 2 red and 2 green leds to simulate motor. Motor 1 fwd/rev, and motor 2 fwd/rev. The two problems i'm having are (1) the "channel0 and 1" and their values scroll down the debug window at breakneck speeds.Any pause in the code(to have time to see the values) delays the performance. Parallax suggested lowering the baud rate which is currently 9600.I've tried doing this, but somehow im not doing it correctly, when the debug window pops up at program start it still shows 9600 and wont allow me to change it from there. It would be great if the "channel0..ect" were stationary and the value to the right of it changed.Problem (2) is i think in the code. green/red leds( for fwd/rev) representing the 2 motors act as they should, except for the red/green on pins 6,7. they flicker when applied singly and glow normal when on with either one of the other motor leds. Also the problem goes away when i comment the "nogo" subroutine, which keeps motors from latching when the joystick is in the center position.


    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.
  • mikeamikea Posts: 283
    edited 2012-02-29 14:32
    ....sorry! copied and forgot to paste' {$STAMP BS2}
    ' {$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
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2012-02-29 15:19
    Here is some code we used to allow a BASIC Stamp 2 to control a BOE-Bot, Stingray (using HB-25) or any other system which uses servo signals. The code reads in the output of your R/C receiver and sends the mixed outputs to the servos or motor controller. A BASIC Stamp can handle more than most give it credit for. =)

    P.S. - I did not write this code, however I have used portions of it in my own demos.
  • mikeamikea Posts: 283
    edited 2012-02-29 15:57
    awesome...thank you chris. -mike
  • mikeamikea Posts: 283
    edited 2012-03-01 04:49
    Does anyone know why both the motor 2 leds would pulse in the above code? The pulsing is somehow directly related to the "nogo" subroutine. I moved the order of "nogo" and minimized the pulsing when the "nogo" was placed in between the 2 motor 1 and motor 2 subroutines. I posed this question and another with a little more detail 5 posts up.I think the code will work ok, but i would like to understand why it acts this way.....any ideas? Thanks -mike
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2012-03-01 08:36
    Mike,

    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.
  • mikeamikea Posts: 283
    edited 2012-03-01 09:47
    Thank you Chris....i'm not sure what a code tag is, but next time i will attach code.Thank you for the answers i appreciate it. -mike
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-03-01 10:07
    mikea wrote: »
    Thank you Chris....i'm not sure what a code tag is, but next time i will attach code.Thank you for the answers i appreciate it. -mike

    Phil made a tutorial on posting code.

    attachment.php?attachmentid=78421&d=1297987572
  • mikeamikea Posts: 283
    edited 2012-03-01 10:19
    cool,looks easy...thanks Duane. -mike
Sign In or Register to comment.