Shop OBEX P1 Docs P2 Docs Learn Events
Servo Upgrade — Parallax Forums

Servo Upgrade

FFAFFA Posts: 20
edited 2017-02-20 19:21 in Robotics
I am upgrading my robot with the some high torque servos for a specific application.

http://www.savoxusa.com/Savox_SC0251MG_Digital_Servo_p/savsc0251mg.htm

I have tried to alter my servo.spin files to drive these servos however I have had no luck. Could somebody please look at my servo.spin file text below and help me make the modification based on my new servos information from the link above? I removed the assembly language section here just to get it to fit here.
{{
*****************************************
* Servo32v7 Driver                   v7 *
* Author: Beau Schwabe                  *
* Copyright (c) 2009 Parallax           *
* See end of file for terms of use.     *
*****************************************


*****************************************************************
 Control up to 32-Servos      Version 7               08-18-2009 
*****************************************************************
 Coded by Beau Schwabe (Parallax).                                            
*****************************************************************

 History:
                            Version 1 -               initial concept

                            Version 2 - (03-08-2006)  Beta release
 
                            Version 3 - (11-04-2007)  Improved servo resolution to 1uS

                            Version 4 - (05-03-2009)  Ability to disable a servo channel
                                                      and remove channel preset requirement            

                            Version 5 - (05-08-2009)  Added ramping ability

                            Version 6 - (07-18-2009)  Fixed slight timing skew in ZoneLoop and
                                                      fixed overhead timing latency in ZoneCore

                            Version 7 - (08-18-2009)  Fixed servo jitter in ramping function when
                                                      servo reached it's target position.
                                                                                                                                          
Theory of Operation:

Each servo requires a pulse that varies from 1mS to 2mS with a period of 20mS.
To prevent a current surge nightmare, I have broken the 20mS period into four
groups or Zones of 8 servos each with a period of 5mS. What this does, is to
ensure that at any given moment in time, a maximum of only 8 servos are receiving
a pulse.

   Zone1 Zone2 Zone3    Zone4          In Zone1, servo pins  0- 7 are active
           In Zone2, servo pins  8-15 are active
  │─5mS│─5mS│─5mS│─5mS│        In Zone3, servo pins 16-23 are active
  │─────────20mS──────────│        In Zone4, servo pins 24-31 are active
                  
    1-2mS servo pulse 
              
The preferred circuit of choice is to place a 4.7K resistor on each signal input
to the servo.    If long leads are used, place a 1000uF cap at the servo power
connector.    Servo's seem to be happy with a 5V supply receiving a 3.3V signal.

}}

CON 
    _1uS = 1_000_000 /        1                                                 'Divisor for 1 uS

    ZonePeriod = 5_000                                                          '5mS (1/4th of typical servo period of 20mS)
    NoGlitchWindow = 3_000                                                      '3mS Glitch prevention window (set value larger than maximum servo width of 2.5mS)
                                                                                'Use at least 500uS for overhead (actual overhead about 300uS)

     LowRange = 500             '<- during Debug I changed this value to 1 to test 1us resolution
    HighRange = 2500                                                                                

VAR
        long          RampFlag
        long          ZoneClocks
        long          NoGlitch
        long          ServoPinDirection
        long          ServoData[32]                                             '0-31 Current Servo Value 
        long          ServoTarget[32]                                           '0-31 Desired Servo Value 
        long          ServoDelay[32]                                            '0-31 Servo Ramp Delay
        byte lpin,rpin
pub setpercent(pin,ppos)
  'position given in 0..100
  set(pin,ppos*12+900) 'from .9..2.1ms
PUB Start
    ZoneClocks := (clkfreq / _1uS * ZonePeriod)                                 'calculate # of clocks per ZonePeriod
    NoGlitch   := $FFFF_FFFF-(clkfreq / _1uS * NoGlitchWindow)                  'calculate # of clocks for GlitchFree servos. Problem occurs when 'cnt' value rollover is less than the servo's pulse width.                                                                                                                                                                                                                         
    cognew(@ServoStart,@ZoneClocks)
pub getServoData
  RampFlag:=1
  return @ServoData
PUB Set(Pin, Width)|S_Width                                                     'Set Servo value
      S_Width := LowRange #> Width <# HighRange                                 'limit Width value
      Pin :=    0 #> Pin <# 31                                                  'limit Pin value between 0 and 31
      ServoData[Pin] := ((clkfreq / _1uS * S_Width)/620)*620
      ServoTarget[Pin] := ServoData[Pin]

      if S_Width==Width 
         dira[Pin] := 1                                                         'set selected servo pin as an OUTPUT
      else
         dira[Pin] := 0                                                         'set selected servo pin as an INPUT only if Width out of range 
      ServoPinDirection := dira                                                 'Read I/O state of ALL pins
