Question about try to control my servos with parallel control
kevinspace
Posts: 56
Hello everyone!
I have an idea about the Propeller controller, but it seems to encounter some problems.
Everybody know the propeller controller which has 8 cogs, so its advantages is enable to implement parallel
control. Therefore, I want to control several servos at the same time.
I connected the Propeller Demo Board with the Propeller Servo Controller by serial port that try to control my
servos with parallel control.
But I discover some problems, I know the Propeller Demo Board chip and the Propeller Servo Controller
chip are contain multi-cog, but the communication of them is only one path (serial port ). Therefore,
the parallel control idea which will be limited to achieve it.
Is there have anyone can supply me any suggestions.
Here is my test code.
OBJ
PSC : "ServoControllerSerial"
CON
_CLKMODE = XTAL1 + PLL16X
_XINFREQ = 5_000_000
COMPIN = 0 'Pin used for communication with the PSC
PSC_BAUD = 0 'Baud rate (0 - 2400, 1 - 38400)
VAR long Stack[100]
PUB LaunchBlinkCogs
coginit(1,Program1, @stack[0])
coginit(2,Program2, @stack[50])
PUB Program1
PSC.START(COMPIN, PSC_BAUD)
PSC.SETPOS (0, 1, 350)
dira[16] := 1
outa[16] := 1
PUB Program2
PSC.START(COMPIN, PSC_BAUD)
PSC.SETPOS (7, 1, 350)
dira[23] := 1
outa[23] := 1
The result of the test code only one servo was turning.
I modified the test code, I added the delay time into the code, the two servo were turning.
But that is not parallel control.
I have an idea about the Propeller controller, but it seems to encounter some problems.
Everybody know the propeller controller which has 8 cogs, so its advantages is enable to implement parallel
control. Therefore, I want to control several servos at the same time.
I connected the Propeller Demo Board with the Propeller Servo Controller by serial port that try to control my
servos with parallel control.
But I discover some problems, I know the Propeller Demo Board chip and the Propeller Servo Controller
chip are contain multi-cog, but the communication of them is only one path (serial port ). Therefore,
the parallel control idea which will be limited to achieve it.
Is there have anyone can supply me any suggestions.
Here is my test code.
OBJ
PSC : "ServoControllerSerial"
CON
_CLKMODE = XTAL1 + PLL16X
_XINFREQ = 5_000_000
COMPIN = 0 'Pin used for communication with the PSC
PSC_BAUD = 0 'Baud rate (0 - 2400, 1 - 38400)
VAR long Stack[100]
PUB LaunchBlinkCogs
coginit(1,Program1, @stack[0])
coginit(2,Program2, @stack[50])
PUB Program1
PSC.START(COMPIN, PSC_BAUD)
PSC.SETPOS (0, 1, 350)
dira[16] := 1
outa[16] := 1
PUB Program2
PSC.START(COMPIN, PSC_BAUD)
PSC.SETPOS (7, 1, 350)
dira[23] := 1
outa[23] := 1
The result of the test code only one servo was turning.
I modified the test code, I added the delay time into the code, the two servo were turning.
But that is not parallel control.
Comments
If you are no longer using the PSC (I don't think that the case due to the OBJ declaration) and want to control servos directly with the Prop, then take a look in the OBEX for Servo32v7.
http://obex.parallax.com/objects/51/
Send two position commands if you want two servos to move at the same time using a single PSC.
I only used one Propeller Demo Board and one Propeller Servo Controller,
and I set one of the Demo Board I/O Pin as serial port which connected with the PSC serial port.
I tried another way to control several servos by only used the Propeller Demo Board, that meaning the way
which doesn't connect with the PSC.
I downloaded the OBEX for Servo32v7 (http://obex.parallax.com/objects/51/),
Then I used the "Servo32v7_RampDemo.spin" to control my servos. I hoped that I can let the servos turn
at the same time by used different cogs.
Here is my test code.
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000 'Note Clock Speed for your setup!!
ServoCh1 = 0 'Select DEMO servo
ServoCh2 = 1
VAR long Stack[100]
PUB LaunchCogs
coginit(1,Servo32_DEMO, @stack[0])
coginit(2,Servo32_DEMO2, @stack[50])
OBJ
SERVO : "Servo32v7.spin"
PUB Servo32_DEMO | temp
SERVO.Start
SERVO.Ramp
SERVO.Set(ServoCh1,1500)
SERVO.SetRamp(ServoCh1,700,200)
repeat 800000
SERVO.SetRamp(ServoCh1,2300,200)
repeat 800000
SERVO.SetRamp(ServoCh1,700,200)
repeat 800000
SERVO.SetRamp(ServoCh1,2300,200)
repeat 800000
SERVO.Set(ServoCh1,1500)
PUB Servo32_DEMO2 | temp2
SERVO.Start
SERVO.Ramp
SERVO.Set(ServoCh2,1500)
SERVO.SetRamp(ServoCh2,700,200)
repeat 800000
SERVO.SetRamp(ServoCh2,2300,200)
repeat 800000
SERVO.SetRamp(ServoCh2,700,200)
repeat 800000
SERVO.SetRamp(ServoCh2,2300,200)
repeat 800000
SERVO.Set(ServoCh2,1500)
Above the code, its result is only let "PUB Servo32_DEMO2" to implement.
Here is the video.
I discovered that I must have to add the delay time bttween the two cogs, in this way that would be able to run the two cogs.
coginit(1,Servo32_DEMO, @stack[0])
waitcnt(clkfreq + cnt)
add these
coginit(2,Servo32_DEMO2, @stack[50])
Here is the video
I looked at your code, why are you starting new cogs?
The Servo 32v7_ RampDempo will control 32 servo with 1 cog, two with ramping. Just as written.
Just add more servos like below I added code to move one more servo, if you want 3 add one more up to 32 servos. The pulse for servo 1 will be on port pin 0, the output for servo2 will be on port pin1.
I tried it on my demo board, but I only have one servo, so I had to move it and then do a reset. Both pins will drive the servo. Let me know if this works for you.
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000 'Note Clock Speed for your setup!!
ServoCh1 = 0
ServoCh2 = 1 'Select DEMO servo
VAR
OBJ
SERVO : "Servo32v7.spin"
PUB Servo32_DEMO | temp
SERVO.Start 'Start Servo handler
SERVO.Ramp '<-OPTIONAL 'Start Background Ramping
'Note: Ramping requires another COG
' If ramping is not started, then
' 'SetRamp' commands within the
' program are ignored
'
'Note: At ANY time, the 'Set' command overides
' the servo position. To 'Ramp' from the
' current position to the next position,
' you must use the 'SetRamp' command
' 'Set(Pin, Width)
SERVO.Set(ServoCh1,1500) 'Move Servo 1 to Center
SERVO.Set(ServoCh2,1500) 'Move Servo 2 to Center
'SetRamp(Pin, Width,Delay)<-- 100 = 1 sec 6000 = 1 min
SERVO.SetRamp(ServoCh1,2000,200) 'Pan Servo 1
SERVO.SetRamp(ServoCh2,2000,200) 'Pan Servo 2
repeat 1500000 'Do nothing here just to wait for
'background ramping to complete
SERVO.SetRamp(ServoCh1,1000,50) 'Pan Servo 1
SERVO.SetRamp(ServoCh2,2000,200) 'Pan Servo 2
repeat 800000 'Do nothing here just to wait for
'background ramping to complete
SERVO.Set(ServoCh1,1500) 'Force Servo to Center
SERVO.Set(ServoCh2,1500) 'Force Servo to Center
Sorry, I lost the format.But you get the Idea.
Jon hit the nail on the head. If you look at the code, Kevin wants more than one process (COG) to control servos. You can't very well have multiple processes telling commanding the servos at the same. However, you could do what Jon so succinctly suggested.
or
Note how a process waits until it can set the shared lock before sending its message, then releases it immediately after.