Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include <labust/tools/conversions.hpp>
00038
00039 #include <nav_msgs/Odometry.h>
00040 #include <geometry_msgs/TwistStamped.h>
00041 #include <std_msgs/Float32.h>
00042 #include <ros/ros.h>
00043 #include <tf/transform_datatypes.h>
00044
00045 struct DvlSim
00046 {
00047 DvlSim():
00048 maxBottomLock(100),
00049 maxDepth(100),
00050 dvl_pub(1)
00051 {
00052 ros::NodeHandle nh,ph("~");
00053
00054 ph.param("MaxBottomLock",maxBottomLock, maxBottomLock);
00055 ph.param("MaxDepth", maxDepth, maxDepth);
00056 ph.param("DvlPub", dvl_pub, dvl_pub);
00057
00058 odom = nh.subscribe<nav_msgs::Odometry>("meas_odom",1,&DvlSim::onOdom, this);
00059 dvl_nu = nh.advertise<geometry_msgs::TwistStamped>("dvl",1);
00060 dvl_ned = nh.advertise<geometry_msgs::TwistStamped>("dvl_ned",1);
00061 altitude_pub = nh.advertise<std_msgs::Float32>("altitude",1);
00062
00063 last_pos[0] = last_pos[1] = last_pos[2] = 0;
00064 }
00065
00066 void onOdom(const typename nav_msgs::Odometry::ConstPtr& msg)
00067 {
00068 static int i=0;
00069 i=++i%dvl_pub;
00070
00071 if (i == 0)
00072 {
00073 double dT = (ros::Time::now() - lastTime).toSec();
00074 lastTime = ros::Time::now();
00075 geometry_msgs::TwistStamped::Ptr dvl(new geometry_msgs::TwistStamped());
00076 dvl->header.stamp = ros::Time::now();
00077 dvl->header.frame_id = msg->header.frame_id;
00078 double pos[3],v[3];
00079 labust::tools::pointToVector(msg->pose.pose.position, pos);
00080 for (int i=0; i<3; ++i)
00081 {
00082 v[i] = (pos[i] - last_pos[i])/dT;
00083 last_pos[i] = pos[i];
00084 }
00085 labust::tools::vectorToPoint(v, dvl->twist.linear);
00086 dvl_ned.publish(dvl);
00087
00088 dvl.reset(new geometry_msgs::TwistStamped());
00089 dvl->header.stamp = ros::Time::now();
00090 dvl->header.frame_id = msg->child_frame_id;
00091
00092 tf::Quaternion q;
00093 tf::quaternionMsgToTF(msg->pose.pose.orientation, q);
00094 tf::Transform t;
00095 t.setRotation(q);
00096 tf::Vector3 nu = t.getBasis().transpose() * tf::Vector3(v[0],v[1],v[2]);
00097 dvl->twist.linear.x = nu.x();
00098 dvl->twist.linear.y = nu.y();
00099 dvl->twist.linear.z = nu.z();
00100 dvl_nu.publish(dvl);
00101
00102 if ((maxDepth - msg->pose.pose.position.z) < maxBottomLock)
00103 {
00104 std_msgs::Float32::Ptr altitude(new std_msgs::Float32());
00105 altitude->data = maxDepth - msg->pose.pose.position.z;
00106 altitude_pub.publish(altitude);
00107 }
00108 }
00109 }
00110
00111 private:
00112 ros::Subscriber odom;
00113 ros::Publisher dvl_nu, altitude_pub, dvl_ned;
00114 ros::Time lastTime;
00115 double last_pos[3];
00116 int dvl_pub;
00117 double maxBottomLock, maxDepth;
00118 };
00119
00120 int main(int argc, char* argv[])
00121 {
00122 ros::init(argc,argv,"dvl_sim");
00123 ros::NodeHandle nh;
00124 DvlSim dvl;
00125 ros::spin();
00126 return 0;
00127 }
00128
00129