Interperating RC servo signals

spironi

New Member
I would like to be able to read the servo signals output from a standard RC receiver. The goal being onboard signal processing, mixing, etc. before outputting some modified servo signal to the servo itself.

Surely this sort of thing has been done a time or two before :) I have been searching the forums but haven't really found what I am looking for. If anybody could point me in the right direction or offer suggestions on how to read the servo commands coming out of a standard RC receiver I would greatly appreciate it.

Thanks in advance,
Spiro

ps: A picaxe now controls my various attic fans and shop HVAC system! I am a hobbiest type of uC guy and new to picaxe, but I like what I see already.
 

gbrusseau

Senior Member
A typical servo takes a series of pulses as its input and moves its arm to a position that is proportional to the input pulse width. This pulse width ranges from 1ms to 2ms. A pulse width of about 1.5ms will center a servo. The pulse rate is approximately one pulse every 20ms. This type of signal is called "pulse width modulation" or PWM. A radio-controlled transmitter/receiver combo is specifically designed to convert joystick inputs at the transmitter into PWM servo outputs at the receiver.
 

goom

Senior Member
Reading and outputting RC signals is really quite easy. Use pulsin to read, pulsout to send to a servo or speed controller.
Here is some code for a rudder/throttle mixer for a 3-screw model boat:

Code:
'Rudder/Throttle Mixer for 3 Motors
'Kevin Goom, 22 December2007
'PICAXE-14M connections are:
' Leg 1               +5V
' Leg 2 (Serial in)       Tie to Ground through 10K resistor (to avoid floating)
' Leg 3 (In4/ADC4)        Wiper of 10K pot (mix proportion)
' Leg 4 (In3)             From receiver throttle channel
' Leg 5 (In2)      Tie to Ground through 10K resistor & switch to +5V
' Leg 6 (In1)         From receiver rudder channel        
' Leg 7 (In0/ADC0)      Wiper of 10K pot (center motor proportion)
' Leg 8 (Out5)            Stbd motor LED indicator
' Leg 9 (Out4)            Center motor LED indicator
' Leg 10(Out3)            Port motor LED indicator
' Leg 11(Out2)            Center motor speed control
' Leg 12(Out1)            Port motor speed control
' Leg 13(Out0)            Stbd motor speed control
' Leg 14                  Ground
symbol PW_Thr_null=b0 'Name the null position throttle input pulse width
symbol PW_Rud_null=b1 'Name the null position rudder input pulse width
symbol PW_Thr=w1  'Name the throttle input pulse width
symbol PW_Rud=w2  'Name the rudder input pulse width
symbol Mix_Prop=b6  'Name the mix proportion ADC signal
symbol CM_Prop=b7  'Name the center motor proportion (in reverse)
symbol PW_Port=b8  'Name output pulse to port motor
symbol PW_Stbd=b9  'Name output pulse to stbd motor
symbol PW_Ctr=b10  'Name output pulse to center motor
symbol Temp=b11
 
initialise:
setint %00000100,%0000100 'Set interrupt when pin2 goes high
let pins=%00111000  'Motor outputs low, indicators high
pause 250    'Wait 1/4 second initially
pulsin 3,1,PW_Thr_Null 'Read zero throttle input pulse width
pulsin 1,1,PW_Rud_Null 'Read center rudder input pulse width
if PW_Thr_Null<135 or PW_Thr_Null>165 then initialise'Go back if no valid throttle null input detected
if PW_Rud_Null<135 or PW_Rud_Null>165 then initialise'Go back if no valid rudder null input detected
readadc 4,Mix_Prop  'Read the mix proportion
readadc 0,CM_Prop  'Read the center motor proportion (for reverse operation)
pulsout 0, PW_Thr_Null 'Send null pulses to each motor
pulsout 1, PW_Thr_Null
pulsout 2, PW_Thr_Null
restart:
pulsin 3,1,PW_Thr  'Read throttle input pulse width
pulsin 1,1,PW_Rud  'Read rudder input pulse width
setfreq m8   'Speed things up for the calculations
if PW_Rud>=PW_Rud_Null then    'Temp = absolute deviation of rudder from null position
   Temp=PW_Rud-PW_Rud_Null*Mix_Prop/256 'times the proportion determined by Mix_Prop
