Radio Control - first go!

A first draft for a radio control, see what you think ;)

Transmitter:

Code:
init:  'set up symbols so i can remember what means what
    symbol servo_pending = b1 'variables i'll use later, just giving them nicer names
    symbol thrust_pending = b2 'they keep track of what commands I need to send
    symbol lift_last_sent = b3 '
    symbol lift_pending = b4 '
    symbol lift_wait_time = b5 ' timer to debounce lift toggle (more about that further on)
    symbol servo_left_pin = pin4 'pins for various switches
    symbol servo_right_pin = pin3'
    symbol thrust_fwd_pin = pin2'
    symbol thrust_bkwd_pin = pin1'
    symbol lift_pin = pin0'
    symbol txled_pin = 4 'pin number for flashy light
    symbol rftx_pin = 5 'pin number for outgoing serial data to rf transmitter
    symbol baudrate = T2400_4 'the speed of the serial connection, in bits per second

startup: high txled_pin 'just flash light to say "I've turned on!"
    pause 1000
    low txled_pin
    let lift_last_sent = "N"

checkpins: 'now we see if any buttons are being pressed
    if servo_left_pin = 1 then
        let servo_pending = "L" 'need to transmit "turn right"
    elseif servo_right_pin = 1 then
        let servo_pending = "R" 'need to transmit "turn left"
    else
        let servo_pending = "M" 'don't want to turn so transmit "go to middle"
    endif
    if thrust_fwd_pin = 1 then
        let thrust_pending = "F" 'need to transmit "go forwards"
    elseif thrust_bkwd_pin = 1 then
        let thrust_pending = "R" 'need to transmit "go backwards"
    else
        let thrust_pending = "O" 'don't want to move so transmit "turn off the thrust fan completely"
    endif
  'lift is a bit trickier; don't want to have to hold down the "hover" button all the time so we do this:
  if lift_pin = 1 and lift_last_sent = "I" and lift_wait_time > 20 then 'toggle pressed, fan is on atm
        let lift_pending = "O" 'so we want to transmit "turn it off"
        let lift_wait_time = 0
    elseif lift_pin = 1 and lift_last_sent = "O" and lift_wait_time > 20 then 'toggle pressed, fan is off atm
        let lift_pending = "I" 'so we want to transmit "turn on"
        let lift_wait_time = 0
    elseif lift_pin = 1 and lift_last_sent = "N" and lift_wait_time > 20 then 'toggle pressed, but its the first time it has been
        let lift_pending = "I" 'so we want to transmit "turn it on"
        let lift_wait_time = 0
    elseif lift_pin = 0 then 'toggle isn't on, so we want to transmit "stay in same state you are atm"
        let lift_pending = lift_last_sent
    endif
    let lift_wait_time = lift_wait_time + 1 'put in a counter so that if you hold down button, lift doesnt keep toggling on and off 10,000 times a second :O

transmit: 'now we send the requests
    high txled_pin 'flash light to show we are doing something
    serout 5, baudrate,  (0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55) 'preamble of 01010101s to tune reciever
    pause 15
    serout 5, baudrate, ("data", servo_pending, thrust_pending, lift_pending) 'send the commands
    low txled_pin 'light off
    let lift_last_sent = lift_pending 'update lift state memory
    goto checkpins 'start again
Receiver:

Code:
init: 'more symbols
    symbol servo_state_pending = b0 'variables again; how I'll determine what needs doing, quickly
    symbol servo_state_current = b1'
    symbol servo_needs_changing = b2'
    symbol thrust_state_pending = b3'
    symbol thrust_state_current = b4'
    symbol thrust_needs_changing = b5'
    symbol lift_state_pending = b6'
    symbol lift_state_current = b7'
    symbol lift_needs_changing = b8'
    symbol servo_pin = 4  'pin number for servo
    symbol servo_middle_pos = 150 'rotation amounts for three servo positions
    symbol servo_left_pos = 160'
    symbol servo_right_pos = 140'
    symbol rfrx_pin = 0 'pin number for incoming serial data from rf receiver
    symbol baudrate = T2400_4 'rf link/serial data rate
    symbol fwd_pin = 0 'pin numbers for power transistors to switch motors on and off
    symbol bkwd_pin = 1'
    symbol lift_pin = 2'
    symbol rxled_pin = 3 'pin number for flashy light

