Shop OBEX P1 Docs P2 Docs Learn Events
Another problem about the object "servo32v7" — Parallax Forums

Another problem about the object "servo32v7"

kevinspacekevinspace Posts: 56
edited 2011-01-21 12:53 in Propeller 1
Hello everybody, I'm encountered another problem about the object "servo32v7_RampDemo".

(http://obex.parallax.com/objects/51/)

I want to use 8 cogs to control 8 servos with the object "servo32v7", but I discover if I'm using the

servo32v7's command once, that will excite 3 cogs. (because the command of Start and the Ramp

which in the object servo32v7both require new cog to excite it )

Just like the program :

CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
ServoCh1 = 0 'Select DEMO servo

OBJ
SERVO : "Servo32v7.spin"

PUB Servo32_DEMO
SERVO.Start ' The Start command will excite a new cog
SERVO.Ramp ' The Ramp command will excite another new cog
SERVO.Set(ServoCh1,1500)

SERVO.SetRamp(ServoCh1,2000,200)
repeat 800000
SERVO.SetRamp(ServoCh1,1000,50)
repeat 800000
SERVO.Set(ServoCh1,1500)

Therefore, If I want to use 8 cogs to control 8 servos with the object "servo32v7",

the cogs will use insufficiently.

Here is my test program :

CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
ServoCh0 = 0 'Select DEMO servo
ServoCh1 = 1
ServoCh2 = 2

VAR long Stack[100]
long Position
OBJ
SERVO[3] : "Servo32v7.spin"

PUB LaunchCogs
cognew(Servo32_DEMO0, @stack[0])
cognew(Servo32_DEMO1, @stack[10])
cognew(Servo32_DEMO2, @stack[20])

PUB Servo32_DEMO0
SERVO[0].Start
SERVO[0].Ramp
SERVO[0].Set(ServoCh0,1500)
waitcnt(clkfreq + cnt)

SERVO[0].SetRamp(ServoCh0,700,100)
waitcnt(clkfreq + cnt)
SERVO[0].SetRamp(ServoCh0,2300,100)
waitcnt(clkfreq + cnt)

PUB Servo32_DEMO1
SERVO[1].Start
SERVO[1].Ramp
SERVO[1].Set(ServoCh1,1500)
waitcnt(clkfreq + cnt)

SERVO[1].SetRamp(ServoCh1,700,100)
waitcnt(clkfreq + cnt)
SERVO[1].SetRamp(ServoCh1,2300,100)
waitcnt(clkfreq + cnt)

PUB Servo32_DEMO2
SERVO[2].Start
SERVO[2].Ramp
SERVO[2].Set(ServoCh2,1500)
waitcnt(clkfreq + cnt)

SERVO[2].SetRamp(ServoCh2,700,100)
waitcnt(clkfreq + cnt)
SERVO[2].SetRamp(ServoCh2,2300,100)
waitcnt(clkfreq + cnt)

Above my test program, that only excite the ServoCh0 and the ServoCh1, but the ServoCh2 didn't excite.
(I think the cogs are not enough to excite)

Could someone can offer me some suggestions?

thanks.