else
   Temp=PW_Rud_Null-PW_Rud*Mix_Prop/256
endif
if Temp<3 then  'Add a bit of hyteresis
Temp=0
endif
if PW_Thr>=PW_Thr_null then
   PW_Ctr=PW_Thr      'Forward 
   if PW_Rud>=PW_Rud_null then
      PW_Port=PW_Thr+Temp max 190 min 110
      PW_Stbd=PW_Thr-Temp max 190 min 110
   else   
      PW_Port=PW_Thr-Temp max 190 min 110
      PW_Stbd=PW_Thr+Temp max 190 min 110
   endif
else         'Reverse
   PW_Ctr=PW_Thr_Null-PW_Thr*CM_Prop/256
   PW_Ctr=PW_Thr_Null-PW_Ctr    'Set reverse throttle to a proportion based on CM_Prop
   if PW_Rud>=PW_Rud_null then
      PW_Port=PW_Thr-Temp max 190 min 110
      PW_Stbd=PW_Thr+Temp max 190 min 110
   else   
      PW_Port=PW_Thr+Temp max 190 min 110
      PW_Stbd=PW_Thr-Temp max 190 min 110
   endif
endif
if PW_Port>=PW_Thr_Null then
   High 3    'Turn on port motor forward indicator
else 
   Low 3    'Turn on port motor reverse indicator
endif
if PW_Stbd>=PW_Thr_Null then
   High 5    'Turn on stbd motor forward indicator
else 
   Low 5    'Turn on stbd motor reverse indicator
endif
if PW_Ctr>=PW_Thr_Null then
   High 4    'Turn on center motor forward indicator
else 
   Low 4    'Turn on center motor reverse indicator
endif
setfreq m4   'Slow back down for output of pulses
pulsout 0, PW_Stbd  'Send pulse to stbd motor speed controller
pulsout 1, PW_Port  'Send pulse to port motor speed controller
pulsout 2, PW_Ctr  'Send pulse to center motor speed controller
goto restart
interrupt:    'Allows re-read of ADC values and null positions
   setfreq m4
   pulsout 0, PW_Thr_Null 'Stop each motor
   pulsout 1, PW_Thr_Null
   pulsout 2, PW_Thr_Null
   pause 15
   if pin2=1 then interrupt  'Loop until pin3 goes low again
   goto initialise
return
 

Wrenow

Senior Member
Spironi,

There are several threads on doing this, and it is, indeed not difficult. I believe you are looking for some background theory on this (and, if not, some might help). There is a decent article on R/C Radio Basics on the NTXBG.org site in the How To section, here:https://ntxbg.org/KnowledgeBase/?category_id=45&menuaction=phpbrain.uikb.view_article&art_id=17
As for more in depth information on the servo signal Google will reveal many, such as this very simple explanation:http://www.seattlerobotics.org/guide/servos.html
or a more technical discussion (including an animation of the relation of pulse length versus position) is here:http://www.mp.ttu.ee/risto/rc/electronics/radio/signal.htm

A couple of things to remember -

1) Read the channels in the order in which the radio sends them or you will miss frames.
2) Don't get greedy. If you try to read all 6 or 8 channels at once, there is not much time left in the frame to allow computations and output. Reading 2 to 3 at a time to output one or two is a good plan.

Another hint - you can use the 3 servo controller board for this (you can read inputs through the servo outputs, and, with a little creativity, can access an additional input as well). This is the setup I use for my Fire Control Assistant project (R/C Model Warship Combat).

You can also use your pulsins to set the timing for the output pulses (after all the processor will be waiting for the next input pulse), and do not need to use the Servo command for a mixer type setup. This may sound cryptic right now, but it will make sense as you get into it.

Cheers,

Wreno
 
Top