34 import rospy, sys, time, math
35 from sensor_msgs.msg
import Range, Imu
45 self.
pub_range = rospy.Publisher(
'/tdk_robokit/range', Range, queue_size=10)
46 self.
pub_imu = rospy.Publisher(
'/tdk_robokit/imu', Imu, queue_size=10)
49 rospy.init_node(
'tdk_robokit', anonymous=
True)
63 com_port = rospy.get_param(
'~robokit_com_port',
'/dev/ttyUSB0')
66 self.
device = boards.SmartSonic(com_port=com_port, event_handler=self)
67 endtime = time.time() + 5
68 while time.time() < endtime:
72 except Exception
as e:
74 if not self.device.openned:
75 print(
"Board not found")
80 self.device.setSRange(min(rx_length,
Ch101Sensor()[
'max_samples']))
82 self.device.setODR(round(1000 / sample_rate_hz))
83 self.device.enableAsicData()
84 self.device.enableIQStream()
85 self.device.enableImu()
86 self.device.startDeviceProcessing()
87 print(
'Board setup successful')
89 def ch_data_handler(self, rx_sensor_id, tx_sensor_id, timestamp, idata, qdata, target_detected, range_cm, amplitude):
91 if rx_sensor_id == tx_sensor_id:
93 msg.header.stamp = rospy.get_rostime()
94 msg.header.frame_id =
"ch-%d" % tx_sensor_id
95 msg.radiation_type = Range.ULTRASOUND
96 msg.field_of_view = math.pi / 2.0
99 msg.range = range_cm / 100.0
114 gyr_scale = (500.0 / 32768.0) / 180.0 * math.pi
115 acc_scale = (4.0 / 32768.0) * 9.81
117 msg.header.stamp = rospy.get_rostime()
119 msg.angular_velocity.x = self.
gyr_raw_x * gyr_scale
120 msg.angular_velocity.y = self.
gyr_raw_y * gyr_scale
121 msg.angular_velocity.z = self.
gyr_raw_z * gyr_scale
122 msg.angular_velocity_covariance = [0.01, 0.0, 0.0, 0.0, 0.01, 0.0, 0.0, 0.0, 0.01]
123 msg.linear_acceleration.x = self.
acc_raw_x * acc_scale
124 msg.linear_acceleration.y = self.
acc_raw_y * acc_scale
125 msg.linear_acceleration.z = self.
acc_raw_z * acc_scale
126 msg.linear_acceleration_covariance = [0.01, 0.0, 0.0, 0.0, 0.01, 0.0, 0.0, 0.0, 0.01]
127 msg.orientation.w = float(grv_w) / 2**30
128 msg.orientation.x = float(grv_x) / 2**30
129 msg.orientation.y = float(grv_y) / 2**30
130 msg.orientation.z = float(grv_z) / 2**30
131 msg.orientation_covariance = [0.01, 0.0, 0.0, 0.0, 0.01, 0.0, 0.0, 0.0, 0.01]
136 print(
'ROS publisher Exception', str(exception))
140 if not rospy.is_shutdown():
142 except rospy.ROSInterruptException:
143 print(
''.join((pub.name,
'interrupted')))
147 if self.device.openned:
148 print(
"Closing device ...")
149 self.device.disableImu()
151 self.device.stopDeviceProcessing()
156 if __name__ ==
'__main__':
def grv_data_handler(self, timestamp, grv_w, grv_x, grv_y, grv_z)
def ch_data_handler(self, rx_sensor_id, tx_sensor_id, timestamp, idata, qdata, target_detected, range_cm, amplitude)
def imu_data_handler(self, timestamp, acc_x, acc_y, acc_z, gyr_x, gyr_y, gyr_z)
def exception_handler(self, exception)