Adafruit 16-Channel 12-bit PWM/Servo Driver - I2C interface
Moderators: adafruit_support_bill, adafruit

Adafruit 16-Channel 12-bit PWM/Servo Driver - I2C interface

by tomega3 on Wed Sep 12, 2012 3:36 pm

Hi, I would like to use the Adafruit 16-Channel 12-bit PWM/Servo Driver - I2C interface
with a HiTech HS-645MG that has been modified for 180 degree rotation. servocity says:

"This servo can operate 180° when given a pulse signal ranging from 600usec to 2400usec. Since most R/C controllers cannot generate this wide of signal range, you will need to purchase our servo stretcher for 180° operation.:

1500 usec is neutral, 600 usec is 90 degrees to the left, and 2400 usec is 90 degrees to the right.

I read over the PCA9685 spec sheet and see that the pulse length goes from 0 to 4096. the example arduino sketch provided by adafruit sets
#define SERVOMIN 150 // this is the 'minimum' pulse length count (out of 4096)
#define SERVOMAX 600 // this is the 'maximum' pulse length count (out of 4096)

What should I set SERVOMIN and SERVOMAX to in order to use the HS-645MG servo for full 180 degree operations.
What do I need to set to have the servo in neutral position? (1500 usec)

Thanks,
Tom
tomega3
 
Posts: 24
Joined: Sun Aug 05, 2012 11:24 am

Re: Adafruit 16-Channel 12-bit PWM/Servo Driver - I2C interface

by adafruit_support_bill on Wed Sep 12, 2012 5:03 pm

The default range definitions in the Servo sample code are pretty close.
Theoretically, they will give you a pulse range between 610 and 2440uS.
Code: Select all | TOGGLE FULL SIZE
#define SERVOMIN  150 // this is the 'minimum' pulse length count (out of 4096)
#define SERVOMAX  600 // this is the 'maximum' pulse length count (out of 4096)

The pulse width is the base clock period (60 Hz = 16.666667 mS) divided by 4096 and multiplied by a number scaled between SERVOMIN and SERVOMAX.

Practically, these are analog servos and you will want to tune them individually to get the max range. The PWM driver chip clock might be off by a few percentage points and the servo controller boards are going to vary by at least as much. I know the HS-645MGs fairly well. I have 18 of them in my 3ODF hexapod and they are all need a bit of trim for accurate IK.
User avatar
adafruit_support_bill
 
Posts: 31079
Joined: Sat Feb 07, 2009 10:11 am

Re: Adafruit 16-Channel 12-bit PWM/Servo Driver - I2C interface

by tomega3 on Wed Sep 12, 2012 5:41 pm

Hi, Thank you very much.

I did the math and get 610 usec min and 2441 usec for max

Question, are your HS-645MG set up for 180 degrees?

with a min of 150 and a max of 600 this is a difference of 450 so 450/180 gives 2.5 steps per increment or decrement of the value sent thru the I2C bus to the servo.
Does this translate into 2.5 degrees of angle on the servo per increment? or am I missing something in the math?
2.5 degrees seems large. How would you find and keep a stable neutral position?

I guess I can test each servo and set a Min and Max for them individually,
like
#define Servo1MIn 160
#define Servo1Max 600
#define Servo2Min 149
#define Servo1Max 620
and so on, then in code when I work with servo1 I just use its defines and for servo2 I use its defines.

What external power supply (voltas and amps) are you using to drive 18 servos?

Really appreciate your help in understanding how to use the adafruit i2c servor board with these 180 degree servos.
Thanks
Tom
tomega3
 
Posts: 24
Joined: Sun Aug 05, 2012 11:24 am

Re: Adafruit 16-Channel 12-bit PWM/Servo Driver - I2C interface

by adafruit_support_bill on Wed Sep 12, 2012 7:08 pm

Yes, my servos are 180 degrees. Assuming a 450 step range for 180 degrees, the math on the resolution is 180/450 or about 0.4 degrees. In practice however, I find that the servo's positional accuracy for a given pulse-width is more like +/- 1 degree.

Whatever your range is for a particular servo, the neutral (90 degree) position will be (Max + Min)/2.

I power my hexapod with a 3300mAh 7.2v rechargeable NiMH pack. That is slightly over spec for these servos, but it gives me better speed and/or payload capacity and I haven't had any problems with them at that voltage.
User avatar
adafruit_support_bill
 
Posts: 31079
Joined: Sat Feb 07, 2009 10:11 am

Re: Adafruit 16-Channel 12-bit PWM/Servo Driver - I2C interface

by tomega3 on Wed Sep 12, 2012 7:56 pm

Thanks, I figured I must have had the numerator and denominator mixed up.

I am know off to find a pan and tilt setup to use with the HS645MG servos.

Any recommendations?

