Servo mixer problum ????

Hi all i need a quick and simple servo mixer for my model boat
I saw this post but if i cut and paste it i get all softs of errors'
I hope for some one to re code??
Lines like (if b2>150 then Cleft) what is this???????????????
Regards AQ

Ah, if all you want is a bog-standard linear mixer, then this (untested) code should do it:-

Main:
pulsin 1,b1 'get forward/reverse signal
pulsin 2,b2 'get left/right signal
b3=b1 'set left drive
b4=b1 'set right drive
if b2>150 then Cleft
if b2<150 then Cright
goto updateoutput
Cleft:
b2=b2-150
b3=b3+b2 max 220
b4=b4-b2 min 75
goto updateoutput
Cright:
b2=150-b2
b3=b3-b2 min 75
b4=b4+b2 max 220

updateoutput:
servo 1,b3
servo 2,b4
pause 20
goto main

You will probably need to play with pause value to stop any jittering. You might also like to play with the max and min values to suite your servo drives but it should be enough to get you going.
 

Buzby

Senior Member
It looks like the following lines :

if b2>150 then Cleft
if b2<150 then Cright

make some sense if you read '&gt;' as '>', and '&lt;' as '<'.

> is 'greater than' is 'gt'.
< is 'less than' is 'lt'

Maybe.
 

MartinM57

Moderator
^^^^^^^
exactly

Older posts (from a previous version of the forum software) appear like that.

It's always good to try to understand code that you're copy'n'pasteing, especially as in this case it appears to be untested...I'd run through it on paper selecting different values of b1 and b2 from the pulsin statements just to see what it actually does - and to see whether it's actually what you want
 
Last edited:

hippy

Technical Support
Staff member
The &....; are HTML mark-up which the forum previously used. Such mark-up always starts with an ampersand (&) and end with a semicolon (;). There are a number of lists and tables which show the full set but the commonest ones found on the forum are -

& &amp;
< &lt;
> &gt;
" &quot;

One trick to return the characters to what they should be is to cut and paste, save as a text file with a .HTM or .HTML extension, then open that file within a web browser.
 

MPep

Senior Member
Try this:
Code:
Main:
    pulsin 3,1,b1 'get forward/reverse signal
    pulsin 4,1,b2 'get left/right signal

    b3=b1 'set left drive
    b4=b1 'set right drive
    if b2 > 150 then Cleft
    if b2 < 150 then Cright
goto updateoutput

Cleft:
    b2=b2 - 150
    b3=b3 + b2 max 220
    b4=b4 - b2 min 75
goto updateoutput

Cright:
    b2=150 - b2
    b3=b3 - b2 min 75
    b4=b4 + b2 max 220

updateoutput:
servo 1,b3
servo 2,b4
goto main
 

Wrenow

Senior Member
Hi all i need a quick and simple servo mixer for my model boat
I saw this post but if i cut and paste it i get all softs of errors'
I hope for some one to re code??
Lines like (if b2&gt;150 then Cleft) what is this???????????????
Regards AQ

Ah, if all you want is a bog-standard linear mixer, then this (untested) code should do it:-

Main:
pulsin 1,b1 'get forward/reverse signal
pulsin 2,b2 'get left/right signal
b3=b1 'set left drive
b4=b1 'set right drive
if b2&gt;150 then Cleft
if b2&lt;150 then Cright
goto updateoutput
Cleft:
b2=b2-150
b3=b3+b2 max 220
b4=b4-b2 min 75
goto updateoutput
Cright:
b2=150-b2
b3=b3-b2 min 75
b4=b4+b2 max 220

updateoutput:
servo 1,b3
servo 2,b4
pause 20
goto main

You will probably need to play with pause value to stop any jittering. You might also like to play with the max and min values to suite your servo drives but it should be enough to get you going.
A couple of things. One, pulsin wants a word vairable, like W1. Using a byte variable will probably cause you untold frustration and grief (it did me at first).

Second, you do not need to use servo for output in this case. Since you are getting your timings from the pulsin, you are probably better off to use pulsout.

I presume you are getting throttle (RC ch3) first, then rudder (RC ch4). You do want to take them in order, so that you do not skip a cycle. Please note: some of the 2.4gHz systems now send out all RC servo pulses simultaneously rather than sequentially, so this may not work as expected without additional code.

Last, it appears you are using the same pins for pulsin and for servo out. Either that or I have not completely woken up yet.

Cheers,

Wreno
 

MPep

Senior Member
After looking at this some more, using the simulator, I found an anomaly that has been cleared using the following code:
Code:
#picaxe 08m
#rem
         --v--
    0V -|    |- +V
 SerIn -|    |- SerOut
   L/R -|    |- OP1
   F/W -|    |- OP2
         -----

