X-Git-Url: https://defiant.homedns.org/gitweb/?p=ros_wild_thumper.git;a=blobdiff_plain;f=scripts%2Fwt_node.py;h=2de2f590141a0960a47d8bd6f14033accc73e0f2;hp=7fdf0444aead981ff55cedb43609cc122f75e001;hb=c3db2ea74a51a2623b04d4bc5796c39be2e28453;hpb=390d3bf8a69f3cd23dae064db94865d3a38fe948 diff --git a/scripts/wt_node.py b/scripts/wt_node.py index 7fdf044..2de2f59 100755 --- a/scripts/wt_node.py +++ b/scripts/wt_node.py @@ -64,9 +64,11 @@ class MoveBase: self.cmd_vel = None self.set_speed(0, 0) rospy.loginfo("Init done") + i2c_write_reg(0x50, 0x90, struct.pack("BB", 1, 1)) # switch direction self.handicap_last = (-1, -1) self.pStripe = LPD8806(1, 0, 12) rospy.Subscriber("cmd_vel_out", Twist, self.cmdVelReceived) + #rospy.Subscriber("imu", Imu, self.imuReceived) rospy.Subscriber("led_stripe", LedStripe, self.led_stripe_received) self.run() @@ -77,8 +79,9 @@ class MoveBase: rospy.loginfo("Reset Status: 0x%x" % reset_val) i = 0 while not rospy.is_shutdown(): + rospy.logdebug("Loop alive") #print struct.unpack(">B", i2c_read_reg(0x50, 0xA2, 1))[0] # count test - self.get_tle_err() + self.get_motor_err() self.get_odom() self.get_voltage() if i % 2: @@ -93,6 +96,24 @@ class MoveBase: self.cmd_vel = None rate.sleep() + def set_motor_handicap(self, front, aft): # percent + if front > 100: front = 100 + if aft > 100: aft = 100 + 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/60)*abs(pitch)*180/pi + self.set_motor_handicap(int(val), 0) + elif pitch < -30*pi/180: + val = (100.0/60)*abs(pitch)*180/pi + self.set_motor_handicap(0, int(val)) + else: + self.set_motor_handicap(0, 0) + def get_reset(self): reset = struct.unpack(">B", i2c_read_reg(0x50, 0xA0, 1))[0] @@ -121,7 +142,7 @@ class MoveBase: return reset - def get_tle_err(self): + def get_motor_err(self): err = struct.unpack(">B", i2c_read_reg(0x50, 0xA1, 1))[0] msg = DiagnosticArray() @@ -131,10 +152,16 @@ class MoveBase: stat.level = DiagnosticStatus.ERROR if err else DiagnosticStatus.OK stat.message = "0x%02x" % err - stat.values.append(KeyValue("aft left", str(bool(err & (1 << 0))))) - stat.values.append(KeyValue("front left", str(bool(err & (1 << 1))))) - stat.values.append(KeyValue("front right", str(bool(err & (1 << 2))))) - stat.values.append(KeyValue("aft right", str(bool(err & (1 << 3))))) + # Diag + stat.values.append(KeyValue("aft left diag", str(bool(err & (1 << 0))))) + stat.values.append(KeyValue("front left diag", str(bool(err & (1 << 1))))) + stat.values.append(KeyValue("aft right diag", str(bool(err & (1 << 2))))) + stat.values.append(KeyValue("front right diag", str(bool(err & (1 << 3))))) + # Stall + stat.values.append(KeyValue("aft left stall", str(bool(err & (1 << 4))))) + stat.values.append(KeyValue("front left stall", str(bool(err & (1 << 5))))) + stat.values.append(KeyValue("aft right stall", str(bool(err & (1 << 6))))) + stat.values.append(KeyValue("front right stall", str(bool(err & (1 << 7))))) msg.status.append(stat) self.pub_diag.publish(msg) @@ -204,7 +231,9 @@ class MoveBase: i2c_write_reg(0x50, 0x50, struct.pack(">ff", trans, rot)) def cmdVelReceived(self, msg): + rospy.logdebug("Set new cmd_vel:", msg.linear.x, msg.angular.z) self.cmd_vel = (msg.linear.x, msg.angular.z) # commit speed on next update cycle + rospy.logdebug("Set new cmd_vel done") # http://rn-wissen.de/wiki/index.php/Sensorarten#Sharp_GP2D12 def get_dist_ir(self, num):