Shop OBEX P1 Docs P2 Docs Learn Events
Prop / Servo32v7 & Servo32_Ramp_v2 questions — Parallax Forums

Prop / Servo32v7 & Servo32_Ramp_v2 questions

Spiral_72Spiral_72 Posts: 791
edited 2012-01-17 21:32 in Propeller 1
First I'd be happy to read the manual if there's a full documentation available.... I haven't found one.

I feel pretty confident with the Servo32v7 object, however due to a problem I can't seem to find in "MY" servo ramping code I decided it was time to try out the Servo32_Ramp_v2 object suggested by someone.

Here's my code which started as Servo32v7_RampDemo code. I edited it to learn how it works:
CON
    _clkmode = xtal1 + pll16x                           
    _xinfreq = 5_000_000                                'Note Clock Speed for your setup!!

    ServoCh1 = 0                                        'Select DEMO servo
    _RampDelay  = 10            ' ramp time in seconds

VAR
    
OBJ
  SERVO : "Servo32v7.spin"

PUB Servo32_DEMO | temp

    SERVO.Start                 'Start Servo handler
    SERVO.Ramp                  '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 

repeat
'         'Set(Pin, Width)
    SERVO.Set(ServoCh1,1500)                    'Move Servo to Center

          'SetRamp(Pin, Width,Delay)<-- 100 = 1 sec 6000 = 1 min    
    SERVO.SetRamp(ServoCh1,2000,_RampDelay*100) 'Pan Servo N seconds
    waitcnt(clkfreq * _RampDelay + cnt)         'Wait for ramp to complete
    
    SERVO.SetRamp(ServoCh1,1000,_RampDelay*100)  'Pan Servo, duration = 1/2 original sweep time
    waitcnt(clkfreq * _RampDelay + cnt)         'Wait for ramp to complete
                                              
    SERVO.Set(ServoCh1,1500)                    'Force Servo to Center



As I understand it, SetRamp is called with the following three parameters:
Pin the servo is connected to
PulseWidth (position) to send the servo to, from it's current position
Delay (Duration) of time for the move where 100 = 1sec, 6000 = 60sec so n = seconds * 100

Correct me, cause this isn't working like I think it should. Where am I wrong?
Prop set to 80Mhz
Constant _RampDelay is set to 10 seconds
Send the servo to center (1500us) with Servo.Set
Ramp the servo to 2000us over 10 seconds ( _RampDelay * 100)
Wait for the ramp to complete (10 seconds)
Ramp the servo to 1000us over 5 seconds ( _RampDelay * 50) or (_RampDelay / 2 *100)
Wait for the ramp to complete (10 seconds)..... so the servo should move to position in 5sec then wait 5sec
Send the servo to center (1500us) with Servo.Set

Instead it centers, moves in about two seconds, waits ten seconds, moves in two seconds, waits ten, then back to center!!??!!


What gives?

Comments

  • Spiral_72Spiral_72 Posts: 791
    edited 2012-01-17 19:17
    If I change _RampDelay to 40 instead of 10..... a factor of four it looks like servo ramp gives me the ten second move I'm looking for. ARG!
  • Spiral_72Spiral_72 Posts: 791
    edited 2012-01-17 19:22
    um, sorry folks. I didn't even need to post all this. I just needed to slow my mind enough to write it all out and it come to me:

    the CoreSpeed constant in Servo32_Ramp_v2 is a scaling function. You change it according to your clock speed. I realized this after saying "It's off by a scale of FOUR".

    CoreSpeed was set to 620..... 620 / 4 is 155 or really close to 160.... the minimum option mentioned in the code comments. Change the CoreSpeed and it works just like I intended.


    Can I delete all this? I've been working on it for an hour and half I swear!
  • JonnyMacJonnyMac Posts: 9,198
    edited 2012-01-17 20:10
    If your project doesn't need more than eight servos I've written a servo controller object -- in Spin, that anyone can understand and modify -- the supports 1us resolution and speed ("ramping") control. Truth be told, I created a driver that mimics the features of the popular SSC-32 servo controller from Lynxmotion. What I like about its features is that one can specify the servo speed in terms of microseconds servo position change per second of real time -- this makes figuring out what speed setting to use far less daunting, and servo behavior, especially when coordinating multiple servos, far more predictable.

    The file in ObEx has demo code that shows you how to use the features.
    -- http://obex.parallax.com/objects/445/
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-01-17 20:10
    Spiral_72,

    I hope you don't delete this. I was also having trouble understanding the ramping option of Servo32v7. These posts have helped me understand it better.

    Thank you.
  • Spiral_72Spiral_72 Posts: 791
    edited 2012-01-17 21:32
    JohnnyMac: Very cool. I'll check it out. Thank you. The Servo32_Ramp_v2 function is a little rough in it's movement for slow and / or small moves. It seems that the increments are too coarse and I don't know how to change the assembly code (yet). I'll definitely look into yours

    Duane: What!? You led me the way man, surely I can't help you!.................I won't delete it.... The way things worked out was kinda silly and a little embarrassing maybe. I answered my own question after giving up and posting it here.

    Like I mentioned the ServoRamp object does not have the intermittent issue that my interpolation routine does, but my code is MUCH smoother. Gosh I wish I knew what was wrong with mine....... I guess that comment doesn't mean much if y'all haven't been following my biped build.

    Don't get me wrong, the servo32_ramp_v2 is fantastic. I loved it with all the large test moves, but the data points I'm feeding it are fine control.... small movements.
Sign In or Register to comment.