00001 // Copyright (C) 2010-2011 Institut de Robotica i Informatica Industrial, CSIC-UPC. 00002 // Author 00003 // All rights reserved. 00004 // 00005 // This file is part of iri-ros-pkg 00006 // iri-ros-pkg is free software: you can redistribute it and/or modify 00007 // it under the terms of the GNU Lesser General Public License as published by 00008 // the Free Software Foundation, either version 3 of the License, or 00009 // at your option) any later version. 00010 // 00011 // This program is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 // GNU Lesser General Public License for more details. 00015 // 00016 // You should have received a copy of the GNU Lesser General Public License 00017 // along with this program. If not, see <http://www.gnu.org/licenses/>. 00018 // 00019 // IMPORTANT NOTE: This code has been generated through a script from the 00020 // iri_ros_scripts. Please do NOT delete any comments to guarantee the correctness 00021 // of the scripts. ROS topics can be easly add by using those scripts. Please 00022 // refer to the IRI wiki page for more information: 00023 // http://wikiri.upc.es/index.php/Robotics_Lab 00024 00025 #ifndef _kinton_odom_alg_node_h_ 00026 #define _kinton_odom_alg_node_h_ 00027 00028 #include <iri_base_algorithm/iri_base_algorithm.h> 00029 #include "kinton_odom_alg.h" 00030 00031 #include <geometry_msgs/PoseWithCovariance.h> 00032 #include <geometry_msgs/TwistWithCovariance.h> 00033 #include <geometry_msgs/Transform.h> 00034 00035 #include <Eigen/Dense> 00036 00037 #include <tf/transform_listener.h> 00038 #include <tf/transform_broadcaster.h> 00039 00040 // [publisher subscriber headers] 00041 #include <nav_msgs/Odometry.h> 00042 #include <sensor_msgs/Imu.h> 00043 #include <geometry_msgs/Point.h> 00044 00045 // [service client headers] 00046 00047 // [action server client headers] 00048 00053 class KintonOdomAlgNode : public algorithm_base::IriBaseAlgorithm<KintonOdomAlgorithm> 00054 { 00055 private: 00056 // [publisher attributes] 00057 ros::Publisher odom_publisher_; 00058 nav_msgs::Odometry Odometry_msg_; 00059 00060 // [subscriber attributes] 00061 ros::Subscriber imu_subscriber_; 00062 void imu_callback(const sensor_msgs::Imu::ConstPtr& msg); 00063 CMutex imu_mutex_; 00064 00065 ros::Subscriber height_point_subscriber_; 00066 void height_point_callback(const geometry_msgs::PointStamped::ConstPtr& msg); 00067 CMutex height_point_mutex_; 00068 00069 // [service attributes] 00070 00071 // [client attributes] 00072 00073 // [action server attributes] 00074 00075 // [action client attributes] 00076 00077 ros::Time last_time_; 00078 ros::Time current_time_; 00079 00080 //Fixed transforms between frames 00081 Eigen::Matrix4d T_acc_, T_gyr_, T_comp_; 00082 00083 //IMU data 00084 Eigen::MatrixXd pos_ang_imu_, vel_ang_imu_, acc_lin_imu_; 00085 00086 //Quadrotor rotation r.t.world 00087 Eigen::Matrix3d Rquad_; 00088 00089 //Linear velocities r.t. odom frame (integrated accelerations) 00090 Eigen::MatrixXd vel_lin_odom_; 00091 00092 //angles r.t odom frame (Integrated angular velocities) 00093 Eigen::MatrixXd pos_ang_odom_; 00094 00095 //positions r.t odom frame (Integrated linear velocities) 00096 Eigen::MatrixXd pos_lin_odom_; 00097 00098 00099 //Height from low-level fused data 00100 double height_; 00101 double height_init_; 00102 bool init_; 00103 00104 geometry_msgs::PoseWithCovariance pose_; 00105 geometry_msgs::TwistWithCovariance twist_; 00106 geometry_msgs::Transform transform_; 00107 00108 // parameter variables 00109 std::string tf_prefix_; 00110 std::string odom_id_; 00111 std::string base_link_id_; 00112 bool publish_tf_; 00113 00114 00115 public: 00122 KintonOdomAlgNode(void); 00123 00130 ~KintonOdomAlgNode(void); 00131 00132 protected: 00133 00134 tf::TransformBroadcaster odom_broadcaster_; 00135 00148 void mainNodeThread(void); 00149 00162 void node_config_update(Config &config, uint32_t level); 00163 00170 void addNodeDiagnostics(void); 00171 00172 // [diagnostic functions] 00173 00174 // [test functions] 00175 00181 void ini_zeros(); 00182 00188 Eigen::Matrix4d getTransform(const tf::StampedTransform& transform); 00189 00190 }; 00191 00192 #endif