startup: 'set some stuff up
    servo_state_current = "M" 'servo should be in middle...
    thrust_state_current = "O" '...thrust should be off...
    lift_state_current = "O" '...and so should lift
    high rxled_pin '"I've turned on!" again
    pause 1000
    low rxled_pin
    servo servo_pin, servo_middle_pos 'actually move servo incase someone has fiddled while it was off
    pause 75

listen: 'wait for transmission from other curcuit
    serin rfrx_pin, baudrate, ("data"), servo_state_pending,thrust_state_pending, lift_state_pending 'read requests from transmitter into these variables
    high rxled_pin 'show something is happening
    goto receive

receive: 'so what now?
    if servo_state_pending != servo_state_current then 'requested servo position different from current
        let servo_needs_changing = 1 'so we'll need to do something about it
        gosub srvo 'go and do it
    endif
    if thrust_state_pending != thrust_state_current then 'requested thrust different form current
        let thrust_needs_changing = 1 'so we'll need to do something about it
        gosub thrust 'go and do it
    endif
    if lift_state_pending != lift_state_current then 'requested liftdifferent from current
        let lift_needs_changing = 1 'so we'll need to do something about it
        gosub lift 'go and do it
    endif
    low rxled_pin 'receive done so turn light off...
    goto listen 'and do it again

srvo: 'move servo around
   if servo_state_pending = "L" then 'want to move to left
        servo servo_pin, servo_left_pos
        pause 100 'give servo a chance to move
    elseif servo_state_pending = "R" then
        servo servo_pin, servo_right_pos 'want to move to right
        pause 100 'give servo a chance to move
    elseif servo_state_pending = "M" then 'want to move to middle
        servo servo_pin, servo_middle_pos
        pause 100 'give servo a chance to move
    endif
    let servo_state_current = servo_state_pending 'update servo state memory
    return 'go back to where we came from

thrust: 'alter thrust fan configuration 
      if thrust_state_pending = "F" then 'want to go forwards
        low bkwd_pin
        high fwd_pin
    elseif thrust_state_pending = "R" then 'want to go backwards
        low fwd_pin
        high bkwd_pin
    elseif thrust_state_pending = "O" then 'All stop, Cap'n
        low fwd_pin
        low bkwd_pin
    endif
    let thrust_state_current = thrust_state_pending 'update thrust state memory
    return 'go back to where we came from

lift: 'alter lift fan configuration
   if lift_state_pending = "I" then 'want to turn it on
        high lift_pin
    elseif lift_state_pending = "O" then 'want to turn it off
        low lift_pin
    endif
    let lift_state_current = lift_state_pending 'update lift state memory
    return 'go back to where we came from
EDIT: Knew I had the commented version lying around somewhere.

This is for a hovercraft where I have a servo for steering and three FETs for control of the thrust and lift motors. At present using a load of switches at TX end but investigating something like this:

http://www.sparkfun.com/products/9032
 
Last edited:

westaust55

Moderator
Sounds like an interesting project - the hovercraft side.

Well done on use of indentation/"white space" in your program code. :)
But comments for the aid of quick understanding by others are not apparent. :eek:

Good use of the preamble, pause and then sending qualifier plus data from the transmitter.
:)

see what you think/quote]
If you are looking for someone to analyse for you and proffer some suggestions then you might like to provide some further informaiton:
  • which PICAXE chips are you using
  • what Tx and RX modules are you using and what frequency?
  • post/upload a schematic diagram
 

Jamster

Senior Member
Be warned with those thumb joy sticks the pots on the sides do not move to the full range therefore they are hard to connect to picaxe. if you manage please post so i can get mine working
 
