Arduino Uno assembled in US now available in the Store @arduino & Adafruit #TeamArduinoCC

Forum rules

16 Channel Servo Driver - travel speed

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

d0ctr

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

Re: 16 Channel Servo Driver - travel speed

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.

Posts: 38658
Joined: Sat Feb 07, 2009 10:11 am

Re: 16 Channel Servo Driver - travel speed

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

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

Code: Select all | TOGGLE FULL SIZE
`#!/usr/bin/pythonfrom Adafruit_PWM_Servo_Driver import PWMimport time# ===========================================================================# Example Code# ===========================================================================# Initialise the PWM device using the default addresspwm = PWM(0x40, debug=True)servoMin  = 150  # Min pulse length out of 4096servoMax  = 600  # Max pulse length out of 4096sweepTime = 30   # We want the sweep to last 30 secondsstepSize  = 10   # We'll change the pulse by a small amount each timesteps     = (servoMax - servoMin) / stepSize    # Calculate the number of steps we'll needstepTime  = 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 Hzfor 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.

Posts: 16945
Joined: Thu Feb 11, 2010 2:51 pm

Re: 16 Channel Servo Driver - travel speed

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/pythonfrom Adafruit_PWM_Servo_Driver import PWMimport time# ===========================================================================# Example Code# ===========================================================================# Initialise the PWM device using the default addresspwm = PWM(0x40, debug=True)servoMin  = 150  # Min pulse length out of 4096servoMax  = 600  # Max pulse length out of 4096sweepTime = 30   # We want the sweep to last 30 secondsstepSize  = 10   # We'll change the pulse by a small amount each timesteps     = (servoMax - servoMin) / stepSize    # Calculate the number of steps we'll needstepTime  = 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 Hzfor 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`