#endrem
Main:
    pulsin 3,1,w1                 'get forward/reverse signal
    pulsin 4,1,w2                 'get left/right signal

sertxd (#w1,"     ",#w2,"     ")

    w3 = w1                     'set left drive
    w4 = w1                     'set right drive
    if w2 > 150 then Left
    if w2 < 150 then Right
goto updateoutput

Left:
    w0 = w2/2
    w3 = w3 + w0 max 220
    w4 = w4 - w0 min 75
goto updateoutput

Right:
    w0 = w2/2
    w3 = w3 - w0 min 75
    w4 = w4 + w0 max 220

updateoutput:

sertxd (#w3,"      ",#w4,CR,LF)

pulsout 1,w3
pulsout 2,w4
goto main
The SERTXD parts are for testing only, and can be deleted once satisfied.
And yes, thanks to Wrenow for ponting out that Word variables must be used with PulsIn. Also, now uses PULSOUT, and differing output pins.

Does this do as required?

MPep
 

goom

Senior Member
Below is some code that I wrote for a 3-screw model boat. It mixes the rudder and throttle signals to control 3 reversing speed controllers (also Picaxe pased). It has an input from a pot. to vary the amount of authority that the rudder has over the port and stbd. motors. The center motor is obviously irrelevant for your particular application.
The code is tested and working in a 6ft Canadian icebreaker model, and does the job quite well. I hope some or all of this will be of some use.

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
 

goom

Senior Member
Pictures of Polar8

Here are a couple of pictures. One of the completed model on the water, and one of the electronics in the process of being installed and tested (can you spot the 4 Picaxes?).
She is a 1/100 scale of a large Canadian icebreaker, designed in the 1970's, but cancelled by the government of the time. She was built using original drawings from one of the two competing shipyards (German and Milne). The Canadian Coastguard has expressed an interest in buying her, but don't seem to have the money to make a realistic offer.
 

Attachments

Hi there i have tried the program and made a board . First thing i blue up a few chips following you pin outs i think your power is the rong way round???.
I have new re made the board and all i get is very slow responce on one servo only ie moves a bitt,pause 1/2 a second then moves a bit more etc

Regards Andy Quirot
 

goom

Senior Member
Andy,
Sorry to hear of your lack of success. Attached is a scematic and PCB layout which I used for my working unit. I'm fairly sure that the connections and code are exactly what I used.
Could there be some confusion as to how the legs are numbered? Leg 1 is the bottom left (+5V) in the attached diagram (looking from the top of the IC). The PCB is a mirror image since I use the toner transfer method. Could there be some confusion between physical legs and the pins nomenclature? It's hard to destroy a Picaxe if the power is connected correctly and there are no shorts to +5v or ground on any of the outputs.
 

Attachments

Hi all could sombody please check this code as it dont seem to work

i know the power is wrong on the chip (found out the hard way??)

Thanks AQ

#picaxe 08m
#rem
--v--
0V -| |- +V
SerIn -| |- SerOut
L/R -| |- OP1
F/W -| |- OP2
-----

#endrem
Main:
pulsin 3,1,w1 'get forward/reverse signal
pulsin 4,1,w2 'get left/right signal

w3 = w1 'set left drive
w4 = w1 'set right drive
if w2 > 150 then Left
if w2 < 150 then Right
goto updateoutput

Left:
w0 = w2/2
w3 = w3 + w0 max 220
w4 = w4 - w0 min 75
goto updateoutput

Right:
w0 = w2/2
w3 = w3 - w0 min 75
w4 = w4 + w0 max 220

updateoutput:
pulsout 1,w3
pulsout 2,w4
goto main
 

BeanieBots

Moderator
Hi all could sombody please check this code as it dont seem to work

i know the power is wrong on the chip (found out the hard way??)

Thanks AQ
I'm sure the code does work.
However, it might not be doing what you want it to;)

What should it do? What DOES it do? and what does it not do that you want it to do?

The use of symbols and more verbose comments would make it much easier for others (and yourself) to follow.

I'm guessing that you are reading in the pulse widths from an RC reciever??
Are they good clean pulses? Have you tried testing them?
Maybe put in a few sertxd lines to report back what values you get.

Also, try swapping over the first two line so that you read the incomming pulses in the other order. You might be reading alternate frames if not done in the correct sequence. This could lead to sloppy servo control but as you don't state the nature "don't work" I can only guess.
 

Wrenow

Senior Member
For what it is worth, the normal (most common?) channel order is ch3 for throttle, and ch4 for rudder. However, some of the newer 2.4gHz output all channels simultaneously. I haven't played with any of them on my projects, so cannot say how bad this affects things.

I Andy has indicated which physical pins he has wired to what, but don't have them on the top of my mind right now.

Cheers,

Wreno
 
Top