Tom
tomega3
 
Posts: 24
Joined: Sun Aug 05, 2012 11:24 am

Re: Adafruit 16-Channel 12-bit PWM/Servo Driver - I2C interface

by adafruit_support_bill on Thu Sep 13, 2012 5:17 am

Depends on what you are mounting on it. Acroname used to have a really nice turret kit designed to hold a CMUCam and a bunch of sensors. The Lynxmotion pan/tilt kit is simple, but sturdy.
User avatar
adafruit_support_bill
 
Posts: 31079
Joined: Sat Feb 07, 2009 10:11 am

Re: Adafruit 16-Channel 12-bit PWM/Servo Driver - I2C interface

by tomega3 on Thu Sep 13, 2012 8:57 am

Thanks again,

Acroname no longer lists a pan tilt setup on their website.

I am considering a Lynx motion base rotate kit and a Servo City DDT500 direct drive tilt system available at robotshop.com

I just need to figure what all the other pieces I need to order to connect the 2 together, I will use a a HS645MG for the tilt system and see if the included hs422 that comes with the base is sufficient.
tomega3
 
Posts: 24
Joined: Sun Aug 05, 2012 11:24 am

Re: Adafruit 16-Channel 12-bit PWM/Servo Driver - I2C interface

by tikka308 on Tue Oct 09, 2012 9:26 pm

I'm using this driver with a Raspberry Pi and an HS-322HD (http://www.servocity.com/html/hs-322hd_ ... eluxe.html) that was modified for 180 degrees. This thread looks like it would answer what I'm struggling but, but it's a little over my head. All I am trying to do with the servo is two things: 1) have it wiggle (e.g. move forward ~10 degrees and reverse ~10 degrees and 2) have it rotate from ~0 degrees all the way to ~180 degrees, pause for 3 seconds, then go back to ~0 degrees.

I understand that tweaking "servoMin" and "servoMax" is what adjusts this - but I don't understand the logic or pattern as I've been experimenting. Not looking for anyone to do the work for me - just hoping someone can help me understand how I go about calculating/adjusting the servoMin & servoMax!

Thanks.

John
tikka308
 
Posts: 11
Joined: Fri Mar 09, 2012 10:09 am

Re: Adafruit 16-Channel 12-bit PWM/Servo Driver - I2C interface

by adafruit_support_bill on Wed Oct 10, 2012 5:46 am

If you run the Servo example sketch that comes with the library, it will continuously cycle between SERVOMIN and SERVOMAX. You need to adjust SERVOMIN so that the servo cycles to the 0 degrees position and SERVOMAX so that it cycles to the 180 degrees position.

Once you have that, you can calculate any degree position using the "map()" function.http://www.arduino.cc/en/Reference/map

Code: Select all | TOGGLE FULL SIZE
pulselen = map(degrees, 0, 180, SERVOMIN, SERVOMAX);
User avatar
adafruit_support_bill
 
Posts: 31079
Joined: Sat Feb 07, 2009 10:11 am

Re: Adafruit 16-Channel 12-bit PWM/Servo Driver - I2C interface

by tikka308 on Wed Oct 10, 2012 10:08 pm

I used the code below (see bold) but get the error "TypeError: argument 2 to map() must support iteration". I've used the map function with Arduino (as referenced in the link above) but with python/Raspberry Pi.

from Adafruit_PWM_Servo_Driver import PWM
import time

pwm = PWM(0x40, debug=True)

servoMin = 150 # Min pulse length out of 4096
servoMax = 600 # Max pulse length out of 4096

def setServoPulse(channel, pulse):
pulseLength = 1000000 # 1,000,000 us per second
pulseLength /= 60 # 60 Hz
print "%d us per period" % pulseLength
pulseLength /= 4096 # 12 bits of resolution
print "%d us per bit" % pulseLength
pulse *= 1000
pulse /= pulseLength
pwm.setPWM(channel, 0, pulse)

pwm.setPWMFreq(60) # Set frequency to 60 Hz
while (True):
# Change speed of continuous servo on channel O

pulselen = map(45,0,180,servoMin,servoMax)
time.sleep(0.5)
pulselen = map(90,0,180,servoMin,servoMax)
tikka308
 
Posts: 11
Joined: Fri Mar 09, 2012 10:09 am

Re: Adafruit 16-Channel 12-bit PWM/Servo Driver - I2C interface

by adafruit_support_bill on Thu Oct 11, 2012 5:44 am

Sorry, I missed the Pi part in your post. Python is not my native language and there may be a library function to do this, but the basic calculation to map 0-180 degrees to pulse length is:

((degrees * (servoMax - servoMin)) / 180) + servoMin
User avatar
adafruit_support_bill
 
Posts: 31079
Joined: Sat Feb 07, 2009 10:11 am