00001 00011 #include <messageMaker.h> 00012 00017 MessageMaker::MessageMaker(SensorData & _data):data(_data){ 00018 } 00019 00028 sensor_msgs::Imu MessageMaker::fillImuMessage(){ 00029 sensor_msgs::Imu imuData; 00030 imuData.header.frame_id = data.frameId(); 00031 imuData.header.stamp = ros::Time::now(); 00032 00033 imuData.angular_velocity.x = data.gyroscope_x(); 00034 imuData.angular_velocity.y = data.gyroscope_y(); 00035 imuData.angular_velocity.z = data.gyroscope_z(); 00036 00037 for(int i=0 ; i < 9 ; i++){ 00038 imuData.angular_velocity_covariance[i]=0.0; 00039 } 00040 imuData.angular_velocity_covariance[0] = 00041 imuData.angular_velocity_covariance[4] = 00042 imuData.angular_velocity_covariance[8] = data.gyrError(); 00043 00044 imuData.linear_acceleration.x = data.accelerometer_x(); 00045 imuData.linear_acceleration.y = data.accelerometer_y(); 00046 imuData.linear_acceleration.z = data.accelerometer_z(); 00047 00048 for(int i=0 ; i < 9 ; i++){ 00049 imuData.linear_acceleration_covariance[i]=0.0; 00050 } 00051 imuData.linear_acceleration_covariance[0] = 00052 imuData.linear_acceleration_covariance[4] = 00053 imuData.linear_acceleration_covariance[8] = data.accError(); 00054 00055 00056 imuData.orientation.x = data.quaternion_x(); 00057 imuData.orientation.y = data.quaternion_y(); 00058 imuData.orientation.z = data.quaternion_z(); 00059 imuData.orientation.w = data.quaternion_w(); 00060 00061 for(int i=0 ; i < 9 ; i++){ 00062 imuData.orientation_covariance[i]=0.0; 00063 } 00064 imuData.orientation_covariance[0] = data.rollError(); 00065 imuData.orientation_covariance[4] = data.pitchError(); 00066 imuData.orientation_covariance[8] = data.yawError(); 00067 00068 return imuData; 00069 } 00070 00077 sensor_msgs::NavSatFix MessageMaker::fillNavSatFixMessage(){ 00078 sensor_msgs::NavSatFix gpsData; 00079 sensor_msgs::NavSatStatus status_msg; 00080 00081 gpsData.header.frame_id = data.frameId() + "_gps" ; 00082 gpsData.header.stamp = ros::Time::now(); 00083 00084 gpsData.altitude = data.altitude(); 00085 gpsData.latitude = data.latitude(); 00086 gpsData.longitude = data.longitude(); 00087 00088 gpsData.position_covariance_type = sensor_msgs::NavSatFix::COVARIANCE_TYPE_DIAGONAL_KNOWN; 00089 00090 for(int i=0 ; i < 9 ; i++){ 00091 gpsData.position_covariance[i]=0.0; 00092 } 00093 00094 //Covariance obtained using DOP and PositionAccuracy from xsrawgpssol.h in the xsens api 00095 gpsData.position_covariance[0]= (data.edop() * data.PositionAccuracy()/100) * (data.edop() * data.PositionAccuracy()/100); 00096 gpsData.position_covariance[4]= (data.ndop() * data.PositionAccuracy()/100) * (data.ndop() * data.PositionAccuracy()/100); 00097 gpsData.position_covariance[8]= (data.vdop() * data.PositionAccuracy()/100) * (data.vdop() * data.PositionAccuracy()/100); 00098 00099 //Status comes from status word of the sensor, no augmentation at this step 00100 if(data.GpsFixStatus()>0){ 00101 status_msg.status = sensor_msgs::NavSatStatus::STATUS_FIX; 00102 } 00103 else{ 00104 status_msg.status = sensor_msgs::NavSatStatus::STATUS_NO_FIX; 00105 } 00106 00107 gpsData.status = status_msg; 00108 00109 return gpsData; 00110 } 00111 00112 00118 geometry_msgs::TwistWithCovarianceStamped MessageMaker::fillVelocityMessage(){ 00119 geometry_msgs::TwistWithCovarianceStamped stamped; 00120 geometry_msgs::TwistWithCovariance& res = stamped.twist; 00121 geometry_msgs::Twist& velocityData = res.twist; 00122 for(int i=0;i<36;i++){ 00123 res.covariance[i]=0.0; 00124 } 00125 res.covariance[0]=res.covariance[7]=res.covariance[14]=0.001; 00126 res.covariance[21]=res.covariance[28]=res.covariance[35]=0.01; 00127 //conversion of angular velocity to ENU frame of reference 00128 tf::Quaternion oq; 00129 data.getOrientationQuaternion(&oq); 00130 00131 tf::Quaternion local_w(data.gyroscope_x(), data.gyroscope_y(), data.gyroscope_z(), 1.0); 00132 tf::Quaternion global_w = oq * local_w * oq.inverse(); 00133 //RPY in ENU frame 00134 double groll, gpitch, gyaw; 00135 tf::Matrix3x3(global_w).getRPY(groll,gpitch, gyaw); 00136 velocityData.angular.x = groll; 00137 velocityData.angular.y = gpitch; 00138 velocityData.angular.z = gyaw; 00139 00140 velocityData.linear.x = data.velocity_x(); 00141 velocityData.linear.y = data.velocity_y(); 00142 velocityData.linear.z = data.velocity_z(); 00143 res.twist=velocityData; 00144 00145 stamped.header.frame_id = data.frameId(); 00146 stamped.header.stamp = ros::Time::now(); 00147 return stamped; 00148 00149 00150 } 00151 00152 00158 geometry_msgs::TwistWithCovarianceStamped MessageMaker::fillGpsVelocityMessage(){ 00159 geometry_msgs::TwistWithCovarianceStamped stamped; 00160 geometry_msgs::TwistWithCovariance& res = stamped.twist; 00161 geometry_msgs::Twist& velocityData = res.twist; 00162 for(int i=0;i<36;i++){ 00163 res.covariance[i]=0.0; 00164 } 00165 res.covariance[0]=res.covariance[7]=res.covariance[14]=0.001; 00166 res.covariance[21]=res.covariance[28]=res.covariance[35]=0.01; 00167 //conversion of angular velocity to ENU frame of reference 00168 00169 velocityData.angular.x = 0.0; 00170 velocityData.angular.y = 0.0; 00171 velocityData.angular.z = 0.0; 00172 00173 velocityData.linear.x = data.gps_velocity_x(); 00174 velocityData.linear.y = data.gps_velocity_y(); 00175 velocityData.linear.z = data.gps_velocity_z(); 00176 res.twist=velocityData; 00177 00178 stamped.header.frame_id = data.frameId(); 00179 stamped.header.stamp = ros::Time::now(); 00180 return stamped; 00181 00182 00183 } 00184 00185 00190 sensor_msgs::Temperature MessageMaker::fillTemperatureMessage(){ 00191 sensor_msgs::Temperature tempData; 00192 00193 tempData.header.frame_id = data.frameId(); 00194 tempData.header.stamp = ros::Time::now(); 00195 00196 tempData.temperature = data.temperature(); 00197 00198 return tempData; 00199 00200 } 00201 00206 sensor_msgs::FluidPressure MessageMaker::fillPressureMessage(){ 00207 sensor_msgs::FluidPressure pressureData; 00208 00209 pressureData.header.frame_id = data.frameId(); 00210 pressureData.header.stamp = ros::Time::now(); 00211 00212 pressureData.fluid_pressure = data.pressure(); 00213 00214 return pressureData; 00215 00216 } 00217 00223 sensor_msgs::MagneticField MessageMaker::fillMagneticFieldMessage(){ 00224 sensor_msgs::MagneticField magneticData; 00225 00226 magneticData.header.frame_id = data.frameId(); 00227 magneticData.header.stamp = ros::Time::now(); 00228 00229 magneticData.magnetic_field.x = data.magnetic_x(); 00230 magneticData.magnetic_field.y = data.magnetic_y(); 00231 magneticData.magnetic_field.z = data.magnetic_z(); 00232 00233 return magneticData; 00234 } 00235 00236 geometry_msgs::Vector3Stamped MessageMaker::fillRPYMessage(){ 00237 geometry_msgs::Vector3Stamped rpyData; 00238 rpyData.header.frame_id = data.frameId(); 00239 rpyData.header.stamp = ros::Time::now(); 00240 00241 rpyData.vector.x = data.roll(); 00242 rpyData.vector.y = data.pitch(); 00243 rpyData.vector.z = data.yaw(); 00244 00245 return rpyData; 00246 } 00247 00253 mtig_driver::GpsInfo MessageMaker::fillGpsInfoMessage(){ 00254 mtig_driver::GpsInfo gps_info; 00255 gps_info.header.frame_id = data.frameId(); 00256 gps_info.header.stamp = ros::Time::now(); 00257 00258 00259 //DOP INFORMATION 00260 gps_info.geometricDOP = data.gdop(); 00261 gps_info.positionDOP = data.pdop(); 00262 gps_info.timeDOP = data.tdop(); 00263 gps_info.verticalDOP = data.vdop(); 00264 gps_info.horizontalDOP = data.hdop(); 00265 gps_info.eastingDOP = data.edop(); 00266 gps_info.northingDOP = data.ndop(); 00267 00268 gps_info.itow = data.itow(); 00269 00270 //POSITION AND SPEED ACCURACY 00271 gps_info.position_accuracy = data.PositionAccuracy(); 00272 gps_info.speed_accuracy = data.SpeedAccuracy(); 00273 00274 //NUMBER OF SATELLITES USED IN GPS ACQUISITION 00275 gps_info.satellite_number = data.SatelliteNumber(); 00276 00277 gps_info.gps_fix = data.GpsFixStatus(); 00278 00279 00280 return gps_info; 00281 }