FRC4564 / Maestro

Python class to support Pololu's Maestro servo controller over USB serial. Great with Raspberry Pi.
MIT License
92 stars 59 forks source link

Any way to code a sequence? #13

Closed nielsenmarkus11 closed 4 years ago

nielsenmarkus11 commented 4 years ago

I'm trying to utilize this to code a sequence, but it seems to only go to the last position. Is there any way to do this? Here's my attempt:

import time

MIN_S = 0
MIN_G = 0
CENTER_S = 6000
CENTER_G = 6000
MAX_S = 12000
MAX_G = 12000

class RubikSolve:

    # Pass the maestro controller object and the maestro channel numbers being used
    # for the left and right motor controllers.  See maestro.py on how to instantiate maestro.
    def __init__(self, maestro, rightSlider, rightGripper):
        self.maestro = maestro
        self.rightSlider = rightSlider
        self.rightGripper = rightGripper
        # Init motor accel/speed params
        self.maestro.setAccel(rightSlider,0)
        self.maestro.setAccel(rightGripper,0)
        self.maestro.setSpeed(rightSlider, 0)
        self.maestro.setSpeed(rightGripper, 110)
        # Motor min/center/max values
        self.minS = MIN_S
        self.minG = MIN_G
        self.centerS = CENTER_S
        self.centerG = CENTER_G
        self.maxS = MAX_S
        self.maxG = MAX_G

    def servoMove(self, servo, position):
        self.maestro.setTarget(servo, position)

    # Right
    def R_clock(self):
        self.servoMove(self.rightSlider, self.minS)
        print('rightSlider')
        time.sleep(1)
        self.servoMove(self.rightGripper, self.minG)
        print('rightGripper')
        time.sleep(1)
        self.servoMove(self.rightSlider, self.maxS)
        print('rightSlider')
        time.sleep(1)
        self.servoMove(self.rightGripper, self.maxG)
        print('rightGripper')

Then once that's defined I run this:

import maestro
m = maestro.Controller()
rs = RubikSolve(m, 0, 1) #maestro channels 0 and 1 for left and right motors

for i in range(1):
    rs.R_clock()

m.close()

Am I missing something simple here?

nielsenmarkus11 commented 4 years ago

Okay... I think I figured it out. I had the wrong min/max for each servo. This was the solution:

MIN_S = 4000
MIN_G = 4000
CENTER_S = 6000
CENTER_G = 6000
MAX_S = 8000
MAX_G = 8000