Comments

  • TtailspinTtailspin Posts: 1,326
    edited 2011-01-14 07:30
    I want to use 8 cogs to control 8 servos with the object "servo32v7",
    You can not work that... must only use one "servo32v7"... then You can make run 32 servo's...

    That is the reason why the Program is called "servo32v7", it will allow for 32 servo's on one cog only..
    (two cogs if You want "ramping")

    Only use Servo.Start, and Servo.Ramp, just one time only...then use ServoSet(ServoCh(X)) and ServoRamp(ServoCh(X))...
  • kevinspacekevinspace Posts: 56
    edited 2011-01-16 19:13
    Ttailspin wrote: »
    You can not work that... must only use one "servo32v7"... then You can make run 32 servo's...

    That is the reason why the Program is called "servo32v7", it will allow for 32 servo's on one cog only..
    (two cogs if You want "ramping")

    Only use Servo.Start, and Servo.Ramp, just one time only...then use ServoSet(ServoCh(X)) and ServoRamp(ServoCh(X))...

    Thanks for your attention, Ttailspin .

    Because I want to control the servos by parallel, so I hope to use one cog to control one servo.

    Therefore, that wii cause not enough cogs for my case, so I think I must to modify the object "servo32v7" for my case.

    In this way, that will be able to do the parallel control, could you help me or give me any suggesstion??
  • Mike GreenMike Green Posts: 23,101
    edited 2011-01-16 19:40
    What do you mean by "control the servos by parallel"?

    Servo32v7 controls up to 32 servos using only one cog. It essentially controls them in parallel. The servos are separated into groups so they don't all start moving at the same time and create a large current surge. Read the comments at the start of the source code for servo32v7 for a description of this.
  • kevinspacekevinspace Posts: 56
    edited 2011-01-21 00:34
    Mike Green wrote: »
    What do you mean by "control the servos by parallel"?

    Servo32v7 controls up to 32 servos using only one cog. It essentially controls them in parallel. The servos are separated into groups so they don't all start moving at the same time and create a large current surge. Read the comments at the start of the source code for servo32v7 for a description of this.

    Hellow, Mike Green!

    The parallel control idea is that control the servos with many cogs, for example, I want to use 3 cogs to control 3 servos with their own PUB respectively,and the 3 cogs will operated some variable respectively, and the variables are global variable which can called by any cogs.

    Because the centralized control which only used one cog to control several servos, threfore, the operated speed is more slower than the parallel control method.

    I try to replace the centralized control method with the parallel control idea.

    Could you can offer some suggestions for me?

    thanks.
  • JasonDorieJasonDorie Posts: 1,930
    edited 2011-01-21 00:48
    I don't think you understand - Servo32 will control 32 servos at "full speed", meaning an update rate of 50 times per second, which is what standard servos require. You simply tell Servo32 object where each servo should be positioned, and it continuously updates ALL the servos constantly, in parallel. You don't need to use another cog - it's already fast enough to control a servo on every single pin of the Propeller.

    It may be that the ramp demo or some other piece of code you're working with isn't handling more than one servo at a time correctly, but I can assure you that the Servo32 object is as fast as it needs to be. In fact, it's possible to modify the assembly code of Servo32 to make it run 8 servos (in parallel) at an update rate of 200 updates per second, all with a single cog.
  • StefanL38StefanL38 Posts: 2,292
    edited 2011-01-21 10:29
    I guess you have not fully understand what cogs, methods and objects are.

    cogs are all co-processors. If you don't need to actualise the servo-positions 100.000 times per second one cog is fast enough to control 32 servos de facto in PARALLEL
    but coded as a single repeat-loop that updates all servos in SEQUENCE.

    CREATING the servo-position signals (examples 30° left, 20° right, 110° right etc. etc.) is done by the PASM-cog of the Servo32v7-object

    Imagine a drummer sitting in front of his drum-kit that has maybe 6 drums hi-hat etc.
    If the drummer is good he will be able to hit several drums within a second

    Your servos need a SINGLE "hit" every 20 milliseconds
    the servo32v7-object can distribute "hits" to 32 DIFFERENT IO-pins within that time. So you really need just ONE cog to serve ALL 32 servos within a timeframe that
    controls them sufficiently to hold or change their position as you like it.

    For any higher functions like
    - if IO-pin 8 is high drive servo 5 to position 45° right
    - if MyVar13 > 120 then drive servp 1 to postion neutral middle etc. etc.
    you might need some cogs in parallel.

    If you can specify the fastest needed update-frequency and what you want to do IN THE END
    meaning giving the forum an overview about your project

    good suggestions on how to solve this can be made

    best regards

    Stefan
  • Mike GMike G Posts: 2,702
    edited 2011-01-21 12:53
    @Kevin, consider taking a look at the Dual Servo control objects in the OBEX to get some ideas for implementing your unique process.
Sign In or Register to comment.