Be warned with those thumb joy sticks the pots on the sides do not move to the full range therefore they are hard to connect to picaxe. if you manage please post so i can get mine working
I've heard that elsehwere, but I'm not really interested in getting a graduated movement; as you can see from the code, i just want to have 'middle', 'left' and 'right' options.
So it should jut be a matter of doing a bit of calibration to obtain the middle readadc value, and then just go 20 or 30 either side to get the extremes.
 

westaust55

Moderator
Had a quick look through the Tx portion only of your commented code. Generally looks and maybe just a couple of comments to review/fix.

checkpins: 'now we see if any buttons are being pressed
if servo_left_pin = 1 then
let servo_pending = "L" 'need to transmit "turn right"
elseif servo_right_pin = 1 then
let servo_pending = "R" 'need to transmit "turn left"
else

The red coloured text does not match the characters/values used for the commands to the servo.
 

scoop

New Member
Every so often I see a design on this forum which is brilliant in it's simplicity.

Even I can follow the circuit diagrams and the code although I think I've spotted a small error in the transmitter circuit. There is a connection to the right of R1 to the "Lift" switch and resistor. I stopped using PCB Wizard because it keeps adding in connections when you haven't asked for them. Should there be current limiting resistors to the LEDs as well? I've always put them in thinking they were needed.

I've had a project knocking around in my head for a little while now and this circuit and code
will enable me to make a device to prove whether my idea will work or not.
 
There is a connection to the right of R1 to the "Lift" switch and resistor.
Oh yeah, that's just where the end of the 22k overlapped with the switch wire. I didn't generate the PCB layout from this diagram, so shouldn't be a problem. But thanks for pointing that out else my teacher would've :eek:.
As for reistors, there technically should, but I didn't bother putting them on this schematic. In reality, the LEDs will be replaced by connections to a MOSFET array (schematic of that attached, imagine the LEDs are simply wires into the terminal block).

Glad to be of help, too! :D
 

Attachments

Last edited:

techElder

Well-known member
Resistors are not normally an option. Current limiting keeps the magic smoke INSIDE of components. It doesn't matter whether the resistors limit the current to the PICAXE or some FET drivers when they are needed.

...As for reistors, there technically should, but I didn't bother putting them on this schematic. In reality, the LEDs will be replaced by connections to a MOSFET array (schematic of that attached, imagine the LEDs are simply wires into the terminal block)....
 

eclectic

Moderator
Calvin
re post #9,

could you please reduce the size of the
attached pictures please?

It's OK for fast broadband,
but murder for the folks still on
Dialup or slow connections. :)

e
 
I was going on Manual 3 (pg. 7), which doesn't show a need for an Ilim resistor. What I'm more worried about is that I ought to have some sort of emf protection, but if I put a 1N4001 diode in, it will create a short-circuit with the motor connected up one way round, so i'm not sure how I could overcome that short of yet more FETs :confused:
 
Sorry, no offense meant. I had to put up with dialup for a long time, so I understand the irritation it causes. I've got them down to sub 100KB-each, any smaller and they become pretty much illegible. So I hope that's alright.
 

pjcassels

New Member
Hey calvin,

I'd be interested to hear how you got on in the end. I'm thinking of doing something very similar with an 18M2 for a university hovercraft project. Did you have any problems with the craft spinning out due to the lack of friction? I'm wondering whether some kind of feedback system might be necessary to prevent this (kind of like the tail rotor on a helicopter)?
 
Hey calvin,

I'd be interested to hear how you got on in the end. I'm thinking of doing something very similar with an 18M2 for a university hovercraft project. Did you have any problems with the craft spinning out due to the lack of friction? I'm wondering whether some kind of feedback system might be necessary to prevent this (kind of like the tail rotor on a helicopter)?
The project's still very much in developement, so I won't be able to give a definite answer for some time as to how well the whole thing works. I'm actually getting set up for the first hover tests right now, so I'll get back to you on how it goes.
 
Top