inspva.cpp
Go to the documentation of this file.
00001 // *****************************************************************************
00002 //
00003 // Copyright (c) 2017, Southwest Research Institute® (SwRI®)
00004 // All rights reserved.
00005 //
00006 // Redistribution and use in source and binary forms, with or without
00007 // modification, are permitted provided that the following conditions are met:
00008 //     * Redistributions of source code must retain the above copyright
00009 //       notice, this list of conditions and the following disclaimer.
00010 //     * Redistributions in binary form must reproduce the above copyright
00011 //       notice, this list of conditions and the following disclaimer in the
00012 //       documentation and/or other materials provided with the distribution.
00013 //     * Neither the name of Southwest Research Institute® (SwRI®) nor the
00014 //       names of its contributors may be used to endorse or promote products
00015 //       derived from this software without specific prior written permission.
00016 //
00017 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020 // ARE DISCLAIMED. IN NO EVENT SHALL SOUTHWEST RESEARCH INSTITUTE BE LIABLE FOR ANY
00021 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00022 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00023 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00024 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00026 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027 //
00028 // *****************************************************************************
00029 
00030 #include <novatel_gps_driver/parsers/inspva.h>
00031 #include <boost/make_shared.hpp>
00032 #include <novatel_gps_driver/parsers/header.h>
00033 
00034 const std::string novatel_gps_driver::InspvaParser::MESSAGE_NAME = "INSPVA";
00035 
00036 uint32_t novatel_gps_driver::InspvaParser::GetMessageId() const
00037 {
00038   return MESSAGE_ID;
00039 }
00040 
00041 const std::string novatel_gps_driver::InspvaParser::GetMessageName() const
00042 {
00043   return MESSAGE_NAME;
00044 }
00045 
00046 novatel_gps_msgs::InspvaPtr
00047 novatel_gps_driver::InspvaParser::ParseBinary(const novatel_gps_driver::BinaryMessage& bin_msg) throw(ParseException)
00048 {
00049   if (bin_msg.data_.size() != BINARY_LENGTH)
00050   {
00051     std::stringstream error;
00052     error << "Unexpected inspva message size: " << bin_msg.data_.size();
00053     throw ParseException(error.str());
00054   }
00055   novatel_gps_msgs::InspvaPtr ros_msg = boost::make_shared<novatel_gps_msgs::Inspva>();
00056   HeaderParser h_parser;
00057   ros_msg->novatel_msg_header = h_parser.ParseBinary(bin_msg);
00058   ros_msg->novatel_msg_header.message_name = GetMessageName();
00059 
00060   ros_msg->week = ParseUInt32(&bin_msg.data_[0]);
00061   ros_msg->seconds = ParseDouble(&bin_msg.data_[4]);
00062   ros_msg->latitude = ParseDouble(&bin_msg.data_[12]);
00063   ros_msg->longitude = ParseDouble(&bin_msg.data_[20]);
00064   ros_msg->height = ParseDouble(&bin_msg.data_[28]);
00065   ros_msg->north_velocity = ParseDouble(&bin_msg.data_[36]);
00066   ros_msg->east_velocity = ParseDouble(&bin_msg.data_[44]);
00067   ros_msg->up_velocity = ParseDouble(&bin_msg.data_[52]);
00068   ros_msg->roll = ParseDouble(&bin_msg.data_[60]);
00069   ros_msg->pitch = ParseDouble(&bin_msg.data_[68]);
00070   ros_msg->azimuth = ParseDouble(&bin_msg.data_[76]);
00071   uint32_t status = ParseUInt32(&bin_msg.data_[84]);
00072 
00073   switch (status)
00074   {
00075     case 0:
00076       ros_msg->status = "INS_INACTIVE";
00077       break;
00078     case 1:
00079       ros_msg->status = "INS_ALIGNING";
00080       break;
00081     case 2:
00082       ros_msg->status = "INS_HIGH_VARIANCE";
00083       break;
00084     case 3:
00085       ros_msg->status = "INS_SOLUTION_GOOD";
00086       break;
00087     case 6:
00088       ros_msg->status = "INS_SOLUTION_FREE";
00089       break;
00090     case 7:
00091       ros_msg->status = "INS_ALIGNMENT_COMPLETE";
00092       break;
00093     case 8:
00094       ros_msg->status = "DETERMINING_ORIENTATION";
00095       break;
00096     case 9:
00097       ros_msg->status = "WAITING_INITIALPOS";
00098       break;
00099     case 10:
00100       ros_msg->status = "WAITING_AZIMUTH";
00101       break;
00102     case 11:
00103       ros_msg->status = "INITIALIZING_BASES";
00104       break;
00105     case 12:
00106       ros_msg->status = "MOTION_DETECT";
00107       break;
00108     default:
00109     {
00110       std::stringstream error;
00111       error << "Unexpected inertial solution status: " << status;
00112       throw ParseException(error.str());
00113     }
00114   }
00115 
00116   return ros_msg;
00117 }
00118 
00119 novatel_gps_msgs::InspvaPtr
00120 novatel_gps_driver::InspvaParser::ParseAscii(const novatel_gps_driver::NovatelSentence& sentence) throw(ParseException)
00121 {
00122   if (sentence.body.size() != ASCII_FIELDS)
00123   {
00124     std::stringstream error;
00125     error << "Unexpected number of fields in INSPVA log: " << sentence.body.size();
00126     throw ParseException(error.str());
00127   }
00128   novatel_gps_msgs::InspvaPtr msg = boost::make_shared<novatel_gps_msgs::Inspva>();
00129   HeaderParser h_parser;
00130   msg->novatel_msg_header = h_parser.ParseAscii(sentence);
00131 
00132   bool valid = true;
00133 
00134   valid &= ParseUInt32(sentence.body[0], msg->week);
00135   valid &= ParseDouble(sentence.body[1], msg->seconds);
00136   valid &= ParseDouble(sentence.body[2], msg->latitude);
00137   valid &= ParseDouble(sentence.body[3], msg->longitude);
00138   valid &= ParseDouble(sentence.body[4], msg->height);
00139   valid &= ParseDouble(sentence.body[5], msg->north_velocity);
00140   valid &= ParseDouble(sentence.body[6], msg->east_velocity);
00141   valid &= ParseDouble(sentence.body[7], msg->up_velocity);
00142   valid &= ParseDouble(sentence.body[8], msg->roll);
00143   valid &= ParseDouble(sentence.body[9], msg->pitch);
00144   valid &= ParseDouble(sentence.body[10], msg->azimuth);
00145   msg->status = sentence.body[11];
00146 
00147   if (!valid)
00148   {
00149     throw ParseException("Error parsing INSPVA log.");
00150   }
00151 
00152   return msg;
00153 }


novatel_gps_driver
Author(s):
autogenerated on Wed Jul 3 2019 19:40:37