00001 /* 00002 * Gazebo - Outdoor Multi-Robot Simulator 00003 * Copyright (C) 2003 00004 * Nate Koenig & Andrew Howard 00005 * 00006 * This program is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation; either version 2 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 General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 * 00020 */ 00021 /* 00022 * Desc: 3D position interface. 00023 * Author: Sachin Chitta and John Hsu 00024 * Date: 10 June 2008 00025 * SVN: $Id$ 00026 */ 00027 #ifndef GAZEBO_ROS_IMU_HH 00028 #define GAZEBO_ROS_IMU_HH 00029 00030 #define USE_CBQ 00031 #ifdef USE_CBQ 00032 #include <ros/callback_queue.h> 00033 #include <ros/advertise_options.h> 00034 #endif 00035 00036 #include <gazebo/Controller.hh> 00037 #include <gazebo/Entity.hh> 00038 #include <gazebo/Model.hh> 00039 #include <gazebo/Body.hh> 00040 #include <gazebo/Param.hh> 00041 #include <gazebo/Time.hh> 00042 00043 #include <ros/ros.h> 00044 #include "boost/thread/mutex.hpp" 00045 #include <sensor_msgs/Imu.h> 00046 #include <std_srvs/Empty.h> 00047 00048 00049 namespace gazebo 00050 { 00053 00099 class GazeboRosIMU : public Controller 00100 { 00102 public: GazeboRosIMU(Entity *parent ); 00103 00105 public: virtual ~GazeboRosIMU(); 00106 00109 protected: virtual void LoadChild(XMLConfigNode *node); 00110 00112 protected: virtual void InitChild(); 00113 00115 protected: virtual void UpdateChild(); 00116 00118 protected: virtual void FiniChild(); 00119 00121 private: Model *myParent; 00122 00124 private: Body *myBody; //Gazebo/ODE body 00125 00127 private: ros::NodeHandle* rosnode_; 00128 private: ros::Publisher pub_; 00129 private: ros::Publisher deprecated_pub_; 00130 00132 private: sensor_msgs::Imu imuMsg; 00133 00135 private: ParamT<std::string> *bodyNameP; 00136 private: std::string bodyName; 00137 00141 private: ParamT<std::string> *frameNameP; 00142 00144 private: ParamT<std::string> *topicNameP; 00145 private: std::string topicName; 00146 private: ParamT<std::string> *deprecatedTopicNameP; 00147 private: std::string deprecatedTopicName; 00148 00150 private: ParamT<Vector3> *xyzOffsetsP; 00151 private: Vector3 xyzOffsets; 00152 private: ParamT<Vector3> *rpyOffsetsP; 00153 private: Vector3 rpyOffsets; 00154 00156 private: boost::mutex lock; 00157 00159 private: Time last_time; 00160 private: Vector3 last_vpos; 00161 private: Vector3 last_veul; 00162 private: Vector3 apos; 00163 private: Vector3 aeul; 00164 private: Pose3d initial_pose; // keep initial pose to offset orientation in imu message 00165 00167 private: ParamT<double> *gaussianNoiseP; 00168 private: double gaussianNoise; 00169 00171 private: double GaussianKernel(double mu,double sigma); 00172 00174 private: ParamT<std::string> *robotNamespaceP; 00175 private: std::string robotNamespace; 00176 00178 private: int imuConnectCount; 00179 private: void IMUConnect(); 00180 private: void IMUDisconnect(); 00181 private: int deprecatedImuConnectCount; 00182 private: void DeprecatedIMUConnect(); 00183 private: void DeprecatedIMUDisconnect(); 00184 00186 private: bool ServiceCallback(std_srvs::Empty::Request &req, 00187 std_srvs::Empty::Response &res); 00188 private: ros::ServiceServer srv_; 00189 private: ParamT<std::string> *serviceNameP; 00190 private: std::string serviceName; 00191 00192 #ifdef USE_CBQ 00193 private: ros::CallbackQueue imu_queue_; 00194 private: void IMUQueueThread(); 00195 private: boost::thread callback_queue_thread_; 00196 #endif 00197 }; 00198 00200 00201 00202 00203 } 00204 00205 #endif 00206