7 Copyright (c) 2017 Shota Hirama <brast351-github@yahoo.co.jp> 8 Copyright (c) 2017 Daisuke Sato <tiryoh@gmail.com> 10 Permission is hereby granted, free of charge, to any person obtaining a copy 11 of this software and associated documentation files (the "Software"), to deal 12 in the Software without restriction, including without limitation the rights 13 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 14 copies of the Software, and to permit persons to whom the Software is 15 furnished to do so, subject to the following conditions: 17 The above copyright notice and this permission notice shall be included in all 18 copies or substantial portions of the Software. 20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 23 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 25 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 37 BYTESIZE = serial.EIGHTBITS
38 PARITY = serial.PARITY_NONE
39 STOPBIT = serial.STOPBITS_ONE
41 self.
ser = serial.Serial(PORT, BAUDRATE, BYTESIZE, PARITY, STOPBIT, TIMEOUT)
47 return [0xFA, 0xAF, id]
51 for i
in range(2, len(checklist)):
57 self.ser.write(
"".join(map(chr, servolist)))
61 a.extend([0x09, 0x00, 0x00, 0x01])
66 a.extend([0x40, 0xFF, 0x00, 0x00])
70 angle = max(-150.0, min(150.0, set_angle))
71 angle = int(angle * 10)
73 a.extend([0x00, 0x1E, 0x02, 0x01, (angle & 0xFF), (angle & 0xFF00) >> 8])
77 angle = max(-150.0, min(150.0, set_angle))
78 angle = int(angle * 10)
79 goal_time = int(set_goal_time * 100)
81 a.extend([0x00, 0x1E, 0x04, 0x01, angle & 0xFF, (angle & 0xFF00) >> 8, goal_time & 0xFF, (goal_time & 0xFF00) >> 8])
86 a.extend([0x00, 0x24, 0x01, 0x01, int(onoff)])
90 if onoff == 1 : self.
setTorque(servo_id, 2)
95 a.extend([0x00, 0x04, 0x01, 0x01, dest])
101 a.extend([0x00, 0x23, 0x01, 0x01, int(max_torque)])
107 b = self.ser.read(26)[7:9]
108 return struct.unpack(
"<h", b)[0] / 10.0
112 b = self.ser.read(26)[9:11]
113 return struct.unpack(
"<h", b)[0] * 10
117 b = self.ser.read(26)[11:13]
118 return struct.unpack(
"<h", b)[0]
122 b = self.ser.read(26)[13:15]
123 return struct.unpack(
"<h", b)[0]
127 b = self.ser.read(26)[15:17]
128 return struct.unpack(
"<h", b)[0]
132 b = self.ser.read(26)[17:19]
133 return struct.unpack(
"<h", b)[0] * 10
137 a.extend([0x0F, 0x24, 0x02, 0x00])
139 b = self.ser.read(9)[7:9]
140 return struct.unpack(
"<h", b)[0]
144 a.extend([0x20, 0xFF, 0x00, 0x00])
def readSpeed(self, servo_id)
def __flash(self, servo_id)
def __requestStatus(self, servo_id)
def setAngleInTime(self, servo_id, set_angle, set_goal_time)
def reboot(self, servo_id)
def readCurrent(self, servo_id)
def readTemperature(self, servo_id)
def readTorqueStatus(self, servo_id)
def readVoltage(self, servo_id)
def __write(self, servolist)
def __checksum(self, checklist)
def __init__(self, port="/dev/ttyUSB0")
def setAngle(self, servo_id, set_angle)
def setBreak(self, servo_id, onoff)
def setTorque(self, servo_id, onoff)
def setServoId(self, servo_id, dest)
def readAngle(self, servo_id)
def readTime(self, servo_id)
def setMaxTorque(self, servo_id, max_torque)
def __bytecreateid(self, id)