+ def get_tle_err(self):
+ err = struct.unpack(">B", i2c_read_reg(0x50, 0x94, 1))[0]
+
+ msg = DiagnosticArray()
+ msg.header.stamp = rospy.Time.now()
+ stat = DiagnosticStatus()
+ stat.name = "Motor: Error Status"
+ stat.level = DiagnosticStatus.OK if not err else DiagnosticStatus.ERROR
+ stat.message = "OK" if not err else "Error"
+
+ stat.values.append(KeyValue("Motor 1", str(bool(err & (1 << 0)))))
+ stat.values.append(KeyValue("Motor 2", str(bool(err & (1 << 1)))))
+ stat.values.append(KeyValue("Motor 3", str(bool(err & (1 << 2)))))
+ stat.values.append(KeyValue("Motor 4", str(bool(err & (1 << 3)))))
+
+ msg.status.append(stat)
+ self.pub_diag.publish(msg)
+
+
+ def get_odom(self):
+ posx, posy, angle = struct.unpack(">fff", i2c_read_reg(0x50, 0x40, 12))
+ speed_trans, speed_rot = struct.unpack(">ff", i2c_read_reg(0x50, 0x38, 8))
+ current_time = rospy.Time.now()
+
+ # since all odometry is 6DOF we'll need a quaternion created from yaw
+ odom_quat = tf.transformations.quaternion_from_euler(0, 0, angle)
+
+ # first, we'll publish the transform over tf
+ self.tf_broadcaster.sendTransform((posx, posy, 0.0), odom_quat, current_time, "base_link", "odom")
+
+ # next, we'll publish the odometry message over ROS
+ odom = Odometry()
+ odom.header.stamp = current_time
+ odom.header.frame_id = "/odom"
+
+ # set the position
+ odom.pose.pose.position.x = posx
+ odom.pose.pose.position.y = posy
+ odom.pose.pose.position.z = 0.0
+ odom.pose.pose.orientation.x = odom_quat[0]
+ odom.pose.pose.orientation.y = odom_quat[1]
+ odom.pose.pose.orientation.z = odom_quat[2]
+ odom.pose.pose.orientation.w = odom_quat[3]
+
+ # set the velocity
+ odom.child_frame_id = "base_link"
+ odom.twist.twist.linear.x = speed_trans
+ odom.twist.twist.linear.y = 0.0
+ odom.twist.twist.angular.z = speed_rot
+
+ # publish the message
+ self.pub_odom.publish(odom)