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
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/
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/
- adafruit_support_bill
- Posts: 88093
- Joined: Sat Feb 07, 2009 10:11 am
Re: 16 Channel Servo Driver - travel speed
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.
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: 6
- Joined: Sat Nov 09, 2013 2:33 am
Re: 16 Channel Servo Driver - travel speed
could you post a python code example ?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.
- adafruit_support_mike
- Posts: 67454
- Joined: Thu Feb 11, 2010 2:51 pm
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
#!/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
-
- Posts: 6
- Joined: Sat Nov 09, 2013 2:33 am
Re: 16 Channel Servo Driver - travel speed
thanks for your fast responseadafruit_support_mike wrote:This script will sweep the control pulses from the lowest to highest value and back again:
Code: Select all
#!/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
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/
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/