16 Channel Servo Driver - travel speed
Moderators: adafruit_support_bill, adafruit

Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/

16 Channel Servo Driver - travel speed

by d0ctr on Sat Jan 12, 2013 7:09 pm

Hey guys,

I just got the 16 Channel Servo Driver a couple days ago, everything's working fine.. I'm on the way to replace my custom build SPI Servo Drivers on my humanoid robot with this I2C one because I decided to let a RPi run the bot via Python, etc. this just makes everything easier, no compiling/flashing/etc. anymore. Just code, run the .py file and done.

But I'm stuck with two things, also I'm new to python.

#1: pwm.setPWM(servoChannel, 0, endPosition)
I didn't really study the library, but what the heck is the second argument (where I placed the 0) for? For me it looks like an offset?

#2: Travel speed
As I'm new to python and to adafruits lib, is there any function to control the speed of travel? For example I want to let the servo travel to it's end position in about 30 seconds, how could I do it? If I have to write the function does anybody have an idea for me? I don't want the whole code! I want to do this on my own but I need an idea how to start. I appreciate every help!


Cheers
d0ctr
User avatar
d0ctr
 
Posts: 1
Joined: Sat Jan 12, 2013 6:42 pm
Location: Düsseldorf, Germany

Re: 16 Channel Servo Driver - travel speed

by adafruit_support_bill on Sun Jan 13, 2013 7:57 am

The library documentation is here: http://learn.adafruit.com/adafruit-16-c ... -reference

To control the servo sweep speed, you need to write a loop that incrementally updates the servo position over time. For example, to sweep 180 degrees in 30 seconds, you could write a loop that increments the position by 3 degrees every 500 milliseconds.
User avatar
adafruit_support_bill
 
Posts: 31070
Joined: Sat Feb 07, 2009 10:11 am

Re: 16 Channel Servo Driver - travel speed

by bennakhi on Sun Nov 10, 2013 6:08 am

adafruit_support_bill wrote:The library documentation is here: http://learn.adafruit.com/adafruit-16-c ... -reference

To control the servo sweep speed, you need to write a loop that incrementally updates the servo position over time. For example, to sweep 180 degrees in 30 seconds, you could write a loop that increments the position by 3 degrees every 500 milliseconds.


could you post a python code example ?
bennakhi
 
Posts: 6
Joined: Sat Nov 09, 2013 2:33 am

Re: 16 Channel Servo Driver - travel speed

by adafruit_support_mike on Sun Nov 10, 2013 2:21 pm

This script will sweep the control pulses from the lowest to highest value and back again:

Code: Select all | TOGGLE FULL SIZE
#!/usr/bin/python

from Adafruit_PWM_Servo_Driver import PWM
import time

# ===========================================================================
# Example Code
# ===========================================================================

# Initialise the PWM device using the default address
pwm = PWM(0x40, debug=True)

servoMin  = 150  # Min pulse length out of 4096
servoMax  = 600  # Max pulse length out of 4096
sweepTime = 30   # We want the sweep to last 30 seconds
stepSize  = 10   # We'll change the pulse by a small amount each time

steps     = (servoMax - servoMin) / stepSize    # Calculate the number of steps we'll need
stepTime  = sweepTime / float( steps )          # Calculate the delay between changes

#  The calculation for stepTime looks a bit strange because of the way Python
#  does math.  If you divide an integer by another integer, it will round the
#  result down to the nearest integer.  If you want a floating point value, you
#  need to include a floating point number in the calculation.  The `float()`
#  function forces the intepreter to treat `steps` as a floating point value.

pwm.setPWMFreq(60)                                # Set frequency to 60 Hz

for t in range( 0, 2*steps ):                     # Make the cycle long enough for a sweep up and back
    if t < steps:
        n = t                                     # For the first half of the cycle, count up
    else:
        n = (2 * steps) - t                       # For the second half of the cycle, count down

    pwm.setPWM( 0, 0, servoMin + (n * stepSize) ) # Make the pulse width depend on the count
    time.sleep( stepTime )                        # Wait before taking the next step
When you void a product warranty, you give up your right to sue the manufacturer if something goes wrong and accept full responsibility for whatever happens next. And then you truly own the product.
User avatar
adafruit_support_mike
 
Posts: 10248
Joined: Thu Feb 11, 2010 2:51 pm

Re: 16 Channel Servo Driver - travel speed

by bennakhi on Sun Nov 10, 2013 4:35 pm

adafruit_support_mike wrote:This script will sweep the control pulses from the lowest to highest value and back again:

Code: Select all | TOGGLE FULL SIZE
#!/usr/bin/python

from Adafruit_PWM_Servo_Driver import PWM
import time

# ===========================================================================
# Example Code
# ===========================================================================

# Initialise the PWM device using the default address
pwm = PWM(0x40, debug=True)

servoMin  = 150  # Min pulse length out of 4096
servoMax  = 600  # Max pulse length out of 4096
sweepTime = 30   # We want the sweep to last 30 seconds
stepSize  = 10   # We'll change the pulse by a small amount each time

steps     = (servoMax - servoMin) / stepSize    # Calculate the number of steps we'll need
stepTime  = sweepTime / float( steps )          # Calculate the delay between changes

#  The calculation for stepTime looks a bit strange because of the way Python
#  does math.  If you divide an integer by another integer, it will round the
#  result down to the nearest integer.  If you want a floating point value, you
#  need to include a floating point number in the calculation.  The `float()`
#  function forces the intepreter to treat `steps` as a floating point value.

pwm.setPWMFreq(60)                                # Set frequency to 60 Hz

for t in range( 0, 2*steps ):                     # Make the cycle long enough for a sweep up and back
    if t < steps:
        n = t                                     # For the first half of the cycle, count up
    else:
        n = (2 * steps) - t                       # For the second half of the cycle, count down

    pwm.setPWM( 0, 0, servoMin + (n * stepSize) ) # Make the pulse width depend on the count
    time.sleep( stepTime )                        # Wait before taking the next step


thanks for your fast response
bennakhi
 
Posts: 6
Joined: Sat Nov 09, 2013 2:33 am