DAT

Comments

  • Hi FFA!

    I've added code tags for you around your code sample. Makes things much easier to read for members to help you.

    You can use code tags anytime you post code.... It's not so obvious, but the "C" button in the text-formatting panel will insert the tags for you.

    Have fun!
  • Thank you.
  • Based on the code you posted , I don't think anyone can figure out what you changed.

    What is the code that is using this driver?
  • The pulse duration is different with the high torque servo. Once the parameters are set correctly in this object then my current code should work.

    I calculate the zone period to be (1/1520)*1000*1000*(1/4) = 164. The parallax servo is at 5000 micro seconds or 5 milli seconds. Does this look correct? The no glitchwindo for the new servo will be roughly 100 and low and high range will be 4000 and 5000
  • It's interesting they wouldn't work with the old code, they seem like drop in replacements for standard RC servos.

    Are you sure it's not the IO pin voltage? Maybe the servo needs a little more signal than 3.3v?

  • FFAFFA Posts: 20
    edited 2017-02-21 00:21
    I thought the same thing.

    I have a Propeller Board of Education with the servo pin set to Vin. It is being powered with a 11.1 volt 3000mAh battery.

    https://www.parallax.com/sites/default/files/downloads/32900-Propeller-BOE-Documentation-v1.1_0.pdf

    Servo running current ~325mA. This seems like it should work.
  • xanaduxanadu Posts: 3,347
    edited 2017-02-21 01:15
    That's too much voltage. Sorry to say the servo may be ruined. The VIN jumper connects the servo power ports directly to your battery. This is okay with 4 or 5 AA batteries.

    Servo voltage should be 6 volts max, requiring up to 2.5 A. That's probably too much for a Board of Education. How many of these are you driving, and what are they doing?

    The servo's signal wire is usually 5 V logic level, most servos are okay with a 3.3 V, though.
  • xanadu wrote: »
    That's too much voltage. Sorry to say the servo may be ruined.

    I've burned out servos with a two cell LiPo. I think it's unlikely your servo survived being connected to a three cell LiPo. A fully charged 3-S LiPo pack can have an output of over 12.6V. Most servos are limited to 6V power supplies.
    xanadu wrote: »
    It's interesting they wouldn't work with the old code, they seem like drop in replacements for standard RC servos.

    I agree with xanadu on this. I think the original servo code should work fine with those servos.
  • I put my old servos back on. Is there a way I can test the new ones?
  • It turns out the servos are OK. The problem is that they are not continuous motion servos and had rotated to the end of their rotation. I can rotate them back and forth now. These would be really good for a griper or robotic arm but not on my robot with wheels.

    I did however get my wires crossed with my PING and fried it instead.
  • PublisonPublison Posts: 12,366
    edited 2017-02-21 15:58
    FFA wrote: »
    It turns out the servos are OK. The problem is that they are not continuous motion servos and had rotated to the end of their rotation. I can rotate them back and forth now. These would be really good for a griper or robotic arm but not on my robot with wheels.

    If I had gone to your first link and hit Technical Specs, I would have seen:
    Maximum travel: Approx 165°(when 800→2200 μsec)

    That would have thrown up a flag and saved you some time. :)

    Glad you back up and running.



  • MikeDYurMikeDYur Posts: 2,176
    edited 2017-02-21 22:41
    FFA wrote: »
    I did however get my wires crossed with my PING and fried it instead.

    There seems to be a rash of this lately, we need to slow down and double check connections before applying power. There should be a catchy phrase like the people in carpentry have: "Measure twice, cut once".
    How about: "Check twice, burn none".


    I do this a lot, given two jumper wires the same color, I will hook them up wrong the first time if i'm in a hurry. Double checking has saved my electronics more than once.
  • xanaduxanadu Posts: 3,347
    edited 2017-02-21 17:05
    I figured it was for a pan or pan/tilt servo setup. Glad they aren't fried, you could modify the servo for continuous rotation if you're into that kind of thing.


  • kwinnkwinn Posts: 8,697
    Sometimes you get lucky. Better to get in the habit of double checking all connections before powering up.
  • MikeDYur wrote: »
    FFA wrote: »
    I did however get my wires crossed with my PING and fried it instead.

    There seems to be a rash of this lately, we need to slow down and double check connections before applying power. There should be a catchy phrase like the people in carpentry have: "Measure twice, cut once".
    How about: "Check twice, burn none".


    I do this a lot, given two jumper wires the same color, I will hook them up wrong the first time if i'm in a hurry. Double checking has saved my electronics more than once.

    Bad habit.

    Enjoy!

    Mike
Sign In or Register to comment.