+ def set_motor_handicap(self, front, aft): # percent
+ if self.handicap_last != (front, aft):
+ i2c_write_reg(0x50, 0x94, struct.pack(">bb", front, aft))
+ self.handicap_last = (front, aft)
+
+ def imuReceived(self, msg):
+ (roll, pitch, yaw) = tf.transformations.euler_from_quaternion(msg.orientation.__getstate__())
+ if pitch > 30*pi/180:
+ val = (100.0/65)*abs(pitch)*180/pi
+ self.set_motor_handicap(0, int(val))
+ elif pitch < -30*pi/180:
+ val = (100.0/65)*abs(pitch)*180/pi
+ self.set_motor_handicap(int(val), 0)
+ else:
+ self.set_motor_handicap(0, 0)
+
+ def get_reset(self):
+ reset = struct.unpack(">B", i2c_read_reg(0x50, 0xA0, 1))[0]
+
+ msg = DiagnosticArray()
+ msg.header.stamp = rospy.Time.now()
+ stat = DiagnosticStatus()
+ stat.name = "Reset reason"
+ stat.level = DiagnosticStatus.ERROR if reset & 0x0c else DiagnosticStatus.OK
+ stat.message = "0x%02x" % reset
+
+ stat.values.append(KeyValue("Watchdog Reset Flag", str(bool(reset & (1 << 3)))))
+ stat.values.append(KeyValue("Brown-out Reset Flag", str(bool(reset & (1 << 2)))))
+ stat.values.append(KeyValue("External Reset Flag", str(bool(reset & (1 << 1)))))
+ stat.values.append(KeyValue("Power-on Reset Flag", str(bool(reset & (1 << 0)))))
+
+ msg.status.append(stat)
+ self.pub_diag.publish(msg)
+ return reset
+
+