Shop OBEX P1 Docs P2 Docs Learn Events
dservo object — Parallax Forums

dservo object

Jonathan HolleJonathan Holle Posts: 48
edited 2010-08-04 12:45 in Propeller 1
Hi,

I got a problem with the dservo object :
Somebody said...
repeat index from 0 to (NumServos - 1)
pin[noparse][[/noparse]index] := lookupz(index: femuravg,femurmg,femurarg,femuravd,femurmd,femurard) 'Initialize value of propeller pins connected to each servo
NumPulses[noparse][[/noparse]index] := 0
'S6(70,0,-540,-410,0,0) 'Initialize initial positions for each servo.
'Note that a known arm storage position is used at the beginning and at the end in order to avoid
'a violent movement of the arm when it is first powered on and servos are energized.


'Once the initial positions have been initialized start the servos object in a new cog.
startOK := servos.start(@pin[noparse][[/noparse]0], @CurrPos[noparse][[/noparse]0], @NewPos[noparse][[/noparse]0], @NumPulses[noparse][[/noparse]0],@GradMove,@AccDecMove,@HoldPulse, NumServos)

'The bits used to set the type of movement and holding pulse option can be set individually for each servo
'however for this example all servo bits are set in the same way.
GradMove~ 'No Gradual Movement
AccDecMove~~ 'Use Accelerated/Decelerated moves
HoldPulse~~ 'Send holding pulses

mouvfemuravg := initfemuravg
mouvfemurmg := initfemurmg
mouvfemurarg := initfemurarg
mouvfemuravd := initfemuravd
mouvfemurmd := initfemurmd
mouvfemurard := initfemurard

repeat 'lowing lines use the sample M6 procedure to move the arm in a pre-defined sequence of movements.
M6(mouvfemuravg, mouvfemurmg, mouvfemurarg, mouvfemuravd, mouvfemurmd, mouvfemurard,100,5)' arm to storage position and hold it for 4 seconds.

'M1(5,900,50,0,1,1,1) 'Rotate Wrist
'M1(5,-900,50,0,1,1,3) 'Rotate Wrist and then wait 3 seconds


servos.stop 'Stop the servos object.

PRI M1(SER,POS,PULSES,GR,AD,HP,WAIT) 'Example of procedure to set all parameters of one servo and move it.
if GR
GradMove := GradMove | |<(SER-1)
else
GradMove := GradMove & !|<(SER-1)
if AD
AccDecMove := AccDecMove | |<(SER-1)
else
AccDecMove := AccDecMove & !|<(SER-1)
if HP
HoldPulse := HoldPulse | |<(SER-1)
else
HoldPulse := HoldPulse & !|<(SER-1)
NewPos[noparse][[/noparse]SER-1] := POS
NumPulses[noparse][[/noparse]SER-1]:= PULSES 'Executes movement
repeat while NumPulses[noparse][[/noparse]SER-1] 'Wait for movement to complete
if WAIT <> 0 'Wait additional seconds (optional)
waitcnt(clkfreq * WAIT + cnt)

PRI M6(POS1,POS2,POS3,POS4,POS5,POS6,PULSES, WAIT) | index 'Example of procedure to set new positions for 6 servos and move all of them at the same time.
NewPos[noparse][[/noparse]0] := POS1
NewPos := POS2
NewPos := POS4
NewPos := POS4
NewPos := POS5
NewPos := POS6
repeat index from 0 to NumServos-1
NumPulses[noparse][[/noparse]index]:= PULSES
repeat while NumPulses[noparse][[/noparse]0] | NumPulses | NumPulses | NumPulses| NumPulses | NumPulses 'Wait for movements to complete
if WAIT <> 0
waitcnt(clkfreq * WAIT + cnt)

PRI S6(POS1,POS2,POS3,POS4,POS5,POS6) 'Example of procedure to initialize the positions of 6 servos.
NewPos[noparse][[/noparse]0] := CurrPos[noparse][[/noparse]0]:= POS1
NewPos := CurrPos:= POS2
NewPos := CurrPos:= POS3
NewPos := CurrPos:= POS4
NewPos := CurrPos:= POS5
NewPos := CurrPos:= POS6

the variables don't works when they are negative but if a replace a variable in the M6 command by a negative number it works. Any idea why ?

Comments

Sign In or Register to comment.