11 SERIAL_BAUDRATE = 115200
12 SERIAL_BYTESIZE = serial.EIGHTBITS
13 SERIAL_PARITY = serial.PARITY_NONE
14 SERIAL_STOPBIT = serial.STOPBITS_ONE
16 self.
ser = serial.Serial(
"/dev/ttyUSB0", SERIAL_BAUDRATE, SERIAL_BYTESIZE, SERIAL_PARITY, SERIAL_STOPBIT,
23 return [0xFA, 0xAF, servo_id]
27 for i
in range(2, len(checklist)):
33 self.ser.write(
"".join(map(chr, servolist)))
37 a.extend([0x09, 0x00, 0x00, 0x01])
42 angle = max(-150.0, min(150.0, set_angle))
43 angle = int(angle * 10)
45 a.extend([0x00, 0x1E, 0x02, 0x01, angle & 0xFF, (angle & 0xFF00) >> 8])
50 a.extend([0x00, 0x24, 0x01, 0x01, int(onoff)])
55 b = self.ser.read(26)[7:9]
56 return struct.unpack(
"<h", b)[0] / 10.0
60 b = self.ser.read(26)[13:15]
61 return struct.unpack(
"<h", b)[0]
66 self.
reso = rospy.get_param(
"~reso", 2.0)
68 sub = rospy.Subscriber(
"nekonote_eef", Float32, self.
callback)
71 self.rs.setTorque(1,
True)
86 current = self.rs.readCurrent(1)
87 return CurrentLoadResponse(current)
91 :type req: HandGrabRequest 93 :return: HandGrabResponse 95 self.rs.setAngle(1, req.hand_angle)
98 for j
in range(int(req.hand_angle * self.
reso), 0, -1):
101 self.rs.setAngle(1, k)
103 if self.rs.readCurrent(1) > 400:
105 return HandGrabResponse(
True)
107 return HandGrabResponse(
False)
110 self.rs.setAngle(1, msg.data)
114 return self.rs.readCurrent(1)
117 if __name__ ==
'__main__':
120 rs.setTorque(i,
False)
def handlehandle(self, req)
def setTorque(self, servo_id, onoff)
def __requestStatus(self, servo_id)
def readAngle(self, servo_id)
def setAngle(self, servo_id, set_angle)
def __bytecreateid(self, servo_id)
def __write(self, servolist)
def service_handle(self, req)
def readCurrent(self, servo_id)
def __checksum(self, checklist)