2 import roslib; roslib.load_manifest(
'ur_driver')
     3 import time, sys, threading, math
    13 from sensor_msgs.msg 
import JointState
    18 joint_names = [
'shoulder_pan_joint', 
'shoulder_lift_joint', 
'elbow_joint',
    19                'wrist_1_joint', 
'wrist_2_joint', 
'wrist_3_joint']
    24     stateRT = RobotStateRT.unpack(buf)
    26     msg = RobotStateRTMsg()
    27     msg.time = stateRT.time
    28     msg.q_target = stateRT.q_target
    29     msg.qd_target = stateRT.qd_target
    30     msg.qdd_target = stateRT.qdd_target
    31     msg.i_target = stateRT.i_target
    32     msg.m_target = stateRT.m_target
    33     msg.q_actual = stateRT.q_actual
    34     msg.qd_actual = stateRT.qd_actual
    35     msg.i_actual = stateRT.i_actual
    36     msg.tool_acc_values = stateRT.tool_acc_values
    37     msg.tcp_force = stateRT.tcp_force
    38     msg.tool_vector = stateRT.tool_vector
    39     msg.tcp_speed = stateRT.tcp_speed
    40     msg.digital_input_bits = stateRT.digital_input_bits
    41     msg.motor_temperatures = stateRT.motor_temperatures
    42     msg.controller_timer = stateRT.controller_timer
    43     msg.test_value = stateRT.test_value
    44     msg.robot_mode = stateRT.robot_mode
    45     msg.joint_modes = stateRT.joint_modes
    46     pub_robot_stateRT.publish(msg)       
    50     msg.header.stamp = rospy.get_rostime()
    51     msg.header.frame_id = 
"From real-time state data"    52     msg.name = joint_names
    53     msg.position = [0.0] * 6
    54     for i, q 
in enumerate(stateRT.q_actual):
    55         msg.position[i] = q + joint_offsets.get(joint_names[i], 0.0)
    56     msg.velocity = stateRT.qd_actual
    58     pub_joint_statesRT.publish(msg)
    64     rospy.init_node(
'testRT_comm', disable_signals=
True)
    66     global pub_joint_statesRT
    67     pub_joint_statesRT = rospy.Publisher(
'joint_statesRT', JointState, queue_size=1)
    68     global pub_robot_stateRT
    69     pub_robot_stateRT = rospy.Publisher(
'robot_stateRT', RobotStateRTMsg, queue_size=1)
    73     robot_hostname = 
'192.168.0.42'    76     rt_socket = socket.create_connection((robot_hostname, rt_port))
    79     while not rospy.is_shutdown():
    80         more = rt_socket.recv(4096)
    85             packet_length = struct.unpack_from(
"!i", buf)[0]
    86             print(
"PacketLength: ", packet_length, 
"; BufferSize: ", len(buf))
    87             if len(buf) >= packet_length:
    88                 packet, buf = buf[:packet_length], buf[packet_length:]
    91             print(
"There is no more...")
    98 if __name__ == 
'__main__': 
main()