00001
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include <mtiG.h>
00029 #include <stdio.h>
00030 #include <stdlib.h>
00031 #include <ros/ros.h>
00036 mtiG::mtiG(XsDevice * _device, int argc, char ** argv):device(_device){
00037
00038 ros::param::get("~override", override_settings);
00039 parseOptions(argc, argv);
00040
00041 if(override_settings){
00042
00043 ROS_DEBUG("OVERRIDE MODE");
00044 configure();
00045 }else{
00046
00047 ROS_DEBUG("UNALTERED MODE");
00048 }
00049 readSettings();
00050 printSettings();
00051 sensorData = SensorData(mSettings);
00052 messageMaker = new MessageMaker(sensorData);
00053
00054 advertise();
00055 }
00056
00061 mtiG::mtiG(XsDevice * _device){
00062 mtiG(_device, 1, NULL);
00063 }
00064
00065
00072 void mtiG::parseOptions(int argc, char** argv){
00073
00074
00075 ros::param::get("~orientation_enabled", mSettings.orientationData);
00076 ros::param::get("~gps_enabled", mSettings.gpsData);
00077 ros::param::get("~temperature_enabled", mSettings.temperatureData);
00078 ros::param::get("~acceleration_enabled", mSettings.accelerationData);
00079 ros::param::get("~pressure_enabled", mSettings.pressureData);
00080 ros::param::get("~magnetic_enabled", mSettings.magneticData);
00081 ros::param::get("~altitude_enabled", mSettings.altitudeData);
00082 ros::param::get("~gyroscope_enabled", mSettings.gyroscopeData);
00083 ros::param::get("~velocity_enabled", mSettings.velocityData);
00084
00085 ros::param::get("~orientation_frequency", mSettings.orientationFreq);
00086 ros::param::get("~gps_frequency", mSettings.gpsFreq);
00087 ros::param::get("~temperature_frequency", mSettings.temperatureFreq);
00088 ros::param::get("~acceleration_frequency", mSettings.accelerationFreq);
00089 ros::param::get("~pressure_frequency", mSettings.pressureFreq);
00090 ros::param::get("~magnetic_frequency", mSettings.magneticFreq);
00091 ros::param::get("~altitude_frequency", mSettings.altitudeFreq);
00092 ros::param::get("~gyroscope_frequency", mSettings.gyroscopeFreq);
00093 ros::param::get("~velocity_frequency", mSettings.velocityFreq);
00094 }
00095
00101 void mtiG::printSettings(){
00102 XsOutputConfigurationArray deviceConfig = device->outputConfiguration();
00103
00104
00105 for(int i =0; i < deviceConfig.size() ; i++)
00106 {
00107 ROS_DEBUG("%.8x; Freq = %d", deviceConfig[i].m_dataIdentifier, deviceConfig[i].m_frequency);
00108 }
00109
00110
00111 ROS_DEBUG_STREAM(
00112 "\nOrientation = " << mSettings.orientationData <<
00113 "\nGPS = " << mSettings.gpsData <<
00114 "\nTemperature = " << mSettings.temperatureData <<
00115 "\nAcceleration = " << mSettings.accelerationData <<
00116 "\nPressure = " << mSettings.pressureData <<
00117 "\nMagnetic = " << mSettings.magneticData <<
00118 "\nAltitude = " << mSettings.altitudeData <<
00119 "\nGyroscope = " << mSettings.gyroscopeData <<
00120 "\nVelocity = " << mSettings.velocityData <<
00121 "\nOrientation Frequency:" << mSettings.orientationFreq <<
00122 "\nGPS Frequency:" << mSettings.gpsFreq <<
00123 "\nTemperature Frequency:" << mSettings.temperatureFreq <<
00124 "\nAcceleration Frequency:" << mSettings.accelerationFreq <<
00125 "\nPressure Frequency:" << mSettings.pressureFreq <<
00126 "\nMagnetic Frequency:" << mSettings.magneticFreq <<
00127 "\nAltitude Frequency:" << mSettings.altitudeFreq <<
00128 "\nGyroscope Frequency:" << mSettings.gyroscopeFreq <<
00129 "\nVelocity Frequency:" << mSettings.velocityFreq
00130 );
00131 }
00132
00138 void mtiG::readSettings(){
00139
00140
00141 XsOutputConfigurationArray deviceConfig = device->outputConfiguration();
00142
00143
00144 mSettings.orientationData = false;
00145 mSettings.gpsData = false;
00146 mSettings.temperatureData = false;
00147 mSettings.accelerationData = false;
00148 mSettings.pressureData = false;
00149 mSettings.magneticData = false;
00150 mSettings.altitudeData = false;
00151 mSettings.gyroscopeData = false;
00152 mSettings.velocityData = false;
00153
00154
00155 for(int i =0; i < deviceConfig.size() ; i++)
00156 {
00157
00158 switch(deviceConfig[i].m_dataIdentifier){
00159
00160 case (XDI_Quaternion):
00161 mSettings.orientationData = true;
00162 break;
00163
00164 case (XDI_LatLon):
00165 case (XDI_GpsAge):
00166 case (XDI_GpsDop):
00167 case (XDI_GpsSol):
00168 ROS_DEBUG("GPS ENABLED IN CURRENT CONFIGURATION");
00169 mSettings.gpsData=true;
00170 break;
00171
00172 case (XDI_Temperature):
00173 mSettings.temperatureData=true;
00174 break;
00175
00176 case (XDI_Acceleration):
00177 mSettings.accelerationData=true;
00178 break;
00179
00180 case (XDI_BaroPressure):
00181 mSettings.pressureData=true;
00182 break;
00183
00184 case (XDI_MagneticField):
00185 mSettings.magneticData=true;
00186 break;
00187
00188 case (XDI_AltitudeEllipsoid):
00189 mSettings.altitudeData=true;
00190 break;
00191
00192 case (XDI_RateOfTurn):
00193 mSettings.gyroscopeData=true;
00194 break;
00195
00196 case (XDI_VelocityXYZ):
00197 mSettings.velocityData=true;
00198 break;
00199
00200 }
00201 }
00202
00203 }
00204
00211 void mtiG::configure(){
00212
00213 XsOutputConfigurationArray configArray;
00214
00215 if(mSettings.orientationData){
00216 XsOutputConfiguration quat(XDI_Quaternion, mSettings.orientationFreq);
00217 configArray.push_back(quat);
00218 }
00219
00220 if(mSettings.gpsData){
00221
00222 XsOutputConfiguration gps(XDI_LatLon, mSettings.gpsFreq);
00223 configArray.push_back(gps);
00224
00225 XsOutputConfiguration gps_age(XDI_GpsAge, mSettings.gpsFreq);
00226 configArray.push_back(gps_age);
00227
00228 XsOutputConfiguration gps_sol(XDI_GpsSol, mSettings.gpsFreq);
00229 configArray.push_back(gps_sol);
00230
00231 XsOutputConfiguration gps_dop(XDI_GpsDop, mSettings.gpsFreq);
00232 configArray.push_back(gps_dop);
00233 }
00234
00235 if(mSettings.temperatureData){
00236
00237 XsOutputConfiguration temp(XDI_Temperature, mSettings.temperatureFreq);
00238 configArray.push_back(temp);
00239 }
00240
00241 if(mSettings.accelerationData){
00242
00243 XsOutputConfiguration accel(XDI_Acceleration, mSettings.accelerationFreq);
00244 configArray.push_back(accel);
00245 }
00246
00247 if(mSettings.pressureData){
00248
00249 XsOutputConfiguration baro(XDI_BaroPressure, mSettings.pressureFreq);
00250 configArray.push_back(baro);
00251 }
00252
00253 if(mSettings.magneticData){
00254
00255 XsOutputConfiguration magnet(XDI_MagneticField, mSettings.magneticFreq);
00256 configArray.push_back(magnet);
00257 }
00258
00259 if(mSettings.altitudeData){
00260
00261 XsOutputConfiguration alt(XDI_AltitudeEllipsoid, mSettings.altitudeFreq);
00262 configArray.push_back(alt);
00263 }
00264
00265 if(mSettings.gyroscopeData){
00266
00267 XsOutputConfiguration gyro(XDI_RateOfTurn, mSettings.gyroscopeFreq);
00268 configArray.push_back(gyro);
00269 }
00270
00271 if(mSettings.velocityData){
00272
00273 XsOutputConfiguration vel_xyz(XDI_VelocityXYZ, mSettings.velocityFreq);
00274 configArray.push_back(vel_xyz);
00275 }
00276
00277
00278 if (!device->setOutputConfiguration(configArray))
00279 {
00280 throw std::runtime_error("Could not configure MTmk4 device. Aborting.");
00281 }
00282 }
00283
00289 void mtiG::advertise(){
00290
00291 ros::NodeHandle nh;
00292 int queue_size;
00293 ros::param::param<int>("~queue_size", queue_size, 50);
00294 if(mSettings.orientationData || mSettings.velocityData || mSettings.accelerationData){
00295 imuPublisher = nh.advertise<sensor_msgs::Imu> ("xsens/imu",queue_size);
00296 rpyPublisher = nh.advertise<geometry_msgs::Vector3Stamped> ("xsens/rpy", queue_size);
00297 }
00298 if(mSettings.gpsData){
00299 gpsPublisher = nh.advertise<sensor_msgs::NavSatFix> ("xsens/gps_data", queue_size);
00300 gpsInfoPublisher = nh.advertise<mtig_driver::GpsInfo> ("xsens/gps_extra", queue_size);
00301 }
00302 if(mSettings.velocityData){
00303 velPublisher = nh.advertise<geometry_msgs::TwistWithCovarianceStamped> ("xsens/velocity", queue_size);
00304 gpsVelPublisher = nh.advertise<geometry_msgs::TwistWithCovarianceStamped> ("xsens/gps_vel", queue_size);
00305 }
00306 if(mSettings.temperatureData){
00307 tempPublisher = nh.advertise<sensor_msgs::Temperature>("xsens/temperature", queue_size);
00308 }
00309 if(mSettings.magneticData){
00310 magFieldPub = nh.advertise<sensor_msgs::MagneticField>("xsens/magnetic", queue_size);
00311 }
00312 if(mSettings.pressureData){
00313 pressurePublisher = nh.advertise<sensor_msgs::FluidPressure>("xsens/pressure", queue_size);
00314 }
00315
00316 }
00317
00322 void mtiG::publish(){
00323 if(mSettings.orientationData || mSettings.velocityData || mSettings.accelerationData){
00324 imuPublisher.publish( messageMaker->fillImuMessage() );
00325 }
00326 if(mSettings.orientationData){
00327 rpyPublisher.publish( messageMaker->fillRPYMessage() );
00328 }
00329 if(mSettings.gpsData){
00330 gpsPublisher.publish( messageMaker->fillNavSatFixMessage() );
00331 gpsInfoPublisher.publish ( messageMaker->fillGpsInfoMessage() );
00332 }
00333 if(mSettings.velocityData){
00334 velPublisher.publish( messageMaker->fillVelocityMessage() );
00335 gpsVelPublisher.publish( messageMaker->fillGpsVelocityMessage() );
00336 }
00337 if(mSettings.temperatureData){
00338 tempPublisher.publish( messageMaker->fillTemperatureMessage() );
00339 }
00340 if(mSettings.magneticData){
00341 magFieldPub.publish( messageMaker->fillMagneticFieldMessage() );
00342 }
00343 if(mSettings.pressureData){
00344 pressurePublisher.publish( messageMaker->fillPressureMessage() );
00345 }
00346 }
00347
00352 void mtiG::fillData(XsDataPacket * packet){
00353 sensorData.fillData(packet);
00354 }