Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 import roslib.message
00034 import struct
00035 import logging
00036 import time
00037 import rospy
00038
00039
00040 from math import radians
00041 from wheeled_robin_driver import SENSOR_GROUP_PACKET_LENGTHS
00042
00043
00044 _struct_Group0 = struct.Struct(">8hB5h2B")
00045 _struct_Group1 = struct.Struct(">8hB")
00046 _struct_Group7 = struct.Struct(">h")
00047
00048 def deserialize(msg, buff, timestamp, packet_id):
00049 """
00050 unpack serialized message in str into this message instance
00051 @param buff: byte array of serialized message
00052 @type buff: str
00053 """
00054 try:
00055 _x = msg
00056
00057 msg.header.stamp = rospy.Time.from_seconds(timestamp)
00058
00059
00060 msg.linear_velocity = 0
00061 msg.angular_velocity = 0
00062 msg.pitch = 0
00063 msg.pitch_rate = 0
00064 msg.left_wheel = 0
00065 msg.right_wheel = 0
00066 msg.left_wheel_rate = 0
00067 msg.right_wheel_rate = 0
00068 msg.mode = 0;
00069 msg.left_current = 0
00070 msg.right_current = 0
00071 msg.voltage = 0
00072 msg.imu_acc_x = 0
00073 msg.imu_acc_y = 0
00074
00075
00076 if packet_id == 0:
00077 (_x.linear_velocity, _x.angular_velocity, _x.pitch, _x.pitch_rate, _x.left_wheel, _x.right_wheel, _x.left_wheel_rate, _x.right_wheel_rate, _x.mode, _x.left_current, _x.right_current, _x.voltage, _x.imu_acc_x, _x.imu_acc_y, _x.digital_outputs, _x.digital_inputs,) = _struct_Group0.unpack(buff[0:SENSOR_GROUP_PACKET_LENGTHS[packet_id]])
00078
00079
00080 msg.linear_velocity = float(msg.linear_velocity) /1000.
00081 msg.angular_velocity = float(msg.angular_velocity) /1000.
00082 msg.pitch = float(msg.pitch) /1000.
00083 msg.pitch_rate = float(msg.pitch_rate) /1000.
00084 msg.left_wheel = float(msg.left_wheel) /1000.
00085 msg.right_wheel = float(msg.right_wheel) /1000.
00086 msg.left_wheel_rate = float(msg.left_wheel_rate) /1000.
00087 msg.right_wheel_rate = float(msg.right_wheel_rate) /1000.
00088 msg.left_current = float(msg.left_current) /1000.
00089 msg.right_current = float(msg.right_current) /1000.
00090 msg.voltage = float(msg.voltage) /1000.
00091 msg.imu_acc_x = float(msg.imu_acc_x) /1000.
00092 msg.imu_acc_y = float(msg.linear_velocity) /1000.
00093 elif packet_id == 1:
00094 (_x.linear_velocity, _x.angular_velocity, _x.pitch, _x.pitch_rate, _x.left_wheel, _x.right_wheel, _x.left_wheel_rate, _x.right_wheel_rate, _x.mode,) = _struct_Group1.unpack(buff[0:SENSOR_GROUP_PACKET_LENGTHS[packet_id]])
00095
00096
00097 msg.linear_velocity = float(msg.linear_velocity) /1000.
00098 msg.angular_velocity = float(msg.angular_velocity) /1000.
00099 msg.pitch = float(msg.pitch) /1000.
00100 msg.pitch_rate = float(msg.pitch_rate) /1000.
00101 msg.left_wheel = float(msg.left_wheel) /1000.
00102 msg.right_wheel = float(msg.right_wheel) /1000.
00103 msg.left_wheel_rate = float(msg.left_wheel_rate) /1000.
00104 msg.right_wheel_rate = float(msg.right_wheel_rate) /1000.
00105
00106 elif packet_id == 7:
00107 (_x.linear_velocity) = _struct_Group .unpack(buff[0:SENSOR_GROUP_PACKET_LENGTHS[packet_id]])
00108
00109
00110 msg.linear_velocity = float(msg.linear_velocity[0]) /1000.
00111 msg.mode = 3
00112
00113 return msg
00114 except struct.error, e:
00115 raise roslib.message.DeserializationError(e)
00116
00117 class WheeledRobinSensorHandler(object):
00118 def __init__(self, robot):
00119 self.robot = robot
00120
00121 def request_packet(self, packet_id):
00122 """Request a sensor packet."""
00123 with self.robot.sci.lock:
00124 self.robot.sci.flush_input()
00125 self.robot.sci.sensors(packet_id)
00126
00127
00128
00129
00130 stamp = time.time()
00131 length = SENSOR_GROUP_PACKET_LENGTHS[packet_id]
00132 return self.robot.sci.read(length), stamp
00133
00134 def get_all(self, sensor_state):
00135 buff, timestamp = self.request_packet(1)
00136 if buff is not None:
00137 deserialize(sensor_state, buff, timestamp,1)