NavSts2Odom.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 '''
00003 Created on Feb 04, 2013
00004 
00005 @author: dnad
00006 '''
00007 import rospy;
00008 from auv_msgs.msg import NavSts;
00009 from nav_msgs.msg import Odometry
00010 import tf
00011 import math
00012       
00013 class MessageTransformer:
00014     def __init__(self):
00015         rospy.Subscriber("stateHat", NavSts, self.onNavSts);
00016         self.pub = rospy.Publisher("uwsim_hook", Odometry);
00017         self.listener = tf.TransformListener();
00018         self.broadcaster = tf.TransformBroadcaster();
00019         self.tf_prefix = rospy.get_param("~tf_prefix");
00020         self.tf_prefix = "/"+self.tf_prefix;
00021            
00022     def onNavSts(self,data):   
00023         q = tf.transformations.quaternion_from_euler(math.pi, 0, math.pi/2)
00024         self.broadcaster.sendTransform((0,0,0), q.conjugate(), rospy.Time.now(), self.tf_prefix + "/uwsim_frame", self.tf_prefix + "/local");
00025         
00026         try:
00027             (trans,rot) = self.listener.lookupTransform(self.tf_prefix + "/uwsim_frame", self.tf_prefix + "/base_link", rospy.Time(0))
00028             
00029             odom = Odometry();  
00030             odom.twist.twist.linear.x = data.body_velocity.x;
00031             odom.twist.twist.linear.y = data.body_velocity.y;
00032             odom.twist.twist.linear.z = data.body_velocity.z;
00033             odom.twist.twist.angular.x = data.orientation_rate.roll;
00034             odom.twist.twist.angular.y = data.orientation_rate.pitch;
00035             odom.twist.twist.angular.z = data.orientation_rate.yaw;
00036             odom.child_frame_id = "base_link"; 
00037             odom.pose.pose.orientation.x = rot[0];
00038             odom.pose.pose.orientation.y = rot[1];
00039             odom.pose.pose.orientation.z = rot[2];
00040             odom.pose.pose.orientation.w = rot[3];
00041             odom.pose.pose.position.x = trans[0];
00042             odom.pose.pose.position.y = trans[1];
00043             odom.pose.pose.position.z = trans[2];
00044             odom.header.stamp = rospy.Time.now();
00045             odom.header.frame_id = "world";
00046             
00047             self.pub.publish(odom);
00048             
00049         except (tf.LookupException, tf.ConnectivityException, tf.ExtrapolationException):
00050             None
00051 
00052 if __name__ == "__main__":
00053     rospy.init_node("navsts2UWSim");
00054     tr = MessageTransformer();
00055     rospy.spin();
00056         
00057         


labust_uwsim
Author(s): Gyula Nagy
autogenerated on Fri Feb 7 2014 11:37:23