brushless speed controler /servo help

Hi all i am building a radio control tank. i have forward brushless speed controlers and i am trying to program a picaxe 14m to do the following/example. I want to set the stick on my radio control to centre when i move the stick forward the speed controlers work in forward ok. Now i want to move the stick down and operate a large relay than bits ok i can do this BUT i want the output to think its moving the stick foward to operate the speed controller. I need some help with th maths. Centre stick posion approx 150ms moving the stick forwards/up goes to approx 200ms. i need to move the stick from centre to back/bottom going from 150ms to approx 200ms to simulate the stick moving forward/up. hope you understand what i meen program so far.
code
low 2
low 3
low 4
low 5


start:

pulsin 2,1,w0
if w0 => 145 then
low 2
pulsout 1,w0
pause 20
endif


if w0 =< 145 then high 2
'if w0 = 140 then let w1 = 75
'endif
'if w0 = 135 then let w1 = 80
'endif
'if w0 = 135 then let w1 = 85
endif
pulsout 1,w0
pause 20

goto start
/code

Regards Andy Quirot
P.S. i know i can buy a forward/backwards controler at £85.00 but the 100Amp forward only controlers are only £25.00 + a relay and a bit of work..
 

jglenn

Senior Member
You need to sense when the stick first goes back from zero, then just add
an offset time to the value. Then it should mimic the forward stick movement.

I suspect the code could be simpler, but can't write it right now.
 

goom

Senior Member
The following code should do what you want:
Code:
start:
pulsin 2,1,w0
if w0 >=150 then
   w1=w0-150*2+110
   'Assumes:
   '  pulse of 110 = stop on the ESC 
   '  pulse of 190 = full speed on the ESC
   '  pulse of 150 at center stick position
   low 2 'turns off reversing relay
else
   w1=150-w0*2+110
   high 2 'turns on reversing relay
endif
pulsout 1,w0
pulsout 1,w1
goto start
You will probably need to fiddle with the constants to calibrate to your particular transmitter/receiver and ESC.
You could always measure the center stick position once on program startup and use that value, but you would always have to center the stick when turning on the system. You could add:
Some hysteresis around the center stick position
A check for valid input pulse width
A failsafe stop command for an invalid pulse (e.g. loss of signal)
Here is some working code that I wrote for a speed controller with a reversing relay (a latching type). It does not output to an ESC, but rather PWM's a FET to drive the motor at variable speed. You may find some bits of code of use to you:
Code:
'PICAXE-08M connections are:
' Leg 1                   +5V
' Leg 2 (Serial in)       Tie to Ground through 10K resistor
' Leg 3  (In4/Out4)        Pulse input from radio receiver
' Leg 4  (In3)             NC
' Leg 5 (In2/Out2)    PWM to motor (via 500 ohm resistor and IRF530 MOSFET)
' Leg 6 (In1/Out1)    Output to latching relay for forward operation (via ULN2003)        
' Leg 7 (Out0/Serial Out) Output to latching relay for reverse operation (via ULN2003)
' Leg 8                   Ground
symbol PW_null=w2  'Name the null position input pulse width
symbol PWin=w1   'Name the input pulse width
symbol Duty=w0   'Name the duty cycle
symbol Hysteresis=b6 'Name the amount of hysteresis
symbol Dir=b7   'Name the direction flag (0 = forward, 1=reverse)
Hysteresis=3   'Set hysteresis
Dir=0    'Set direction flag to forward initially
low 0    'Initial state of output to reverse of latching relay
low 1    'Initial state of output to forward of latching relay
pulsout 1,10000  'Set latching relay to forward with 0.1 sec pulse
       
initialise:
   pwmout 2,255,0     'Make sure motor is off initially
   Pause 500      'Wait 1/2 second initially
   pulsin 4,1,PW_Null    'Measure the input pulse width initially (null position)
   if PW_Null<135 or PW_Null>165 then initialise'Go back if no valid null input detected
restart:
   pwmout 2,255,0     'Stop PWM signal to motor on signal loss
   pulsin 4,1,PWin     'Measure the input pulse width initially (null position)
   if PWin<75 or PWin>225 then restart 'Go back if no valid input detected
recheck:
   pulsin 4,1,PWin     'Measure the input pulse width
   if PWIn<75 or PWin>225 then restart 'Go back if no valid input detected
   if PWin > PW_Null then forward_  'Check for forward rotation
reverse_:
   Duty=PW_Null-PWin
   if Duty<hysteresis then stop_  'Stop motor if input within deadband 
 if Dir=1 then ContR
  pwmout 2,255,0    'Stop PWM signal to motor
  Pause 500     'Pause for 1/2 second on changing forward to reverse
    pulsout 0,10000      'Set latching relay to reverse with 0.1 sec pulse
   ContR:
 Dir=1      'Set the direction flag to reverse
   Duty=Duty*26 max 1020    'Set duty cycle from 0 to 1023
   pwmout 2,255,Duty    'Send PWM signal to motor
   goto recheck     'Return to measure input pulse
forward_:
   Duty=PWin-PW_Null
   if Duty<hysteresis then stop_  'Stop motor if input within deadband
 if Dir=0 then ContF
  pwmout 2,255,0    'Stop PWM signal to motor
  Pause 500     'Pause for 1/2 second on changing reverse to forward
    pulsout 1,10000    'Set latching relay to forward with 0.1 sec pulse
   ContF:
 Dir=0      'Set the direction flag to forward
   Duty=Duty*26 max 1020    'Set duty cycle from 0 to 1023
   pwmout 2,255,Duty    'Send PWM signal to motor
   goto recheck     'Return to measure input pulse
stop_:
   pwmout 2,255,0     'Stop PWM signal to motor
   goto recheck     'Return to measure input pulse
 
What radio are you using? (brand and model). Some radios can be programmed to do what you want. Helicopter fliers use what you want to do. In their case is to reverse the collective with the stick back and increase the power. When the stick goes forward they also get full power but with positive collective.
By the way if you are doing your project in the US please be aware that there are surface frequencies (for cars, tanks, boats, robots, etc) and different frequencies for aircraft. I imagine that similar restriction exist in most countries.
 
Servo and brushless motor reversing

I dont know how you worked out the maths so quick but it works perfect. i had to remove on line (pulsout 1,w0) i will build a pcb and test it using the motors Thanks to all Regards Andy Quirot (Jersey Channel Islands)
 
Top