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
00038 #ifndef IMU_FILTER_TF_BROADCAST_H
00039 #define IMU_FILTER_TF_BROADCAST_H
00040
00041 #include <tf/transform_broadcaster.h>
00042 #include <tf/transform_listener.h>
00043
00044 #include <imu_filter/imu_state.h>
00045 #include <imu_filter/tf_helper.h>
00046 #include <imu_filter/message_helper.h>
00047
00048 namespace imu_filter
00049 {
00050
00051 class TfHandler
00052 {
00053 public:
00057 static TfHandler & instance()
00058 {
00059 static TfHandler instance_;
00060 return instance_;
00061 }
00062
00069 void broadcastIMUFrame( const Eigen::Quaterniond & orientation, const Eigen::Vector3d & position, const ros::Time & time )
00070 {
00071 tf_helper::toTfTransform( orientation, position, imuFrame_ );
00072
00073 bc_.sendTransform( tf::StampedTransform( imuFrame_, time, baseFrame_, "imu_local" ) );
00074 }
00075
00081 void setPseudoObservation( const Observation::Vector & vec, const ros::Time & time )
00082 {
00083 tf_helper::toTfTransform( vec, imuFrame_ );
00084 bc_.sendTransform( tf::StampedTransform( imuFrame_, time, baseFrame_, "imu_pseudo_obs" ) );
00085
00086 qMsg_.x = vec[ 0 ];
00087 qMsg_.y = vec[ 1 ];
00088 qMsg_.z = vec[ 2 ];
00089 qMsg_.w = vec[ 3 ];
00090 vMsg_.x = vec[ 4 ];
00091 vMsg_.y = vec[ 5 ];
00092 vMsg_.z = vec[ 6 ];
00093 pubPseudoRot_.publish( qMsg_ );
00094 pubPseudoPos_.publish( vMsg_ );
00095 }
00096
00103 void broadcastTfPose( const Eigen::Affine3d & pose, const ros::Time & t, const std::string & frame )
00104 {
00105 tf_helper::toTfTransform( pose, imuFrame_ );
00106 bc_.sendTransform( tf::StampedTransform( imuFrame_, t, baseFrame_, frame ) );
00107 }
00108
00109
00125 void publishImuState( const ImuState & state, const ros::Time & t )
00126 {
00127
00128 Eigen::Affine3d world2Imu;
00129 world2Imu.linear() = state.orientation().toRotationMatrix();
00130 world2Imu.translation() = state.position();
00131
00132 Eigen::Affine3d body2Imu;
00133 body2Imu.linear() = state.body2ImuRotation().toRotationMatrix();
00134 body2Imu.translation() = state.body2ImuTranslation();
00135
00136 Eigen::Affine3d world2Body = world2Imu * body2Imu.inverse();
00137
00138 poseMsg_.header.stamp = t;
00139 poseMsg_.header.frame_id = baseFrame_;
00140 message_helper::eigenPose2Msg( world2Body, poseMsg_ );
00141 pubImuPose_.publish( poseMsg_ );
00142
00143 message_helper::quaternionToMsg( state.orientation(), qMsg_ );
00144 pubImuRot_.publish( qMsg_ );
00145
00146 message_helper::vec3ToMsg( state.position(), vMsg_ );
00147 pubImuPos_.publish( vMsg_ );
00148
00149 message_helper::vec3ToMsg( state.velocity(), vMsg_ );
00150 pubImuVel_.publish( vMsg_ );
00151
00152 message_helper::vec3ToMsg( state.gyroBias(), vMsg_ );
00153 pubImuGBias_.publish( vMsg_ );
00154
00155 message_helper::vec3ToMsg( state.accBias(), vMsg_ );
00156 pubImuABias_.publish( vMsg_ );
00157
00158 message_helper::vec3ToMsg( state.gravity(), vMsg_ );
00159 pubGravity_.publish( vMsg_ );
00160 }
00161
00165 void setBaseFrame( const std::string & frame_id ){ baseFrame_ = frame_id; }
00166
00170 void publishKFRelativePose( const Eigen::Affine3d & pose, const ros::Time & t )
00171 {
00172 message_helper::eigenPose2Msg( pose, poseMsg_ );
00173 poseMsg_.header.stamp = t;
00174 poseMsg_.header.frame_id = baseFrame_;
00175 pubPoseRelativeToKf_.publish( poseMsg_ );
00176 }
00177
00178 private:
00179 ros::NodeHandle nh_;
00180
00181 TfHandler() :
00182 baseFrame_( "map" )
00183 {
00184 imuFrame_.setOrigin( tf::Vector3( 0, 0, 0 ) );
00185 pubPseudoRot_ = nh_.advertise<geometry_msgs::Quaternion>( "pseudoRot", 1 );
00186 pubPseudoPos_ = nh_.advertise<geometry_msgs::Vector3>( "pseudoPos", 1 );
00187 pubGtRot_ = nh_.advertise<geometry_msgs::Quaternion>( "gtRot", 1 );
00188 pubGtPos_ = nh_.advertise<geometry_msgs::Vector3>( "gtPos", 1 );
00189 pubImuPose_ = nh_.advertise<geometry_msgs::PoseStamped>( "imuCamPoseEstimate", 1 );
00190 pubImuRot_ = nh_.advertise<geometry_msgs::Quaternion>( "imu_rot", 1 );
00191 pubImuPos_ = nh_.advertise<geometry_msgs::Vector3>( "imu_pos", 1 );
00192 pubImuVel_ = nh_.advertise<geometry_msgs::Vector3>( "imu_vel", 1 );
00193 pubImuGBias_ = nh_.advertise<geometry_msgs::Vector3>( "imu_gyro_bias", 1 );
00194 pubImuABias_ = nh_.advertise<geometry_msgs::Vector3>( "imu_acc_bias", 1 );
00195 pubGravity_ = nh_.advertise<geometry_msgs::Vector3>( "imu_gravity", 1 );
00196 pubPoseRelativeToKf_ = nh_.advertise<geometry_msgs::PoseStamped>( "imuCamPoseRelative2KF", 1 );
00197 }
00198
00199 TfHandler( const TfHandler & );
00200
00201 std::string baseFrame_;
00202 tf::TransformBroadcaster bc_;
00203 tf::TransformListener tfIn_;
00204 tf::Transform imuFrame_;
00205 tf::StampedTransform tmpT_;
00206
00207 ros::Publisher pubPseudoRot_;
00208 ros::Publisher pubPseudoPos_;
00209 ros::Publisher pubGtRot_;
00210 ros::Publisher pubGtPos_;
00211 ros::Publisher pubImuPose_;
00212 ros::Publisher pubImuRot_;
00213 ros::Publisher pubImuPos_;
00214 ros::Publisher pubImuVel_;
00215 ros::Publisher pubImuGBias_;
00216 ros::Publisher pubImuABias_;
00217 ros::Publisher pubGravity_;
00218 ros::Publisher pubPoseRelativeToKf_;
00219
00220 geometry_msgs::Quaternion qMsg_;
00221 geometry_msgs::Vector3 vMsg_;
00222 geometry_msgs::PoseStamped poseMsg_;
00223 };
00224
00225 }
00226
00227 #endif