]> defiant.homedns.org Git - ros_wild_thumper.git/commitdiff
move_base: use imu to control motor handicap
authorErik Andresen <erik@vontaene.de>
Fri, 5 Jun 2015 17:22:48 +0000 (17:22 +0000)
committerErik Andresen <erik@vontaene.de>
Fri, 5 Jun 2015 17:22:48 +0000 (17:22 +0000)
launch/teleop.launch
launch/wild_thumper.launch [new file with mode: 0644]
scripts/move_base.py
wild_thumper.launch [deleted file]

index 46188952a3b284eb0496fe5e5c6f830c01149a2e..5fb511c4ab5cc27c279fc03a137651ac2e40849a 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0"?>
 <launch>
-       <node pkg="turtlebot_teleop" type="turtlebot_teleop_joy" name="turtlebot_teleop_joystick">
+       <node pkg="turtlebot_teleop" type="turtlebot_teleop_joy" name="turtlebot_teleop_joystick" respawn="true">
                <param name="scale_linear" value="0.2"/>
                <param name="scale_angular" value="-0.2"/>
                <param name="axis_deadman" value="3"/>
diff --git a/launch/wild_thumper.launch b/launch/wild_thumper.launch
new file mode 100644 (file)
index 0000000..42682bf
--- /dev/null
@@ -0,0 +1,16 @@
+<?xml version="1.0"?>
+<launch>
+       <param name="robot_description" command="$(find xacro)/xacro.py $(find wild_thumper)/urdf/wild_thumper.urdf.xacro" />
+
+       <node name="robot_state_publisher" pkg="robot_state_publisher" type="state_publisher" />
+
+       <node pkg="diagnostic_aggregator" type="aggregator_node" name="diagnostic_aggregator" >
+               <rosparam command="load" file="$(find wild_thumper)/cfg/analyzers.yaml" />
+       </node>
+
+       <node pkg="razor_imu_9dof" type="imu_node.py" name="imu_node" output="screen">
+               <rosparam file="$(find wild_thumper)/cfg/razor.yaml" command="load"/>
+       </node>
+
+       <node pkg="wild_thumper" type="move_base.py" name="move_base" output="screen" respawn="true" />
+</launch>
index 127bccacb10a43ea69e56d57d5ca88af9b9405ed..6c066f391f9b50a70c24f2a77a8ac335894f263b 100755 (executable)
@@ -9,6 +9,7 @@ from math import *
 from geometry_msgs.msg import Twist
 from nav_msgs.msg import Odometry
 from diagnostic_msgs.msg import DiagnosticArray, DiagnosticStatus, KeyValue
+from sensor_msgs.msg import Imu
 
 WHEEL_DIST = 0.248
 
@@ -16,6 +17,7 @@ class MoveBase:
        def __init__(self):
                rospy.init_node('wild_thumper_move_base')
                rospy.Subscriber("cmd_vel", Twist, self.cmdVelReceived)
+               rospy.Subscriber("imu", Imu, self.imuReceived)
                self.tf_broadcaster = tf.broadcaster.TransformBroadcaster()
                self.pub_odom = rospy.Publisher("odom", Odometry, queue_size=16)
                self.pub_diag = rospy.Publisher("diagnostics", DiagnosticArray, queue_size=16)
@@ -39,6 +41,22 @@ class MoveBase:
                        #self.get_dist_right()
                        rate.sleep()
 
+       def set_motor_handicap(self, front, aft): # percent
+               i2c_write_reg(0x50, 0x94, struct.pack(">bb", front, aft))
+
+       def imuReceived(self, msg):
+               (roll, pitch, yaw) = tf.transformations.euler_from_quaternion(msg.orientation.__getstate__())
+               if pitch > 30*pi/180:
+                       val = (100/90)*abs(pitch)*180/pi
+                       print "aft handicap", val
+                       self.set_motor_handicap(0, val)
+               elif pitch < -30*pi/180:
+                       val = (100/90)*abs(pitch)*180/pi
+                       print "front handicap", val
+                       self.set_motor_handicap(val, 0)
+               else:
+                       self.set_motor_handicap(0, 0)
+
        def get_reset(self):
                reset = struct.unpack(">B", i2c_read_reg(0x50, 0xA0, 1))[0]
 
@@ -69,10 +87,10 @@ class MoveBase:
                stat.level = DiagnosticStatus.ERROR if err else DiagnosticStatus.OK
                stat.message = "0x%02x" % err
 
-               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)))))
+               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)))))
 
                msg.status.append(stat)
                self.pub_diag.publish(msg)
@@ -84,7 +102,7 @@ class MoveBase:
                msg.header.stamp = rospy.Time.now()
                stat = DiagnosticStatus()
                stat.name = "Voltage"
-               stat.level = DiagnosticStatus.ERROR if volt < 6 else DiagnosticStatus.OK
+               stat.level = DiagnosticStatus.ERROR if volt < 7 else DiagnosticStatus.OK
                stat.message = "%.2fV" % volt
 
                msg.status.append(stat)
diff --git a/wild_thumper.launch b/wild_thumper.launch
deleted file mode 100644 (file)
index af52d92..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-<?xml version="1.0"?>
-<launch>
-       <param name="robot_description" command="$(find xacro)/xacro.py $(find wild_thumper)/urdf/wild_thumper.urdf.xacro" />
-
-       <node name="robot_state_publisher" pkg="robot_state_publisher" type="state_publisher" />
-
-       <node pkg="diagnostic_aggregator" type="aggregator_node" name="diagnostic_aggregator" >
-               <rosparam command="load" file="$(find wild_thumper)/cfg/analyzers.yaml" />
-       </node>
-
-       <node pkg="razor_imu_9dof" type="imu_node.py" name="imu_node" output="screen">
-               <rosparam file="$(find wild_thumper)/cfg/razor.yaml" command="load"/>
-       </node>
-</launch>