Shop OBEX P1 Docs P2 Docs Learn Events
Servo32_Demo Object questions — Parallax Forums

Servo32_Demo Object questions

Paul K.Paul K. Posts: 150
edited 2007-10-11 12:34 in Propeller 1
I've been playing around with this program and trying to figure this out.
Below is a portion of the·object that·I dont know how to accomplish what I need it to do.·

'Pan selected DEMO servo3 & 4 back-n-forth opposite of each other
···· repeat temp from 1000 to 2000
····· waitcnt (cnt+125_000)
····· SERVO.Set(PanServo3,temp)
····· SERVO.Set(PanServo4,3000-temp)
···· repeat temp from 2000 to 1000
····· waitcnt (cnt+125_000)
····· SERVO.Set(PanServo3,temp)
····· SERVO.Set(PanServo4,3000-temp)

How·can this be·modified·to control two servos with different temp values.
For example I need servo 3 to travel from 1500 to 2000 and servo 4 to travel from 1000 to 1500.
I can do it where each moves but I cant get them to move at the same time.·

Is this even possible.

Thanks
Paul

Comments

  • Beau SchwabeBeau Schwabe Posts: 6,559
    edited 2007-10-10 17:50
    Paul,
    Try this....

    Servos move in same direction:
         repeat temp from 1500 to 2000
          waitcnt (cnt+125_000)
          SERVO.Set(PanServo3,temp)
          SERVO.Set(PanServo4,temp-500)
         repeat temp from 2000 to 1500
          waitcnt (cnt+125_000)
          SERVO.Set(PanServo3,temp)
          SERVO.Set(PanServo4,temp-500)
    
    

    Servos move in opposite·direction:
         repeat temp from 1500 to 2000
          waitcnt (cnt+125_000)
          SERVO.Set(PanServo3,temp)
          SERVO.Set(PanServo4,3000-temp)
         repeat temp from 2000 to 1500
          waitcnt (cnt+125_000)
          SERVO.Set(PanServo3,temp)
          SERVO.Set(PanServo4,3000-temp)
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • Paul K.Paul K. Posts: 150
    edited 2007-10-10 18:29
    Beau

    I understand your two examples.· My example that I gave was actually a bad one.
    What I meant is something like this

    Servo1 needs to move from 1200 to 1500
    Servo2 needs to move from 1000 to 1800

    This is more of what I was trying to ask in the first post.
    Subtracting or adding to temp dosent quite work.· Unless I'm missing something.

    is there another way of coding the repeat so multipule values can be instereted only directed to
    either one of the servos.

    Hope this makes sense
    Paul

    Post Edited (Paul K.) : 10/10/2007 6:42:23 PM GMT
  • Beau SchwabeBeau Schwabe Posts: 6,559
    edited 2007-10-10 19:17
    Paul,
    This is just math trivia... What you need to do is determine a common reference denominator that
    represents the passage of time from point A to point B.· This can be any arbitrary value.· Typically,
    I use 0 to 100 as a percentage, but because we want a decent resolution we might use something
    more like 0 to 1000.· So we setup the subroutine like this....
    repeat temp from 0 to 1000
      waitcnt (cnt+125_000)         'This is simply an arbitrary delay, you can adjust this to whatever you want
      
      temp1 = temp * 300 / 1000     'This equates to the current incremental temp value times the delta of Servo3
                                    'so that while temp goes from 0 to 1000, temp1 will go from 0 to 300
                                    '
                                    '1500 - 1200 = 300
     
     
      temp2 = temp * 800 / 1000     'Same thing for Servo4... This equates to the current incremental temp value
                                    'times the delta of Servo4 so that while temp goes from 0 to 1000, temp2 will
                                    'go from 0 to 800
                                    '
                                    '1800 - 1000 = 800
    'Servo3
    '---------------------------------------------------------------------------------
      SERVO.Set(PanServo3,1200 + temp1)    '<--- Don't use BOTH ; use one or the other
    'or to switch direction...
      SERVO.Set(PanServo3,1500 - temp1)    '<--- Don't use BOTH ; use one or the other
    '---------------------------------------------------------------------------------
     
    'Servo4
    '---------------------------------------------------------------------------------
      SERVO.Set(PanServo4,1000 + temp2)    '<--- Don't use BOTH ; use one or the other
    'or to switch direction...
      SERVO.Set(PanServo4,1800 - temp2)    '<--- Don't use BOTH ; use one or the other
    '---------------------------------------------------------------------------------
    

    ·

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.

    Post Edited (Beau Schwabe (Parallax)) : 10/11/2007 1:54:38 PM GMT
  • Stan671Stan671 Posts: 103
    edited 2007-10-11 12:34
    You explained that very well, Beau. Thanks.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Stan Dobrowski
Sign In or Register to comment.