def test_moveSync(self): servos = set() for num in range(16): joint = Joint(str(num)) servo = Servo(joint, num) servo.pulse = 750 servos.add(servo) self._driver.move(servos) # blocking time.sleep(1) for i in range(5): for servo in servos: servo.pulse = 2000 self._driver.moveSync(servos, 0.5) # non blocking # Wait previous move to end self._driver.waitEndOfSyncMove() for servo in servos: servo.pulse = 750 self._driver.moveSync(servos, 0.5) # non blocking # Wait previous move to end self._driver.waitEndOfSyncMove()
def main(): """ """ def hexdec(value): """ """ try: return str(int(value)) except ValueError: return str(int(value, 16)) # Parser options parser = argparse.ArgumentParser(description="This tool is used to calibrate servos.") parser.add_argument("-l", "--logger", choices=("trace", "debug", "info", "warning", "error", "exception", "critical"), default="info", dest="loggerLevel", metavar="LEVEL", help="logger level") parser.add_argument("-d", "--driver", choices=("pru", "pca9685", "veyron", "pololuserial", "fake"), default="fake", help="servos driver to use") # Only for pca9685 pca9685Group = parser.add_argument_group("pca9685") pca9685Group.add_argument("-t", "--target", choices=("bbb", "rpi", "fake"), default="fake", help="target to run I²C backend") pca9685Group.add_argument("-b", "--bus", type=int, default=-1, help="I²C bus to use") pca9685Group.add_argument("-f", "--frequency", type=float, default=50., help="PWM frequency, in Hz") pca9685Group.add_argument("-a", "--address", type=hexdec, nargs='+', help="I²C address of PCA 9685 chips") # Only for veyron/pololuserial veyronPololuGroup = parser.add_argument_group("veyron/pololuserial") veyronPololuGroup.add_argument("-p", "--port", default="/dev/ttyACM0", help="serial port") veyronPololuGroup.add_argument("-r", "--baudrate", type=int, default=9600, help="serial baudrate") args = parser.parse_args() Logger().setLevel(args.loggerLevel) nbServos = None if args.driver == "pru": from py4bot.drivers.servosPRU import ServosPRU nbServos = 32 driver = ServosPRU() elif args.driver =="pca9685": from py4bot.drivers.pipeDriver import PipeDriver nbServos = 16 * len(args.address) ARGS = [ "py4bot-pca9685.py", "--logger", args.loggerLevel, "--target", args.target, "--bus", str(args.bus), "--frequency", str(args.frequency) ] + args.address driver = PipeDriver(ARGS) elif args.driver =="veyron": from py4bot.drivers.veyron import Veyron nbServos = 24 driver = Veyron(args.port, args.baudrate) elif args.driver =="pololuserial": from py4bot.drivers.pololuSerial import PololuSerial nbServos = 8 driver = PololuSerial(args.port, args.baudrate) elif args.driver =="fake": from py4bot.drivers.fakeDriver import FakeDriver nbServos = 32 driver = FakeDriver() # Create servo pool #servoPool = ServoPool() # TODO when using legsIndex and all settings params -> manage joints with names servos = [] for num in range(nbServos): joint = Joint(str(num)) servo = Servo(joint, num) servo.pulse = 0 servo.guiPulse = DEFAULT_PULSE servo.guiEnable = DEFAULT_ENABLE servo.guiAngleMin = DEFAULT_ANGLE_MIN servo.guiAngleMax = DEFAULT_ANGLE_MAX servo.guiAngleNeutral = DEFAULT_ANGLE_NEUTRAL try: servo._offset = settings.SERVOS_CALIBRATION[num]['offset'] servo._ratio = settings.SERVOS_CALIBRATION[num]['ratio'] servo._pulse90 = settings.SERVOS_CALIBRATION[num]['pulse90'] except NameError: #Logger().exception("main()", debug=True) servo._offset = 90. - DEFAULT_ANGLE_NEUTRAL servo._ratio = DEFAULT_RATIO servo._pulse90 = DEFAULT_PULSE servos.append(servo) # Create Tkinter application root = tk.Tk() root.title("Servos Calibrator") root.resizable(0, 0) # Create View params = {'nbServos': nbServos} view = View(root, params) # Create controller model = {'servos': servos, 'driver': driver} controller = Controller(model, view) root.mainloop() # Stop servos for servo in servos: servo.pulse = 0