Shop OBEX P1 Docs P2 Docs Learn Events
Stopping Servo32 object. and powering down the servos. — Parallax Forums

Stopping Servo32 object. and powering down the servos.

DgswanerDgswaner Posts: 795
edited 2008-08-18 18:51 in Propeller 1
when my bot is in IR Remote mode, there is no need to have the servos on and holding a position. I tried adding a cogstop(CogID) line to the Servo object when 9999 was sent as the Width. SERVO.Set(PanServo,9999). but this didn't seem to have the desired effect.

here is what I used.

PUB Set(Pin, Width)                                                             'Set Servo value
      If width == 9999
         stopcog(cogid)
      else
        Width := 1000 #> Width <# 2000                                            'limit Width value between 1000uS and 2000uS
          Pin :=    0 #>   Pin <# 31                                              'limit Pin value between 0 and 31
        ServoData[noparse][[/noparse]Pin] := (clkfreq / _1uS * Width)                                 'calculate # of clocks for a specific Pulse Width
        dira[noparse][[/noparse]Pin] := 1                                                            'set selected servo pin as an OUTPUT
        ServoPinDirection := dira                                                 'Read I/O state of ALL pins



I even tried a version where I made the pins go low, but it still didn't work. is there a way to stop this object?

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"A complex design is the sign of an inferior designer." - Jamie Hyneman, Myth Buster

DGSwaner

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-08-18 17:47
    COGSTOP( COGID ) won't work because COGID returns the cog # for the cog running the COGID.

    You have to modify the Start method of Servo32, add a long variable called "cogNo" to the VAR section at the beginning, add "cogNo :=" just in front of the COGNEW in the Start method so you'll save the cog #, then use "IF cogNo => 0" followed by "COGSTOP( cogNo )" in your Set method.
  • DgswanerDgswaner Posts: 795
    edited 2008-08-18 18:30
    I've seen that before I think I can make it work. but just so I understand.

    cog 0: running main control loop
    cog 1: servo handler

    if the code Cog 1 is running executes a COGID command it would return 0?

    I have no doubt that your right, but reading the manual made me thing it would return 1. and therefor work. I have a lot to learn!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "A complex design is the sign of an inferior designer." - Jamie Hyneman, Myth Buster

    DGSwaner
  • Mike GreenMike Green Posts: 23,101
    edited 2008-08-18 18:36
    If COGID is executed by cog #1, the COGID will return 1. If COGID is executed by cog #0, the COGID will return 0.
    COGNEW returns the number of the cog that's started or -1 if there are no cogs available.
  • DgswanerDgswaner Posts: 795
    edited 2008-08-18 18:51
    ok, I see where I was wrong. I was thinking the whole servo object was running in a separate cog. but it's just the servostart function that is running in a separate cog.

    Thanks for your help. and patience

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "A complex design is the sign of an inferior designer." - Jamie Hyneman, Myth Buster

    DGSwaner
Sign In or Register to comment.