corrimudata.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/corrimudata.h>
00031 #include <novatel_gps_driver/parsers/header.h>
00032 #include <boost/make_shared.hpp>
00033 
00034 const std::string novatel_gps_driver::CorrImuDataParser::MESSAGE_NAME = "CORRIMUDATA";
00035 
00036 uint32_t novatel_gps_driver::CorrImuDataParser::GetMessageId() const
00037 {
00038   return MESSAGE_ID;
00039 }
00040 
00041 const std::string novatel_gps_driver::CorrImuDataParser::GetMessageName() const
00042 {
00043   return MESSAGE_NAME;
00044 }
00045 
00046 novatel_gps_msgs::NovatelCorrectedImuDataPtr
00047 novatel_gps_driver::CorrImuDataParser::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 corrimudata message size: " << bin_msg.data_.size();
00053     throw ParseException(error.str());
00054   }
00055   novatel_gps_msgs::NovatelCorrectedImuDataPtr ros_msg = boost::make_shared<novatel_gps_msgs::NovatelCorrectedImuData>();
00056   HeaderParser h_parser;
00057   ros_msg->novatel_msg_header = h_parser.ParseBinary(bin_msg);
00058   ros_msg->novatel_msg_header.message_name = "CORRIMUDATA";
00059 
00060   ros_msg->gps_week_num = ParseUInt32(&bin_msg.data_[0]);
00061   ros_msg->gps_seconds = ParseDouble(&bin_msg.data_[4]);
00062   ros_msg->pitch_rate = ParseDouble(&bin_msg.data_[12]);
00063   ros_msg->roll_rate = ParseDouble(&bin_msg.data_[20]);
00064   ros_msg->yaw_rate = ParseDouble(&bin_msg.data_[28]);
00065   ros_msg->lateral_acceleration = ParseDouble(&bin_msg.data_[36]);
00066   ros_msg->longitudinal_acceleration = ParseDouble(&bin_msg.data_[44]);
00067   ros_msg->vertical_acceleration = ParseDouble(&bin_msg.data_[52]);
00068 
00069   return ros_msg;
00070 }
00071 
00072 novatel_gps_msgs::NovatelCorrectedImuDataPtr
00073 novatel_gps_driver::CorrImuDataParser::ParseAscii(const novatel_gps_driver::NovatelSentence& sentence) throw(ParseException)
00074 {
00075   if (sentence.body.size() != ASCII_FIELDS)
00076   {
00077     std::stringstream error;
00078     error << "Unexpected number of fields in CORRIMUDATA log: " << sentence.body.size();
00079     throw ParseException(error.str());
00080   }
00081   novatel_gps_msgs::NovatelCorrectedImuDataPtr msg = boost::make_shared<novatel_gps_msgs::NovatelCorrectedImuData>();
00082   HeaderParser h_parser;
00083   msg->novatel_msg_header = h_parser.ParseAscii(sentence);
00084 
00085   bool valid = true;
00086 
00087   valid &= ParseUInt32(sentence.body[0], msg->gps_week_num);
00088   valid &= ParseDouble(sentence.body[1], msg->gps_seconds);
00089   valid &= ParseDouble(sentence.body[2], msg->pitch_rate);
00090   valid &= ParseDouble(sentence.body[3], msg->roll_rate);
00091   valid &= ParseDouble(sentence.body[4], msg->yaw_rate);
00092   valid &= ParseDouble(sentence.body[5], msg->lateral_acceleration);
00093   valid &= ParseDouble(sentence.body[6], msg->longitudinal_acceleration);
00094   valid &= ParseDouble(sentence.body[7], msg->vertical_acceleration);
00095 
00096   if (!valid)
00097   {
00098     throw ParseException("Error parsing CORRIMUDATA log.");
00099   }
00100 
00101   return msg;
00102 }


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