0

PWM Python Code to turn continuous rotation servo FS5103R
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

PWM Python Code to turn continuous rotation servo FS5103R

by srjack13 on Sun Jan 10, 2021 5:49 pm

I recently purchased this FS5103R servo and I am having trouble sending pulses of determined lengths. I have not yet found a library that allows me to access this feature (I have looked in the Servo Kit library, PCA9685 library, and the motor library).
Any tips or a line of python code that allows me to access this feature is appreciated. I found an old script that uses that PCA9685 library to send these pulses, but it does not work any more and when looking into the library I do not see this class. I will put the script below.
The function of this is to have a "clock" that instead of hands pointing to certain times, it points to the current location of each user. If you believe this PWM feature is no longer available, a recommendation for a servo that I can purchase would be appreciated, I am new to all of this. Thank you.

Code: Select all | TOGGLE FULL SIZE
from __future__ import division
import time

# Import the PCA9685 module.
import Adafruit_PCA9685

# Import sys module for accepting variables
import sys

# Initialise the PCA9685 using the default address (0x40).
pwm = Adafruit_PCA9685.PCA9685()

#Time to set variables for which servo to use and what location
#to move to.
servo_number = sys.argv[1]
location = sys.argv[2]

#The location_list compares the location variable with the
#13 locations I have on the clock face
#PWM list is the PWM off values I need to enter to point in the right directions
location_list = ['Home','Lessons','Concert','Lost','Tavern','Mortal Peril','Opera','Siblings','Travel','Doctors','Work','Parents','School']
PWM_list = [246, 287, 328, 369, 410, 450, 491, 532, 573, 614, 655, 696, 717]

for idx, location in enumerate(location_list):
   PWM_index = idx
   servo_max = PWM_list[idx]

# Configure min and max servo pulse lengths
servo_min = 246  # Min pulse length out of 4096. This sets you back to Home

# Helper function to make setting a servo pulse width simpler.
def set_servo_pulse(channel, pulse):
    pulse_length = 1000000    # 1,000,000 us per second
    pulse_length //= 60       # 60 Hz
    print('{0}us per period'.format(pulse_length))
    pulse_length //= 4096     # 12 bits of resolution
    print('{0}us per bit'.format(pulse_length))
    pulse *= 1000
    pulse //= pulse_length
    pwm.set_pwm(channel, 0, pulse)

# Set frequency to 60hz, good for servos.
pwm.set_pwm_freq(60)

print('Moving servo on channel 0, press Ctrl-C to quit...')
while True:
    # Move servo on channel O between extremes.
    pwm.set_pwm(servo_number, 0, servo_min)
    time.sleep(1)
    pwm.set_pwm(servo_number, 0, servo_max)
    time.sleep(1)

srjack13
 
Posts: 2
Joined: Sun Sep 27, 2020 8:39 pm

Re: PWM Python Code to turn continuous rotation servo FS5103

by tannewt on Mon Jan 11, 2021 7:01 pm

A continuous rotating servo doesn't allow for you to set the rotation directly. Instead, it can only move relatively.

I think this is what you want: https://www.adafruit.com/product/3614

It's continuous but also has feedback for where it's pointing. That way you can move it relatively until it's at the position you want. I don't know of a library that does this for you though.

tannewt
 
Posts: 2034
Joined: Thu Oct 06, 2016 8:48 pm

Please be positive and constructive with your questions and comments.