bestvel.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 
00031 #include <novatel_gps_driver/parsers/bestvel.h>
00032 #include <novatel_gps_driver/parsers/header.h>
00033 #include <boost/make_shared.hpp>
00034 
00035 const std::string novatel_gps_driver::BestvelParser::MESSAGE_NAME = "BESTVEL";
00036 
00037 uint32_t novatel_gps_driver::BestvelParser::GetMessageId() const
00038 {
00039   return MESSAGE_ID;
00040 }
00041 
00042 const std::string novatel_gps_driver::BestvelParser::GetMessageName() const
00043 {
00044   return MESSAGE_NAME;
00045 }
00046 
00047 novatel_gps_msgs::NovatelVelocityPtr novatel_gps_driver::BestvelParser::ParseBinary(const BinaryMessage& bin_msg) throw(ParseException)
00048 {
00049   if (bin_msg.data_.size() != BINARY_LENGTH)
00050   {
00051     std::stringstream error;
00052     error << "Unexpected velocity message size: " << bin_msg.data_.size();
00053     throw ParseException(error.str());
00054   }
00055   novatel_gps_msgs::NovatelVelocityPtr ros_msg = boost::make_shared<novatel_gps_msgs::NovatelVelocity>();
00056   HeaderParser h_parser;
00057   ros_msg->novatel_msg_header = h_parser.ParseBinary(bin_msg);
00058   ros_msg->novatel_msg_header.message_name = MESSAGE_NAME;
00059 
00060   uint16_t solution_status = ParseUInt16(&bin_msg.data_[0]);
00061   if (solution_status > MAX_SOLUTION_STATUS)
00062   {
00063     std::stringstream error;
00064     error << "Unknown solution status: " << solution_status;
00065     throw ParseException(error.str());
00066   }
00067   ros_msg->solution_status = SOLUTION_STATUSES[solution_status];
00068   uint16_t pos_type = ParseUInt16(&bin_msg.data_[4]);
00069   if (pos_type > MAX_POSITION_TYPE)
00070   {
00071     std::stringstream error;
00072     error << "Unknown position type: " << pos_type;
00073     throw ParseException(error.str());
00074   }
00075   ros_msg->velocity_type = POSITION_TYPES[pos_type];
00076   ros_msg->latency = ParseFloat(&bin_msg.data_[8]);
00077   ros_msg->age = ParseFloat(&bin_msg.data_[12]);
00078   ros_msg->horizontal_speed = ParseDouble(&bin_msg.data_[16]);
00079   ros_msg->track_ground = ParseDouble(&bin_msg.data_[24]);
00080   ros_msg->vertical_speed = ParseDouble(&bin_msg.data_[32]);
00081 
00082   return ros_msg;
00083 }
00084 
00085 novatel_gps_msgs::NovatelVelocityPtr novatel_gps_driver::BestvelParser::ParseAscii(const NovatelSentence& sentence) throw(ParseException)
00086 {
00087   novatel_gps_msgs::NovatelVelocityPtr msg = boost::make_shared<novatel_gps_msgs::NovatelVelocity>();
00088   HeaderParser h_parser;
00089   msg->novatel_msg_header = h_parser.ParseAscii(sentence);
00090 
00091   if (sentence.body.size() != ASCII_LENGTH)
00092   {
00093     std::stringstream error;
00094     error << "Unexpected number of BESTVEL message fields: " << sentence.body.size();
00095     throw ParseException(error.str());
00096   }
00097   bool valid = true;
00098   msg->solution_status = sentence.body[0];
00099   msg->velocity_type = sentence.body[1];
00100   valid = valid && ParseFloat(sentence.body[2], msg->latency);
00101   valid = valid && ParseFloat(sentence.body[3], msg->age);
00102   valid = valid && ParseDouble(sentence.body[4], msg->horizontal_speed);
00103   valid = valid && ParseDouble(sentence.body[5], msg->track_ground);
00104   valid = valid && ParseDouble(sentence.body[6], msg->vertical_speed);
00105 
00106   if (!valid)
00107   {
00108     throw ParseException("Invalid field in BESTVEL message");
00109   }
00110 
00111   return msg;
00112 }


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