def main(): port = "/dev/tty.usbserial-AL034G1T" serial = ServoSerial(port=port) serial.open() servo = Packet(pyservos.AX12) # servo = Packet(pyservos.XL320) # build # 59 rpm max data = [] ids = [1, 2, 3] pos = [150, 200, 90] vel = [200, 100, 300] # 0.111 rpm for i, p, v in zip(ids, pos, vel): data.append([i] + angle2int(p) + le(v)) pkt = servo.makeSyncWritePacket(pyservos.AX12.GOAL_POSITION, data) print(pkt) ans = serial.sendPkt(pkt) # send packet to servo ans = servo.processStatusPacket(ans) if ans: print('status: {}'.format(ans))
# you will need to CHANGE this to the correct port port = "/dev/ttyS0" ID = 1 angle = int(sys.argv[1]) print('Setting servo[{}] to {:.2f} on port {}'.format(ID, angle, port)) try: serial = ServoSerial(port=port) serial.open() except Exception as e: print(e) print('Oops, wrong port') print('bye ....') exit(1) if True: servo = Packet(pyservos.AX12) print('We are talking to an AX12 servo') else: servo = Packet(pyservos.XL320) print('We are talking to an XL320 servo') pkt = servo.makeServoMovePacket(ID, angle) ans = serial.sendPkt(pkt) # send packet to servo ans = servo.processStatusPacket(ans) if ans: print('status: {}'.format(ans))