35 from simple_message
import SimpleMessageSocket, \
36 SimpleMessageType, JointTrajPtReplyMessage, ReplyCode, \
37 SpecialSequence, ExecuteProgramReplyMessage
38 from robot_controller
import RobotController
41 HOST, PORT =
"0.0.0.0", 11000
54 self._q_abort.get(
True, 0.001)
56 with self._q_move.mutex:
57 self._q_move.queue.clear()
60 used_buffer_size = self._ctl.sys_stat(5)
61 if used_buffer_size < 4:
63 joints, speed = self._q_move.get(
False)
64 self._ctl.move(joints, speed)
68 def move(self, joints, speed):
69 self._q_move.put((joints, speed))
72 self._q_abort.put(
True)
78 address = self.client_address[0]
79 print(
'connected with {}'.format(address))
91 recv_msg = sock.recv()
93 msg_handler = msg_handlers.get(
96 reply_msg = msg_handler(ctl, recv_msg, motion_thread)
102 joint_deg = map(math.degrees, recv_msg.joint_data[:6])
106 if recv_msg.sequence == SpecialSequence.STOP_TRAJECTORY:
107 motion_thread.abort()
108 print(
"abort move command")
110 speed = recv_msg.velocity * 100
113 motion_thread.move(joint_deg, speed)
115 reply_msg = JointTrajPtReplyMessage()
116 reply_msg.reply_code = ReplyCode.SUCCESS
122 print(recv_msg.param)
123 print(
"received: Execute program message")
125 result = ctl.exec_program(recv_msg.name, recv_msg.param)
127 reply_msg = ExecuteProgramReplyMessage()
128 reply_msg.reply_code = ReplyCode.SUCCESS
129 reply_msg.result = reply_msg.Result.SUCCESS
if result
else reply_msg.Result.FAILURE
134 raise NotImplementedError(
135 "Unknown msg_type: {}".format(recv_msg.msg_type))
140 self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
141 self.socket.bind(self.server_address)
144 if __name__ ==
"__main__":
146 server.serve_forever()
def on_unkown_message(self, ctl, recv_msg, motion_thread)
def on_joint_traj_pt(self, ctl, recv_msg, motion_thread)
def move(self, joints, speed)
def on_execute_program(self, ctl, recv_msg, motion_thread)