repo_id
stringlengths 19
138
| file_path
stringlengths 32
200
| content
stringlengths 1
12.9M
| __index_level_0__
int64 0
0
|
|---|---|---|---|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/parser/velodyne64_parser.cc
|
/******************************************************************************
* Copyright 2017 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/drivers/lidar/velodyne/parser/velodyne_parser.h"
namespace apollo {
namespace drivers {
namespace velodyne {
Velodyne64Parser::Velodyne64Parser(const Config& config)
: VelodyneParser(config) {
for (int i = 0; i < 4; i++) {
gps_base_usec_[i] = 0;
previous_packet_stamp_[i] = 0;
}
need_two_pt_correction_ = true;
// init Unpack function and order function by model.
if (config_.model() == HDL64E_S2) {
inner_time_ = &velodyne::INNER_TIME_64;
is_s2_ = true;
} else { // 64E_S3
inner_time_ = &velodyne::INNER_TIME_64E_S3;
is_s2_ = false;
}
if (config_.mode() == LAST) {
mode_ = LAST;
} else if (config_.mode() == DUAL) {
mode_ = DUAL;
}
}
void Velodyne64Parser::setup() {
VelodyneParser::setup();
if (!config_.calibration_online() && config_.organized()) {
InitOffsets();
}
}
void Velodyne64Parser::SetBaseTimeFromPackets(const VelodynePacket& pkt) {
// const RawPacket* raw = (const RawPacket*)&pkt.data[0];
const RawPacket* raw = (const RawPacket*)pkt.data().c_str();
StatusType status_type = StatusType(raw->status_type);
char status_value = raw->status_value;
static int year = -1, month = -1, day = -1, hour = -1, minute = -1,
second = -1;
static int gps_status = 0;
static tm time;
switch (status_type) {
case YEAR:
year = status_value + 2000;
break;
case MONTH:
month = status_value;
break;
case DATE:
day = status_value;
break;
case HOURS:
hour = status_value;
break;
case MINUTES:
minute = status_value;
break;
case SECONDS:
second = status_value;
break;
case GPS_STATUS:
gps_status = status_value;
break;
default:
break;
}
AINFO << "Get base time from packets. Obtained (" << year << "." << month
<< "." << day << " " << hour << ":" << minute << ":" << second;
if (status_type == GPS_STATUS && year > 0 && month > 0 && day > 0 &&
hour >= 0 && minute >= 0 && second >= 0) {
if (gps_status != 65) {
AWARN << "Sync failed because Velodyne-GPS Sync is NOT good! "
<< "Status: " << static_cast<int>(gps_status)
<< " (65 = both; 86 = gps only; 80 = PPS only; 0 "
<< "= GPS not connected)";
}
time.tm_year = year - 1900;
time.tm_mon = month - 1;
time.tm_mday = day;
time.tm_hour = hour;
time.tm_min = 0;
time.tm_sec = 0;
// AINFO << "Set base unix time: (%d.%d.%d %d:%d:%d)", time.tm_year,
// time.tm_mon, time.tm_mday, time.tm_hour, time.tm_min, time.tm_sec;
uint64_t unix_base = static_cast<uint64_t>(timegm(&time));
for (int i = 0; i < 4; ++i) {
gps_base_usec_[i] = unix_base * 1000000;
}
}
}
void Velodyne64Parser::CheckGpsStatus(const VelodynePacket& pkt) {
// const RawPacket* raw = (const RawPacket*)&pkt.data[0];
const RawPacket* raw = (const RawPacket*)pkt.data().c_str();
StatusType status_type = StatusType(raw->status_type);
char status_value = raw->status_value;
if (status_type == StatusType::GPS_STATUS) {
if (status_value != 65) {
AWARN << "Sync failed because Velodyne-GPS Sync is NOT good! "
<< "Status: " << static_cast<int>(status_value)
<< " (65 = both; 86 = gps only; 80 = PPS only; "
<< "0 = GPS not connected)";
}
}
}
void Velodyne64Parser::InitOffsets() {
int width = 64;
// pre compute col offsets
for (int i = 0; i < width; ++i) {
int col = velodyne::ORDER_64[i];
// compute offset, NOTICE: std::map doesn't have const [] since [] may
// insert new values into map
const LaserCorrection& corrections = calibration_.laser_corrections_[col];
int offset =
static_cast<int>(corrections.rot_correction / ANGULAR_RESOLUTION + 0.5);
offsets_[i] = offset;
}
}
void Velodyne64Parser::GeneratePointcloud(
const std::shared_ptr<VelodyneScan>& scan_msg,
std::shared_ptr<PointCloud> pointcloud) {
if (config_.calibration_online() && !calibration_.initialized_) {
if (online_calibration_.decode(scan_msg) == -1) {
return;
}
calibration_ = online_calibration_.calibration();
if (config_.organized()) {
InitOffsets();
}
}
// allocate a point cloud with same time and frame ID as raw data
pointcloud->mutable_header()->set_frame_id(scan_msg->header().frame_id());
pointcloud->set_height(1);
pointcloud->mutable_header()->set_sequence_num(
scan_msg->header().sequence_num());
bool skip = false;
size_t packets_size = scan_msg->firing_pkts_size();
for (size_t i = 0; i < packets_size; ++i) {
if (gps_base_usec_[0] == 0) {
// only set one time type when call this function, so cannot break
SetBaseTimeFromPackets(scan_msg->firing_pkts(static_cast<int>(i)));
// If base time not ready then set empty_unpack true
skip = true;
} else {
CheckGpsStatus(scan_msg->firing_pkts(static_cast<int>(i)));
Unpack(scan_msg->firing_pkts(static_cast<int>(i)), pointcloud);
last_time_stamp_ = pointcloud->measurement_time();
ADEBUG << "stamp: " << std::fixed << last_time_stamp_;
}
}
if (skip) {
pointcloud->Clear();
} else {
int size = pointcloud->point_size();
if (size == 0) {
// we discard this pointcloud if empty
AERROR << "All points is NAN! Please check velodyne:" << config_.model();
} else {
uint64_t timestamp = pointcloud->point(size - 1).timestamp();
pointcloud->set_measurement_time(static_cast<double>(timestamp) / 1e9);
pointcloud->mutable_header()->set_lidar_timestamp(timestamp);
}
pointcloud->set_width(pointcloud->point_size());
}
}
uint64_t Velodyne64Parser::GetTimestamp(double base_time, float time_offset,
uint16_t block_id) {
double t = base_time - time_offset;
double timestamp = 0.0;
int index = 0;
if (is_s2_) {
index = block_id & 1; // % 2
double& previous_packet_stamp = previous_packet_stamp_[index];
uint64_t& gps_base_usec = gps_base_usec_[index];
timestamp = static_cast<double>(
GetGpsStamp(t, &previous_packet_stamp, &gps_base_usec));
} else { // 64E_S3
index = block_id & 3; // % 4
double& previous_packet_stamp = previous_packet_stamp_[index];
uint64_t& gps_base_usec = gps_base_usec_[index];
timestamp = static_cast<double>(
GetGpsStamp(t, &previous_packet_stamp, &gps_base_usec));
}
return static_cast<uint64_t>(timestamp);
}
int Velodyne64Parser::IntensityCompensate(const LaserCorrection& corrections,
const uint16_t raw_distance,
int intensity) {
float tmp = 1.0f - static_cast<float>(raw_distance) / 65535.0f;
intensity +=
static_cast<int>(corrections.focal_slope *
(fabs(corrections.focal_offset - 256 * tmp * tmp)));
if (intensity < corrections.min_intensity) {
intensity = corrections.min_intensity;
}
if (intensity > corrections.max_intensity) {
intensity = corrections.max_intensity;
}
return intensity;
}
void Velodyne64Parser::Unpack(const VelodynePacket& pkt,
std::shared_ptr<PointCloud> pc) {
ADEBUG << "Received packet, time: " << pkt.stamp();
// const RawPacket* raw = (const RawPacket*)&pkt.data[0];
const RawPacket* raw = (const RawPacket*)pkt.data().c_str();
double basetime = raw->gps_timestamp; // usec
for (int i = 0; i < BLOCKS_PER_PACKET; ++i) { // 12
if (mode_ != DUAL && !is_s2_ && ((i & 3) >> 1) > 0) {
// i%4/2 even-numbered block contain duplicate data
continue;
}
// upper bank lasers are numbered [0..31], lower bank lasers are [32..63]
// NOTE: this is a change from the old velodyne_common implementation
int bank_origin = (raw->blocks[i].laser_block_id == LOWER_BANK) ? 32 : 0;
for (int j = 0, k = 0; j < SCANS_PER_BLOCK;
++j, k += RAW_SCAN_SIZE) { // 32, 3
// One point
uint8_t laser_number =
static_cast<uint8_t>(j + bank_origin); // hardware laser number
LaserCorrection& corrections =
calibration_.laser_corrections_[laser_number];
union RawDistance raw_distance;
raw_distance.bytes[0] = raw->blocks[i].data[k];
raw_distance.bytes[1] = raw->blocks[i].data[k + 1];
// compute time
uint64_t timestamp = GetTimestamp(basetime, (*inner_time_)[i][j],
static_cast<uint16_t>(i));
if (j == SCANS_PER_BLOCK - 1) {
// set header stamp before organize the point cloud
pc->set_measurement_time(static_cast<double>(timestamp) / 1e9);
}
float real_distance = raw_distance.raw_distance * DISTANCE_RESOLUTION;
float distance = real_distance + corrections.dist_correction;
if (raw_distance.raw_distance == 0 ||
!is_scan_valid(raw->blocks[i].rotation, distance)) {
// if organized append a nan point to the cloud
if (config_.organized()) {
apollo::drivers::PointXYZIT* point_new = pc->add_point();
point_new->set_x(nan);
point_new->set_y(nan);
point_new->set_z(nan);
point_new->set_timestamp(timestamp);
point_new->set_intensity(0);
}
continue;
}
apollo::drivers::PointXYZIT* point = pc->add_point();
point->set_timestamp(timestamp);
// Position Calculation, append this point to the cloud
ComputeCoords(real_distance, corrections, raw->blocks[i].rotation, point);
point->set_intensity(IntensityCompensate(
corrections, raw_distance.raw_distance, raw->blocks[i].data[k + 2]));
// append this point to the cloud
}
}
}
void Velodyne64Parser::Order(std::shared_ptr<PointCloud> cloud) {
int height = 64;
cloud->set_height(height);
int width = cloud->point_size() / cloud->height();
cloud->set_width(width);
std::shared_ptr<PointCloud> cloud_origin = std::make_shared<PointCloud>();
cloud_origin->CopyFrom(*cloud);
for (int i = 0; i < height; ++i) {
int col = velodyne::ORDER_64[i];
for (int j = 0; j < width; ++j) {
// make sure offset is initialized, should be init at setup() just once
int row = (j + offsets_[i] + width) % width;
int target_index = j * height + i;
int origin_index = row * height + col;
cloud->mutable_point(target_index)
->CopyFrom(cloud_origin->point(origin_index));
}
}
}
} // namespace velodyne
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/parser/velodyne_parser.h
|
/******************************************************************************
* Copyright 2017 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
/* -*- mode: C++ -*-
*
* Copyright (C) 2007 Austin Robot Technology, Yaxin Liu, Patrick Beeson
* Copyright (C) 2009 Austin Robot Technology, Jack O'Quin
*
* License: Modified BSD Software License Agreement
*
* $Id$
*/
/** \file
*
* Velodyne HDL-64E 3D LIDAR data accessors
*
* \ingroup velodyne
*
* These classes Unpack raw Velodyne LIDAR packets into several
* useful formats.
*
* velodyne::Data -- virtual base class for unpacking data into
* various formats
*
* velodyne::DataScans -- derived class, unpacks into vector of
* individual laser scans
*
* velodyne::DataXYZ -- derived class, unpacks into XYZ format
*
* \todo make a separate header for each class?
*
* \author Yaxin Liu
* \author Patrick Beeson
* \author Jack O'Quin
*/
#pragma once
#include <cerrno>
#include <cmath>
#include <cstdint>
#include <limits>
#include <memory>
#include <string>
#include <boost/format.hpp>
#include "modules/drivers/lidar/proto/velodyne.pb.h"
#include "modules/drivers/lidar/proto/velodyne_config.pb.h"
#include "modules/common_msgs/sensor_msgs/pointcloud.pb.h"
#include "modules/drivers/lidar/velodyne/parser/calibration.h"
#include "modules/drivers/lidar/velodyne/parser/const_variables.h"
#include "modules/drivers/lidar/velodyne/parser/online_calibration.h"
namespace apollo {
namespace drivers {
namespace velodyne {
using apollo::drivers::PointCloud;
using apollo::drivers::PointXYZIT;
using apollo::drivers::velodyne::DUAL;
using apollo::drivers::velodyne::HDL32E;
using apollo::drivers::velodyne::HDL64E_S2;
using apollo::drivers::velodyne::HDL64E_S3D;
using apollo::drivers::velodyne::HDL64E_S3S;
using apollo::drivers::velodyne::LAST;
using apollo::drivers::velodyne::STRONGEST;
using apollo::drivers::velodyne::VelodynePacket;
using apollo::drivers::velodyne::VelodyneScan;
using apollo::drivers::velodyne::VLP16;
using apollo::drivers::velodyne::VLP32C;
using apollo::drivers::velodyne::VLS128;
/**
* Raw Velodyne packet constants and structures.
*/
static const int BLOCK_SIZE = 100;
static const int RAW_SCAN_SIZE = 3;
static const int SCANS_PER_BLOCK = 32;
static const int BLOCK_DATA_SIZE = (SCANS_PER_BLOCK * RAW_SCAN_SIZE);
static const float ROTATION_RESOLUTION = 0.01f; /**< degrees */
// static const uint16_t ROTATION_MAX_UNITS = 36000; [>*< hundredths of degrees
// <]
// because angle_rang is [0, 36000], so the size is 36001
static const uint16_t ROTATION_MAX_UNITS = 36001; /**< hundredths of degrees */
/** According to Bruce Hall DISTANCE_MAX is 65.0, but we noticed
* valid packets with readings up to 130.0. */
static const float DISTANCE_MAX = 130.0f; /**< meters */
static const float DISTANCE_RESOLUTION = 0.002f; /**< meters */
static const float DISTANCE_MAX_UNITS =
(DISTANCE_MAX / DISTANCE_RESOLUTION + 1.0f);
// laser_block_id
static const uint16_t UPPER_BANK = 0xeeff;
static const uint16_t LOWER_BANK = 0xddff;
static const float ANGULAR_RESOLUTION = 0.00300919f;
/** Special Defines for VLP16 support **/
static const int VLP16_FIRINGS_PER_BLOCK = 2;
static const int VLP16_SCANS_PER_FIRING = 16;
static const float VLP16_BLOCK_TDURATION = 110.592f;
static const float VLP16_DSR_TOFFSET = 2.304f;
static const float VLP16_FIRING_TOFFSET = 55.296f;
static const float VLS128_CHANNEL_TDURATION = 2.304f;
static const float VLS128_SEQ_TDURATION = 55.296f;
static const float VLP32_DISTANCE_RESOLUTION = 0.004f;
static const float VSL128_DISTANCE_RESOLUTION = 0.004f;
static const float CHANNEL_TDURATION = 2.304f;
static const float SEQ_TDURATION = 55.296f;
/** \brief Raw Velodyne data block.
*
* Each block contains data from either the upper or lower laser
* bank. The device returns three times as many upper bank blocks.
*
* use cstdint types, so things work with both 64 and 32-bit machines
*/
struct RawBlock {
uint16_t laser_block_id; ///< UPPER_BANK or LOWER_BANK
uint16_t rotation; ///< 0-35999, divide by 100 to get degrees
uint8_t data[BLOCK_DATA_SIZE];
};
/** used for unpacking the first two data bytes in a block
*
* They are packed into the actual data stream misaligned. I doubt
* this works on big endian machines.
*/
union RawDistance {
uint16_t raw_distance;
uint8_t bytes[2];
};
static const int PACKET_SIZE = 1206;
static const int BLOCKS_PER_PACKET = 12;
static const int PACKET_STATUS_SIZE = 4;
static const int SCANS_PER_PACKET = (SCANS_PER_BLOCK * BLOCKS_PER_PACKET);
enum StatusType {
HOURS = 72,
MINUTES = 77,
SECONDS = 83,
DATE = 68,
MONTH = 78,
YEAR = 89,
GPS_STATUS = 71
};
/** \brief Raw Velodyne packet.
*
* revolution is described in the device manual as incrementing
* (mod 65536) for each physical turn of the device. Our device
* seems to alternate between two different values every third
* packet. One value increases, the other decreases.
*
* status has either a temperature encoding or the microcode level
*/
struct RawPacket {
RawBlock blocks[BLOCKS_PER_PACKET];
// uint16_t revolution;
// uint8_t status[PACKET_STATUS_SIZE];
unsigned int gps_timestamp;
unsigned char status_type;
unsigned char status_value;
};
/** Special Definition for VLS128 support **/
// static const int VLS128_NUM_CHANS_PER_BLOCK = 128;
// static const int VLS128_BLOCK_DATA_SIZE = VLS128_NUM_CHANS_PER_BLOCK *
// RAW_SCAN_SIZE;
//
// struct Vls128RawBlock {
// uint16_t header;
// uint16_t rotation;
// uint8_t data[VLS128_BLOCK_DATA_SIZE];
// };
//
// struct Vls128RawPacket {
// Vls128RawBlock blocks[3];
// uint16_t revolution;
// uint8_t status[PACKET_STATUS_SIZE];
// };
// Convert related config, get value from private_nh param server, used by
// velodyne raw data
// struct Config {
// double max_range; ///< maximum range to publish
// double min_range; ///< minimum range to publish
// double max_angle;
// double min_angle;
// double view_direction;
// double view_width;
// bool calibration_online;
// std::string calibration_file;
// std::string model; // VLP16,32E, 64E_32
// bool organized; // is point cloud Order
//};
// enum Mode { STRONGEST, LAST, DUAL };
static const float nan = std::numeric_limits<float>::signaling_NaN();
/** \brief Velodyne data conversion class */
class VelodyneParser {
public:
VelodyneParser() {}
explicit VelodyneParser(const Config& config);
virtual ~VelodyneParser() {}
/** \brief Set up for data processing.
*
* Perform initializations needed before data processing can
* begin:
*
* - read device-specific angles calibration
*
* @param private_nh private node handle for ROS parameters
* @returns 0 if successful;
* errno value for failure
*/
virtual void GeneratePointcloud(const std::shared_ptr<VelodyneScan>& scan_msg,
std::shared_ptr<PointCloud> out_msg) = 0;
virtual void setup();
// Order point cloud fod IDL by velodyne model
virtual void Order(std::shared_ptr<PointCloud> cloud) = 0;
const Calibration& get_calibration() { return calibration_; }
const double get_last_timestamp() { return last_time_stamp_; }
protected:
const float (*inner_time_)[12][32];
Calibration calibration_;
float sin_rot_table_[ROTATION_MAX_UNITS];
float cos_rot_table_[ROTATION_MAX_UNITS];
double last_time_stamp_;
Config config_;
// Last Velodyne packet time stamp. (Full time)
bool need_two_pt_correction_;
Mode mode_;
PointXYZIT get_nan_point(uint64_t timestamp);
void init_angle_params(double view_direction, double view_width);
/**
* \brief Compute coords with the data in block
*
* @param tmp A two bytes union store the value of laser distance information
* @param index The index of block
*/
void ComputeCoords(const float& raw_distance,
const LaserCorrection& corrections,
const uint16_t rotation, PointXYZIT* point);
bool is_scan_valid(int rotation, float distance);
/**
* \brief Unpack velodyne packet
*
*/
virtual void Unpack(const VelodynePacket& pkt,
std::shared_ptr<PointCloud> pc) = 0;
uint64_t GetGpsStamp(double current_stamp, double* previous_stamp,
uint64_t* gps_base_usec);
virtual uint64_t GetTimestamp(double base_time, float time_offset,
uint16_t laser_block_id) = 0;
}; // class VelodyneParser
class Velodyne64Parser : public VelodyneParser {
public:
explicit Velodyne64Parser(const Config& config);
~Velodyne64Parser() {}
void GeneratePointcloud(const std::shared_ptr<VelodyneScan>& scan_msg,
std::shared_ptr<PointCloud> out_msg);
void Order(std::shared_ptr<PointCloud> cloud);
void setup() override;
private:
void SetBaseTimeFromPackets(const VelodynePacket& pkt);
void CheckGpsStatus(const VelodynePacket& pkt);
uint64_t GetTimestamp(double base_time, float time_offset,
uint16_t laser_block_id);
void Unpack(const VelodynePacket& pkt, std::shared_ptr<PointCloud> pc);
void InitOffsets();
int IntensityCompensate(const LaserCorrection& corrections,
const uint16_t raw_distance, int intensity);
// Previous Velodyne packet time stamp. (offset to the top hour)
double previous_packet_stamp_[4];
uint64_t gps_base_usec_[4]; // full time
bool is_s2_;
int offsets_[64];
OnlineCalibration online_calibration_;
}; // class Velodyne64Parser
class Velodyne32Parser : public VelodyneParser {
public:
explicit Velodyne32Parser(const Config& config);
~Velodyne32Parser() {}
void GeneratePointcloud(const std::shared_ptr<VelodyneScan>& scan_msg,
std::shared_ptr<PointCloud> out_msg);
void Order(std::shared_ptr<PointCloud> cloud);
private:
uint64_t GetTimestamp(double base_time, float time_offset,
uint16_t laser_block_id);
void Unpack(const VelodynePacket& pkt, std::shared_ptr<PointCloud> pc);
void UnpackVLP32C(const VelodynePacket& pkt, std::shared_ptr<PointCloud> pc);
// Previous laser firing time stamp. (offset to the top hour)
double previous_firing_stamp_;
uint64_t gps_base_usec_; // full time
}; // class Velodyne32Parser
class Velodyne16Parser : public VelodyneParser {
public:
explicit Velodyne16Parser(const Config& config);
~Velodyne16Parser() {}
void GeneratePointcloud(const std::shared_ptr<VelodyneScan>& scan_msg,
std::shared_ptr<PointCloud> out_msg);
void Order(std::shared_ptr<PointCloud> cloud);
private:
uint64_t GetTimestamp(double base_time, float time_offset,
uint16_t laser_block_id);
void Unpack(const VelodynePacket& pkt, std::shared_ptr<PointCloud> pc);
// Previous Velodyne packet time stamp. (offset to the top hour)
double previous_packet_stamp_;
uint64_t gps_base_usec_; // full time
}; // class Velodyne16Parser
class Velodyne128Parser : public VelodyneParser {
public:
explicit Velodyne128Parser(const Config& config);
~Velodyne128Parser() {}
void GeneratePointcloud(const std::shared_ptr<VelodyneScan>& scan_msg,
std::shared_ptr<PointCloud> out_msg);
void Order(std::shared_ptr<PointCloud> cloud);
private:
uint64_t GetTimestamp(double base_time, float time_offset,
uint16_t laser_block_id);
void Unpack(const VelodynePacket& pkt, std::shared_ptr<PointCloud> pc);
int IntensityCompensate(const LaserCorrection& corrections,
const uint16_t raw_distance, int intensity);
// Previous Velodyne packet time stamp. (offset to the top hour)
double previous_packet_stamp_;
uint64_t gps_base_usec_; // full time
}; // class Velodyne128Parser
class VelodyneParserFactory {
public:
static VelodyneParser* CreateParser(Config config);
};
} // namespace velodyne
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/parser/online_calibration.h
|
/******************************************************************************
* Copyright 2017 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#pragma once
#include <memory>
#include <string>
#include <vector>
#include "modules/drivers/lidar/proto/velodyne.pb.h"
#include "cyber/cyber.h"
#include "modules/drivers/lidar/velodyne/parser/calibration.h"
namespace apollo {
namespace drivers {
namespace velodyne {
using apollo::drivers::velodyne::VelodynePacket;
using apollo::drivers::velodyne::VelodyneScan;
constexpr double DEGRESS_TO_RADIANS = 3.1415926535897 / 180.0;
class OnlineCalibration {
public:
OnlineCalibration() {}
~OnlineCalibration() {}
int decode(const std::shared_ptr<VelodyneScan>& scan_msgs);
void dump(const std::string& file_path);
void get_unit_index();
bool inited() const { return inited_; }
Calibration calibration() const { return calibration_; }
private:
bool inited_;
Calibration calibration_;
std::vector<uint8_t> status_types_;
std::vector<uint8_t> status_values_;
// store first two "unit#" value index
std::vector<int> unit_indexs_;
};
} // namespace velodyne
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/parser/velodyne32_parser.cc
|
/******************************************************************************
* Copyright 2018 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/drivers/lidar/velodyne/parser/velodyne_parser.h"
namespace apollo {
namespace drivers {
namespace velodyne {
Velodyne32Parser::Velodyne32Parser(const Config& config)
: VelodyneParser(config), previous_firing_stamp_(0), gps_base_usec_(0) {
inner_time_ = &velodyne::INNER_TIME_HDL32E;
need_two_pt_correction_ = false;
if (config_.model() == VLP32C) {
inner_time_ = &velodyne::INNER_TIME_VLP32C;
}
}
void Velodyne32Parser::GeneratePointcloud(
const std::shared_ptr<VelodyneScan>& scan_msg,
std::shared_ptr<PointCloud> out_msg) {
// allocate a point cloud with same time and frame ID as raw data
out_msg->mutable_header()->set_frame_id(scan_msg->header().frame_id());
out_msg->set_height(1);
out_msg->mutable_header()->set_sequence_num(
scan_msg->header().sequence_num());
gps_base_usec_ = scan_msg->basetime();
size_t packets_size = scan_msg->firing_pkts_size();
if (config_.model() == VLP32C) {
for (size_t i = 0; i < packets_size; ++i) {
UnpackVLP32C(scan_msg->firing_pkts(static_cast<int>(i)), out_msg);
}
} else {
for (size_t i = 0; i < packets_size; ++i) {
Unpack(scan_msg->firing_pkts(static_cast<int>(i)), out_msg);
}
}
// set measurement and lidar_timestampe
int size = out_msg->point_size();
if (size == 0) {
// we discard this pointcloud if empty
AERROR << "All points is NAN!Please check velodyne:" << config_.model();
} else {
// take the last point's timestamp as the whole frame's measurement time.
uint64_t timestamp = out_msg->point(size - 1).timestamp();
out_msg->set_measurement_time(static_cast<double>(timestamp) / 1e9);
out_msg->mutable_header()->set_lidar_timestamp(timestamp);
}
// set default width
out_msg->set_width(out_msg->point_size());
last_time_stamp_ = out_msg->measurement_time();
}
uint64_t Velodyne32Parser::GetTimestamp(double base_time, float time_offset,
uint16_t block_id) {
double t = base_time - time_offset;
if (config_.model() == VLP32C) {
t = base_time + time_offset;
}
// Now t is the exact laser firing time for a specific data point.
if (t < previous_firing_stamp_) {
// plus 3600 when large jump back, discard little jump back for wrong time
// in lidar
if (std::abs(previous_firing_stamp_ - t) > 3599000000) {
gps_base_usec_ += static_cast<uint64_t>(3600 * 1e6);
AINFO << "Base time plus 3600s. Model: " << config_.model() << std::fixed
<< ". current:" << t << ", last time:" << previous_firing_stamp_;
} else if (config_.model() != VLP32C ||
(previous_firing_stamp_ - t > 34.560f) ||
(previous_firing_stamp_ - t < 34.559f)) {
AWARN << "Current stamp:" << std::fixed << t
<< " less than previous stamp:" << previous_firing_stamp_
<< ". GPS time stamp maybe incorrect!";
}
} else if (previous_firing_stamp_ != 0 &&
t - previous_firing_stamp_ > 100000) { // 100ms
AERROR << "Current stamp:" << std::fixed << t
<< " ahead previous stamp:" << previous_firing_stamp_
<< " over 100ms. GPS time stamp incorrect!";
}
previous_firing_stamp_ = t;
// in nano seconds
uint64_t gps_stamp = gps_base_usec_ * 1000 + static_cast<uint64_t>(t * 1000);
return gps_stamp;
}
void Velodyne32Parser::UnpackVLP32C(const VelodynePacket& pkt,
std::shared_ptr<PointCloud> pc) {
const RawPacket* raw = (const RawPacket*)pkt.data().c_str();
// This is the packet timestamp which marks the moment of the first data point
// in the first firing sequence of the first data block. The time stamp’s
// value is the number of microseconds elapsed since the top of the hour. The
// number ranges from 0 to 3,599,999,999, the number of microseconds in one
// hour (Sec. 9.3.1.6 in VLP-32C User Manual).
double basetime = static_cast<double>(raw->gps_timestamp); // usec
float azimuth = 0.0f;
float azimuth_diff = 0.0f;
float last_azimuth_diff = 0.0f;
float azimuth_corrected_f = 0.0f;
int azimuth_corrected = 0;
for (int i = 0; i < BLOCKS_PER_PACKET; i++) { // 12
azimuth = static_cast<float>(raw->blocks[i].rotation);
if (i < (BLOCKS_PER_PACKET - 1)) {
azimuth_diff = static_cast<float>(
(36000 + raw->blocks[i + 1].rotation - raw->blocks[i].rotation) %
36000);
last_azimuth_diff = azimuth_diff;
} else {
azimuth_diff = last_azimuth_diff;
}
for (int laser_id = 0, k = 0; laser_id < SCANS_PER_BLOCK;
++laser_id, k += RAW_SCAN_SIZE) { // 32, 3
LaserCorrection& corrections = calibration_.laser_corrections_[laser_id];
union RawDistance raw_distance;
raw_distance.bytes[0] = raw->blocks[i].data[k];
raw_distance.bytes[1] = raw->blocks[i].data[k + 1];
// compute the actual timestamp associated with the data point at data
// block i and laser_id
uint64_t timestamp = GetTimestamp(basetime, (*inner_time_)[i][laser_id],
static_cast<uint16_t>(i));
azimuth_corrected_f =
azimuth + (azimuth_diff * (static_cast<float>(laser_id) / 2.0f) *
CHANNEL_TDURATION / SEQ_TDURATION);
azimuth_corrected =
static_cast<int>(round(fmod(azimuth_corrected_f, 36000.0)));
float real_distance =
raw_distance.raw_distance * VLP32_DISTANCE_RESOLUTION;
float distance = real_distance + corrections.dist_correction;
// AINFO << "raw_distance:" << raw_distance.raw_distance << ", distance:"
// << distance;
if (raw_distance.raw_distance == 0 ||
!is_scan_valid(azimuth_corrected, distance)) {
if (config_.organized()) {
apollo::drivers::PointXYZIT* point_new = pc->add_point();
point_new->set_x(nan);
point_new->set_y(nan);
point_new->set_z(nan);
point_new->set_timestamp(timestamp);
point_new->set_intensity(0);
}
continue;
}
apollo::drivers::PointXYZIT* point = pc->add_point();
point->set_timestamp(timestamp);
// Position Calculation, append this point to the cloud
ComputeCoords(real_distance, corrections,
static_cast<uint16_t>(azimuth_corrected), point);
point->set_intensity(raw->blocks[i].data[k + 2]);
}
}
}
void Velodyne32Parser::Unpack(const VelodynePacket& pkt,
std::shared_ptr<PointCloud> pc) {
// const RawPacket* raw = (const RawPacket*)&pkt.data[0];
const RawPacket* raw = (const RawPacket*)pkt.data().c_str();
double basetime = raw->gps_timestamp; // usec
for (int i = 0; i < BLOCKS_PER_PACKET; i++) { // 12
for (int laser_id = 0, k = 0; laser_id < SCANS_PER_BLOCK;
++laser_id, k += RAW_SCAN_SIZE) { // 32, 3
LaserCorrection& corrections = calibration_.laser_corrections_[laser_id];
union RawDistance raw_distance;
raw_distance.bytes[0] = raw->blocks[i].data[k];
raw_distance.bytes[1] = raw->blocks[i].data[k + 1];
// compute time
uint64_t timestamp = static_cast<uint64_t>(GetTimestamp(
basetime, (*inner_time_)[i][laser_id], static_cast<uint16_t>(i)));
int rotation = static_cast<int>(raw->blocks[i].rotation);
float real_distance = raw_distance.raw_distance * DISTANCE_RESOLUTION;
float distance = real_distance + corrections.dist_correction;
if (raw_distance.raw_distance == 0 ||
!is_scan_valid(rotation, distance)) {
// if organized append a nan point to the cloud
if (config_.organized()) {
apollo::drivers::PointXYZIT* point_new = pc->add_point();
point_new->set_x(nan);
point_new->set_y(nan);
point_new->set_z(nan);
point_new->set_timestamp(timestamp);
point_new->set_intensity(0);
}
continue;
}
apollo::drivers::PointXYZIT* point = pc->add_point();
point->set_timestamp(timestamp);
// Position Calculation, append this point to the cloud
ComputeCoords(real_distance, corrections, static_cast<uint16_t>(rotation),
point);
point->set_intensity(raw->blocks[i].data[k + 2]);
// append this point to the cloud
}
}
}
void Velodyne32Parser::Order(std::shared_ptr<PointCloud> cloud) {
if (config_.model() == VLP32C) {
return;
}
int width = 32;
cloud->set_width(width);
int height = cloud->point_size() / cloud->width();
cloud->set_height(height);
std::shared_ptr<PointCloud> cloud_origin = std::make_shared<PointCloud>();
cloud_origin->CopyFrom(*cloud);
for (int i = 0; i < width; ++i) {
int col = velodyne::ORDER_HDL32E[i];
for (int j = 0; j < height; ++j) {
// make sure offset is initialized, should be init at setup() just once
int target_index = j * width + i;
int origin_index = j * width + col;
cloud->mutable_point(target_index)
->CopyFrom(cloud_origin->point(origin_index));
}
}
}
} // namespace velodyne
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/parser/online_calibration.cc
|
/******************************************************************************
* Copyright 2017 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/drivers/lidar/velodyne/parser/online_calibration.h"
namespace apollo {
namespace drivers {
namespace velodyne {
using apollo::drivers::velodyne::VelodynePacket;
using apollo::drivers::velodyne::VelodyneScan;
int OnlineCalibration::decode(const std::shared_ptr<VelodyneScan>& scan_msgs) {
if (inited_) {
return 0;
}
for (auto& packet : scan_msgs->firing_pkts()) {
if (packet.data().size() < 1206) {
AERROR << "Ivalid packet data size, expect 1206, actually "
<< packet.data().size();
return -1;
}
uint8_t* data =
reinterpret_cast<uint8_t*>(const_cast<char*>(packet.data().c_str()));
status_types_.emplace_back(data[1204]);
status_values_.emplace_back(data[1205]);
}
// read calibration when get 2s packet
if (status_types_.size() < 5789 * 2) {
AINFO << "Wait for more scan msgs";
return -1;
}
get_unit_index();
int unit_size = static_cast<int>(unit_indexs_.size());
if (unit_size < 2) {
// can not find two unit# index, may be lost packet
AINFO << "unit count less than 2, maybe lost packets";
return -1;
}
if (unit_indexs_[unit_size - 1] - unit_indexs_[unit_size - 2] !=
65 * 64) { // 64 lasers
// lost packet
AERROR << "two unit distance is wrong";
return -1;
}
int start_index = unit_indexs_[unit_size - 2];
for (int i = 0; i < 64; ++i) {
LaserCorrection laser_correction;
int index_16 = start_index + i * 64 + 16;
int index_32 = start_index + i * 64 + 32;
int index_48 = start_index + i * 64 + 48;
laser_correction.laser_ring = status_values_[index_16];
laser_correction.vert_correction =
*reinterpret_cast<int16_t*>(&status_values_[index_16 + 1]) / 100.0f *
static_cast<float>(DEGRESS_TO_RADIANS);
laser_correction.rot_correction =
*reinterpret_cast<int16_t*>(&status_values_[index_16 + 3]) / 100.0f *
static_cast<float>(DEGRESS_TO_RADIANS);
laser_correction.dist_correction =
*reinterpret_cast<int16_t*>(&status_values_[index_16 + 5]) / 10.0f /
100.0f; // to meter
laser_correction.dist_correction_x =
*reinterpret_cast<int16_t*>(&status_values_[index_32]) / 10.0f /
100.0f; // to meter
laser_correction.dist_correction_y =
*reinterpret_cast<int16_t*>(&status_values_[index_32 + 2]) / 10.0f /
100.0f; // to meter
laser_correction.vert_offset_correction =
*reinterpret_cast<int16_t*>(&status_values_[index_32 + 4]) / 10.0f /
100.0f; // to meter
laser_correction.horiz_offset_correction =
static_cast<int16_t>(static_cast<int16_t>(status_values_[index_48])
<< 8 |
status_values_[index_32 + 6]) /
10.0f / 100.0f; // to meter
laser_correction.focal_distance =
*reinterpret_cast<int16_t*>(&status_values_[index_48 + 1]) / 10.0f /
100.0f; // to meter
laser_correction.focal_slope =
*reinterpret_cast<int16_t*>(&status_values_[index_48 + 3]) /
10.0f; // to meter
laser_correction.max_intensity = status_values_[index_48 + 6];
laser_correction.min_intensity = status_values_[index_48 + 5];
laser_correction.cos_rot_correction = cosf(laser_correction.rot_correction);
laser_correction.sin_rot_correction = sinf(laser_correction.rot_correction);
laser_correction.cos_vert_correction =
cosf(laser_correction.vert_correction);
laser_correction.sin_vert_correction =
sinf(laser_correction.vert_correction);
laser_correction.focal_offset =
256.0f * static_cast<float>(
std::pow(1 - laser_correction.focal_distance / 13100, 2));
calibration_.laser_corrections_[laser_correction.laser_ring] =
laser_correction;
}
calibration_.num_lasers_ = 64;
calibration_.initialized_ = true;
inited_ = true;
return 0;
}
void OnlineCalibration::get_unit_index() {
int size = static_cast<int>(status_values_.size());
// simple check only for value, maybe need more check fro status type
int start_index = 0;
if (unit_indexs_.size() > 0) {
start_index = unit_indexs_.back() + 5;
}
for (; start_index < size - 5; ++start_index) {
if (status_values_[start_index] == 85 // "U"
&& status_values_[start_index + 1] == 78 // "N"
&& status_values_[start_index + 2] == 73 // "I"
&& status_values_[start_index + 3] == 84 // "T"
&& status_values_[start_index + 4] == 35) { // "#"
unit_indexs_.emplace_back(start_index);
}
}
}
void OnlineCalibration::dump(const std::string& file_path) {
if (!inited_) {
AERROR << "Please decode calibraion info first";
return;
}
std::ofstream ofs(file_path.c_str(), std::ios::out);
ofs << "lasers:" << std::endl;
for (auto& correction : calibration_.laser_corrections_) {
ofs << "- {";
ofs << "dist_correction: " << correction.second.dist_correction << ", ";
ofs << "dist_correction_x: " << correction.second.dist_correction_x << ", ";
ofs << "dist_correction_y: " << correction.second.dist_correction_y << ", ";
ofs << "focal_distance: " << correction.second.focal_distance << ", ";
ofs << "focal_slope: " << correction.second.focal_slope << ", ";
ofs << "horiz_offset_correction: "
<< correction.second.horiz_offset_correction << ", ";
ofs << "laser_id: " << correction.second.laser_ring << ", ";
ofs << "max_intensity: " << correction.second.max_intensity << ", ";
ofs << "min_intensity: " << correction.second.min_intensity << ", ";
ofs << "rot_correction: " << correction.second.rot_correction << ", ";
ofs << "vert_correction: " << correction.second.vert_correction << ", ";
ofs << "vert_offset_correction: "
<< correction.second.vert_offset_correction;
ofs << "}" << std::endl;
}
ofs << "num_lasers: " << calibration_.num_lasers_ << std::endl;
ofs.close();
}
} // namespace velodyne
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/parser/convert.cc
|
/******************************************************************************
* Copyright 2017 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/drivers/lidar/velodyne/parser/convert.h"
namespace apollo {
namespace drivers {
namespace velodyne {
using apollo::drivers::PointCloud;
using apollo::drivers::velodyne::VelodyneScan;
void Convert::init(const Config& velodyne_config) {
config_ = velodyne_config;
// we use Beijing time by default
parser_.reset(VelodyneParserFactory::CreateParser(config_));
if (parser_.get() == nullptr) {
AFATAL << "Create parser failed.";
return;
}
parser_->setup();
}
/** @brief Callback for raw scan messages. */
void Convert::ConvertPacketsToPointcloud(
const std::shared_ptr<VelodyneScan>& scan_msg,
std::shared_ptr<PointCloud> point_cloud) {
ADEBUG << "Convert scan msg seq " << scan_msg->header().sequence_num();
parser_->GeneratePointcloud(scan_msg, point_cloud);
if (point_cloud == nullptr || point_cloud->point().empty()) {
AERROR << "point cloud has no point";
return;
}
if (config_.organized()) {
parser_->Order(point_cloud);
point_cloud->set_is_dense(false);
} else {
point_cloud->set_is_dense(true);
}
}
} // namespace velodyne
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/parser/util.cc
|
/******************************************************************************
* Copyright 2017 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/drivers/lidar/velodyne/parser/util.h"
namespace apollo {
namespace drivers {
namespace velodyne {
void init_sin_cos_rot_table(float* sin_rot_table, float* cos_rot_table,
uint16_t rotation, float rotation_resolution) {
for (uint16_t i = 0; i < rotation; ++i) {
// float rotation = angles::from_degrees(rotation_resolution * i);
float rotation =
rotation_resolution * static_cast<float>(i * M_PI) / 180.0f;
cos_rot_table[i] = cosf(rotation);
sin_rot_table[i] = sinf(rotation);
}
}
} // namespace velodyne
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/parser/velodyne_parser.cc
|
/******************************************************************************
* Copyright 2017 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "cyber/cyber.h"
#include "modules/drivers/lidar/velodyne/parser/util.h"
#include "modules/drivers/lidar/velodyne/parser/velodyne_parser.h"
namespace apollo {
namespace drivers {
namespace velodyne {
uint64_t VelodyneParser::GetGpsStamp(double current_packet_stamp,
double *previous_packet_stamp,
uint64_t *gps_base_usec) {
if (current_packet_stamp < *previous_packet_stamp) {
// plus 3600 when large jump back, discard little jump back for wrong time
// in lidar
if (std::abs(*previous_packet_stamp - current_packet_stamp) > 3599000000) {
*gps_base_usec += static_cast<uint64_t>(3600 * 1e6);
AINFO << "Base time plus 3600s. Model: " << config_.model() << std::fixed
<< ". current:" << current_packet_stamp
<< ", last time:" << *previous_packet_stamp;
} else {
AWARN << "Current stamp:" << std::fixed << current_packet_stamp
<< " less than previous stamp:" << *previous_packet_stamp
<< ". GPS time stamp maybe incorrect!";
}
} else if (*previous_packet_stamp != 0 &&
current_packet_stamp - *previous_packet_stamp > 100000) { // 100ms
AERROR << "Current stamp:" << std::fixed << current_packet_stamp
<< " ahead previous stamp:" << *previous_packet_stamp
<< " over 100ms. GPS time stamp incorrect!";
}
*previous_packet_stamp = current_packet_stamp;
uint64_t gps_stamp =
*gps_base_usec + static_cast<uint64_t>(current_packet_stamp);
gps_stamp = gps_stamp * 1000;
return gps_stamp;
}
PointXYZIT VelodyneParser::get_nan_point(uint64_t timestamp) {
PointXYZIT nan_point;
nan_point.set_timestamp(timestamp);
nan_point.set_x(nan);
nan_point.set_y(nan);
nan_point.set_z(nan);
nan_point.set_intensity(0);
return nan_point;
}
VelodyneParser::VelodyneParser(const Config &config)
: last_time_stamp_(0), config_(config), mode_(STRONGEST) {}
void VelodyneParser::init_angle_params(double view_direction,
double view_width) {
// converting angle parameters into the velodyne reference (rad)
double tmp_min_angle = view_direction + view_width / 2;
double tmp_max_angle = view_direction - view_width / 2;
// computing positive modulo to keep theses angles into [0;2*M_PI]
tmp_min_angle = fmod(fmod(tmp_min_angle, 2 * M_PI) + 2 * M_PI, 2 * M_PI);
tmp_max_angle = fmod(fmod(tmp_max_angle, 2 * M_PI) + 2 * M_PI, 2 * M_PI);
// converting into the hardware velodyne ref (negative yaml and degrees)
// adding 0.5 performs a centered double to int conversion
config_.set_min_angle(100 * (2 * M_PI - tmp_min_angle) * 180 / M_PI + 0.5);
config_.set_max_angle(100 * (2 * M_PI - tmp_max_angle) * 180 / M_PI + 0.5);
if (config_.min_angle() == config_.max_angle()) {
// avoid returning empty cloud if min_angle = max_angle
config_.set_min_angle(0);
config_.set_max_angle(36000);
}
}
/** Set up for on-line operation. */
void VelodyneParser::setup() {
if (!config_.calibration_online()) {
calibration_.read(config_.calibration_file());
if (!calibration_.initialized_) {
AFATAL << "Unable to open calibration file: "
<< config_.calibration_file();
}
}
// setup angle parameters.
init_angle_params(config_.view_direction(), config_.view_width());
init_sin_cos_rot_table(sin_rot_table_, cos_rot_table_, ROTATION_MAX_UNITS,
ROTATION_RESOLUTION);
}
bool VelodyneParser::is_scan_valid(int rotation, float range) {
// check range first
if (range < config_.min_range() || range > config_.max_range()) {
return false;
}
// condition added to avoid calculating points which are not
// in the interesting defined area (min_angle < area < max_angle)
// not used now
// if ((config_.min_angle > config_.max_angle && (rotation <=
// config_.max_angle || rotation >= config_.min_angle))
// || (config_.min_angle < config_.max_angle && rotation >=
// config_.min_angle
// && rotation <= config_.max_angle)) {
// return true;
// }
return true;
}
void VelodyneParser::ComputeCoords(const float &raw_distance,
const LaserCorrection &corrections,
const uint16_t rotation, PointXYZIT *point) {
// ROS_ASSERT_MSG(rotation < 36000, "rotation must between 0 and 35999");
assert(rotation <= 36000);
double x = 0.0;
double y = 0.0;
double z = 0.0;
double distance = raw_distance + corrections.dist_correction;
// cos(a-b) = cos(a)*cos(b) + sin(a)*sin(b)
// sin(a-b) = sin(a)*cos(b) - cos(a)*sin(b)
double cos_rot_angle =
cos_rot_table_[rotation] * corrections.cos_rot_correction +
sin_rot_table_[rotation] * corrections.sin_rot_correction;
double sin_rot_angle =
sin_rot_table_[rotation] * corrections.cos_rot_correction -
cos_rot_table_[rotation] * corrections.sin_rot_correction;
// double vert_offset = corrections.vert_offset_correction;
// Compute the distance in the xy plane (w/o accounting for rotation)
double xy_distance = distance * corrections.cos_vert_correction;
// Calculate temporal X, use absolute value.
double xx = fabs(xy_distance * sin_rot_angle -
corrections.horiz_offset_correction * cos_rot_angle);
// Calculate temporal Y, use absolute value
double yy = fabs(xy_distance * cos_rot_angle +
corrections.horiz_offset_correction * sin_rot_angle);
// Get 2points calibration values,Linear interpolation to get distance
// correction for X and Y, that means distance correction use
// different value at different distance
double distance_corr_x = 0;
double distance_corr_y = 0;
if (need_two_pt_correction_ && raw_distance <= 2500) {
distance_corr_x =
(corrections.dist_correction - corrections.dist_correction_x) *
(xx - 2.4) / 22.64 +
corrections.dist_correction_x; // 22.64 = 25.04 - 2.4
distance_corr_y =
(corrections.dist_correction - corrections.dist_correction_y) *
(yy - 1.93) / 23.11 +
corrections.dist_correction_y; // 23.11 = 25.04 - 1.93
} else {
distance_corr_x = distance_corr_y = corrections.dist_correction;
}
double distance_x = raw_distance + distance_corr_x;
xy_distance = distance_x * corrections.cos_vert_correction;
// xy_distance = distance_x * cos_vert_correction - vert_offset *
// sin_vert_correction;
x = xy_distance * sin_rot_angle -
corrections.horiz_offset_correction * cos_rot_angle;
double distance_y = raw_distance + distance_corr_y;
xy_distance = distance_y * corrections.cos_vert_correction;
// xy_distance = distance_y * cos_vert_correction - vert_offset *
// sin_vert_correction;
y = xy_distance * cos_rot_angle +
corrections.horiz_offset_correction * sin_rot_angle;
z = distance * corrections.sin_vert_correction +
corrections.vert_offset_correction;
// z = distance * sin_vert_correction + vert_offset * cos_vert_correction;
/** Use standard ROS coordinate system (right-hand rule) */
point->set_x(static_cast<float>(y));
point->set_y(static_cast<float>(-x));
point->set_z(static_cast<float>(z));
}
VelodyneParser *VelodyneParserFactory::CreateParser(Config source_config) {
Config config = source_config;
if (config.model() == VLP16) {
config.set_calibration_online(false);
return new Velodyne16Parser(config);
} else if (config.model() == HDL32E || config.model() == VLP32C) {
config.set_calibration_online(false);
return new Velodyne32Parser(config);
} else if (config.model() == HDL64E_S3S || config.model() == HDL64E_S3D ||
config.model() == HDL64E_S2) {
return new Velodyne64Parser(config);
} else if (config.model() == VLS128) {
return new Velodyne128Parser(config);
} else {
AERROR << "invalid model, must be 64E_S2|64E_S3S"
<< "|64E_S3D_STRONGEST|64E_S3D_LAST|64E_S3D_DUAL|HDL32E|VLP16";
return nullptr;
}
}
} // namespace velodyne
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/parser/velodyne_convert_component.cc
|
/******************************************************************************
* Copyright 2017 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include <memory>
#include <string>
#include <thread>
#include "cyber/cyber.h"
#include "modules/drivers/lidar/velodyne/parser/velodyne_convert_component.h"
namespace apollo {
namespace drivers {
namespace velodyne {
bool VelodyneConvertComponent::Init() {
Config velodyne_config;
if (!GetProtoConfig(&velodyne_config)) {
AWARN << "Load config failed, config file" << config_file_path_;
return false;
}
conv_.reset(new Convert());
conv_->init(velodyne_config);
writer_ =
node_->CreateWriter<PointCloud>(velodyne_config.convert_channel_name());
point_cloud_pool_.reset(new CCObjectPool<PointCloud>(pool_size_));
point_cloud_pool_->ConstructAll();
for (int i = 0; i < pool_size_; i++) {
auto point_cloud = point_cloud_pool_->GetObject();
if (point_cloud == nullptr) {
AERROR << "fail to getobject, i: " << i;
return false;
}
point_cloud->mutable_point()->Reserve(140000);
}
AINFO << "Point cloud comp convert init success";
return true;
}
bool VelodyneConvertComponent::Proc(
const std::shared_ptr<VelodyneScan>& scan_msg) {
std::shared_ptr<PointCloud> point_cloud_out = point_cloud_pool_->GetObject();
if (point_cloud_out == nullptr) {
AWARN << "poin cloud pool return nullptr, will be create new.";
point_cloud_out = std::make_shared<PointCloud>();
point_cloud_out->mutable_point()->Reserve(140000);
}
if (point_cloud_out == nullptr) {
AWARN << "point cloud out is nullptr";
return false;
}
point_cloud_out->Clear();
conv_->ConvertPacketsToPointcloud(scan_msg, point_cloud_out);
if (point_cloud_out == nullptr || point_cloud_out->point().empty()) {
AWARN << "point_cloud_out convert is empty.";
return false;
}
writer_->Write(point_cloud_out);
return true;
}
} // namespace velodyne
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/parser/util.h
|
/******************************************************************************
* Copyright 2017 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#pragma once
#include <cmath>
#include <fstream>
#include <string>
namespace apollo {
namespace drivers {
namespace velodyne {
template <typename T>
void dump_msg(const T& msg, const std::string& file_path) {
// std::ofstream ofs(file_path.c_str(),
// std::ofstream::out | std::ofstream::binary);
// uint32_t serial_size = ros::serialization::serializationLength(msg);
// boost::shared_array<uint8_t> obuffer(new uint8_t[serial_size]);
// ros::serialization::OStream ostream(obuffer.get(), serial_size);
// ros::serialization::serialize(ostream, msg);
// ofs.write((char*)obuffer.get(), serial_size);
// ofs.close();
}
template <class T>
void load_msg(const std::string& file_path, T* msg) {
// std::ifstream ifs(file_path.c_str(),
// std::ifstream::in | std::ifstream::binary);
// ifs.seekg(0, std::ios::end);
// std::streampos end = ifs.tellg();
// ifs.seekg(0, std::ios::beg);
// std::streampos begin = ifs.tellg();
//
// uint32_t file_size = end - begin;
// boost::shared_array<uint8_t> ibuffer(new uint8_t[file_size]);
// ifs.read((char*)ibuffer.get(), file_size);
// ros::serialization::IStream istream(ibuffer.get(), file_size);
// ros::serialization::deserialize(istream, *msg);
// ifs.close();
}
void init_sin_cos_rot_table(float* sin_rot_table, float* cos_rot_table,
uint16_t rotation, float rotation_resolution);
} // namespace velodyne
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/parser/velodyne16_parser.cc
|
/******************************************************************************
* Copyright 2017 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/drivers/lidar/velodyne/parser/velodyne_parser.h"
namespace apollo {
namespace drivers {
namespace velodyne {
Velodyne16Parser::Velodyne16Parser(const Config& config)
: VelodyneParser(config), previous_packet_stamp_(0), gps_base_usec_(0) {
inner_time_ = &velodyne::INNER_TIME_16;
need_two_pt_correction_ = false;
}
void Velodyne16Parser::GeneratePointcloud(
const std::shared_ptr<VelodyneScan>& scan_msg,
std::shared_ptr<PointCloud> out_msg) {
// allocate a point cloud with same time and frame ID as raw data
out_msg->mutable_header()->set_frame_id(scan_msg->header().frame_id());
out_msg->set_height(1);
out_msg->mutable_header()->set_sequence_num(
scan_msg->header().sequence_num());
gps_base_usec_ = scan_msg->basetime();
size_t packets_size = scan_msg->firing_pkts_size();
for (size_t i = 0; i < packets_size; ++i) {
Unpack(scan_msg->firing_pkts(static_cast<int>(i)), out_msg);
last_time_stamp_ = out_msg->measurement_time();
ADEBUG << "stamp: " << std::fixed << last_time_stamp_;
}
if (out_msg->point().empty()) {
// we discard this pointcloud if empty
AERROR << "All points is NAN!Please check velodyne:" << config_.model();
}
// set default width
out_msg->set_width(out_msg->point_size());
}
uint64_t Velodyne16Parser::GetTimestamp(double base_time, float time_offset,
uint16_t block_id) {
double t = base_time - time_offset;
uint64_t timestamp = Velodyne16Parser::GetGpsStamp(t, &previous_packet_stamp_,
&gps_base_usec_);
return timestamp;
}
/** @brief convert raw packet to point cloud
*
* @param pkt raw packet to Unpack
* @param pc shared pointer to point cloud (points are appended)
*/
void Velodyne16Parser::Unpack(const VelodynePacket& pkt,
std::shared_ptr<PointCloud> pc) {
float azimuth_diff = 0.0f;
float last_azimuth_diff = 0.0f;
float azimuth_corrected_f = 0.0f;
int azimuth_corrected = 0;
// const RawPacket* raw = (const RawPacket*)&pkt.data[0];
const RawPacket* raw = (const RawPacket*)pkt.data().c_str();
double basetime = raw->gps_timestamp; // usec
for (int block = 0; block < BLOCKS_PER_PACKET; block++) {
float azimuth = static_cast<float>(raw->blocks[block].rotation);
if (block < (BLOCKS_PER_PACKET - 1)) {
azimuth_diff =
static_cast<float>((36000 + raw->blocks[block + 1].rotation -
raw->blocks[block].rotation) %
36000);
last_azimuth_diff = azimuth_diff;
} else {
azimuth_diff = last_azimuth_diff;
}
for (int firing = 0, k = 0; firing < VLP16_FIRINGS_PER_BLOCK; ++firing) {
for (int dsr = 0; dsr < VLP16_SCANS_PER_FIRING;
++dsr, k += RAW_SCAN_SIZE) {
LaserCorrection& corrections = calibration_.laser_corrections_[dsr];
/** Position Calculation */
union RawDistance raw_distance;
raw_distance.bytes[0] = raw->blocks[block].data[k];
raw_distance.bytes[1] = raw->blocks[block].data[k + 1];
/** correct for the laser rotation as a function of timing during the
* firings **/
azimuth_corrected_f =
azimuth + (azimuth_diff *
((static_cast<float>(dsr) * VLP16_DSR_TOFFSET) +
(static_cast<float>(firing) * VLP16_FIRING_TOFFSET)) /
VLP16_BLOCK_TDURATION);
azimuth_corrected =
static_cast<int>(round(fmod(azimuth_corrected_f, 36000.0)));
// set 4th param to LOWER_BANK, only use lower_gps_base_usec_ and
// lower_previous_packet_stamp_
uint64_t timestamp = GetTimestamp(
basetime,
(*inner_time_)[block][firing * VLP16_SCANS_PER_FIRING + dsr],
LOWER_BANK);
if (block == BLOCKS_PER_PACKET - 1 &&
firing == VLP16_FIRINGS_PER_BLOCK - 1 &&
dsr == VLP16_SCANS_PER_FIRING - 1) {
// set header stamp before organize the point cloud
pc->set_measurement_time(static_cast<double>(timestamp) / 1e9);
}
float real_distance = raw_distance.raw_distance * DISTANCE_RESOLUTION;
float distance = real_distance + corrections.dist_correction;
if (raw_distance.raw_distance == 0 ||
!is_scan_valid(azimuth_corrected, distance)) {
// if organized append a nan point to the cloud
if (config_.organized()) {
PointXYZIT* point = pc->add_point();
point->set_x(nan);
point->set_y(nan);
point->set_z(nan);
point->set_timestamp(timestamp);
point->set_intensity(0);
}
continue;
}
PointXYZIT* point = pc->add_point();
point->set_timestamp(timestamp);
// append this point to the cloud
ComputeCoords(real_distance, corrections,
static_cast<uint16_t>(azimuth_corrected), point);
point->set_intensity(raw->blocks[block].data[k + 2]);
// append this point to the cloud
if (block == 0 && firing == 0) {
ADEBUG << "point x:" << point->x() << " y:" << point->y()
<< " z:" << point->z()
<< " intensity:" << int(point->intensity());
}
}
}
}
}
void Velodyne16Parser::Order(std::shared_ptr<PointCloud> cloud) {
int width = 16;
cloud->set_width(width);
int height = cloud->point_size() / cloud->width();
cloud->set_height(height);
std::shared_ptr<PointCloud> cloud_origin = std::make_shared<PointCloud>();
cloud_origin->CopyFrom(*cloud);
for (int i = 0; i < width; ++i) {
int col = velodyne::ORDER_16[i];
for (int j = 0; j < height; ++j) {
// make sure offset is initialized, should be init at setup() just once
int target_index = j * width + i;
int origin_index = j * width + col;
cloud->mutable_point(target_index)
->CopyFrom(cloud_origin->point(origin_index));
}
}
}
} // namespace velodyne
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/parser/BUILD
|
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
load("//tools:cpplint.bzl", "cpplint")
load("//tools/install:install.bzl", "install")
package(default_visibility = ["//visibility:public"])
install(
name = "install",
library_dest = "drivers/lib/lidar/velodyne/parser",
targets = [
":libvelodyne_convert_component.so",
],
)
cc_binary(
name = "libvelodyne_convert_component.so",
linkshared = True,
linkstatic = True,
deps = [":velodyne_convert_component_lib"],
)
cc_library(
name = "velodyne_convert_component_lib",
srcs = ["velodyne_convert_component.cc"],
hdrs = ["velodyne_convert_component.h"],
copts = ['-DMODULE_NAME=\\"velodyne\\"'],
deps = [
"//cyber",
"//modules/drivers/lidar/velodyne/parser:convert",
],
alwayslink = True
)
cc_library(
name = "convert",
srcs = [
"calibration.cc",
"convert.cc",
"online_calibration.cc",
"util.cc",
"velodyne128_parser.cc",
"velodyne16_parser.cc",
"velodyne32_parser.cc",
"velodyne64_parser.cc",
"velodyne_parser.cc",
],
hdrs = [
"calibration.h",
"const_variables.h",
"convert.h",
"online_calibration.h",
"util.h",
"velodyne_parser.h",
],
copts = ['-DMODULE_NAME=\\"velodyne\\"'],
deps = [
"//cyber",
"//modules/drivers/lidar/proto:velodyne_config_cc_proto",
"//modules/common_msgs/sensor_msgs:pointcloud_cc_proto",
"@boost",
"@com_github_jbeder_yaml_cpp//:yaml-cpp",
"@eigen",
],
)
cpplint()
| 0
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/parser/convert.h
|
/******************************************************************************
* Copyright 2017 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#pragma once
#include <memory>
#include <string>
#include "modules/common_msgs/sensor_msgs/pointcloud.pb.h"
#include "modules/drivers/lidar/velodyne/parser/velodyne_parser.h"
#include "modules/drivers/lidar/proto/velodyne_config.pb.h"
#include "modules/drivers/lidar/proto/velodyne.pb.h"
namespace apollo {
namespace drivers {
namespace velodyne {
using apollo::drivers::PointCloud;
using apollo::drivers::velodyne::VelodyneScan;
// convert velodyne data to pointcloud and republish
class Convert {
public:
Convert() = default;
virtual ~Convert() = default;
// init velodyne config struct from private_nh
// void init(ros::NodeHandle& node, ros::NodeHandle& private_nh);
void init(const Config& velodyne_config);
// convert velodyne data to pointcloud and public
void ConvertPacketsToPointcloud(const std::shared_ptr<VelodyneScan>& scan_msg,
std::shared_ptr<PointCloud> point_cloud_out);
private:
// RawData class for converting data to point cloud
std::unique_ptr<VelodyneParser> parser_;
// ros::Subscriber velodyne_scan_;
// ros::Publisher pointcloud_pub_;
// std::string topic_packets_;
std::string channel_pointcloud_;
/// configuration parameters, get config struct from velodyne_parser.h
Config config_;
// queue size for ros node pub
// int queue_size_ = 10;
};
} // namespace velodyne
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/parser/velodyne_convert_component.h
|
/******************************************************************************
* Copyright 2017 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#pragma once
#include <deque>
#include <memory>
#include <string>
#include <thread>
#include "modules/drivers/lidar/proto/velodyne.pb.h"
#include "modules/drivers/lidar/proto/velodyne_config.pb.h"
#include "cyber/base/concurrent_object_pool.h"
#include "cyber/cyber.h"
#include "modules/drivers/lidar/velodyne/parser/convert.h"
namespace apollo {
namespace drivers {
namespace velodyne {
using apollo::cyber::Component;
using apollo::cyber::Reader;
using apollo::cyber::Writer;
using apollo::cyber::base::CCObjectPool;
using apollo::drivers::PointCloud;
using apollo::drivers::velodyne::VelodyneScan;
class VelodyneConvertComponent : public Component<VelodyneScan> {
public:
bool Init() override;
bool Proc(const std::shared_ptr<VelodyneScan>& scan_msg) override;
private:
std::shared_ptr<Writer<PointCloud>> writer_;
std::unique_ptr<Convert> conv_ = nullptr;
std::shared_ptr<CCObjectPool<PointCloud>> point_cloud_pool_ = nullptr;
int pool_size_ = 8;
};
CYBER_REGISTER_COMPONENT(VelodyneConvertComponent)
} // namespace velodyne
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/parser
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/parser/scripts/gen_calibration.py
|
#!/usr/bin/env python3
###############################################################################
# Copyright 2017 The Apollo Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
###############################################################################
# Software License Agreement (BSD License)
#
# Copyright (C) 2012, Austin Robot Technology
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of Austin Robot Technology, Inc. nor the names
# of its contributors may be used to endorse or promote products
# derived from this software without specific prior written
# permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# Revision $Id$
"""
Generate YAML calibration file from Velodyne db.xml.
The input data provided by the manufacturer are in degrees and
centimeters. The YAML file uses radians and meters, following ROS
standards [REP-0103].
"""
from xml.etree import ElementTree
import math
import optparse
import os
import six
import sys
import yaml
# parse the command line
usage = """usage: %prog infile.xml [outfile.yaml]
Default output file is input file with .yaml suffix."""
parser = optparse.OptionParser(usage=usage)
options, args = parser.parse_args()
if len(args) < 1:
parser.error('XML file name missing')
sys.exit(9)
xmlFile = args[0]
if len(args) >= 2:
yamlFile = args[1]
else:
yamlFile, ext = os.path.splitext(xmlFile)
yamlFile += '.yaml'
print('converting "' + xmlFile + '" to "' + yamlFile + '"')
calibrationGood = True
def xmlError(msg):
'handle XML calibration error'
global calibrationGood
calibrationGood = False
print('gen_calibration.py: ' + msg)
db = None
try:
db = ElementTree.parse(xmlFile)
except IOError:
xmlError('unable to read ' + xmlFile)
except ElementTree.ParseError:
xmlError('XML parse failed for ' + xmlFile)
if not calibrationGood:
sys.exit(2)
# create a dictionary to hold all relevant calibration values
calibration = {'num_lasers': 0, 'lasers': []}
cm2meters = 0.01 # convert centimeters to meters
def addLaserCalibration(laser_num, key, val):
"""Define key and corresponding value for laser_num"""
global calibration
if laser_num < len(calibration['lasers']):
calibration['lasers'][laser_num][key] = val
else:
calibration['lasers'].append({key: val})
# add enabled flags
num_enabled = 0
enabled_lasers = []
enabled = db.find('DB/enabled_')
if enabled is None:
print('no enabled tags found: assuming all 64 enabled')
num_enabled = 64
enabled_lasers = [True for i in range(num_enabled)]
else:
index = 0
for el in enabled:
if el.tag == 'item':
this_enabled = int(el.text) != 0
enabled_lasers.append(this_enabled)
index += 1
if this_enabled:
num_enabled += 1
calibration['num_lasers'] = num_enabled
print(str(num_enabled) + ' lasers')
# add minimum laser intensities
minIntensities = db.find('DB/minIntensity_')
if minIntensities is not None:
index = 0
for el in minIntensities:
if el.tag == 'item':
if enabled_lasers[index]:
value = int(el.text)
if value != 256:
addLaserCalibration(index, 'min_intensity', value)
index += 1
# add maximum laser intensities
maxIntensities = db.find('DB/maxIntensity_')
if maxIntensities is not None:
index = 0
for el in maxIntensities:
if el.tag == 'item':
if enabled_lasers[index]:
value = int(el.text)
if value != 256:
addLaserCalibration(index, 'max_intensity', value)
index += 1
# add calibration information for each laser
for el in db.find('DB/points_'):
if el.tag == 'item':
for px in el:
for field in px:
if field.tag == 'id_':
index = int(field.text)
if not enabled_lasers[index]:
break # skip this laser, it is not enabled
addLaserCalibration(index, 'laser_id', index)
if field.tag == 'rotCorrection_':
addLaserCalibration(index, 'rot_correction',
math.radians(float(field.text)))
elif field.tag == 'vertCorrection_':
addLaserCalibration(index, 'vert_correction',
math.radians(float(field.text)))
elif field.tag == 'distCorrection_':
addLaserCalibration(index, 'dist_correction',
float(field.text) * cm2meters)
elif field.tag == 'distCorrectionX_':
addLaserCalibration(index, 'dist_correction_x',
float(field.text) * cm2meters)
elif field.tag == 'distCorrectionY_':
addLaserCalibration(index, 'dist_correction_y',
float(field.text) * cm2meters)
elif field.tag == 'vertOffsetCorrection_':
addLaserCalibration(index, 'vert_offset_correction',
float(field.text) * cm2meters)
elif field.tag == 'horizOffsetCorrection_':
addLaserCalibration(index, 'horiz_offset_correction',
float(field.text) * cm2meters)
elif field.tag == 'focalDistance_':
addLaserCalibration(index, 'focal_distance',
float(field.text) * cm2meters)
elif field.tag == 'focalSlope_':
addLaserCalibration(index, 'focal_slope', float(field.text))
# validate input data
if calibration['num_lasers'] <= 0:
xmlError('no lasers defined')
elif calibration['num_lasers'] != num_enabled:
xmlError('inconsistent number of lasers defined')
# TODO: make sure all required fields are present.
# (Which ones are required?)
if calibrationGood:
# write calibration data to YAML file
with open(yamlFile, 'w') as f:
yaml.dump(calibration, f)
| 0
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/parser
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/parser/scripts/velodyne_check.py
|
#!/usr/bin/env python3
"""
velodyne check
"""
import time
from cyber.python.cyber_py3 import cyber_time
from sensor_msgs.msg import PointCloud2
prev_stamp = 0
count = 0
LOG_FILE = None
EXCEPT_LOG_FILE = None
def create_log_file():
data_time = time.strftime(
'%Y-%m-%d-%H-%M-%S', time.localtime(cyber_time.Time.now().to_sec()))
file_name = '/apollo/data/log/velodyne_hz.' + data_time + '.log'
except_file_name = '/apollo/data/log/velodyne_hz.' + data_time + '.log.err'
global LOG_FILE
global EXCEPT_LOG_FILE
LOG_FILE = open(file_name, 'a+')
EXCEPT_LOG_FILE = open(except_file_name, 'a+')
def log_latency(log_file, frequence):
pass
def callback(pointcloud):
global count
global prev_stamp
count += 1
stamp = pointcloud.header.stamp.to_time()
if prev_stamp == 0:
prev_stamp = stamp
return
interval = stamp - prev_stamp
frequence = 1.0 / interval
log_info = "%f: %.2fms\t%.2fHz\n" % (stamp, interval * 1000, frequence)
LOG_FILE.write(log_info)
if frequence < 9:
EXCEPT_LOG_FILE.write(log_info)
prev_stamp = stamp
def listener():
node_name = 'velodyne_check'
topic = '/apollo/sensor/velodyne64/compensator/PointCloud2'
rospy.init_node(node_name)
rospy.Subscriber(topic, PointCloud2, callback)
rospy.spin()
if __name__ == "__main__":
create_log_file()
listener()
| 0
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/parser
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/parser/scripts/extrinsics_broadcaster.py
|
#!/usr/bin/env python3
###############################################################################
# Copyright 2017 The Apollo Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
###############################################################################
"""
Broadcaster static transform
"""
from subprocess import call
import sys
import yaml
def main():
"""Main function.
Reading transform info from a yaml file and publish to tf2
"""
if len(sys.argv) < 2:
print('Usage: %s extrinsic_example.yaml' % sys.argv[0])
return
with open(sys.argv[1]) as fp:
transform_stamped = yaml.safe_load(file_path)
command = 'rosrun tf2_ros static_transform_publisher ' \
'%f %f %f %f %f %f %f %s %s' % \
(transform_stamped['transform']['translation']['x'],
transform_stamped['transform']['translation']['y'],
transform_stamped['transform']['translation']['z'],
transform_stamped['transform']['rotation']['x'],
transform_stamped['transform']['rotation']['y'],
transform_stamped['transform']['rotation']['z'],
transform_stamped['transform']['rotation']['w'],
transform_stamped['header']['frame_id'],
transform_stamped['child_frame_id'])
print(command)
try:
return call(command, shell=True)
except OSError as e:
print(e)
if __name__ == '__main__':
main()
| 0
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/compensator/compensator.h
|
/******************************************************************************
* Copyright 2017 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#pragma once
#include <memory>
#include <string>
#include "Eigen/Eigen"
// Eigen 3.3.7: #define ALIVE (0)
// fastrtps: enum ChangeKind_t { ALIVE, ... };
#if defined(ALIVE)
#undef ALIVE
#endif
#include "modules/drivers/lidar/proto/velodyne_config.pb.h"
#include "modules/common_msgs/sensor_msgs/pointcloud.pb.h"
#include "modules/transform/buffer.h"
namespace apollo {
namespace drivers {
namespace velodyne {
using apollo::drivers::PointCloud;
class Compensator {
public:
explicit Compensator(const CompensatorConfig& config) : config_(config) {}
virtual ~Compensator() {}
bool MotionCompensation(const std::shared_ptr<const PointCloud>& msg,
std::shared_ptr<PointCloud> msg_compensated);
private:
/**
* @brief get pose affine from tf2 by gps timestamp
* novatel-preprocess broadcast the tf2 transfrom.
*/
bool QueryPoseAffineFromTF2(const uint64_t& timestamp, void* pose,
const std::string& child_frame_id);
/**
* @brief motion compensation for point cloud
*/
void MotionCompensation(const std::shared_ptr<const PointCloud>& msg,
std::shared_ptr<PointCloud> msg_compensated,
const uint64_t timestamp_min,
const uint64_t timestamp_max,
const Eigen::Affine3d& pose_min_time,
const Eigen::Affine3d& pose_max_time);
/**
* @brief get min timestamp and max timestamp from points in pointcloud2
*/
inline void GetTimestampInterval(const std::shared_ptr<const PointCloud>& msg,
uint64_t* timestamp_min,
uint64_t* timestamp_max);
bool IsValid(const Eigen::Vector3d& point);
transform::Buffer* tf2_buffer_ptr_ = transform::Buffer::Instance();
CompensatorConfig config_;
};
} // namespace velodyne
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/compensator/compensator.cc
|
/******************************************************************************
* Copyright 2017 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/drivers/lidar/velodyne/compensator/compensator.h"
#include <limits>
#include <memory>
#include <string>
namespace apollo {
namespace drivers {
namespace velodyne {
bool Compensator::QueryPoseAffineFromTF2(const uint64_t& timestamp, void* pose,
const std::string& child_frame_id) {
cyber::Time query_time(timestamp);
std::string err_string;
if (!tf2_buffer_ptr_->canTransform(
config_.world_frame_id(), child_frame_id, query_time,
config_.transform_query_timeout(), &err_string)) {
AERROR << "Can not find transform. " << timestamp
<< " frame_id:" << child_frame_id << " Error info: " << err_string;
return false;
}
apollo::transform::TransformStamped stamped_transform;
try {
stamped_transform = tf2_buffer_ptr_->lookupTransform(
config_.world_frame_id(), child_frame_id, query_time);
} catch (tf2::TransformException& ex) {
AERROR << ex.what();
return false;
}
Eigen::Affine3d* tmp_pose = (Eigen::Affine3d*)pose;
*tmp_pose =
Eigen::Translation3d(stamped_transform.transform().translation().x(),
stamped_transform.transform().translation().y(),
stamped_transform.transform().translation().z()) *
Eigen::Quaterniond(stamped_transform.transform().rotation().qw(),
stamped_transform.transform().rotation().qx(),
stamped_transform.transform().rotation().qy(),
stamped_transform.transform().rotation().qz());
return true;
}
bool Compensator::MotionCompensation(
const std::shared_ptr<const PointCloud>& msg,
std::shared_ptr<PointCloud> msg_compensated) {
if (msg->height() == 0 || msg->width() == 0) {
AERROR << "PointCloud width & height should not be 0";
return false;
}
uint64_t start = cyber::Time::Now().ToNanosecond();
Eigen::Affine3d pose_min_time;
Eigen::Affine3d pose_max_time;
uint64_t timestamp_min = 0;
uint64_t timestamp_max = 0;
std::string frame_id = msg->header().frame_id();
GetTimestampInterval(msg, ×tamp_min, ×tamp_max);
msg_compensated->mutable_header()->set_timestamp_sec(
cyber::Time::Now().ToSecond());
msg_compensated->mutable_header()->set_frame_id(msg->header().frame_id());
msg_compensated->mutable_header()->set_lidar_timestamp(
msg->header().lidar_timestamp());
msg_compensated->set_measurement_time(msg->measurement_time());
msg_compensated->set_height(msg->height());
msg_compensated->set_is_dense(msg->is_dense());
uint64_t new_time = cyber::Time().Now().ToNanosecond();
AINFO << "compenstator new msg diff:" << new_time - start
<< ";meta:" << msg->header().lidar_timestamp();
msg_compensated->mutable_point()->Reserve(240000);
// compensate point cloud, remove nan point
if (QueryPoseAffineFromTF2(timestamp_min, &pose_min_time, frame_id) &&
QueryPoseAffineFromTF2(timestamp_max, &pose_max_time, frame_id)) {
uint64_t tf_time = cyber::Time().Now().ToNanosecond();
AINFO << "compenstator tf msg diff:" << tf_time - new_time
<< ";meta:" << msg->header().lidar_timestamp();
MotionCompensation(msg, msg_compensated, timestamp_min, timestamp_max,
pose_min_time, pose_max_time);
uint64_t com_time = cyber::Time().Now().ToNanosecond();
msg_compensated->set_width(msg_compensated->point_size() / msg->height());
AINFO << "compenstator com msg diff:" << com_time - tf_time
<< ";meta:" << msg->header().lidar_timestamp();
return true;
}
return false;
}
inline void Compensator::GetTimestampInterval(
const std::shared_ptr<const PointCloud>& msg, uint64_t* timestamp_min,
uint64_t* timestamp_max) {
*timestamp_max = 0;
*timestamp_min = std::numeric_limits<uint64_t>::max();
for (const auto& point : msg->point()) {
uint64_t timestamp = point.timestamp();
if (timestamp < *timestamp_min) {
*timestamp_min = timestamp;
}
if (timestamp > *timestamp_max) {
*timestamp_max = timestamp;
}
}
}
void Compensator::MotionCompensation(
const std::shared_ptr<const PointCloud>& msg,
std::shared_ptr<PointCloud> msg_compensated, const uint64_t timestamp_min,
const uint64_t timestamp_max, const Eigen::Affine3d& pose_min_time,
const Eigen::Affine3d& pose_max_time) {
using std::abs;
using std::acos;
using std::sin;
Eigen::Vector3d translation =
pose_min_time.translation() - pose_max_time.translation();
Eigen::Quaterniond q_max(pose_max_time.linear());
Eigen::Quaterniond q_min(pose_min_time.linear());
Eigen::Quaterniond q1(q_max.conjugate() * q_min);
Eigen::Quaterniond q0(Eigen::Quaterniond::Identity());
q1.normalize();
translation = q_max.conjugate() * translation;
// int total = msg->width * msg->height;
double d = q0.dot(q1);
double abs_d = abs(d);
double f = 1.0 / static_cast<double>(timestamp_max - timestamp_min);
// Threshold for a "significant" rotation from min_time to max_time:
// The LiDAR range accuracy is ~2 cm. Over 70 meters range, it means an angle
// of 0.02 / 70 =
// 0.0003 rad. So, we consider a rotation "significant" only if the scalar
// part of quaternion is
// less than cos(0.0003 / 2) = 1 - 1e-8.
if (abs_d < 1.0 - 1.0e-8) {
double theta = acos(abs_d);
double sin_theta = sin(theta);
double c1_sign = (d > 0) ? 1 : -1;
for (const auto& point : msg->point()) {
float x_scalar = point.x();
if (std::isnan(x_scalar)) {
// if (config_.organized()) {
auto* point_new = msg_compensated->add_point();
point_new->CopyFrom(point);
// } else {
// AERROR << "nan point do not need motion compensation";
// }
continue;
}
float y_scalar = point.y();
float z_scalar = point.z();
Eigen::Vector3d p(x_scalar, y_scalar, z_scalar);
uint64_t tp = point.timestamp();
double t = static_cast<double>(timestamp_max - tp) * f;
Eigen::Translation3d ti(t * translation);
double c0 = sin((1 - t) * theta) / sin_theta;
double c1 = sin(t * theta) / sin_theta * c1_sign;
Eigen::Quaterniond qi(c0 * q0.coeffs() + c1 * q1.coeffs());
Eigen::Affine3d trans = ti * qi;
p = trans * p;
auto* point_new = msg_compensated->add_point();
point_new->set_intensity(point.intensity());
point_new->set_timestamp(point.timestamp());
point_new->set_x(static_cast<float>(p.x()));
point_new->set_y(static_cast<float>(p.y()));
point_new->set_z(static_cast<float>(p.z()));
}
return;
}
// Not a "significant" rotation. Do translation only.
for (auto& point : msg->point()) {
float x_scalar = point.x();
if (std::isnan(x_scalar)) {
// AERROR << "nan point do not need motion compensation";
continue;
}
float y_scalar = point.y();
float z_scalar = point.z();
Eigen::Vector3d p(x_scalar, y_scalar, z_scalar);
uint64_t tp = point.timestamp();
double t = static_cast<double>(timestamp_max - tp) * f;
Eigen::Translation3d ti(t * translation);
p = ti * p;
auto* point_new = msg_compensated->add_point();
point_new->set_intensity(point.intensity());
point_new->set_timestamp(point.timestamp());
point_new->set_x(static_cast<float>(p.x()));
point_new->set_y(static_cast<float>(p.y()));
point_new->set_z(static_cast<float>(p.z()));
}
}
} // namespace velodyne
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/compensator/compensator_component.h
|
/******************************************************************************
* Copyright 2017 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#pragma once
#include <memory>
#include <vector>
#include "cyber/base/concurrent_object_pool.h"
#include "cyber/cyber.h"
#include "modules/drivers/lidar/velodyne/compensator/compensator.h"
namespace apollo {
namespace drivers {
namespace velodyne {
using apollo::cyber::Component;
using apollo::cyber::Reader;
using apollo::cyber::Writer;
using apollo::cyber::base::CCObjectPool;
using apollo::drivers::PointCloud;
class CompensatorComponent : public Component<PointCloud> {
public:
bool Init() override;
bool Proc(const std::shared_ptr<PointCloud>& point_cloud) override;
private:
std::unique_ptr<Compensator> compensator_ = nullptr;
int pool_size_ = 8;
int seq_ = 0;
std::shared_ptr<Writer<PointCloud>> writer_ = nullptr;
std::shared_ptr<CCObjectPool<PointCloud>> compensator_pool_ = nullptr;
};
CYBER_REGISTER_COMPONENT(CompensatorComponent)
} // namespace velodyne
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/compensator/BUILD
|
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
load("//tools:cpplint.bzl", "cpplint")
load("//tools/install:install.bzl", "install")
package(default_visibility = ["//visibility:public"])
install(
name = "install",
library_dest = "drivers/lib/lidar/velodyne/compensator",
targets = [
":libvelodyne_compensator_component.so",
],
)
cc_binary(
name = "libvelodyne_compensator_component.so",
linkshared = True,
linkstatic = True,
deps = [":compensator_component_lib"],
)
cc_library(
name = "compensator_component_lib",
srcs = ["compensator_component.cc"],
hdrs = ["compensator_component.h"],
copts = ['-DMODULE_NAME=\\"velodyne\\"'],
deps = [
"//cyber",
"//modules/common/adapters:adapter_gflags",
"//modules/common/latency_recorder",
"//modules/drivers/lidar/proto:velodyne_cc_proto",
"//modules/drivers/lidar/velodyne/compensator:compensator_lib",
],
alwayslink = True,
)
cc_library(
name = "compensator_lib",
srcs = ["compensator.cc"],
hdrs = ["compensator.h"],
copts = ['-DMODULE_NAME=\\"velodyne\\"'],
deps = [
"//modules/drivers/lidar/proto:velodyne_config_cc_proto",
"//modules/common_msgs/sensor_msgs:pointcloud_cc_proto",
"//modules/transform:buffer",
"@eigen",
],
)
cpplint()
| 0
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/compensator/compensator_component.cc
|
/******************************************************************************
* Copyright 2017 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/drivers/lidar/velodyne/compensator/compensator_component.h"
#include <memory>
#include "cyber/time/time.h"
#include "modules/common/adapters/adapter_gflags.h"
#include "modules/common/latency_recorder/latency_recorder.h"
#include "modules/drivers/lidar/proto/velodyne.pb.h"
using apollo::cyber::Time;
namespace apollo {
namespace drivers {
namespace velodyne {
bool CompensatorComponent::Init() {
CompensatorConfig config;
if (!GetProtoConfig(&config)) {
AWARN << "Load config failed, config file" << ConfigFilePath();
return false;
}
writer_ = node_->CreateWriter<PointCloud>(config.output_channel());
compensator_.reset(new Compensator(config));
compensator_pool_.reset(new CCObjectPool<PointCloud>(pool_size_));
compensator_pool_->ConstructAll();
for (int i = 0; i < pool_size_; ++i) {
auto point_cloud = compensator_pool_->GetObject();
if (point_cloud == nullptr) {
AERROR << "fail to getobject:" << i;
return false;
}
point_cloud->mutable_point()->Reserve(140000);
}
return true;
}
bool CompensatorComponent::Proc(
const std::shared_ptr<PointCloud>& point_cloud) {
const auto start_time = Time::Now();
std::shared_ptr<PointCloud> point_cloud_compensated =
compensator_pool_->GetObject();
if (point_cloud_compensated == nullptr) {
AWARN << "compensator fail to getobject, will be new";
point_cloud_compensated = std::make_shared<PointCloud>();
point_cloud_compensated->mutable_point()->Reserve(140000);
}
if (point_cloud_compensated == nullptr) {
AWARN << "compensator point_cloud is nullptr";
return false;
}
point_cloud_compensated->Clear();
if (compensator_->MotionCompensation(point_cloud, point_cloud_compensated)) {
const auto end_time = Time::Now();
const auto diff = end_time - start_time;
const auto meta_diff =
end_time - Time(point_cloud_compensated->header().lidar_timestamp());
AINFO << "compenstator diff (ms):" << (diff.ToNanosecond() / 1e6)
<< ";meta (ns):"
<< point_cloud_compensated->header().lidar_timestamp()
<< ";meta diff (ms): " << (meta_diff.ToNanosecond() / 1e6);
static common::LatencyRecorder latency_recorder(FLAGS_pointcloud_topic);
latency_recorder.AppendLatencyRecord(
point_cloud_compensated->header().lidar_timestamp(), start_time,
end_time);
point_cloud_compensated->mutable_header()->set_sequence_num(seq_);
writer_->Write(point_cloud_compensated);
seq_++;
}
return true;
}
} // namespace velodyne
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/params/VLP32C_calibration_example.yaml
|
lasers:
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 0, max_intensity: 255,
min_intensity: 0, rot_correction: -0.024434609527920613, vert_correction: -0.4363323129985824,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 1, max_intensity: 255,
min_intensity: 0, rot_correction: 0.07330382858376185, vert_correction: -0.017453292519943295,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 2, max_intensity: 255,
min_intensity: 0, rot_correction: -0.024434609527920613, vert_correction: -0.029094638630745476,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 3, max_intensity: 255,
min_intensity: 0, rot_correction: 0.024434609527920613, vert_correction: -0.2729520417193932,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 4, max_intensity: 255,
min_intensity: 0, rot_correction: -0.024434609527920613, vert_correction: -0.19739673840055869,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 5, max_intensity: 255,
min_intensity: 0, rot_correction: 0.024434609527920613, vert_correction: 0.0, vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 6, max_intensity: 255,
min_intensity: 0, rot_correction: -0.07330382858376185, vert_correction: -0.011641346110802179,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 7, max_intensity: 255,
min_intensity: 0, rot_correction: 0.024434609527920613, vert_correction: -0.15433946575385857,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 8, max_intensity: 255,
min_intensity: 0, rot_correction: -0.024434609527920613, vert_correction: -0.12660618393966866,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 9, max_intensity: 255,
min_intensity: 0, rot_correction: 0.07330382858376185, vert_correction: 0.005811946409141118,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 10, max_intensity: 255,
min_intensity: 0, rot_correction: -0.024434609527920613, vert_correction: -0.005811946409141118,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 11, max_intensity: 255,
min_intensity: 0, rot_correction: 0.024434609527920613, vert_correction: -0.10730284241261137,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 12, max_intensity: 255,
min_intensity: 0, rot_correction: -0.07330382858376185, vert_correction: -0.0930784090088576,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 13, max_intensity: 255,
min_intensity: 0, rot_correction: 0.024434609527920613, vert_correction: 0.02326523892908441,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 14, max_intensity: 255,
min_intensity: 0, rot_correction: -0.07330382858376185, vert_correction: 0.011641346110802179,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 15, max_intensity: 255,
min_intensity: 0, rot_correction: 0.024434609527920613, vert_correction: -0.06981317007977318,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 16, max_intensity: 255,
min_intensity: 0, rot_correction: -0.024434609527920613, vert_correction: -0.08145451619057535,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 17, max_intensity: 255,
min_intensity: 0, rot_correction: 0.07330382858376185, vert_correction: 0.029094638630745476,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 18, max_intensity: 255,
min_intensity: 0, rot_correction: -0.024434609527920613, vert_correction: 0.017453292519943295,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 19, max_intensity: 255,
min_intensity: 0, rot_correction: 0.07330382858376185, vert_correction: -0.06400122367063206,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 20, max_intensity: 255,
min_intensity: 0, rot_correction: -0.07330382858376185, vert_correction: -0.058171823968971005,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 21, max_intensity: 255,
min_intensity: 0, rot_correction: 0.024434609527920613, vert_correction: 0.058171823968971005,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 22, max_intensity: 255,
min_intensity: 0, rot_correction: -0.024434609527920613, vert_correction: 0.04071853144902771,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 23, max_intensity: 255,
min_intensity: 0, rot_correction: 0.024434609527920613, vert_correction: -0.04654793115068877,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 24, max_intensity: 255,
min_intensity: 0, rot_correction: -0.024434609527920613, vert_correction: -0.05235987755982989,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 25, max_intensity: 255,
min_intensity: 0, rot_correction: 0.024434609527920613, vert_correction: 0.12217304763960307,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 26, max_intensity: 255,
min_intensity: 0, rot_correction: -0.024434609527920613, vert_correction: 0.08145451619057535,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 27, max_intensity: 255,
min_intensity: 0, rot_correction: 0.07330382858376185, vert_correction: -0.04071853144902771,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 28, max_intensity: 255,
min_intensity: 0, rot_correction: -0.07330382858376185, vert_correction: -0.03490658503988659,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 29, max_intensity: 255,
min_intensity: 0, rot_correction: 0.024434609527920613, vert_correction: 0.2617993877991494,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 30, max_intensity: 255,
min_intensity: 0, rot_correction: -0.024434609527920613, vert_correction: 0.18034487160857407,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 31, max_intensity: 255,
min_intensity: 0, rot_correction: 0.024434609527920613, vert_correction: -0.02326523892908441,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 32, max_intensity: 255,
min_intensity: 0, rot_correction: 0.0, vert_correction: 0.0, vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 33, max_intensity: 255,
min_intensity: 0, rot_correction: 0.0, vert_correction: 0.0, vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 34, max_intensity: 255,
min_intensity: 0, rot_correction: 0.0, vert_correction: 0.0, vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 35, max_intensity: 255,
min_intensity: 0, rot_correction: 0.0, vert_correction: 0.0, vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 36, max_intensity: 255,
min_intensity: 0, rot_correction: 0.0, vert_correction: 0.0, vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 37, max_intensity: 255,
min_intensity: 0, rot_correction: 0.0, vert_correction: 0.0, vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 38, max_intensity: 255,
min_intensity: 0, rot_correction: 0.0, vert_correction: 0.0, vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 39, max_intensity: 255,
min_intensity: 0, rot_correction: 0.0, vert_correction: 0.0, vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 40, max_intensity: 255,
min_intensity: 0, rot_correction: 0.0, vert_correction: 0.0, vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 41, max_intensity: 255,
min_intensity: 0, rot_correction: 0.0, vert_correction: 0.0, vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 42, max_intensity: 255,
min_intensity: 0, rot_correction: 0.0, vert_correction: 0.0, vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 43, max_intensity: 255,
min_intensity: 0, rot_correction: 0.0, vert_correction: 0.0, vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 44, max_intensity: 255,
min_intensity: 0, rot_correction: 0.0, vert_correction: 0.0, vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 45, max_intensity: 255,
min_intensity: 0, rot_correction: 0.0, vert_correction: 0.0, vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 46, max_intensity: 255,
min_intensity: 0, rot_correction: 0.0, vert_correction: 0.0, vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 47, max_intensity: 255,
min_intensity: 0, rot_correction: 0.0, vert_correction: 0.0, vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 48, max_intensity: 255,
min_intensity: 0, rot_correction: 0.0, vert_correction: 0.0, vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 49, max_intensity: 255,
min_intensity: 0, rot_correction: 0.0, vert_correction: 0.0, vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 50, max_intensity: 255,
min_intensity: 0, rot_correction: 0.0, vert_correction: 0.0, vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 51, max_intensity: 255,
min_intensity: 0, rot_correction: 0.0, vert_correction: 0.0, vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 52, max_intensity: 255,
min_intensity: 0, rot_correction: 0.0, vert_correction: 0.0, vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 53, max_intensity: 255,
min_intensity: 0, rot_correction: 0.0, vert_correction: 0.0, vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 54, max_intensity: 255,
min_intensity: 0, rot_correction: 0.0, vert_correction: 0.0, vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 55, max_intensity: 255,
min_intensity: 0, rot_correction: 0.0, vert_correction: 0.0, vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 56, max_intensity: 255,
min_intensity: 0, rot_correction: 0.0, vert_correction: 0.0, vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 57, max_intensity: 255,
min_intensity: 0, rot_correction: 0.0, vert_correction: 0.0, vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 58, max_intensity: 255,
min_intensity: 0, rot_correction: 0.0, vert_correction: 0.0, vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 59, max_intensity: 255,
min_intensity: 0, rot_correction: 0.0, vert_correction: 0.0, vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 60, max_intensity: 255,
min_intensity: 0, rot_correction: 0.0, vert_correction: 0.0, vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 61, max_intensity: 255,
min_intensity: 0, rot_correction: 0.0, vert_correction: 0.0, vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 62, max_intensity: 255,
min_intensity: 0, rot_correction: 0.0, vert_correction: 0.0, vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 63, max_intensity: 255,
min_intensity: 0, rot_correction: 0.0, vert_correction: 0.0, vert_offset_correction: 0.0}
num_lasers: 64
| 0
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/params/velodyne32_novatel_extrinsics_example.yaml
|
# proj: +proj=utm +zone=50 +ellps=WGS84
# scale:1.11177
# (XXX) Manually adjusted
header:
stamp:
secs: 1422601952
nsecs: 288805456
seq: 0
frame_id: novatel
transform:
translation:
x: -0.1941689746184177
y: 1.438544324620427
z: 0
rotation:
x: -0.00971305
y: 0.00327669
z: 0.7157
w: 0.698332
child_frame_id: velodyne32
| 0
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/params/HDL32E_calibration_example.yaml
|
lasers:
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 0, max_intensity: 255,
min_intensity: 0, rot_correction: -0.024434609527920613, vert_correction: -0.4363323129985824,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 1, max_intensity: 255,
min_intensity: 0, rot_correction: 0.07330382858376185, vert_correction: -0.017453292519943295,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 2, max_intensity: 255,
min_intensity: 0, rot_correction: -0.024434609527920613, vert_correction: -0.029094638630745476,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 3, max_intensity: 255,
min_intensity: 0, rot_correction: 0.024434609527920613, vert_correction: -0.2729520417193932,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 4, max_intensity: 255,
min_intensity: 0, rot_correction: -0.024434609527920613, vert_correction: -0.19739673840055869,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 5, max_intensity: 255,
min_intensity: 0, rot_correction: 0.024434609527920613, vert_correction: 0.0, vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 6, max_intensity: 255,
min_intensity: 0, rot_correction: -0.07330382858376185, vert_correction: -0.011641346110802179,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 7, max_intensity: 255,
min_intensity: 0, rot_correction: 0.024434609527920613, vert_correction: -0.15433946575385857,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 8, max_intensity: 255,
min_intensity: 0, rot_correction: -0.024434609527920613, vert_correction: -0.12660618393966866,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 9, max_intensity: 255,
min_intensity: 0, rot_correction: 0.07330382858376185, vert_correction: 0.005811946409141118,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 10, max_intensity: 255,
min_intensity: 0, rot_correction: -0.024434609527920613, vert_correction: -0.005811946409141118,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 11, max_intensity: 255,
min_intensity: 0, rot_correction: 0.024434609527920613, vert_correction: -0.10730284241261137,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 12, max_intensity: 255,
min_intensity: 0, rot_correction: -0.07330382858376185, vert_correction: -0.0930784090088576,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 13, max_intensity: 255,
min_intensity: 0, rot_correction: 0.024434609527920613, vert_correction: 0.02326523892908441,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 14, max_intensity: 255,
min_intensity: 0, rot_correction: -0.07330382858376185, vert_correction: 0.011641346110802179,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 15, max_intensity: 255,
min_intensity: 0, rot_correction: 0.024434609527920613, vert_correction: -0.06981317007977318,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 16, max_intensity: 255,
min_intensity: 0, rot_correction: -0.024434609527920613, vert_correction: -0.08145451619057535,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 17, max_intensity: 255,
min_intensity: 0, rot_correction: 0.07330382858376185, vert_correction: 0.029094638630745476,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 18, max_intensity: 255,
min_intensity: 0, rot_correction: -0.024434609527920613, vert_correction: 0.017453292519943295,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 19, max_intensity: 255,
min_intensity: 0, rot_correction: 0.07330382858376185, vert_correction: -0.06400122367063206,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 20, max_intensity: 255,
min_intensity: 0, rot_correction: -0.07330382858376185, vert_correction: -0.058171823968971005,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 21, max_intensity: 255,
min_intensity: 0, rot_correction: 0.024434609527920613, vert_correction: 0.058171823968971005,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 22, max_intensity: 255,
min_intensity: 0, rot_correction: -0.024434609527920613, vert_correction: 0.04071853144902771,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 23, max_intensity: 255,
min_intensity: 0, rot_correction: 0.024434609527920613, vert_correction: -0.04654793115068877,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 24, max_intensity: 255,
min_intensity: 0, rot_correction: -0.024434609527920613, vert_correction: -0.05235987755982989,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 25, max_intensity: 255,
min_intensity: 0, rot_correction: 0.024434609527920613, vert_correction: 0.12217304763960307,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 26, max_intensity: 255,
min_intensity: 0, rot_correction: -0.024434609527920613, vert_correction: 0.08145451619057535,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 27, max_intensity: 255,
min_intensity: 0, rot_correction: 0.07330382858376185, vert_correction: -0.04071853144902771,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 28, max_intensity: 255,
min_intensity: 0, rot_correction: -0.07330382858376185, vert_correction: -0.03490658503988659,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 29, max_intensity: 255,
min_intensity: 0, rot_correction: 0.024434609527920613, vert_correction: 0.2617993877991494,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 30, max_intensity: 255,
min_intensity: 0, rot_correction: -0.024434609527920613, vert_correction: 0.18034487160857407,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 31, max_intensity: 255,
min_intensity: 0, rot_correction: 0.024434609527920613, vert_correction: -0.02326523892908441,
vert_offset_correction: 0.0}
num_lasers: 32
| 0
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/params/VLP16_calibration.yaml
|
lasers:
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 0, rot_correction: 0.0,
vert_correction: -0.2617993877991494, vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 1, rot_correction: 0.0,
vert_correction: 0.017453292519943295, vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 2, rot_correction: 0.0,
vert_correction: -0.22689280275926285, vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 3, rot_correction: 0.0,
vert_correction: 0.05235987755982989, vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 4, rot_correction: 0.0,
vert_correction: -0.19198621771937624, vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 5, rot_correction: 0.0,
vert_correction: 0.08726646259971647, vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 6, rot_correction: 0.0,
vert_correction: -0.15707963267948966, vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 7, rot_correction: 0.0,
vert_correction: 0.12217304763960307, vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 8, rot_correction: 0.0,
vert_correction: -0.12217304763960307, vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 9, rot_correction: 0.0,
vert_correction: 0.15707963267948966, vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 10, rot_correction: 0.0,
vert_correction: -0.08726646259971647, vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 11, rot_correction: 0.0,
vert_correction: 0.19198621771937624, vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 12, rot_correction: 0.0,
vert_correction: -0.05235987755982989, vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 13, rot_correction: 0.0,
vert_correction: 0.22689280275926285, vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 14, rot_correction: 0.0,
vert_correction: -0.017453292519943295, vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, horiz_offset_correction: 0.0, laser_id: 15, rot_correction: 0.0,
vert_correction: 0.2617993877991494, vert_offset_correction: 0.0}
num_lasers: 16
| 0
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/params/velodyne128_novatel_extrinsics_example.yaml
|
# proj: +proj=utm +zone=50 +ellps=WGS84
# scale:1.11177
# (XXX) Manually adjusted
header:
stamp:
secs: 1422601952
nsecs: 288805456
seq: 0
frame_id: novatel
transform:
translation:
x: -0.1941689746184177
y: 1.438544324620427
z: 0
rotation:
x: -0.00971305
y: 0.00327669
z: 0.7157
w: 0.698332
child_frame_id: velodyne128
| 0
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/params/velodyne16_novatel_extrinsics_example.yaml
|
# proj: +proj=utm +zone=50 +ellps=WGS84
# scale:1.11177
# (XXX) Manually adjusted
header:
stamp:
secs: 1422601952
nsecs: 288805456
seq: 0
frame_id: novatel
transform:
translation:
x: -0.1941689746184177
y: 1.438544324620427
z: 0
rotation:
x: -0.00971305
y: 0.00327669
z: 0.7157
w: 0.698332
child_frame_id: lidar16
| 0
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/params/64E_S3_calibration_example.yaml
|
lasers:
- {dist_correction: 1.3310837000000002, dist_correction_x: 1.3770219000000001, dist_correction_y: 1.3692569,
focal_distance: 18.2, focal_slope: 1.25, horiz_offset_correction: 0.025999999, laser_id: 0,
min_intensity: 40, rot_correction: -0.08161468505603088, vert_correction: -0.11965835805470787,
vert_offset_correction: 0.21521845}
- {dist_correction: 1.5022441000000002, dist_correction_x: 1.551907, dist_correction_y: 1.5218600000000002,
focal_distance: 19.5, focal_slope: 0.89999998, horiz_offset_correction: -0.025999999,
laser_id: 1, min_intensity: 40, rot_correction: -0.04553043386737336, vert_correction: -0.11397218356212396,
vert_offset_correction: 0.21480394}
- {dist_correction: 1.4610335, dist_correction_x: 1.4894365999999999, dist_correction_y: 1.4851279,
focal_distance: 24.0, focal_slope: 0.60000002, horiz_offset_correction: 0.025999999,
laser_id: 2, min_intensity: 40, rot_correction: 0.055975309652043614, vert_correction: 0.009938637275542775,
vert_offset_correction: 0.20585846}
- {dist_correction: 1.4593767, dist_correction_x: 1.4863893, dist_correction_y: 1.5044385,
focal_distance: 15.0, focal_slope: 0.57999998, horiz_offset_correction: -0.025999999,
laser_id: 3, min_intensity: 20, rot_correction: 0.09417747425476496, vert_correction: 0.015293448094199089,
vert_offset_correction: 0.20547337}
- {dist_correction: 1.3566989, dist_correction_x: 1.4133217, dist_correction_y: 1.3925482,
focal_distance: 24.0, focal_slope: 0.68000001, horiz_offset_correction: 0.025999999,
laser_id: 4, min_intensity: 10, rot_correction: -0.006260811931498271, vert_correction: -0.10872301857028842,
vert_offset_correction: 0.21442179}
- {dist_correction: 1.325462, dist_correction_x: 1.3808411, dist_correction_y: 1.3766566,
focal_distance: 23.0, focal_slope: 1.0, horiz_offset_correction: -0.025999999, laser_id: 5,
min_intensity: 40, rot_correction: 0.03374377862436714, vert_correction: -0.10302289715165183,
vert_offset_correction: 0.21400728000000002}
- {dist_correction: 1.3804121, dist_correction_x: 1.4392418, dist_correction_y: 1.4120797999999999,
focal_distance: 15.0, focal_slope: 1.0, horiz_offset_correction: 0.025999999, laser_id: 6,
min_intensity: 40, rot_correction: -0.019672321584221403, vert_correction: -0.14444458161373525,
vert_offset_correction: 0.21703222}
- {dist_correction: 1.2936794, dist_correction_x: 1.347278, dist_correction_y: 1.3466246000000002,
focal_distance: 15.0, focal_slope: 0.44999999, horiz_offset_correction: -0.025999999,
laser_id: 7, min_intensity: 40, rot_correction: 0.01949520557172902, vert_correction: -0.13803292087498711,
vert_offset_correction: 0.21656187}
- {dist_correction: 1.3281824, dist_correction_x: 1.3840763999999999, dist_correction_y: 1.3553201000000001,
focal_distance: 24.0, focal_slope: 0.69999999, horiz_offset_correction: 0.025999999,
laser_id: 8, min_intensity: 40, rot_correction: 0.06796476168215607, vert_correction: -0.09723503279552974,
vert_offset_correction: 0.2135869}
- {dist_correction: 1.3168753000000002, dist_correction_x: 1.3684203, dist_correction_y: 1.3768073,
focal_distance: 12.5, focal_slope: 1.88, horiz_offset_correction: -0.025999999,
laser_id: 9, min_intensity: 15, rot_correction: 0.10789684777023513, vert_correction: -0.09083248442080624,
vert_offset_correction: 0.21312244}
- {dist_correction: 1.3434329, dist_correction_x: 1.3877518, dist_correction_y: 1.3378757,
focal_distance: 14.200000000000001, focal_slope: 1.0, horiz_offset_correction: 0.025999999,
laser_id: 10, min_intensity: 32, rot_correction: 0.05466209250691655, vert_correction: -0.13257402315759792,
vert_offset_correction: 0.21616206999999998}
- {dist_correction: 1.410976, dist_correction_x: 1.4601607, dist_correction_y: 1.4580339,
focal_distance: 16.2, focal_slope: 1.42, horiz_offset_correction: -0.025999999,
laser_id: 11, min_intensity: 20, rot_correction: 0.09423285006127223, vert_correction: -0.12565873370055278,
vert_offset_correction: 0.21565645}
- {dist_correction: 1.4031206, dist_correction_x: 1.4463712000000002, dist_correction_y: 1.4252437,
focal_distance: 16.0, focal_slope: 1.5, horiz_offset_correction: 0.025999999, laser_id: 12,
min_intensity: 40, rot_correction: -0.0815891107465014, vert_correction: -0.048322650001957436,
vert_offset_correction: 0.21005047000000002}
- {dist_correction: 1.4906659, dist_correction_x: 1.5213858, dist_correction_y: 1.5438446,
focal_distance: 24.0, focal_slope: 0.89999998, horiz_offset_correction: -0.025999999,
laser_id: 13, min_intensity: 40, rot_correction: -0.042767865640792914, vert_correction: -0.04228439023936871,
vert_offset_correction: 0.20961538000000002}
- {dist_correction: 1.4034319, dist_correction_x: 1.4787109, dist_correction_y: 1.4540779000000001,
focal_distance: 18.25, focal_slope: 1.28, horiz_offset_correction: 0.025999999,
laser_id: 14, min_intensity: 40, rot_correction: -0.09506545414494838, vert_correction: -0.08369175078428102,
vert_offset_correction: 0.21260506}
- {dist_correction: 1.4204994, dist_correction_x: 1.4631395, dist_correction_y: 1.4709152,
focal_distance: 24.0, focal_slope: 0.85000002, horiz_offset_correction: -0.025999999,
laser_id: 15, min_intensity: 5, rot_correction: -0.05629401200944554, vert_correction: -0.07800546982661276,
vert_offset_correction: 0.21219351}
- {dist_correction: 1.3781027000000001, dist_correction_x: 1.4234451000000001, dist_correction_y: 1.402811,
focal_distance: 24.0, focal_slope: 0.64999998, horiz_offset_correction: 0.025999999,
laser_id: 16, min_intensity: 20, rot_correction: -0.006953210400236127, vert_correction: -0.037386209214779975,
vert_offset_correction: 0.20926262}
- {dist_correction: 1.4926901000000001, dist_correction_x: 1.5231508, dist_correction_y: 1.533821,
focal_distance: 24.0, focal_slope: 1.3, horiz_offset_correction: -0.025999999, laser_id: 17,
min_intensity: 40, rot_correction: 0.0325987501326085, vert_correction: -0.03089340986443587,
vert_offset_correction: 0.2087952}
- {dist_correction: 1.4091856000000003, dist_correction_x: 1.4681752000000001, dist_correction_y: 1.4059554,
focal_distance: 19.5, focal_slope: 1.2, horiz_offset_correction: 0.025999999, laser_id: 18,
min_intensity: 40, rot_correction: -0.01993377714215791, vert_correction: -0.07255814015150577,
vert_offset_correction: 0.21179958}
- {dist_correction: 1.4439574, dist_correction_x: 1.4918503, dist_correction_y: 1.5174495,
focal_distance: 24.0, focal_slope: 1.08, horiz_offset_correction: -0.025999999,
laser_id: 19, min_intensity: 40, rot_correction: 0.019156510467745507, vert_correction: -0.06694369345519108,
vert_offset_correction: 0.21139391}
- {dist_correction: 1.385416, dist_correction_x: 1.4211823000000001, dist_correction_y: 1.3838962000000001,
focal_distance: 24.0, focal_slope: 0.89999998, horiz_offset_correction: 0.025999999,
laser_id: 20, min_intensity: 20, rot_correction: 0.06749099380203145, vert_correction: -0.025542003485018495,
vert_offset_correction: 0.20841011}
- {dist_correction: 1.3506885, dist_correction_x: 1.3907740999999998, dist_correction_y: 1.4149554,
focal_distance: 15.0, focal_slope: 1.5, horiz_offset_correction: -0.025999999, laser_id: 21,
min_intensity: 25, rot_correction: 0.10734663097821467, vert_correction: -0.02076124995783319,
vert_offset_correction: 0.20806618000000002}
- {dist_correction: 1.4093637, dist_correction_x: 1.4668224, dist_correction_y: 1.4281065000000002,
focal_distance: 24.0, focal_slope: 1.05, horiz_offset_correction: 0.025999999, laser_id: 22,
min_intensity: 20, rot_correction: 0.05406100460318821, vert_correction: -0.06128428882267426,
vert_offset_correction: 0.21098528000000003}
- {dist_correction: 1.4325951000000001, dist_correction_x: 1.4729167, dist_correction_y: 1.4990692,
focal_distance: 24.0, focal_slope: 1.1, horiz_offset_correction: -0.025999999, laser_id: 23,
min_intensity: 25, rot_correction: 0.09399946637902482, vert_correction: -0.0558247208988523,
vert_offset_correction: 0.21059135}
- {dist_correction: 1.4315011999999998, dist_correction_x: 1.4700916000000002, dist_correction_y: 1.4469348,
focal_distance: 18.0, focal_slope: 1.3, horiz_offset_correction: 0.025999999, laser_id: 24,
min_intensity: 40, rot_correction: -0.08114413032705918, vert_correction: 0.02273144743065447,
vert_offset_correction: 0.20493834}
- {dist_correction: 1.5009029, dist_correction_x: 1.520565, dist_correction_y: 1.5116005000000001,
focal_distance: 13.0, focal_slope: 1.6, horiz_offset_correction: -0.025999999, laser_id: 25,
min_intensity: 20, rot_correction: -0.04326525655234326, vert_correction: 0.028328753248385324,
vert_offset_correction: 0.2045356}
- {dist_correction: 1.4601657000000001, dist_correction_x: 1.5346069, dist_correction_y: 1.4926462,
focal_distance: 19.0, focal_slope: 1.22, horiz_offset_correction: 0.025999999, laser_id: 26,
min_intensity: 25, rot_correction: -0.09472309734019418, vert_correction: -0.012219067895570672,
vert_offset_correction: 0.20745176}
- {dist_correction: 1.4716342, dist_correction_x: 1.4949742000000001, dist_correction_y: 1.5043279999999999,
focal_distance: 24.0, focal_slope: 1.05, horiz_offset_correction: -0.025999999,
laser_id: 27, min_intensity: 40, rot_correction: -0.05594181678369785, vert_correction: -0.00694564265259948,
vert_offset_correction: 0.20707254}
- {dist_correction: 1.4052167, dist_correction_x: 1.433842, dist_correction_y: 1.4167058000000001,
focal_distance: 24.0, focal_slope: 0.62, horiz_offset_correction: 0.025999999, laser_id: 28,
max_intensity: 247, rot_correction: -0.006995295524489466, vert_correction: 0.033475100893985886,
vert_offset_correction: 0.20416519000000002}
- {dist_correction: 1.3814494, dist_correction_x: 1.4175862000000001, dist_correction_y: 1.4481818999999998,
focal_distance: 9.5, focal_slope: 0.64999998, horiz_offset_correction: -0.025999999,
laser_id: 29, rot_correction: 0.03146800716077744, vert_correction: 0.038048141041562095,
vert_offset_correction: 0.20383595}
- {dist_correction: 1.4359364, dist_correction_x: 1.4610498, dist_correction_y: 1.4626150999999998,
focal_distance: 24.0, focal_slope: 1.0, horiz_offset_correction: 0.025999999, laser_id: 30,
rot_correction: -0.020034746184715038, vert_correction: -0.0009359327939286667,
vert_offset_correction: 0.20664042}
- {dist_correction: 1.5459198, dist_correction_x: 1.5764232000000002, dist_correction_y: 1.5538023,
focal_distance: 24.0, focal_slope: 0.60000002, horiz_offset_correction: -0.025999999,
laser_id: 31, rot_correction: 0.016155285570181508, vert_correction: 0.004705896181034346,
vert_offset_correction: 0.20623474000000003}
- {dist_correction: 1.1667847, dist_correction_x: 1.2093217, dist_correction_y: 1.1973188000000001,
focal_distance: 11.200000000000001, focal_slope: 2.0, horiz_offset_correction: 0.025999999,
laser_id: 32, rot_correction: -0.13439190574659765, vert_correction: -0.3857982592758488,
vert_offset_correction: 0.15938778}
- {dist_correction: 1.3473508, dist_correction_x: 1.3845827, dist_correction_y: 1.3630843,
focal_distance: 0.25, focal_slope: 1.05, horiz_offset_correction: -0.025999999,
laser_id: 33, rot_correction: -0.07439245850607153, vert_correction: -0.3785477426840439,
vert_offset_correction: 0.15886445000000002}
- {dist_correction: 1.4667661, dist_correction_x: 1.5010345, dist_correction_y: 1.4894231,
focal_distance: 0.25, focal_slope: 0.55000001, horiz_offset_correction: 0.025999999,
laser_id: 34, rot_correction: 0.08399387076845975, vert_correction: -0.19277114464387568,
vert_offset_correction: 0.14627924}
- {dist_correction: 1.3857962000000001, dist_correction_x: 1.4016576, dist_correction_y: 1.4214679000000001,
focal_distance: 10.700000000000001, focal_slope: 1.95, horiz_offset_correction: -0.025999999,
laser_id: 35, rot_correction: 0.13869732059733156, vert_correction: -0.1832230940780379,
vert_offset_correction: 0.14566446}
- {dist_correction: 1.2559687, dist_correction_x: 1.314409, dist_correction_y: 1.2831798,
focal_distance: 0.25, focal_slope: 0.68000001, horiz_offset_correction: 0.025999999,
laser_id: 36, rot_correction: -0.013359949485026569, vert_correction: -0.37221338432319584,
vert_offset_correction: 0.15840972}
- {dist_correction: 1.2784181, dist_correction_x: 1.3320613000000001, dist_correction_y: 1.3252941999999999,
focal_distance: 5.0, focal_slope: 1.05, horiz_offset_correction: -0.025999999, laser_id: 37,
rot_correction: 0.04679879779605343, vert_correction: -0.36306379242558834, vert_offset_correction: 0.15775683000000001}
- {dist_correction: 1.4554490999999998, dist_correction_x: 1.4834776, dist_correction_y: 1.4328893,
focal_distance: 0.25, focal_slope: 0.89999998, horiz_offset_correction: 0.025999999,
laser_id: 38, rot_correction: -0.0367889872153448, vert_correction: -0.4249079113138031,
vert_offset_correction: 0.16226606000000002}
- {dist_correction: 1.3148943, dist_correction_x: 1.3089389, dist_correction_y: 1.3059167,
focal_distance: 0.25, focal_slope: 1.14, horiz_offset_correction: -0.025999999,
laser_id: 39, rot_correction: 0.025408527685142977, vert_correction: -0.4161521704152007,
vert_offset_correction: 0.16161318000000002}
- {dist_correction: 1.3943299999999998, dist_correction_x: 1.4614526, dist_correction_y: 1.4163436999999999,
focal_distance: 0.25, focal_slope: 1.1, horiz_offset_correction: 0.025999999, laser_id: 40,
rot_correction: 0.10580715633017605, vert_correction: -0.35237440124870145, vert_offset_correction: 0.15699979}
- {dist_correction: 1.3258452, dist_correction_x: 1.3723018, dist_correction_y: 1.3585162,
focal_distance: 11.0, focal_slope: 2.0, horiz_offset_correction: -0.025999999, laser_id: 41,
rot_correction: 0.16625067816426262, vert_correction: -0.3405110143504606, vert_offset_correction: 0.15616653}
- {dist_correction: 1.2818515, dist_correction_x: 1.3116125, dist_correction_y: 1.2767683,
focal_distance: 0.25, focal_slope: 1.15, horiz_offset_correction: 0.025999999, laser_id: 42,
rot_correction: 0.085578542462808, vert_correction: -0.4053964043668604, vert_offset_correction: 0.16081802}
- {dist_correction: 1.3025641, dist_correction_x: 1.306756, dist_correction_y: 1.3192126,
focal_distance: 11.0, focal_slope: 2.0, horiz_offset_correction: -0.025999999, laser_id: 43,
rot_correction: 0.14599672211615558, vert_correction: -0.3945403866062856, vert_offset_correction: 0.16002289}
- {dist_correction: 1.3803821, dist_correction_x: 1.4453227000000002, dist_correction_y: 1.4189592,
focal_distance: 7.5, focal_slope: 1.65, horiz_offset_correction: 0.025999999, laser_id: 44,
rot_correction: -0.12990728397892748, vert_correction: -0.27829582100997935, vert_offset_correction: 0.15190372}
- {dist_correction: 1.3855829, dist_correction_x: 1.4360785000000003, dist_correction_y: 1.4143494,
focal_distance: 0.25, focal_slope: 0.44999999, horiz_offset_correction: -0.025999999,
laser_id: 45, rot_correction: -0.07095512504671905, vert_correction: -0.27276871233476374,
vert_offset_correction: 0.15153282}
- {dist_correction: 1.4291447, dist_correction_x: 1.5031113, dist_correction_y: 1.4612855999999999,
focal_distance: 11.0, focal_slope: 2.0, horiz_offset_correction: 0.025999999, laser_id: 46,
rot_correction: -0.15548156907379085, vert_correction: -0.33037724874094604, vert_offset_correction: 0.1554603}
- {dist_correction: 1.3185988, dist_correction_x: 1.368288, dist_correction_y: 1.3403458000000001,
focal_distance: 0.25, focal_slope: 0.87, horiz_offset_correction: -0.025999999,
laser_id: 47, rot_correction: -0.09458243252912968, vert_correction: -0.32480641956796796,
vert_offset_correction: 0.15507416}
- {dist_correction: 1.2958147, dist_correction_x: 1.3547591, dist_correction_y: 1.3134447,
focal_distance: 8.0, focal_slope: 0.5, horiz_offset_correction: 0.025999999, laser_id: 48,
rot_correction: -0.012556921052723024, vert_correction: -0.26406503460774833, vert_offset_correction: 0.15095106}
- {dist_correction: 1.3524262999999999, dist_correction_x: 1.4048238000000002, dist_correction_y: 1.3833192,
focal_distance: 11.5, focal_slope: 0.75, horiz_offset_correction: -0.025999999,
laser_id: 49, rot_correction: 0.0465344781528144, vert_correction: -0.25600904856614803,
vert_offset_correction: 0.15041503}
- {dist_correction: 1.4327817999999999, dist_correction_x: 1.521676, dist_correction_y: 1.4596446,
focal_distance: 8.0, focal_slope: 0.55000001, horiz_offset_correction: 0.025999999,
laser_id: 50, rot_correction: -0.03541076353689795, vert_correction: -0.3174075499897435,
vert_offset_correction: 0.15456353}
- {dist_correction: 1.2927597, dist_correction_x: 1.3607455, dist_correction_y: 1.3262041,
focal_distance: 12.0, focal_slope: 1.0, horiz_offset_correction: -0.025999999, laser_id: 51,
rot_correction: 0.024000019053515523, vert_correction: -0.3090081878711059, vert_offset_correction: 0.15398686}
- {dist_correction: 1.2832906, dist_correction_x: 1.3427673, dist_correction_y: 1.3046936,
focal_distance: 0.25, focal_slope: 0.55000001, horiz_offset_correction: 0.025999999,
laser_id: 52, rot_correction: 0.10328391114128757, vert_correction: -0.24691972288761194,
vert_offset_correction: 0.14981296}
- {dist_correction: 1.3556834, dist_correction_x: 1.3843172000000001, dist_correction_y: 1.4073567,
focal_distance: 8.0, focal_slope: 1.45, horiz_offset_correction: -0.025999999, laser_id: 53,
rot_correction: 0.1608431280334671, vert_correction: -0.23562499916625584, vert_offset_correction: 0.14906861}
- {dist_correction: 1.4477757, dist_correction_x: 1.4988086000000003, dist_correction_y: 1.4539804,
focal_distance: 0.25, focal_slope: 0.40000001, horiz_offset_correction: 0.025999999,
laser_id: 54, rot_correction: 0.08332717244749044, vert_correction: -0.29996661440090433,
vert_offset_correction: 0.15336954}
- {dist_correction: 1.3134518, dist_correction_x: 1.3721104, dist_correction_y: 1.3486082,
focal_distance: 11.8, focal_slope: 2.0, horiz_offset_correction: -0.025999999, laser_id: 55,
rot_correction: 0.14256122648850544, vert_correction: -0.28963557422603686, vert_offset_correction: 0.15266838}
- {dist_correction: 1.3645108, dist_correction_x: 1.3878029, dist_correction_y: 1.38006,
focal_distance: 9.0, focal_slope: 1.72, horiz_offset_correction: 0.025999999, laser_id: 56,
rot_correction: -0.127917886139005, vert_correction: -0.17316514208057154, vert_offset_correction: 0.14501919}
- {dist_correction: 1.2707110000000001, dist_correction_x: 1.3007936000000002, dist_correction_y: 1.2961798,
focal_distance: 0.25, focal_slope: 1.1799999, horiz_offset_correction: -0.025999999,
laser_id: 57, rot_correction: -0.06966258481724036, vert_correction: -0.16474304530309739,
vert_offset_correction: 0.14448062}
- {dist_correction: 1.5419878, dist_correction_x: 1.5731976, dist_correction_y: 1.5622852,
focal_distance: 11.0, focal_slope: 2.0, horiz_offset_correction: 0.025999999, laser_id: 58,
rot_correction: -0.1500442436259563, vert_correction: -0.2226748131960906, vert_offset_correction: 0.14822011}
- {dist_correction: 1.3663246000000002, dist_correction_x: 1.4071829, dist_correction_y: 1.3874036,
focal_distance: 0.25, focal_slope: 0.60000002, horiz_offset_correction: -0.025999999,
laser_id: 59, rot_correction: -0.09168929971186607, vert_correction: -0.21831496327131622,
vert_offset_correction: 0.14793559}
- {dist_correction: 1.3740880000000002, dist_correction_x: 1.390457, dist_correction_y: 1.3650523,
focal_distance: 0.25, focal_slope: 1.05, horiz_offset_correction: 0.025999999, laser_id: 60,
rot_correction: -0.012412686868805287, vert_correction: -0.1585304899800875, vert_offset_correction: 0.14408432}
- {dist_correction: 1.2724805000000001, dist_correction_x: 1.3366646, dist_correction_y: 1.2967293000000002,
focal_distance: 0.25, focal_slope: 1.1, horiz_offset_correction: -0.025999999, laser_id: 61,
rot_correction: 0.046071171776226244, vert_correction: -0.14934852571551407, vert_offset_correction: 0.14350002}
- {dist_correction: 1.5069861, dist_correction_x: 1.541098, dist_correction_y: 1.5027698,
focal_distance: 6.0, focal_slope: 0.64999998, horiz_offset_correction: 0.025999999,
laser_id: 62, rot_correction: -0.03386790818609823, vert_correction: -0.2094526700218796,
vert_offset_correction: 0.14735891}
- {dist_correction: 1.3585458, dist_correction_x: 1.3712567000000002, dist_correction_y: 1.3735513000000001,
focal_distance: 4.5, focal_slope: 0.5, horiz_offset_correction: -0.025999999, laser_id: 63,
rot_correction: 0.023830393994172697, vert_correction: -0.20165593518737052, vert_offset_correction: 0.14685337}
num_lasers: 64
| 0
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/params/velodyne64_novatel_extrinsics_example.yaml
|
# proj: +proj=utm +zone=50 +ellps=WGS84
# scale:1.11177
# (XXX) Manually adjusted
header:
stamp:
secs: 1422601952
nsecs: 288805456
seq: 0
frame_id: novatel
transform:
translation:
x: -0.1941689746184177
y: 1.438544324620427
z: 0
rotation:
x: -0.00971305
y: 0.00327669
z: 0.7157
w: 0.698332
child_frame_id: velodyne64
| 0
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/params/velodyne128_VLS_calibration.yaml
|
lasers:
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 0, rot_correction: -0.1108982206717197, vert_correction: -0.2049365607691742,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 1, rot_correction: -0.07937757438070212, vert_correction: -0.034732052114687155,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 2, rot_correction: -0.04768239516448509, vert_correction: 0.059341194567807204,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 3, rot_correction: -0.015899949485668342, vert_correction: -0.09232791743050003,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 4, rot_correction: 0.015899949485668342, vert_correction: -0.013613568165555772,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 5, rot_correction: 0.04768239516448509, vert_correction: 0.0804596785169386,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 6, rot_correction: 0.07937757438070212, vert_correction: -0.07120943348136864,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 7, rot_correction: 0.1108982206717197, vert_correction: 0.022863813201125717,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 8, rot_correction: -0.1108982206717197, vert_correction: -0.11344640137963143,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 9, rot_correction: -0.07937757438070212, vert_correction: -0.01937315469713706,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 10, rot_correction: -0.04768239516448509, vert_correction: 0.0747000919853573,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 11, rot_correction: -0.015899949485668342, vert_correction: -0.07696902001294993,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 12, rot_correction: 0.015899949485668342, vert_correction: 0.0017453292519943296,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 13, rot_correction: 0.04768239516448509, vert_correction: 0.11309733552923257,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 14, rot_correction: 0.07937757438070212, vert_correction: -0.05585053606381855,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 15, rot_correction: 0.1108982206717197, vert_correction: 0.03822271061867582,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 16, rot_correction: -0.1108982206717197, vert_correction: -0.06736970912698112,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 17, rot_correction: -0.07937757438070212, vert_correction: 0.026703537555513242,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 18, rot_correction: -0.04768239516448509, vert_correction: -0.16133823605435582,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 19, rot_correction: -0.015899949485668342, vert_correction: -0.030892327760299633,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 20, rot_correction: 0.015899949485668342, vert_correction: 0.04782202150464463,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 21, rot_correction: 0.04768239516448509, vert_correction: -0.10384709049366261,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 22, rot_correction: 0.07937757438070212, vert_correction: -0.009773843811168246,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 23, rot_correction: 0.1108982206717197, vert_correction: 0.08429940287132612,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 24, rot_correction: -0.1108982206717197, vert_correction: -0.05201081170943102,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 25, rot_correction: -0.07937757438070212, vert_correction: 0.04206243497306335,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 26, rot_correction: -0.04768239516448509, vert_correction: -0.1096066770252439,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 27, rot_correction: -0.015899949485668342, vert_correction: -0.015533430342749533,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 28, rot_correction: 0.015899949485668342, vert_correction: 0.06318091892219473,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 29, rot_correction: 0.04768239516448509, vert_correction: -0.08848819307611251,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 30, rot_correction: 0.07937757438070212, vert_correction: 0.005585053606381855,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 31, rot_correction: 0.1108982206717197, vert_correction: 0.1322959573011702,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 32, rot_correction: -0.1108982206717197, vert_correction: -0.005934119456780721,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 33, rot_correction: -0.07937757438070212, vert_correction: 0.09040805525330627,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 34, rot_correction: -0.04768239516448509, vert_correction: -0.0635299847725936,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 35, rot_correction: -0.015899949485668342, vert_correction: 0.030543261909900768,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 36, rot_correction: 0.015899949485668342, vert_correction: -0.4363323129985824,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 37, rot_correction: 0.04768239516448509, vert_correction: -0.04241150082346221,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 38, rot_correction: 0.07937757438070212, vert_correction: 0.05166174585903215,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 39, rot_correction: 0.1108982206717197, vert_correction: -0.10000736613927509,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 40, rot_correction: -0.1108982206717197, vert_correction: 0.00942477796076938,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 41, rot_correction: -0.07937757438070212, vert_correction: 0.16929693744344995,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 42, rot_correction: -0.04768239516448509, vert_correction: -0.04817108735504349,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 43, rot_correction: -0.015899949485668342, vert_correction: 0.04590215932745086,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 44, rot_correction: 0.015899949485668342, vert_correction: -0.13351768777756623,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 45, rot_correction: 0.04768239516448509, vert_correction: -0.027052603405912107,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 46, rot_correction: 0.07937757438070212, vert_correction: 0.06702064327658225,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 47, rot_correction: 0.1108982206717197, vert_correction: -0.08464846872172498,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 48, rot_correction: -0.1108982206717197, vert_correction: 0.05550147021341968,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 49, rot_correction: -0.07937757438070212, vert_correction: -0.09616764178488756,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 50, rot_correction: -0.04768239516448509, vert_correction: -0.0020943951023931952,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 51, rot_correction: -0.015899949485668342, vert_correction: 0.10000736613927509,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 52, rot_correction: 0.015899949485668342, vert_correction: -0.07504915783575616,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 53, rot_correction: 0.04768239516448509, vert_correction: 0.019024088846738195,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 54, rot_correction: 0.07937757438070212, vert_correction: -0.2799857186049304,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 55, rot_correction: 0.1108982206717197, vert_correction: -0.038571776469074684,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 56, rot_correction: -0.1108982206717197, vert_correction: 0.07086036763096977,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 57, rot_correction: -0.07937757438070212, vert_correction: -0.08080874436733745,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 58, rot_correction: -0.04768239516448509, vert_correction: 0.013264502315156905,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 59, rot_correction: -0.015899949485668342, vert_correction: 0.2617993877991494,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 60, rot_correction: 0.015899949485668342, vert_correction: -0.05969026041820607,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 61, rot_correction: 0.04768239516448509, vert_correction: 0.03438298626428829,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 62, rot_correction: 0.07937757438070212, vert_correction: -0.11955505376161157,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 63, rot_correction: 0.1108982206717197, vert_correction: -0.023212879051524585,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 64, rot_correction: -0.1108982206717197, vert_correction: -0.09808750396208132,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 65, rot_correction: -0.07937757438070212, vert_correction: -0.004014257279586958,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 66, rot_correction: -0.04768239516448509, vert_correction: 0.0947713783832921,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 67, rot_correction: -0.015899949485668342, vert_correction: -0.06161012259539983,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 68, rot_correction: 0.015899949485668342, vert_correction: 0.01710422666954443,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 69, rot_correction: 0.04768239516448509, vert_correction: -0.34177037412552963,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 70, rot_correction: 0.07937757438070212, vert_correction: -0.040491638646268445,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 71, rot_correction: 0.1108982206717197, vert_correction: 0.053581608036225914,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 72, rot_correction: -0.1108982206717197, vert_correction: -0.08272860654453122,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 73, rot_correction: -0.07937757438070212, vert_correction: 0.011344640137963142,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 74, rot_correction: -0.04768239516448509, vert_correction: 0.20507618710933373,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 75, rot_correction: -0.015899949485668342, vert_correction: -0.046251225177849735,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 76, rot_correction: 0.015899949485668342, vert_correction: 0.03246312408709453,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 77, rot_correction: 0.04768239516448509, vert_correction: -0.12479104151759457,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 78, rot_correction: 0.07937757438070212, vert_correction: -0.025132741228718343,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 79, rot_correction: 0.1108982206717197, vert_correction: 0.06894050545377602,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 80, rot_correction: -0.1108982206717197, vert_correction: -0.03665191429188092,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 81, rot_correction: -0.07937757438070212, vert_correction: 0.05742133239061344,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 82, rot_correction: -0.04768239516448509, vert_correction: -0.0942477796076938,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 83, rot_correction: -0.015899949485668342, vert_correction: -0.00017453292519943296,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 84, rot_correction: 0.015899949485668342, vert_correction: 0.07853981633974483,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 85, rot_correction: 0.04768239516448509, vert_correction: -0.07312929565856241,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 86, rot_correction: 0.07937757438070212, vert_correction: 0.020943951023931952,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 87, rot_correction: 0.1108982206717197, vert_correction: -0.23675391303303078,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 88, rot_correction: -0.1108982206717197, vert_correction: -0.02129301687433082,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 89, rot_correction: -0.07937757438070212, vert_correction: 0.07278022980816354,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 90, rot_correction: -0.04768239516448509, vert_correction: -0.07888888219014369,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 91, rot_correction: -0.015899949485668342, vert_correction: 0.015184364492350668,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 92, rot_correction: 0.015899949485668342, vert_correction: 0.10611601852125524,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 93, rot_correction: 0.04768239516448509, vert_correction: -0.05777039824101231,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 94, rot_correction: 0.07937757438070212, vert_correction: 0.03630284844148206,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 95, rot_correction: 0.1108982206717197, vert_correction: -0.11606439525762292,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 96, rot_correction: -0.1108982206717197, vert_correction: 0.024783675378319478,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 97, rot_correction: -0.07937757438070212, vert_correction: -0.18057176441133332,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 98, rot_correction: -0.04768239516448509, vert_correction: -0.032812189937493394,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 99, rot_correction: -0.015899949485668342, vert_correction: 0.061261056745000965,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 100, rot_correction: 0.015899949485668342, vert_correction: -0.10576695267085637,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 101, rot_correction: 0.04768239516448509, vert_correction: -0.011693705988362009,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 102, rot_correction: 0.07937757438070212, vert_correction: 0.08237954069413235,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 103, rot_correction: 0.1108982206717197, vert_correction: -0.06928957130417489,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 104, rot_correction: -0.1108982206717197, vert_correction: 0.04014257279586958,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 105, rot_correction: -0.07937757438070212, vert_correction: -0.11152653920243766,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 106, rot_correction: -0.04768239516448509, vert_correction: -0.017453292519943295,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 107, rot_correction: -0.015899949485668342, vert_correction: 0.07661995416255106,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 108, rot_correction: 0.015899949485668342, vert_correction: -0.09040805525330627,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 109, rot_correction: 0.04768239516448509, vert_correction: 0.003665191429188092,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 110, rot_correction: 0.07937757438070212, vert_correction: 0.12182398178920421,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 111, rot_correction: 0.1108982206717197, vert_correction: -0.05393067388662478,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 112, rot_correction: -0.1108982206717197, vert_correction: 0.08691739674931762,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 113, rot_correction: -0.07937757438070212, vert_correction: -0.06544984694978735,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 114, rot_correction: -0.04768239516448509, vert_correction: 0.028623399732707003,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 115, rot_correction: -0.015899949485668342, vert_correction: -0.1457698991265664,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 116, rot_correction: 0.015899949485668342, vert_correction: -0.044331363000655974,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 117, rot_correction: 0.04768239516448509, vert_correction: 0.04974188368183839,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 118, rot_correction: 0.07937757438070212, vert_correction: -0.10192722831646885,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 119, rot_correction: 0.1108982206717197, vert_correction: -0.007853981633974483,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 120, rot_correction: -0.1108982206717197, vert_correction: 0.14713125594312199,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 121, rot_correction: -0.07937757438070212, vert_correction: -0.05009094953223726,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 122, rot_correction: -0.04768239516448509, vert_correction: 0.0439822971502571,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 123, rot_correction: -0.015899949485668342, vert_correction: -0.10768681484805014,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 124, rot_correction: 0.015899949485668342, vert_correction: -0.02897246558310587,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 125, rot_correction: 0.04768239516448509, vert_correction: 0.0651007810993885,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 126, rot_correction: 0.07937757438070212, vert_correction: -0.08656833089891874,
vert_offset_correction: 0.0}
- {dist_correction: 0.0, dist_correction_x: 0.0, dist_correction_y: 0.0, focal_distance: 0.0,
focal_slope: 0.0, laser_id: 127, rot_correction: 0.1108982206717197, vert_correction: 0.007504915783575617,
vert_offset_correction: 0.0}
num_lasers: 128
| 0
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/conf/velodyne16_front_center_conf.pb.txt
|
frame_id: "velodyne16_front_center"
scan_channel: "/apollo/sensor/lidar16/front/center/Scan"
rpm: 600.0
model: VLP16
mode: STRONGEST
prefix_angle: 18000
firing_data_port: 2370
positioning_data_port: 8310
use_sensor_sync: false
max_range: 100.0
min_range: 0.9
use_gps_time: true
calibration_online: false
calibration_file: "/apollo/modules/drivers/lidar/velodyne/params/VLP16_calibration.yaml"
organized: false
convert_channel_name: "/apollo/sensor/lidar16/front/center/PointCloud2"
use_poll_sync: true
is_main_frame: false
| 0
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/conf/velodyne16_front_up_compensator.pb.txt
|
world_frame_id: "world"
transform_query_timeout: 0.02
output_channel: "/apollo/sensor/lidar16/front/up/compensator/PointCloud2"
| 0
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/conf/velodyne128_conf.pb.txt
|
frame_id: "velodyne128"
scan_channel: "/apollo/sensor/lidar128/Scan"
rpm: 600.0
model: VLS128
mode: STRONGEST
prefix_angle: 18000
firing_data_port: 2368
positioning_data_port: 8308
use_sensor_sync: false
max_range: 100.0
min_range: 0.9
use_gps_time: true
calibration_online: false
calibration_file: "/apollo/modules/drivers/lidar/velodyne/params/velodyne128_VLS_calibration.yaml"
organized: false
convert_channel_name: "/apollo/sensor/lidar128/PointCloud2"
use_poll_sync: true
is_main_frame: true
| 0
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/conf/velodyne16_fusion_compensator.pb.txt
|
world_frame_id: "world"
transform_query_timeout: 0.02
output_channel: "/apollo/sensor/lidar16/fusion/compensator/PointCloud2"
| 0
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/conf/velodyne16_rear_left_conf.pb.txt
|
frame_id: "velodyne16_rear_left"
scan_channel: "/apollo/sensor/lidar16/rear/left/Scan"
rpm: 600.0
model: VLP16
mode: STRONGEST
prefix_angle: 18000
firing_data_port: 2369
positioning_data_port: 8309
use_sensor_sync: false
max_range: 100.0
min_range: 0.9
use_gps_time: true
calibration_online: false
calibration_file: "/apollo/modules/drivers/lidar/velodyne/params/VLP16_calibration.yaml"
organized: false
convert_channel_name: "/apollo/sensor/lidar16/rear/left/PointCloud2"
use_poll_sync: true
is_main_frame: false
| 0
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/conf/velodyne_fusion_conf.pb.txt
|
max_interval_ms: 50
drop_expired_data : true
fusion_channel: "/apollo/sensor/lidar16/fusion/PointCloud2"
input_channel: [
"/apollo/sensor/lidar16/rear/left/PointCloud2",
"/apollo/sensor/lidar16/rear/right/PointCloud2"
]
# wait time after main channel receive msg, unit second
wait_time_s: 0.02
| 0
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/conf/velodyne32_conf.pb.txt
|
frame_id: "velodyne32"
scan_channel: "/apollo/sensor/velodyne32/VelodyneScan"
rpm: 600.0
model: HDL32E
mode: STRONGEST
firing_data_port: 8308
use_sensor_sync: false
max_range: 130.0
min_range: 0.4
use_gps_time: true
calibration_online: false
calibration_file: "/apollo/modules/drivers/lidar/velodyne/params/HDL32E_calibration_example.yaml"
organized: false
convert_channel_name: "/apollo/sensor/velodyne32/PointCloud2"
use_poll_sync: true
is_main_frame: true
| 0
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/conf/velodyne16_front_up_conf.pb.txt
|
frame_id: "velodyne16_front_up"
scan_channel: "/apollo/sensor/lidar16/front/up/Scan"
rpm: 600.0
model: VLP16
mode: STRONGEST
prefix_angle: 18000
firing_data_port: 2372
positioning_data_port: 8312
use_sensor_sync: false
max_range: 100.0
min_range: 0.9
use_gps_time: true
calibration_online: false
calibration_file: "/apollo/modules/drivers/lidar/velodyne/params/VLP16_calibration.yaml"
organized: false
convert_channel_name: "/apollo/sensor/lidar16/front/up/PointCloud2"
use_poll_sync: true
is_main_frame: false
| 0
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/conf/velodyne16_rear_right_conf.pb.txt
|
frame_id: "velodyne16_rear_right"
scan_channel: "/apollo/sensor/lidar16/rear/right/Scan"
rpm: 600.0
model: VLP16
mode: STRONGEST
prefix_angle: 18000
firing_data_port: 2371
positioning_data_port: 8311
use_sensor_sync: false
max_range: 100.0
min_range: 0.9
use_gps_time: true
calibration_online: false
calibration_file: "/apollo/modules/drivers/lidar/velodyne/params/VLP16_calibration.yaml"
organized: false
convert_channel_name: "/apollo/sensor/lidar16/rear/right/PointCloud2"
use_poll_sync: true
is_main_frame: false
| 0
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/conf/velodyne16_up_center_conf.pb.txt
|
frame_id: "velodyne16_front_center"
scan_channel: "/apollo/sensor/lidar16/up/center/Scan"
rpm: 600.0
model: VLP16
mode: STRONGEST
prefix_angle: 18000
firing_data_port: 2372
positioning_data_port: 8312
use_sensor_sync: false
max_range: 100.0
min_range: 0.9
use_gps_time: true
calibration_online: false
calibration_file: "/apollo/modules/drivers/lidar/velodyne/params/VLP16_calibration.yaml"
organized: false
convert_channel_name: "/apollo/sensor/lidar16/up/center/PointCloud2"
use_poll_sync: true
is_main_frame: false
| 0
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/conf/velodyne64_compensator.pb.txt
|
world_frame_id: "world"
target_frame_id: "novatel"
transform_query_timeout: 0.02
output_channel: "/apollo/sensor/velodyne64/compensator/PointCloud2"
| 0
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/conf/velodyne64_conf.pb.txt
|
frame_id: "velodyne64"
scan_channel: "/apollo/sensor/velodyne64/VelodyneScan"
rpm: 600.0
model: HDL64E_S3D
mode: STRONGEST
prefix_angle: 18000
firing_data_port: 2368
use_sensor_sync: false
max_range: 100.0
min_range: 0.9
use_gps_time: true
calibration_online: true
calibration_file: "/apollo/modules/drivers/lidar/velodyne/params/velodyne64_S3_calibration.yaml"
organized: false
convert_channel_name: "/apollo/sensor/velodyne64/PointCloud2"
use_poll_sync: true
is_main_frame: true
| 0
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/conf/velodyne128_compensator.pb.txt
|
world_frame_id: "world"
transform_query_timeout: 0.02
output_channel: "/apollo/sensor/lidar128/compensator/PointCloud2"
| 0
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/conf/velodyne_vlp32c_conf.pb.txt
|
frame_id: "velodyne32"
scan_channel: "/apollo/sensor/velodyne32/VelodyneScan"
rpm: 600.0
model: VLP32C
mode: STRONGEST
firing_data_port: 8308
use_sensor_sync: false
max_range: 200
min_range: 0.4
use_gps_time: true
calibration_online: false
calibration_file: "/apollo/modules/drivers/lidar/velodyne/params/VLP32C_calibration_example.yaml"
organized: false
convert_channel_name: "/apollo/sensor/velodyne32/PointCloud2"
use_poll_sync: true
is_main_frame: true
| 0
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne
|
apollo_public_repos/apollo/modules/drivers/lidar/velodyne/conf/velodyne128_fusion_compensator.pb.txt
|
world_frame_id: "world"
transform_query_timeout: 0.02
output_channel: "/apollo/sensor/lidar128/compensator/PointCloud2"
| 0
|
apollo_public_repos/apollo/modules/drivers
|
apollo_public_repos/apollo/modules/drivers/gnss/gnss_component.h
|
/******************************************************************************
* Copyright 2017 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#pragma once
#include <memory>
#include <string>
#include <vector>
#include "cyber/cyber.h"
#include "modules/common/monitor_log/monitor_log_buffer.h"
#include "modules/drivers/gnss/stream/raw_stream.h"
namespace apollo {
namespace drivers {
namespace gnss {
using apollo::cyber::Component;
using apollo::cyber::Reader;
using apollo::cyber::Writer;
using apollo::drivers::gnss::RawData;
class GnssDriverComponent : public Component<> {
public:
GnssDriverComponent();
bool Init() override;
private:
std::unique_ptr<RawStream> raw_stream_ = nullptr;
apollo::common::monitor::MonitorLogBuffer monitor_logger_buffer_;
};
CYBER_REGISTER_COMPONENT(GnssDriverComponent)
} // namespace gnss
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers
|
apollo_public_repos/apollo/modules/drivers/gnss/gnss_component.cc
|
/******************************************************************************
* Copyright 2017 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/drivers/gnss/gnss_component.h"
namespace apollo {
namespace drivers {
namespace gnss {
using apollo::cyber::proto::RoleAttributes;
GnssDriverComponent::GnssDriverComponent()
: monitor_logger_buffer_(
apollo::common::monitor::MonitorMessageItem::GNSS) {}
bool GnssDriverComponent::Init() {
config::Config gnss_config;
if (!apollo::cyber::common::GetProtoFromFile(config_file_path_,
&gnss_config)) {
monitor_logger_buffer_.ERROR("Unable to load gnss conf file: " +
config_file_path_);
return false;
}
AINFO << "Gnss config: " << gnss_config.DebugString();
raw_stream_.reset(new RawStream(gnss_config, node_));
if (!raw_stream_->Init()) {
monitor_logger_buffer_.ERROR("Init gnss stream failed");
AERROR << "Init gnss stream failed";
return false;
}
raw_stream_->Start();
monitor_logger_buffer_.INFO("gnss is started.");
return true;
}
} // namespace gnss
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers
|
apollo_public_repos/apollo/modules/drivers/gnss/BUILD
|
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
load("//tools/install:install.bzl", "install")
load("//tools:cpplint.bzl", "cpplint")
package(default_visibility = ["//visibility:public"])
GNSS_COPTS = ['-DMODULE_NAME=\\"gnss\\"']
cc_binary(
name = "libgnss_component.so",
linkshared = True,
linkstatic = True,
deps = [":gnss_component_lib"],
)
cc_library(
name = "gnss_component_lib",
srcs = ["gnss_component.cc"],
hdrs = ["gnss_component.h"],
copts = GNSS_COPTS,
alwayslink = True,
deps = [
"//cyber",
"//modules/common_msgs/chassis_msgs:chassis_cc_proto",
"//modules/common_msgs/config_msgs:vehicle_config_cc_proto",
"//modules/common/monitor_log",
"//modules/common_msgs/basic_msgs:drive_state_cc_proto",
"//modules/common_msgs/basic_msgs:vehicle_signal_cc_proto",
"//modules/drivers/gnss/proto:gnss_status_cc_proto",
"//modules/common_msgs/sensor_msgs:ins_cc_proto",
"//modules/drivers/gnss/stream:gnss_stream",
],
)
install(
name = "install",
data_dest = "drivers/addition_data/gnss",
library_dest = "drivers/lib/gnss",
data = [
":runtime_data",
],
targets = [
":libgnss_component.so",
],
)
filegroup(
name = "runtime_data",
srcs = glob([
"conf/*.txt",
"dag/*.dag",
"launch/*.launch",
]),
)
cpplint()
| 0
|
apollo_public_repos/apollo/modules/drivers/gnss
|
apollo_public_repos/apollo/modules/drivers/gnss/proto/BUILD
|
## Auto generated by `proto_build_generator.py`
load("@rules_proto//proto:defs.bzl", "proto_library")
load("@rules_cc//cc:defs.bzl", "cc_proto_library")
load("//tools:python_rules.bzl", "py_proto_library")
package(default_visibility = ["//visibility:public"])
cc_proto_library(
name = "config_cc_proto",
deps = [
":config_proto",
],
)
proto_library(
name = "config_proto",
srcs = ["config.proto"],
)
py_proto_library(
name = "config_py_pb2",
deps = [
":config_proto",
],
)
cc_proto_library(
name = "gnss_status_cc_proto",
deps = [
":gnss_status_proto",
],
)
proto_library(
name = "gnss_status_proto",
srcs = ["gnss_status.proto"],
deps = [
"//modules/common_msgs/basic_msgs:header_proto",
],
)
py_proto_library(
name = "gnss_status_py_pb2",
deps = [
":gnss_status_proto",
"//modules/common_msgs/basic_msgs:header_py_pb2",
],
)
| 0
|
apollo_public_repos/apollo/modules/drivers/gnss
|
apollo_public_repos/apollo/modules/drivers/gnss/proto/config.proto
|
syntax = "proto2";
package apollo.drivers.gnss.config;
message Stream {
enum Format {
UNKNOWN = 0;
NMEA = 1;
RTCM_V2 = 2;
RTCM_V3 = 3;
NOVATEL_TEXT = 10;
NOVATEL_BINARY = 11;
UBLOX_TEXT = 20;
UBLOX_BINARY = 21;
}
optional Format format = 1;
message Serial {
optional bytes device = 1; // Something like "/dev/ttyXXX".
optional int32 baud_rate = 2 [default = 9600];
// In general, we assumes no parity, 8 data bits, 1 stop bit, no
// handshaking, break detection enabled. If not, add more fields here.
}
message Tcp {
optional bytes address = 1; // Something like "192.168.10.6".
optional int32 port = 2 [default = 3001];
}
message Udp {
optional bytes address = 1; // Something like "192.168.10.6".
optional int32 port = 2 [default = 3001];
}
message Ntrip {
optional bytes address = 1; // Something like "1.1.1.1".
optional int32 port = 2 [default = 2101];
optional bytes mount_point = 3; // Something like "demo".
optional bytes user = 4;
optional bytes password = 5;
optional uint32 timeout_s = 6 [default = 30];
}
oneof type {
Serial serial = 2;
Tcp tcp = 3;
Udp udp = 4;
Ntrip ntrip = 5;
}
optional bool push_location = 6;
}
// Device-specific configuration.
message NovatelConfig {
// See Page 75 of SPAN on OEM6 Firmware Reference Manual for details.
optional int32 imu_orientation = 1 [default = 5];
}
message UbloxConfig {}
enum ImuType {
// We currently use the following IMUs. We'll extend this list when a new IMU
// is introduced.
IMAR_FSAS = 13; // iMAR iIMU-FSAS
ISA100C = 26; // Northrop Grumman Litef ISA-100C
ADIS16488 = 31; // Analog Devices ADIS16488
STIM300 = 32; // Sensonor STIM300
ISA100 = 34; // Northrop Grumman Litef ISA-100
ISA100_400HZ = 38; // Northrop Grumman Litef ISA-100
ISA100C_400HZ = 39; // Northrop Grumman Litef ISA-100
CPT_XW5651 = 40; // IMU@SPAN-CPT, and XingWangYuda 5651
G320N = 41; // EPSON G320N
UM442 = 42; // UM442
IAM20680 = 57; // InvenSense-IAM20680
}
message TF {
optional string frame_id = 1 [default = "world"];
optional string child_frame_id = 2 [default = "novatel"];
optional bool enable = 3 [default = false];
}
message Config {
// The driver reads data from this port. This port should always be provided.
optional Stream data = 1;
// If given, the driver sends commands to this port. If not given, the driver
// sends commands to the data port.
optional Stream command = 2;
// The driver gets RTK correction data from this remote port. Usually this is
// an NTRIP port.
optional Stream rtk_from = 3;
// If given, the driver sends RTK correction data to this port. If not given,
// the driver sends RTK correction data to the data port.
optional Stream rtk_to = 4;
repeated bytes login_commands = 5;
repeated bytes logout_commands = 6;
oneof device_config {
NovatelConfig novatel_config = 7;
UbloxConfig ublox_config = 8;
}
enum RtkSolutionType {
RTK_RECEIVER_SOLUTION = 1;
RTK_SOFTWARE_SOLUTION = 2;
}
optional RtkSolutionType rtk_solution_type = 9;
optional ImuType imu_type = 10;
optional string proj4_text = 11;
optional TF tf = 12;
// If given, the driver will send velocity info to novatel with command stream
optional string wheel_parameters = 13;
optional string gpsbin_folder = 14;
}
| 0
|
apollo_public_repos/apollo/modules/drivers/gnss
|
apollo_public_repos/apollo/modules/drivers/gnss/proto/gnss_status.proto
|
syntax = "proto2";
package apollo.drivers.gnss;
import "modules/common_msgs/basic_msgs/header.proto";
message StreamStatus {
optional apollo.common.Header header = 1;
enum Type {
DISCONNECTED = 0;
CONNECTED = 1;
}
optional Type ins_stream_type = 2 [default = DISCONNECTED];
optional Type rtk_stream_in_type = 3 [default = DISCONNECTED];
optional Type rtk_stream_out_type = 4 [default = DISCONNECTED];
}
message InsStatus {
optional apollo.common.Header header = 1;
enum Type {
// Invalid solution due to insufficient observations, no initial GNSS, ...
INVALID = 0;
// Use with caution. The covariance matrix may be unavailable or incorrect.
// High-variance result due to aligning, insufficient vehicle dynamics, ...
CONVERGING = 1;
// Safe to use. The INS has fully converged.
GOOD = 2;
}
optional Type type = 2 [default = INVALID];
}
message GnssStatus {
optional apollo.common.Header header = 1;
optional bool solution_completed = 2 [default = false];
optional uint32 solution_status = 3 [default = 0];
optional uint32 position_type = 4 [default = 0];
// Number of satellites in position solution.
optional int32 num_sats = 5 [default = 0];
}
| 0
|
apollo_public_repos/apollo/modules/drivers/gnss
|
apollo_public_repos/apollo/modules/drivers/gnss/test/parser_cli.cc
|
/******************************************************************************
* Copyright 2018 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
// A command-line interface (CLI) tool of parser. It parses a binary log file.
// It is supposed to be
// used for verifying if the parser works properly.
#include <fstream>
#include <iostream>
#include <memory>
#include "cyber/cyber.h"
#include "cyber/init.h"
#include "cyber/record/record_reader.h"
#include "modules/drivers/gnss/parser/data_parser.h"
#include "modules/drivers/gnss/proto/config.pb.h"
#include "modules/drivers/gnss/stream/stream.h"
namespace apollo {
namespace drivers {
namespace gnss {
constexpr size_t BUFFER_SIZE = 128;
void ParseBin(const char* filename, DataParser* parser) {
std::ios::sync_with_stdio(false);
std::ifstream f(filename, std::ifstream::binary);
char b[BUFFER_SIZE];
while (f) {
f.read(b, BUFFER_SIZE);
std::string msg(reinterpret_cast<const char*>(b), f.gcount());
parser->ParseRawData(msg);
}
}
void ParseRecord(const char* filename, DataParser* parser) {
cyber::record::RecordReader reader(filename);
cyber::record::RecordMessage message;
while (reader.ReadMessage(&message)) {
if (message.channel_name == "/apollo/sensor/gnss/raw_data") {
apollo::drivers::gnss::RawData msg;
msg.ParseFromString(message.content);
parser->ParseRawData(msg.data());
}
std::this_thread::sleep_for(std::chrono::milliseconds(2));
}
}
void Parse(const char* filename, const char* file_type,
const std::shared_ptr<::apollo::cyber::Node>& node) {
std::string type = std::string(file_type);
config::Config config;
if (!apollo::cyber::common::GetProtoFromFile(
std::string("/apollo/modules/drivers/gnss/conf/gnss_conf.pb.txt"),
&config)) {
std::cout << "Unable to load gnss conf file";
}
DataParser* parser = new DataParser(config, node);
parser->Init();
if (type == "bin") {
ParseBin(filename, parser);
} else if (type == "record") {
ParseRecord(filename, parser);
} else {
std::cout << "unknown file type";
}
delete parser;
}
} // namespace gnss
} // namespace drivers
} // namespace apollo
int main(int argc, char** argv) {
if (argc < 3) {
std::cout << "Usage: " << argv[0] << " filename [record|bin]" << std::endl;
return 0;
}
::apollo::cyber::Init("parser_cli");
std::shared_ptr<::apollo::cyber::Node> parser_node(
::apollo::cyber::CreateNode("parser_cli"));
::apollo::drivers::gnss::Parse(argv[1], argv[2], parser_node);
return 0;
}
| 0
|
apollo_public_repos/apollo/modules/drivers/gnss
|
apollo_public_repos/apollo/modules/drivers/gnss/test/BUILD
|
load("@rules_cc//cc:defs.bzl", "cc_binary")
load("//tools:cpplint.bzl", "cpplint")
load("//tools/install:install.bzl", "install")
package(default_visibility = ["//visibility:public"])
install(
name = "install",
runtime_dest = "drivers/bin",
targets = [
":parser_cli",
],
)
cc_binary(
name = "parser_cli",
srcs = ["parser_cli.cc"],
deps = [
"//cyber",
"//modules/drivers/gnss/proto:gnss_status_cc_proto",
"//modules/drivers/gnss/stream:gnss_stream",
"@com_github_gflags_gflags//:gflags",
],
)
cpplint()
| 0
|
apollo_public_repos/apollo/modules/drivers/gnss
|
apollo_public_repos/apollo/modules/drivers/gnss/util/macros.h
|
/******************************************************************************
* Copyright 2017 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
// Commonly-used macro definitions. Some of them are copied from
// https://chromium.googlesource.com/chromium/src/base/+/master/macros.h
#pragma once
#include <cstddef>
// Put this in the declarations for a class to be uncopyable.
#define DISABLE_COPY(TypeName) TypeName(const TypeName &) = delete
// Put this in the declarations for a class to be unassignable.
#define DISABLE_ASSIGN(TypeName) void operator=(const TypeName &) = delete
// A macro to disallow the copy constructor and operator= functions.
// This should be used in the private: declarations for a class.
#define DISABLE_COPY_AND_ASSIGN(TypeName) \
DISABLE_COPY(TypeName); \
DISABLE_ASSIGN(TypeName)
// A macro to disallow all the implicit constructors, namely the
// default constructor, copy constructor and operator= functions.
//
// This should be used in the private: declarations for a class
// that wants to prevent anyone from instantiating it. This is
// especially useful for classes containing only static methods.
#define DISABLE_IMPLICIT_CONSTRUCTORS(TypeName) \
TypeName() = delete; \
DISABLE_COPY_AND_ASSIGN(TypeName)
// Creates a thread-safe singleton.
#define MAKE_SINGLETON(TypeName) \
public: \
static TypeName *Instance() { \
static TypeName Instance; \
return &Instance; \
} \
\
private: \
DISABLE_COPY_AND_ASSIGN(TypeName)
namespace apollo {
// array_size(a) returns the number of elements in a.
template <class T, size_t N>
constexpr size_t array_size(T (&)[N]) {
return N;
}
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/gnss
|
apollo_public_repos/apollo/modules/drivers/gnss/util/time_conversion.h
|
/******************************************************************************
* Copyright 2017 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
// Converts GPS timestamp from/to UNIX system timestamp.
// This helper is considering leap second.
#pragma once
#include <stdint.h>
#include "modules/drivers/gnss/util/macros.h"
namespace apollo {
namespace drivers {
namespace util {
// File expires on: December 2017
// There's two concept about 'time'.
// 1. Unix time : It counts seconds since Jan 1,1970.
// Unix time doesn't include the leap seconds.
//
// 2. GPS time : It counts seconds since Jan 6,1980.
// GPS time does include the leap seconds.
//
// Leap seconds was added in every a few years, See details:
// http://tycho.usno.navy.mil/leapsec.html
// https://en.wikipedia.org/wiki/Leap_second
//
/* leap_seconds table since 1980.
+======+========+========+======+========+========+
| Year | Jun 30 | Dec 31 | Year | Jun 30 | Dec 31 |
+======+========+========+======+========+========+
| 1980 | (already +19) | 1994 | +1 | 0 |
+------+--------+--------+------+--------+--------+
| 1981 | +1 | 0 | 1995 | 0 | +1 |
+------+--------+--------+------+--------+--------+
| 1982 | +1 | 0 | 1997 | +1 | 0 |
+------+--------+--------+------+--------+--------+
| 1983 | +1 | 0 | 1998 | 0 | +1 |
+------+--------+--------+------+--------+--------+
| 1985 | +1 | 0 | 2005 | 0 | +1 |
+------+--------+--------+------+--------+--------+
| 1987 | 0 | +1 | 2008 | 0 | +1 |
+------+--------+--------+------+--------+--------+
| 1989 | 0 | +1 | 2012 | +1 | 0 |
+------+--------+--------+------+--------+--------+
| 1990 | 0 | +1 | 2015 | +1 | 0 |
+------+--------+--------+------+--------+--------+
| 1992 | +1 | 0 | 2016 | 0 | +1 |
+------+--------+--------+------+--------+--------+
| 1993 | +1 | 0 | 2017 | 0 | 0 |
+------+--------+--------+------+--------+--------+
Current TAI - UTC = 37. (mean that: 2017 - 1970/01/01 = 37 seconds)
*/
// We build a lookup table to describe relationship that between UTC and
// Leap_seconds.
//
// Column1: UTC time diff (second).
// Shell Example:
// date +%s -d"Jan 1, 2017 00:00:00"
// return 1483257600.
//
// date +%s -d"Jan 1, 1970 00:00:00"
// return 28800.
//
// The diff between 1970/01/01 and 2017/01/01 is 1483228800.
// (1483257600-28800)
//
// Column2: Leap seconds diff with GPS basetime(Jan 6,1980).
// We Know that The leap_seconds have been already added 37 seconds
// util now(2017).
// So we can calculate leap_seconds diff between GPS (from Jan 6,1980)
// and UTC time.
// calc with the formula.
static const int32_t LEAP_SECONDS[][2] = {
{1483228800, 18}, // 2017/01/01
{1435708800, 17}, // 2015/07/01
{1341100800, 16}, // 2012/07/01
{1230768000, 15}, // 2009/01/01
{1136073600, 14}, // 2006/01/01
{915148800, 13}, // 1999/01/01
{867711600, 12}, // 1997/07/01
{820480320, 11}, // 1996/01/01 ;)
//....
//..
// etc.
};
// seconds that UNIX time afront of GPS, without leap seconds.
// Shell:
// time1 = date +%s -d"Jan 6, 1980 00:00:00"
// time2 = date +%s -d"Jan 1, 1970 00:00:00"
// dif_tick = time1-time2
// 315964800 = 315993600 - 28800
const int32_t GPS_AND_SYSTEM_DIFF_SECONDS = 315964800;
template <typename T>
T unix2gps(const T unix_seconds) {
for (size_t i = 0; i < array_size(LEAP_SECONDS); ++i) {
if (unix_seconds >= LEAP_SECONDS[i][0]) {
return unix_seconds - (GPS_AND_SYSTEM_DIFF_SECONDS - LEAP_SECONDS[i][1]);
}
}
return static_cast<T>(0);
}
template <typename T>
T gps2unix(const T gps_seconds) {
for (size_t i = 0; i < array_size(LEAP_SECONDS); ++i) {
T result = gps_seconds + (GPS_AND_SYSTEM_DIFF_SECONDS - LEAP_SECONDS[i][1]);
if (result >= LEAP_SECONDS[i][0]) {
return result;
}
}
return static_cast<T>(0);
}
} // namespace util
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/gnss
|
apollo_public_repos/apollo/modules/drivers/gnss/util/BUILD
|
load("@rules_cc//cc:defs.bzl", "cc_library")
load("//tools:cpplint.bzl", "cpplint")
package(default_visibility = ["//visibility:public"])
cc_library(
name = "gnss_util",
srcs = [],
hdrs = [
"macros.h",
"time_conversion.h",
],
)
cpplint()
| 0
|
apollo_public_repos/apollo/modules/drivers/gnss
|
apollo_public_repos/apollo/modules/drivers/gnss/launch/gnss.launch
|
<cyber>
<module>
<name>gnss</name>
<dag_conf>/apollo/modules/drivers/gnss/dag/gnss.dag</dag_conf>
<process_name>gnss</process_name>
</module>
</cyber>
| 0
|
apollo_public_repos/apollo/modules/drivers/gnss
|
apollo_public_repos/apollo/modules/drivers/gnss/dag/gnss.dag
|
# Define all coms in DAG streaming.
module_config {
module_library : "/apollo/bazel-bin/modules/drivers/gnss/libgnss_component.so"
components {
class_name : "GnssDriverComponent"
config {
name : "gnss"
config_file_path : "/apollo/modules/drivers/gnss/conf/gnss_conf.pb.txt"
}
}
}
| 0
|
apollo_public_repos/apollo/modules/drivers/gnss
|
apollo_public_repos/apollo/modules/drivers/gnss/stream/tcp_stream.cc
|
/******************************************************************************
* Copyright 2017 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include <arpa/inet.h>
#include <fcntl.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
#include <cerrno>
#include <cinttypes>
#include <iostream>
#include "cyber/cyber.h"
#include "modules/drivers/gnss/stream/stream.h"
#include "modules/drivers/gnss/stream/tcp_stream.h"
namespace apollo {
namespace drivers {
namespace gnss {
TcpStream::TcpStream(const char* address, uint16_t port, uint32_t timeout_usec,
bool auto_reconnect)
: sockfd_(-1), errno_(0), auto_reconnect_(auto_reconnect) {
peer_addr_ = inet_addr(address);
peer_port_ = htons(port);
timeout_usec_ = timeout_usec;
}
TcpStream::~TcpStream() { this->close(); }
void TcpStream::open() {
int fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (fd < 0) {
// error
AERROR << "create socket failed, errno: " << errno << ", "
<< strerror(errno);
return;
}
sockfd_ = fd;
}
bool TcpStream::InitSocket() {
if (sockfd_ < 0) {
return false;
}
// block or not block
if (timeout_usec_ != 0) {
int flags = fcntl(sockfd_, F_GETFL, 0);
if (flags == -1) {
::close(sockfd_);
AERROR << "fcntl get flag failed, error: " << strerror(errno);
return false;
}
if (fcntl(sockfd_, F_SETFL, flags & ~O_NONBLOCK) == -1) {
::close(sockfd_);
AERROR << "fcntl set block failed, error: " << strerror(errno);
return false;
}
timeval block_to = {timeout_usec_ / 1000000, timeout_usec_ % 1000000};
if (setsockopt(sockfd_, SOL_SOCKET, SO_RCVTIMEO, &block_to,
sizeof(block_to)) < 0) {
::close(sockfd_);
AERROR << "setsockopt set rcv timeout failed, error: " << strerror(errno);
return false;
}
if (setsockopt(sockfd_, SOL_SOCKET, SO_SNDTIMEO, &block_to,
sizeof(block_to)) < 0) {
::close(sockfd_);
AERROR << "setsockopt set snd timeout failed, error: " << strerror(errno);
return false;
}
} else {
int flags = fcntl(sockfd_, F_GETFL, 0);
if (flags == -1) {
::close(sockfd_);
AERROR << "fcntl get flag failed, error: " << strerror(errno);
return false;
}
if (fcntl(sockfd_, F_SETFL, flags | O_NONBLOCK) == -1) {
::close(sockfd_);
AERROR << "fcntl set non block failed, error: " << strerror(errno);
return false;
}
}
// disable Nagle
int ret = 0;
int enable = 1;
ret = setsockopt(sockfd_, IPPROTO_TCP, TCP_NODELAY,
reinterpret_cast<void*>(&enable), sizeof(enable));
if (ret == -1) {
::close(sockfd_);
AERROR << "setsockopt disable Nagle failed, errno: " << errno << ", "
<< strerror(errno);
return false;
}
return true;
}
void TcpStream::close() {
if (sockfd_ > 0) {
::close(sockfd_);
sockfd_ = -1;
status_ = Stream::Status::DISCONNECTED;
}
}
bool TcpStream::Reconnect() {
if (auto_reconnect_) {
Disconnect();
if (Connect()) {
return true;
}
}
return false;
}
bool TcpStream::Connect() {
if (sockfd_ < 0) {
this->open();
if (sockfd_ < 0) {
// error
return false;
}
}
if (status_ == Stream::Status::CONNECTED) {
return true;
}
fd_set fds;
timeval timeo = {10, 0};
int ret = 0;
sockaddr_in peer_addr;
bzero(&peer_addr, sizeof(peer_addr));
peer_addr.sin_family = AF_INET;
peer_addr.sin_port = peer_port_;
peer_addr.sin_addr.s_addr = peer_addr_;
int fd_flags = fcntl(sockfd_, F_GETFL);
if (fd_flags < 0 || fcntl(sockfd_, F_SETFL, fd_flags | O_NONBLOCK) < 0) {
AERROR << "Failed to set noblock, error: " << strerror(errno);
return false;
}
while ((ret = ::connect(sockfd_, reinterpret_cast<sockaddr*>(&peer_addr),
sizeof(peer_addr))) < 0) {
if (errno == EINTR) {
AINFO << "Tcp connect return EINTR, continue.";
continue;
} else {
if ((errno != EISCONN) && (errno != EINPROGRESS) && (errno != EALREADY)) {
status_ = Stream::Status::ERROR;
errno_ = errno;
AERROR << "Connect failed, error: " << strerror(errno);
return false;
}
FD_ZERO(&fds);
FD_SET(sockfd_, &fds);
ret = select(sockfd_ + 1, NULL, &fds, NULL, &timeo);
if (ret < 0) {
status_ = Stream::Status::ERROR;
errno_ = errno;
AERROR << "Wait connect failed, error: " << strerror(errno);
return false;
} else if (ret == 0) {
AINFO << "Tcp connect timeout.";
return false;
} else if (FD_ISSET(sockfd_, &fds)) {
int error = 0;
socklen_t len = sizeof(int);
if (getsockopt(sockfd_, SOL_SOCKET, SO_ERROR, &error, &len) < 0) {
status_ = Stream::Status::ERROR;
errno_ = errno;
AERROR << "Getsockopt failed, error: " << strerror(errno);
return false;
}
if (error != 0) {
status_ = Stream::Status::ERROR;
errno_ = errno;
AERROR << "Socket error: " << strerror(errno);
return false;
}
// connect successfully
break;
} else {
status_ = Stream::Status::ERROR;
errno_ = errno;
AERROR << "Should not be here.";
return false;
}
}
}
if (!InitSocket()) {
close();
status_ = Stream::Status::ERROR;
errno_ = errno;
AERROR << "Failed to init socket.";
return false;
}
AINFO << "Tcp connect success.";
status_ = Stream::Status::CONNECTED;
Login();
return true;
}
bool TcpStream::Disconnect() {
if (sockfd_ < 0) {
// not open
return false;
}
this->close();
return true;
}
size_t TcpStream::read(uint8_t* buffer, size_t max_length) {
ssize_t ret = 0;
if (status_ != Stream::Status::CONNECTED) {
Reconnect();
if (status_ != Stream::Status::CONNECTED) {
return 0;
}
}
if (!Readable(10000)) {
return 0;
}
while ((ret = ::recv(sockfd_, buffer, max_length, 0)) < 0) {
if (errno == EINTR) {
continue;
} else {
// error
if (errno != EAGAIN) {
status_ = Stream::Status::ERROR;
errno_ = errno;
AERROR << "Read errno " << errno << ", error " << strerror(errno);
}
}
return 0;
}
if (ret == 0) {
status_ = Stream::Status::ERROR;
errno_ = errno;
AERROR << "Remote closed.";
if (Reconnect()) {
AINFO << "Reconnect tcp success.";
}
}
return ret;
}
size_t TcpStream::write(const uint8_t* buffer, size_t length) {
size_t total_nsent = 0;
if (status_ != Stream::Status::CONNECTED) {
Reconnect();
if (status_ != Stream::Status::CONNECTED) {
return 0;
}
}
while (length > 0) {
ssize_t nsent = ::send(sockfd_, buffer, length, 0);
if (nsent < 0) {
if (errno == EINTR) {
continue;
} else {
// error
if (errno == EPIPE || errno == ECONNRESET) {
status_ = Stream::Status::DISCONNECTED;
errno_ = errno;
} else if (errno != EAGAIN) {
status_ = Stream::Status::ERROR;
errno_ = errno;
}
return total_nsent;
}
}
total_nsent += nsent;
length -= nsent;
buffer += nsent;
}
return total_nsent;
}
bool TcpStream::Readable(uint32_t timeout_us) {
// Setup a select call to block for serial data or a timeout
timespec timeout_ts;
fd_set readfds;
FD_ZERO(&readfds);
FD_SET(sockfd_, &readfds);
timeout_ts.tv_sec = timeout_us / 1000000;
timeout_ts.tv_nsec = (timeout_us % 1000000) * 1000;
int r = pselect(sockfd_ + 1, &readfds, NULL, NULL, &timeout_ts, NULL);
if (r < 0) {
status_ = Stream::Status::ERROR;
errno_ = errno;
AERROR << "Failed to wait tcp data: " << errno << ", " << strerror(errno);
return false;
} else if (r == 0 || !FD_ISSET(sockfd_, &readfds)) {
return false;
}
// Data available to read.
return true;
}
Stream* Stream::create_tcp(const char* address, uint16_t port,
uint32_t timeout_usec) {
return new TcpStream(address, port, timeout_usec);
}
} // namespace gnss
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/gnss
|
apollo_public_repos/apollo/modules/drivers/gnss/stream/ntrip_stream.cc
|
/******************************************************************************
* Copyright 2017 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include <unistd.h>
#include <iostream>
#include <mutex>
#include "cyber/cyber.h"
#include "modules/common/util/string_util.h"
#include "modules/common/util/util.h"
#include "modules/drivers/gnss/stream/stream.h"
#include "modules/drivers/gnss/stream/tcp_stream.h"
namespace {
template <typename T>
constexpr bool is_zero(T value) {
return value == static_cast<T>(0);
}
} // namespace
namespace apollo {
namespace drivers {
namespace gnss {
class NtripStream : public Stream {
public:
NtripStream(const std::string& address, uint16_t port,
const std::string& mountpoint, const std::string& user,
const std::string& passwd, uint32_t timeout_s);
~NtripStream();
virtual size_t read(uint8_t* buffer, size_t max_length);
virtual size_t write(const uint8_t* data, size_t length);
virtual bool Connect();
virtual bool Disconnect();
private:
void Reconnect();
bool is_login_ = false;
const std::string mountpoint_;
const std::string write_data_prefix_;
const std::string login_data_;
double timeout_s_ = 60.0;
double data_active_s_ = 0.0;
std::unique_ptr<TcpStream> tcp_stream_;
std::mutex internal_mutex_;
};
NtripStream::NtripStream(const std::string& address, uint16_t port,
const std::string& mountpoint, const std::string& user,
const std::string& passwd, uint32_t timeout_s)
: mountpoint_(mountpoint),
write_data_prefix_("GET /" + mountpoint +
" HTTP/1.0\r\n"
"User-Agent: NTRIP gnss_driver/0.0\r\n"
"accept: */* \r\n\r\n"),
login_data_("GET /" + mountpoint +
" HTTP/1.0\r\n"
"User-Agent: NTRIP gnss_driver/0.0\r\n"
"accept: */* \r\n"
"Authorization: Basic " +
common::util::EncodeBase64(user + ":" + passwd) + "\r\n\r\n"),
timeout_s_(timeout_s),
tcp_stream_(new TcpStream(address.c_str(), port, 0, false)) {}
NtripStream::~NtripStream() { this->Disconnect(); }
bool NtripStream::Connect() {
if (is_login_) {
return true;
}
if (!tcp_stream_) {
AERROR << "New tcp stream failed.";
return true;
}
if (!tcp_stream_->Connect()) {
status_ = Stream::Status::DISCONNECTED;
AERROR << "Tcp connect failed.";
return false;
}
uint8_t buffer[2048];
size_t size = 0;
size_t try_times = 0;
size = tcp_stream_->write(
reinterpret_cast<const uint8_t*>(login_data_.data()), login_data_.size());
if (size != login_data_.size()) {
tcp_stream_->Disconnect();
status_ = Stream::Status::ERROR;
AERROR << "Send ntrip request failed.";
return false;
}
bzero(buffer, sizeof(buffer));
AINFO << "Read ntrip response.";
size = tcp_stream_->read(buffer, sizeof(buffer) - 1);
while ((size == 0) && (try_times < 3)) {
sleep(1);
size = tcp_stream_->read(buffer, sizeof(buffer) - 1);
++try_times;
}
if (!size) {
tcp_stream_->Disconnect();
status_ = Stream::Status::DISCONNECTED;
AERROR << "No response from ntripcaster.";
return false;
}
if (std::strstr(reinterpret_cast<char*>(buffer), "ICY 200 OK\r\n")) {
status_ = Stream::Status::CONNECTED;
is_login_ = true;
AINFO << "Ntrip login successfully.";
return true;
}
if (std::strstr(reinterpret_cast<char*>(buffer), "SOURCETABLE 200 OK\r\n")) {
AERROR << "Mountpoint " << mountpoint_ << " not exist.";
}
if (std::strstr(reinterpret_cast<char*>(buffer), "HTTP/")) {
AERROR << "Authentication failed.";
}
AINFO << "No expect data.";
AINFO << "Recv data length: " << size;
// AINFO << "Data from server: " << reinterpret_cast<char*>(buffer);
tcp_stream_->Disconnect();
status_ = Stream::Status::ERROR;
return false;
}
bool NtripStream::Disconnect() {
if (is_login_) {
bool ret = tcp_stream_->Disconnect();
if (!ret) {
return false;
}
status_ = Stream::Status::DISCONNECTED;
is_login_ = false;
}
return true;
}
void NtripStream::Reconnect() {
AINFO << "Reconnect ntrip caster.";
std::unique_lock<std::mutex> lock(internal_mutex_);
Disconnect();
Connect();
if (status_ != Stream::Status::CONNECTED) {
AINFO << "Reconnect ntrip caster failed.";
return;
}
data_active_s_ = cyber::Time::Now().ToSecond();
AINFO << "Reconnect ntrip caster success.";
}
size_t NtripStream::read(uint8_t* buffer, size_t max_length) {
if (!tcp_stream_) {
return 0;
}
size_t ret = 0;
if (tcp_stream_->get_status() != Stream::Status::CONNECTED) {
Reconnect();
if (status_ != Stream::Status::CONNECTED) {
return 0;
}
}
if (is_zero(data_active_s_)) {
data_active_s_ = cyber::Time::Now().ToSecond();
}
ret = tcp_stream_->read(buffer, max_length);
if (ret) {
data_active_s_ = cyber::Time::Now().ToSecond();
}
// timeout detect
if ((cyber::Time::Now().ToSecond() - data_active_s_) > timeout_s_) {
AINFO << "Ntrip timeout.";
Reconnect();
}
return ret;
}
size_t NtripStream::write(const uint8_t* buffer, size_t length) {
if (!tcp_stream_) {
return 0;
}
std::unique_lock<std::mutex> lock(internal_mutex_, std::defer_lock);
if (!lock.try_lock()) {
AINFO << "Try lock failed.";
return 0;
}
if (tcp_stream_->get_status() != Stream::Status::CONNECTED) {
return 0;
}
std::string data(reinterpret_cast<const char*>(buffer), length);
data = write_data_prefix_ + data;
size_t ret = tcp_stream_->write(reinterpret_cast<const uint8_t*>(data.data()),
data.size());
if (ret != data.size()) {
AERROR << "Send ntrip data size " << data.size() << ", return " << ret;
status_ = Stream::Status::ERROR;
return 0;
}
return length;
}
Stream* Stream::create_ntrip(const std::string& address, uint16_t port,
const std::string& mountpoint,
const std::string& user, const std::string& passwd,
uint32_t timeout_s) {
return new NtripStream(address, port, mountpoint, user, passwd, timeout_s);
}
} // namespace gnss
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/gnss
|
apollo_public_repos/apollo/modules/drivers/gnss/stream/serial_stream.cc
|
/******************************************************************************
* Copyright 2017 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include <fcntl.h>
#include <linux/netlink.h>
#include <linux/serial.h>
#include <sys/ioctl.h>
#include <sys/select.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <termios.h>
#include <unistd.h>
#include <cerrno>
#include <cstring>
#include <ctime>
#include <thread>
#include "cyber/cyber.h"
#include "modules/drivers/gnss/stream/stream.h"
namespace apollo {
namespace drivers {
namespace gnss {
speed_t get_serial_baudrate(uint32_t rate) {
switch (rate) {
case 9600:
return B9600;
case 19200:
return B19200;
case 38400:
return B38400;
case 57600:
return B57600;
case 115200:
return B115200;
case 230400:
return B230400;
case 460800:
return B460800;
case 921600:
return B921600;
default:
return 0;
}
}
class SerialStream : public Stream {
public:
SerialStream(const char* device_name, speed_t baud_rate,
uint32_t timeout_usec);
~SerialStream();
virtual bool Connect();
virtual bool Disconnect();
virtual size_t read(uint8_t* buffer, size_t max_length);
virtual size_t write(const uint8_t* data, size_t length);
private:
SerialStream() {}
void open();
void close();
bool configure_port(int fd);
bool wait_readable(uint32_t timeout_us);
bool wait_writable(uint32_t timeout_us);
void check_remove();
std::string device_name_;
speed_t baud_rate_;
uint32_t bytesize_;
uint32_t parity_;
uint32_t stopbits_;
uint32_t flowcontrol_;
uint32_t byte_time_us_;
uint32_t timeout_usec_;
int fd_;
int errno_;
bool is_open_;
};
SerialStream::SerialStream(const char* device_name, speed_t baud_rate,
uint32_t timeout_usec)
: device_name_(device_name),
baud_rate_(baud_rate),
bytesize_(8),
parity_(0),
stopbits_(1),
flowcontrol_(0),
timeout_usec_(timeout_usec),
fd_(-1),
errno_(0),
is_open_(false) {
if (device_name_.empty()) {
status_ = Stream::Status::ERROR;
}
}
SerialStream::~SerialStream() { this->close(); }
void SerialStream::open(void) {
int fd = 0;
fd = ::open(device_name_.c_str(), O_RDWR | O_NOCTTY | O_NONBLOCK);
if (fd == -1) {
switch (errno) {
case EINTR:
// Recurse because this is a recoverable error.
return open();
case ENFILE:
case EMFILE:
default:
AERROR << "Open device " << device_name_
<< " failed, error: " << strerror(errno);
return;
}
}
if (!configure_port(fd)) {
::close(fd);
return;
}
fd_ = fd;
is_open_ = true;
}
bool SerialStream::configure_port(int fd) {
if (fd < 0) {
return false;
}
struct termios options; // The options for the file descriptor
if (tcgetattr(fd, &options) == -1) {
AERROR << "tcgetattr failed.";
return false;
}
// set up raw mode / no echo / binary
options.c_cflag |= (tcflag_t)(CLOCAL | CREAD);
options.c_lflag &= (tcflag_t) ~(ICANON | ECHO | ECHOE | ECHOK | ECHONL |
ISIG | IEXTEN); // |ECHOPRT
options.c_oflag &= (tcflag_t) ~(OPOST);
options.c_iflag &= (tcflag_t) ~(INLCR | IGNCR | ICRNL | IGNBRK);
#ifdef IUCLC
options.c_iflag &= (tcflag_t)~IUCLC;
#endif
#ifdef PARMRK
options.c_iflag &= (tcflag_t)~PARMRK;
#endif
#ifdef BSD_SOURCE_ // depend glibc
::cfsetspeed(&options, baud_rate_);
#else
::cfsetispeed(&options, baud_rate_);
::cfsetospeed(&options, baud_rate_);
#endif
// setup char len
options.c_cflag &= (tcflag_t)~CSIZE;
// eight bits
options.c_cflag |= CS8;
// setup stopbits:stopbits_one
options.c_cflag &= (tcflag_t) ~(CSTOPB);
// setup parity: parity_none
options.c_iflag &= (tcflag_t) ~(INPCK | ISTRIP);
options.c_cflag &= (tcflag_t) ~(PARENB | PARODD);
// setup flow control : flowcontrol_none
// xonxoff
#ifdef IXANY
options.c_iflag &= (tcflag_t) ~(IXON | IXOFF | IXANY);
#else
options.c_iflag &= (tcflag_t) ~(IXON | IXOFF);
#endif
// rtscts
#ifdef CRTSCTS
options.c_cflag &= static_cast<uint64_t>(~(CRTSCTS));
#elif defined CNEW_RTSCTS
options.c_cflag &= static_cast<uint64_t>(~(CNEW_RTSCTS));
#else
#error "OS Support seems wrong."
#endif
// http://www.unixwiz.net/techtips/termios-vmin-vtime.html
// this basically sets the read call up to be a polling read,
// but we are using select to ensure there is data available
// to read before each call, so we should never needlessly poll
options.c_cc[VMIN] = 0;
options.c_cc[VTIME] = 0;
// activate settings
::tcsetattr(fd, TCSANOW, &options);
// Update byte_time_ based on the new settings.
uint32_t bit_time_us = static_cast<uint32_t>(1e6 / 115200);
byte_time_us_ = bit_time_us * (1 + bytesize_ + parity_ + stopbits_);
return true;
}
bool SerialStream::Connect() {
if (!is_open_) {
this->open();
if (!is_open_) {
status_ = Stream::Status::ERROR;
errno_ = errno;
return false;
}
}
if (status_ == Stream::Status::CONNECTED) {
return true;
}
status_ = Stream::Status::CONNECTED;
Login();
return true;
}
void SerialStream::close(void) {
if (is_open_) {
::close(fd_);
fd_ = -1;
is_open_ = false;
status_ = Stream::Status::DISCONNECTED;
}
}
bool SerialStream::Disconnect() {
if (!is_open_) {
// not open
return false;
}
this->close();
return true;
}
void SerialStream::check_remove() {
char data = 0;
ssize_t nsent = ::write(fd_, &data, 0);
if (nsent < 0) {
AERROR << "Serial stream detect write failed, error: " << strerror(errno);
switch (errno) {
case EBADF:
case EIO:
status_ = Stream::Status::DISCONNECTED;
AERROR << "Device " << device_name_ << " removed.";
Disconnect();
break;
}
}
}
size_t SerialStream::read(uint8_t* buffer, size_t max_length) {
if (!is_open_) {
if (!Connect()) {
return 0;
}
AINFO << "Connect " << device_name_ << " success.";
}
ssize_t bytes_read = 0;
ssize_t bytes_current_read = 0;
wait_readable(10000); // wait 10ms
while (max_length > 0) {
bytes_current_read = ::read(fd_, buffer, max_length);
if (bytes_current_read < 0) {
switch (errno) {
case EAGAIN:
case EINVAL:
bytes_current_read = 0;
break;
case EBADF:
case EIO:
AERROR << "Serial stream read data failed, error: "
<< strerror(errno);
Disconnect();
if (Connect()) {
AINFO << "Reconnect " << device_name_ << " success.";
bytes_current_read = 0;
break; // has recoverable
}
default:
AERROR << "Serial stream read data failed, error: " << strerror(errno)
<< ", errno: " << errno;
status_ = Stream::Status::ERROR;
errno_ = errno;
return bytes_read;
}
}
if (bytes_current_read == 0) {
if (!bytes_read) {
check_remove();
return 0;
}
return bytes_read;
}
max_length -= bytes_current_read;
buffer += bytes_current_read;
bytes_read += bytes_current_read;
}
return bytes_read;
}
size_t SerialStream::write(const uint8_t* data, size_t length) {
if (!is_open_) {
if (!Connect()) {
return 0;
}
AINFO << "Connect " << device_name_ << " success.";
}
size_t total_nsent = 0;
size_t delay_times = 0;
while ((length > 0) && (delay_times < 5)) {
ssize_t nsent = ::write(fd_, data, length);
if (nsent < 0) {
AERROR << "Serial stream write data failed, error: " << strerror(errno);
switch (errno) {
case EAGAIN:
case EINVAL:
nsent = 0;
break;
case EBADF:
case EIO:
Disconnect();
if (Connect()) {
AINFO << "Reconnect " << device_name_ << "success.";
nsent = 0;
break; // has recoverable
}
default:
status_ = Stream::Status::ERROR;
errno_ = errno;
return total_nsent;
}
}
if (nsent == 0) {
if (!wait_writable(byte_time_us_)) {
break;
}
++delay_times;
continue;
}
total_nsent += nsent;
length -= nsent;
data += nsent;
}
return total_nsent;
}
bool SerialStream::wait_readable(uint32_t timeout_us) {
// Setup a select call to block for serial data or a timeout
timespec timeout_ts;
fd_set readfds;
FD_ZERO(&readfds);
FD_SET(fd_, &readfds);
timeout_ts.tv_sec = timeout_us / 1000000;
timeout_ts.tv_nsec = (timeout_us % 1000000) * 1000;
int r = pselect(fd_ + 1, &readfds, NULL, NULL, &timeout_ts, NULL);
if (r <= 0) {
return false;
}
// This shouldn't happen, if r > 0 our fd has to be in the list!
if (!FD_ISSET(fd_, &readfds)) {
return false;
}
// Data available to read.
return true;
}
bool SerialStream::wait_writable(uint32_t timeout_us) {
// Setup a select call to block for serial data or a timeout
timespec timeout_ts;
fd_set writefds;
FD_ZERO(&writefds);
FD_SET(fd_, &writefds);
timeout_ts.tv_sec = timeout_us / 1000000;
timeout_ts.tv_nsec = (timeout_us % 1000000) * 1000;
int r = pselect(fd_ + 1, NULL, &writefds, NULL, &timeout_ts, NULL);
if (r <= 0) {
return false;
}
// This shouldn't happen, if r > 0 our fd has to be in the list!
if (!FD_ISSET(fd_, &writefds)) {
return false;
}
// Data available to write.
return true;
}
Stream* Stream::create_serial(const char* device_name, uint32_t baud_rate,
uint32_t timeout_usec) {
speed_t baud = get_serial_baudrate(baud_rate);
return baud == 0 ? nullptr
: new SerialStream(device_name, baud, timeout_usec);
}
} // namespace gnss
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/gnss
|
apollo_public_repos/apollo/modules/drivers/gnss/stream/raw_stream.cc
|
/******************************************************************************
* Copyright 2017 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include <cmath>
#include <ctime>
#include <memory>
#include <thread>
#include <vector>
#include "absl/strings/str_cat.h"
#include "cyber/cyber.h"
#include "modules/common/adapters/adapter_gflags.h"
#include "modules/common/util/message_util.h"
#include "modules/drivers/gnss/proto/config.pb.h"
#include "modules/drivers/gnss/stream/raw_stream.h"
#include "modules/drivers/gnss/stream/stream.h"
namespace apollo {
namespace drivers {
namespace gnss {
using apollo::canbus::Chassis;
void switch_stream_status(const apollo::drivers::gnss::Stream::Status &status,
StreamStatus_Type *report_status_type) {
switch (status) {
case apollo::drivers::gnss::Stream::Status::CONNECTED:
*report_status_type = StreamStatus::CONNECTED;
break;
case apollo::drivers::gnss::Stream::Status::DISCONNECTED:
*report_status_type = StreamStatus::DISCONNECTED;
break;
case apollo::drivers::gnss::Stream::Status::ERROR:
default:
*report_status_type = StreamStatus::DISCONNECTED;
break;
}
}
std::string getLocalTimeFileStr(const std::string &gpsbin_folder) {
time_t it = std::time(0);
char local_time_char[64];
std::tm time_tm;
localtime_r(&it, &time_tm);
std::strftime(local_time_char, sizeof(local_time_char), "%Y%m%d_%H%M%S",
&time_tm);
std::string local_time_str = local_time_char;
ACHECK(cyber::common::EnsureDirectory(gpsbin_folder))
<< "gbsbin folder : " << gpsbin_folder << " create fail";
std::string local_time_file_str =
gpsbin_folder + "/" + local_time_str + ".bin";
return local_time_file_str;
}
Stream *create_stream(const config::Stream &sd) {
switch (sd.type_case()) {
case config::Stream::kSerial:
if (!sd.serial().has_device()) {
AERROR << "Serial def has no device field.";
return nullptr;
}
if (!sd.serial().has_baud_rate()) {
AERROR << "Serial def has no baud_rate field. Use default baud rate "
<< sd.serial().baud_rate();
return nullptr;
}
return Stream::create_serial(sd.serial().device().c_str(),
sd.serial().baud_rate());
case config::Stream::kTcp:
if (!sd.tcp().has_address()) {
AERROR << "tcp def has no address field.";
return nullptr;
}
if (!sd.tcp().has_port()) {
AERROR << "tcp def has no port field.";
return nullptr;
}
return Stream::create_tcp(sd.tcp().address().c_str(),
static_cast<uint16_t>(sd.tcp().port()));
case config::Stream::kUdp:
if (!sd.udp().has_address()) {
AERROR << "tcp def has no address field.";
return nullptr;
}
if (!sd.udp().has_port()) {
AERROR << "tcp def has no port field.";
return nullptr;
}
return Stream::create_udp(sd.udp().address().c_str(),
static_cast<uint16_t>(sd.udp().port()));
case config::Stream::kNtrip:
if (!sd.ntrip().has_address()) {
AERROR << "ntrip def has no address field.";
return nullptr;
}
if (!sd.ntrip().has_port()) {
AERROR << "ntrip def has no port field.";
return nullptr;
}
if (!sd.ntrip().has_mount_point()) {
AERROR << "ntrip def has no mount point field.";
return nullptr;
}
if (!sd.ntrip().has_user()) {
AERROR << "ntrip def has no user field.";
return nullptr;
}
if (!sd.ntrip().has_password()) {
AERROR << "ntrip def has no passwd field.";
return nullptr;
}
return Stream::create_ntrip(
sd.ntrip().address(), static_cast<uint16_t>(sd.ntrip().port()),
sd.ntrip().mount_point(), sd.ntrip().user(), sd.ntrip().password(),
sd.ntrip().timeout_s());
default:
return nullptr;
}
}
RawStream::RawStream(const config::Config &config,
const std::shared_ptr<apollo::cyber::Node> &node)
: config_(config), node_(node) {
data_parser_ptr_.reset(new DataParser(config_, node_));
rtcm_parser_ptr_.reset(new RtcmParser(config_, node_));
}
RawStream::~RawStream() {
this->Logout();
this->Disconnect();
if (gpsbin_stream_ != nullptr) {
gpsbin_stream_->close();
}
if (data_thread_ptr_ != nullptr && data_thread_ptr_->joinable()) {
data_thread_ptr_->join();
}
if (rtk_thread_ptr_ != nullptr && rtk_thread_ptr_->joinable()) {
rtk_thread_ptr_->join();
}
}
bool RawStream::Init() {
CHECK_NOTNULL(data_parser_ptr_);
CHECK_NOTNULL(rtcm_parser_ptr_);
if (!data_parser_ptr_->Init()) {
AERROR << "Init data parser failed.";
return false;
}
if (!rtcm_parser_ptr_->Init()) {
AERROR << "Init rtcm parser failed.";
return false;
}
stream_status_.set_ins_stream_type(StreamStatus::DISCONNECTED);
stream_status_.set_rtk_stream_in_type(StreamStatus::DISCONNECTED);
stream_status_.set_rtk_stream_out_type(StreamStatus::DISCONNECTED);
stream_writer_ = node_->CreateWriter<StreamStatus>(FLAGS_stream_status_topic);
common::util::FillHeader("gnss", &stream_status_);
stream_writer_->Write(stream_status_);
// Creates streams.
Stream *s = nullptr;
if (!config_.has_data()) {
AINFO << "Error: Config file must provide the data stream.";
return false;
}
s = create_stream(config_.data());
if (s == nullptr) {
AERROR << "Failed to create data stream.";
return false;
}
data_stream_.reset(s);
Status *status = new Status();
if (!status) {
AERROR << "Failed to create data stream status.";
return false;
}
data_stream_status_.reset(status);
if (config_.has_command()) {
s = create_stream(config_.command());
if (s == nullptr) {
AERROR << "Failed to create command stream.";
return false;
}
command_stream_.reset(s);
status = new Status();
if (!status) {
AERROR << "Failed to create command stream status.";
return false;
}
command_stream_status_.reset(status);
} else {
command_stream_ = data_stream_;
command_stream_status_ = data_stream_status_;
}
if (config_.has_rtk_from()) {
s = create_stream(config_.rtk_from());
if (s == nullptr) {
AERROR << "Failed to create rtk_from stream.";
return false;
}
in_rtk_stream_.reset(s);
if (config_.rtk_from().has_push_location()) {
push_location_ = config_.rtk_from().push_location();
}
status = new Status();
if (!status) {
AERROR << "Failed to create rtk_from stream status.";
return false;
}
in_rtk_stream_status_.reset(status);
if (config_.has_rtk_to()) {
s = create_stream(config_.rtk_to());
if (s == nullptr) {
AERROR << "Failed to create rtk_to stream.";
return false;
}
out_rtk_stream_.reset(s);
status = new Status();
if (!status) {
AERROR << "Failed to create rtk_to stream status.";
return false;
}
out_rtk_stream_status_.reset(status);
} else {
out_rtk_stream_ = data_stream_;
out_rtk_stream_status_ = data_stream_status_;
}
if (config_.has_rtk_solution_type()) {
if (config_.rtk_solution_type() ==
config::Config::RTK_SOFTWARE_SOLUTION) {
rtk_software_solution_ = true;
}
}
}
if (config_.login_commands().empty()) {
AWARN << "No login_commands in config file.";
}
if (config_.logout_commands().empty()) {
AWARN << "No logout_commands in config file.";
}
// connect and login
if (!Connect()) {
AERROR << "gnss driver connect failed.";
return false;
}
if (!Login()) {
AERROR << "gnss driver login failed.";
return false;
}
const std::string gpsbin_file = getLocalTimeFileStr(config_.gpsbin_folder());
gpsbin_stream_.reset(new std::ofstream(
gpsbin_file, std::ios::app | std::ios::out | std::ios::binary));
stream_writer_ = node_->CreateWriter<StreamStatus>(FLAGS_stream_status_topic);
raw_writer_ = node_->CreateWriter<RawData>(FLAGS_gnss_raw_data_topic);
rtcm_writer_ = node_->CreateWriter<RawData>(FLAGS_rtcm_data_topic);
cyber::ReaderConfig reader_config;
reader_config.channel_name = FLAGS_gnss_raw_data_topic;
reader_config.pending_queue_size = 100;
gpsbin_reader_ = node_->CreateReader<RawData>(
reader_config, [&](const std::shared_ptr<RawData> &raw_data) {
GpsbinCallback(raw_data);
});
chassis_reader_ = node_->CreateReader<Chassis>(
FLAGS_chassis_topic,
[&](const std::shared_ptr<Chassis> &chassis) { chassis_ptr_ = chassis; });
return true;
}
void RawStream::Start() {
data_thread_ptr_.reset(new std::thread(&RawStream::DataSpin, this));
rtk_thread_ptr_.reset(new std::thread(&RawStream::RtkSpin, this));
if (config_.has_wheel_parameters()) {
wheel_velocity_timer_.reset(new cyber::Timer(
1000, [this]() { this->OnWheelVelocityTimer(); }, false));
wheel_velocity_timer_->Start();
}
}
void RawStream::OnWheelVelocityTimer() {
if (chassis_ptr_ == nullptr) {
AINFO << "No chassis message received";
return;
}
auto latency_sec =
cyber::Time::Now().ToSecond() - chassis_ptr_->header().timestamp_sec();
auto latency_ms = std::lround(latency_sec * 1000);
auto speed_cmps = std::lround(chassis_ptr_->speed_mps() * 100);
auto cmd_wheelvelocity = absl::StrCat("WHEELVELOCITY ", latency_ms,
" 100 0 0 0 0 0 ", speed_cmps, "\r\n");
AINFO << "Write command: " << cmd_wheelvelocity;
command_stream_->write(cmd_wheelvelocity);
}
bool RawStream::Connect() {
if (data_stream_) {
if (data_stream_->get_status() != Stream::Status::CONNECTED) {
if (!data_stream_->Connect()) {
AERROR << "data stream connect failed.";
return false;
}
data_stream_status_->status = Stream::Status::CONNECTED;
stream_status_.set_ins_stream_type(StreamStatus::CONNECTED);
}
}
if (command_stream_) {
if (command_stream_->get_status() != Stream::Status::CONNECTED) {
if (!command_stream_->Connect()) {
AERROR << "command stream connect failed.";
return false;
}
command_stream_status_->status = Stream::Status::CONNECTED;
}
}
if (in_rtk_stream_) {
if (in_rtk_stream_->get_status() != Stream::Status::CONNECTED) {
if (!in_rtk_stream_->Connect()) {
AERROR << "in rtk stream connect failed.";
} else {
in_rtk_stream_status_->status = Stream::Status::CONNECTED;
stream_status_.set_rtk_stream_in_type(StreamStatus::CONNECTED);
}
}
} else {
stream_status_.set_rtk_stream_in_type(StreamStatus::CONNECTED);
}
if (out_rtk_stream_) {
if (out_rtk_stream_->get_status() != Stream::Status::CONNECTED) {
if (!out_rtk_stream_->Connect()) {
AERROR << "out rtk stream connect failed.";
} else {
out_rtk_stream_status_->status = Stream::Status::CONNECTED;
stream_status_.set_rtk_stream_out_type(StreamStatus::CONNECTED);
}
}
} else {
stream_status_.set_rtk_stream_out_type(StreamStatus::CONNECTED);
}
return true;
}
bool RawStream::Disconnect() {
if (data_stream_) {
if (data_stream_->get_status() == Stream::Status::CONNECTED) {
if (!data_stream_->Disconnect()) {
AERROR << "data stream disconnect failed.";
return false;
}
}
}
if (command_stream_) {
if (command_stream_->get_status() == Stream::Status::CONNECTED) {
if (!command_stream_->Disconnect()) {
AERROR << "command stream disconnect failed.";
return false;
}
}
}
if (in_rtk_stream_) {
if (in_rtk_stream_->get_status() == Stream::Status::CONNECTED) {
if (!in_rtk_stream_->Disconnect()) {
AERROR << "in rtk stream disconnect failed.";
return false;
}
}
}
if (out_rtk_stream_) {
if (out_rtk_stream_->get_status() == Stream::Status::CONNECTED) {
if (!out_rtk_stream_->Disconnect()) {
AERROR << "out rtk stream disconnect failed.";
return false;
}
}
}
return true;
}
bool RawStream::Login() {
std::vector<std::string> login_data;
for (const auto &login_command : config_.login_commands()) {
data_stream_->write(login_command);
login_data.emplace_back(login_command);
AINFO << "Login command: " << login_command;
// sleep a little to avoid overrun of the slow serial interface.
cyber::Duration(0.5).Sleep();
}
data_stream_->RegisterLoginData(login_data);
if (config_.has_wheel_parameters()) {
AINFO << "Write command: " << config_.wheel_parameters();
command_stream_->write(config_.wheel_parameters());
}
return true;
}
bool RawStream::Logout() {
for (const auto &logout_command : config_.logout_commands()) {
data_stream_->write(logout_command);
AINFO << "Logout command: " << logout_command;
}
return true;
}
void RawStream::StreamStatusCheck() {
bool status_report = false;
StreamStatus_Type report_stream_status;
if (data_stream_ &&
(data_stream_->get_status() != data_stream_status_->status)) {
data_stream_status_->status = data_stream_->get_status();
status_report = true;
switch_stream_status(data_stream_status_->status, &report_stream_status);
stream_status_.set_ins_stream_type(report_stream_status);
}
if (in_rtk_stream_ &&
(in_rtk_stream_->get_status() != in_rtk_stream_status_->status)) {
in_rtk_stream_status_->status = in_rtk_stream_->get_status();
status_report = true;
switch_stream_status(in_rtk_stream_status_->status, &report_stream_status);
stream_status_.set_rtk_stream_in_type(report_stream_status);
}
if (out_rtk_stream_ &&
(out_rtk_stream_->get_status() != out_rtk_stream_status_->status)) {
out_rtk_stream_status_->status = out_rtk_stream_->get_status();
status_report = true;
switch_stream_status(out_rtk_stream_status_->status, &report_stream_status);
stream_status_.set_rtk_stream_out_type(report_stream_status);
}
if (status_report) {
common::util::FillHeader("gnss", &stream_status_);
stream_writer_->Write(stream_status_);
}
}
void RawStream::DataSpin() {
common::util::FillHeader("gnss", &stream_status_);
stream_writer_->Write(stream_status_);
while (cyber::OK()) {
size_t length = data_stream_->read(buffer_, BUFFER_SIZE);
if (length > 0) {
std::shared_ptr<RawData> msg_pub = std::make_shared<RawData>();
if (!msg_pub) {
AERROR << "New data sting msg failed.";
continue;
}
msg_pub->set_data(reinterpret_cast<const char *>(buffer_), length);
raw_writer_->Write(msg_pub);
data_parser_ptr_->ParseRawData(msg_pub->data());
if (push_location_) {
PushGpgga(length);
}
}
StreamStatusCheck();
}
}
void RawStream::RtkSpin() {
if (in_rtk_stream_ == nullptr) {
return;
}
while (cyber::OK()) {
size_t length = in_rtk_stream_->read(buffer_rtk_, BUFFER_SIZE);
if (length > 0) {
if (rtk_software_solution_) {
PublishRtkData(length);
} else {
PublishRtkData(length);
if (out_rtk_stream_ == nullptr) {
continue;
}
size_t ret = out_rtk_stream_->write(buffer_rtk_, length);
if (ret != length) {
AERROR << "Expect write out rtk stream bytes " << length
<< " but got " << ret;
}
}
}
}
}
void RawStream::PublishRtkData(const size_t length) {
std::shared_ptr<RawData> rtk_msg = std::make_shared<RawData>();
CHECK_NOTNULL(rtk_msg);
rtk_msg->set_data(reinterpret_cast<const char *>(buffer_rtk_), length);
rtcm_writer_->Write(rtk_msg);
rtcm_parser_ptr_->ParseRtcmData(rtk_msg->data());
}
void RawStream::PushGpgga(const size_t length) {
if (!in_rtk_stream_) {
return;
}
char *gpgga = strstr(reinterpret_cast<char *>(buffer_), "$GPGGA");
if (gpgga) {
char *p = strchr(gpgga, '*');
if (p) {
p += 5;
if (size_t(p - reinterpret_cast<char *>(buffer_)) <= length) {
AINFO_EVERY(5) << "Push gpgga.";
in_rtk_stream_->write(reinterpret_cast<uint8_t *>(gpgga),
reinterpret_cast<uint8_t *>(p) - buffer_);
}
}
}
}
void RawStream::GpsbinCallback(const std::shared_ptr<RawData const> &raw_data) {
if (gpsbin_stream_ == nullptr) {
return;
}
gpsbin_stream_->write(raw_data->data().c_str(), raw_data->data().size());
}
} // namespace gnss
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/gnss
|
apollo_public_repos/apollo/modules/drivers/gnss/stream/stream.h
|
/******************************************************************************
* Copyright 2017 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
// This defines an stream interface for communication via USB, Ethernet, etc.
#pragma once
#include <cstdint>
#include <string>
#include <vector>
#include "cyber/cyber.h"
#include "modules/drivers/gnss/util/macros.h"
namespace apollo {
namespace drivers {
namespace gnss {
// An abstract class of Stream.
// One should use the create_xxx() functions to create a Stream object.
class Stream {
public:
// Return a pointer to a Stream object. The caller should take ownership.
static Stream *create_tcp(const char *address, uint16_t port,
uint32_t timeout_usec = 1000000);
static Stream *create_udp(const char *address, uint16_t port,
uint32_t timeout_usec = 1000000);
// Currently the following baud rates are supported:
// 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600.
static Stream *create_serial(const char *device_name, uint32_t baud_rate,
uint32_t timeout_usec = 0);
static Stream *create_ntrip(const std::string &address, uint16_t port,
const std::string &mountpoint,
const std::string &user,
const std::string &passwd,
uint32_t timeout_s = 30);
virtual ~Stream() {}
// Stream status.
enum class Status {
DISCONNECTED,
CONNECTED,
ERROR,
};
static constexpr size_t NUM_STATUS =
static_cast<int>(Stream::Status::ERROR) + 1;
Status get_status() const { return status_; }
// Returns whether it was successful to connect.
virtual bool Connect() = 0;
// Returns whether it was successful to disconnect.
virtual bool Disconnect() = 0;
void RegisterLoginData(const std::vector<std::string> login_data) {
login_data_.assign(login_data.begin(), login_data.end());
}
void Login() {
for (size_t i = 0; i < login_data_.size(); ++i) {
write(login_data_[i]);
AINFO << "Login: " << login_data_[i];
// sleep a little to avoid overrun of the slow serial interface.
cyber::Duration(0.5).Sleep();
}
}
// Reads up to max_length bytes. Returns actually number of bytes read.
virtual size_t read(uint8_t *buffer, size_t max_length) = 0;
// Returns how many bytes it was successful to write.
virtual size_t write(const uint8_t *buffer, size_t length) = 0;
size_t write(const std::string &buffer) {
return write(reinterpret_cast<const uint8_t *>(buffer.data()),
buffer.size());
}
protected:
Stream() {}
Status status_ = Status::DISCONNECTED;
private:
std::vector<std::string> login_data_;
DISABLE_COPY_AND_ASSIGN(Stream);
};
} // namespace gnss
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/gnss
|
apollo_public_repos/apollo/modules/drivers/gnss/stream/raw_stream.h
|
/******************************************************************************
* Copyright 2017 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#pragma once
#include <fstream>
#include <memory>
#include <string>
#include <thread>
#include "cyber/cyber.h"
#include "modules/common_msgs/chassis_msgs/chassis.pb.h"
#include "modules/drivers/gnss/proto/config.pb.h"
#include "modules/drivers/gnss/proto/gnss_status.pb.h"
#include "modules/drivers/gnss/parser/data_parser.h"
#include "modules/drivers/gnss/parser/rtcm_parser.h"
#include "modules/drivers/gnss/stream/stream.h"
namespace apollo {
namespace drivers {
namespace gnss {
class RawStream {
public:
RawStream(const config::Config& config,
const std::shared_ptr<apollo::cyber::Node>& node);
~RawStream();
bool Init();
struct Status {
bool filter[Stream::NUM_STATUS] = {false};
Stream::Status status;
};
void Start();
private:
void DataSpin();
void RtkSpin();
bool Connect();
bool Disconnect();
bool Login();
bool Logout();
void StreamStatusCheck();
void PublishRtkData(size_t length);
void PushGpgga(size_t length);
void GpsbinSpin();
void GpsbinCallback(const std::shared_ptr<RawData const>& raw_data);
void OnWheelVelocityTimer();
std::unique_ptr<cyber::Timer> wheel_velocity_timer_ = nullptr;
std::shared_ptr<apollo::canbus::Chassis> chassis_ptr_ = nullptr;
static constexpr size_t BUFFER_SIZE = 2048;
uint8_t buffer_[BUFFER_SIZE] = {0};
uint8_t buffer_rtk_[BUFFER_SIZE] = {0};
std::shared_ptr<Stream> data_stream_;
std::shared_ptr<Stream> command_stream_;
std::shared_ptr<Stream> in_rtk_stream_;
std::shared_ptr<Stream> out_rtk_stream_;
std::shared_ptr<Status> data_stream_status_;
std::shared_ptr<Status> command_stream_status_;
std::shared_ptr<Status> in_rtk_stream_status_;
std::shared_ptr<Status> out_rtk_stream_status_;
bool rtk_software_solution_ = false;
bool push_location_ = false;
bool is_healthy_ = true;
config::Config config_;
const std::string raw_data_topic_;
const std::string rtcm_data_topic_;
StreamStatus stream_status_;
std::unique_ptr<std::thread> data_thread_ptr_;
std::unique_ptr<std::thread> rtk_thread_ptr_;
std::unique_ptr<DataParser> data_parser_ptr_;
std::unique_ptr<RtcmParser> rtcm_parser_ptr_;
std::unique_ptr<std::thread> gpsbin_thread_ptr_;
std::unique_ptr<std::ofstream> gpsbin_stream_ = nullptr;
std::shared_ptr<apollo::cyber::Node> node_ = nullptr;
std::shared_ptr<apollo::cyber::Writer<StreamStatus>> stream_writer_ = nullptr;
std::shared_ptr<apollo::cyber::Writer<RawData>> raw_writer_ = nullptr;
std::shared_ptr<apollo::cyber::Writer<RawData>> rtcm_writer_ = nullptr;
std::shared_ptr<apollo::cyber::Reader<RawData>> gpsbin_reader_ = nullptr;
std::shared_ptr<apollo::cyber::Reader<apollo::canbus::Chassis>>
chassis_reader_ = nullptr;
};
} // namespace gnss
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/gnss
|
apollo_public_repos/apollo/modules/drivers/gnss/stream/tcp_stream.h
|
/******************************************************************************
* Copyright 2017 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#pragma once
namespace apollo {
namespace drivers {
namespace gnss {
class TcpStream : public Stream {
typedef uint16_t be16_t;
typedef uint32_t be32_t;
public:
TcpStream(const char *address, uint16_t port, uint32_t timeout_usec,
bool auto_reconnect = true);
~TcpStream();
virtual bool Connect();
virtual bool Disconnect();
virtual size_t read(uint8_t *buffer, size_t max_length);
virtual size_t write(const uint8_t *data, size_t length);
private:
bool Reconnect();
bool Readable(uint32_t timeout_us);
TcpStream() {}
void open();
void close();
bool InitSocket();
be16_t peer_port_ = 0;
be32_t peer_addr_ = 0;
uint32_t timeout_usec_ = 0;
int sockfd_ = -1;
int errno_ = 0;
bool auto_reconnect_ = false;
};
} // namespace gnss
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/gnss
|
apollo_public_repos/apollo/modules/drivers/gnss/stream/udp_stream.cc
|
/******************************************************************************
* Copyright 2017 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include <arpa/inet.h>
#include <fcntl.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
#include <cerrno>
#include "cyber/cyber.h"
#include "modules/drivers/gnss/stream/stream.h"
namespace apollo {
namespace drivers {
namespace gnss {
class UdpStream : public Stream {
typedef uint16_t be16_t;
typedef uint32_t be32_t;
public:
UdpStream(const char* address, uint16_t port, uint32_t timeout_usec);
~UdpStream();
virtual bool Connect();
virtual bool Disconnect();
virtual size_t read(uint8_t* buffer, size_t max_length);
virtual size_t write(const uint8_t* data, size_t length);
private:
UdpStream() {}
void open();
void close();
be16_t peer_port_ = 0;
be32_t peer_addr_ = 0;
uint32_t timeout_usec_ = 0;
int sockfd_ = -1;
int errno_ = 0;
};
Stream* Stream::create_udp(const char* address, uint16_t port,
uint32_t timeout_usec) {
return new UdpStream(address, port, timeout_usec);
}
UdpStream::UdpStream(const char* address, uint16_t port, uint32_t timeout_usec)
: sockfd_(-1), errno_(0) {
peer_addr_ = inet_addr(address);
peer_port_ = htons(port);
timeout_usec_ = timeout_usec;
// call open or call open in connect later
}
UdpStream::~UdpStream() { this->close(); }
void UdpStream::open() {
int fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (fd < 0) {
// error
AERROR << "Create socket failed, errno: " << errno << ", "
<< strerror(errno);
return;
}
// block or not block
if (timeout_usec_ != 0) {
int flags = fcntl(fd, F_GETFL, 0);
if (flags == -1) {
::close(fd);
AERROR << "fcntl get flag failed, errno: " << errno << ", "
<< strerror(errno);
return;
}
if (fcntl(fd, F_SETFL, flags & ~O_NONBLOCK) == -1) {
::close(fd);
AERROR << "fcntl set block failed, errno: " << errno << ", "
<< strerror(errno);
return;
}
struct timeval block_to = {timeout_usec_ / 1000000,
timeout_usec_ % 1000000};
if (setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO,
reinterpret_cast<char*>(&block_to), sizeof(block_to)) < 0) {
::close(fd);
AERROR << "setsockopt set rcv timeout failed, errno: " << errno << ", "
<< strerror(errno);
return;
}
if (setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO,
reinterpret_cast<char*>(&block_to), sizeof(block_to)) < 0) {
::close(fd);
AERROR << "setsockopt set snd timeout failed, errno: " << errno << ", "
<< strerror(errno);
return;
}
} else {
int flags = fcntl(fd, F_GETFL, 0);
if (flags == -1) {
::close(fd);
AERROR << "fcntl get flag failed, errno: " << errno << ", "
<< strerror(errno);
return;
}
if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) == -1) {
::close(fd);
AERROR << "fcntl set non block failed, errno: " << errno << ", "
<< strerror(errno);
return;
}
}
sockfd_ = fd;
}
void UdpStream::close() {
if (sockfd_ > 0) {
::close(sockfd_);
sockfd_ = -1;
status_ = Stream::Status::DISCONNECTED;
}
}
bool UdpStream::Connect() {
if (sockfd_ < 0) {
this->open();
if (sockfd_ < 0) {
return false;
}
}
if (status_ == Stream::Status::CONNECTED) {
return true;
}
// upper layer support ping method ??
Login();
status_ = Stream::Status::CONNECTED;
return true;
}
bool UdpStream::Disconnect() {
if (sockfd_ < 0) {
// not open
return false;
}
this->close();
return true;
}
size_t UdpStream::read(uint8_t* buffer, size_t max_length) {
ssize_t ret = 0;
struct sockaddr_in peer_sockaddr;
socklen_t socklenth = sizeof(peer_sockaddr);
bzero(&peer_sockaddr, sizeof(peer_sockaddr));
peer_sockaddr.sin_family = AF_INET;
peer_sockaddr.sin_port = peer_port_;
peer_sockaddr.sin_addr.s_addr = peer_addr_;
while ((ret = ::recvfrom(sockfd_, buffer, max_length, 0,
(struct sockaddr*)&peer_sockaddr,
reinterpret_cast<socklen_t*>(&socklenth))) < 0) {
if (errno == EINTR) {
continue;
} else {
// error
if (errno != EAGAIN) {
status_ = Stream::Status::ERROR;
errno_ = errno;
}
}
return 0;
}
return ret;
}
size_t UdpStream::write(const uint8_t* data, size_t length) {
size_t total_nsent = 0;
struct sockaddr_in peer_sockaddr;
bzero(&peer_sockaddr, sizeof(peer_sockaddr));
peer_sockaddr.sin_family = AF_INET;
peer_sockaddr.sin_port = peer_port_;
peer_sockaddr.sin_addr.s_addr = peer_addr_;
while (length > 0) {
ssize_t nsent =
::sendto(sockfd_, data, length, 0, (struct sockaddr*)&peer_sockaddr,
(socklen_t)sizeof(peer_sockaddr));
if (nsent < 0) { // error
if (errno == EINTR) {
continue;
} else {
// error
if (errno == EPIPE || errno == ECONNRESET) {
status_ = Stream::Status::DISCONNECTED;
errno_ = errno;
} else if (errno != EAGAIN) {
status_ = Stream::Status::ERROR;
errno_ = errno;
}
return total_nsent;
}
}
total_nsent += nsent;
length -= nsent;
data += nsent;
}
return total_nsent;
}
} // namespace gnss
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/gnss
|
apollo_public_repos/apollo/modules/drivers/gnss/stream/BUILD
|
load("@rules_cc//cc:defs.bzl", "cc_library")
load("//tools:cpplint.bzl", "cpplint")
package(default_visibility = ["//visibility:public"])
cc_library(
name = "gnss_stream",
deps = [
":ntrip_stream",
":raw_stream",
":serial_stream",
":tcp_stream",
":udp_stream",
],
)
cc_library(
name = "ntrip_stream",
srcs = ["ntrip_stream.cc"],
hdrs = ["tcp_stream.h"],
deps = [
":stream",
"//cyber",
"//modules/common/adapters:adapter_gflags",
"//modules/common/math",
"//modules/common_msgs/basic_msgs:pnc_point_cc_proto",
"//modules/common/util",
],
)
cc_library(
name = "raw_stream",
srcs = ["raw_stream.cc"],
hdrs = ["raw_stream.h"],
deps = [
":ntrip_stream",
":serial_stream",
":stream",
"//cyber",
"//modules/common_msgs/chassis_msgs:chassis_cc_proto",
"//modules/common/adapters:adapter_gflags",
"//modules/common_msgs/config_msgs:vehicle_config_cc_proto",
"//modules/common_msgs/basic_msgs:drive_state_cc_proto",
"//modules/common_msgs/basic_msgs:vehicle_signal_cc_proto",
"//modules/common/util:util_tool",
"//modules/drivers/gnss/parser:gnss_parser",
"//modules/drivers/gnss/proto:gnss_status_cc_proto",
"//modules/common_msgs/sensor_msgs:heading_cc_proto",
"//modules/common_msgs/localization_msgs:imu_cc_proto",
"//modules/drivers/gnss/util:gnss_util",
"@com_google_absl//:absl",
],
)
cc_library(
name = "serial_stream",
srcs = ["serial_stream.cc"],
deps = [
":stream",
"//cyber",
"//modules/drivers/gnss/util:gnss_util",
],
)
cc_library(
name = "tcp_stream",
srcs = ["tcp_stream.cc"],
hdrs = ["tcp_stream.h"],
deps = [
":stream",
"//cyber",
],
)
cc_library(
name = "udp_stream",
srcs = ["udp_stream.cc"],
deps = [
":stream",
"//cyber",
"//modules/drivers/gnss/util:gnss_util",
],
)
cc_library(
name = "stream",
hdrs = ["stream.h"],
deps = [
"//cyber",
"//modules/drivers/gnss/util:gnss_util",
],
)
cpplint()
| 0
|
apollo_public_repos/apollo/modules/drivers/gnss
|
apollo_public_repos/apollo/modules/drivers/gnss/parser/parser.h
|
/******************************************************************************
* Copyright 2017 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#pragma once
#include <cstdint>
#include <string>
#include "google/protobuf/message.h"
#include "modules/drivers/gnss/proto/config.pb.h"
#include "modules/drivers/gnss/util/macros.h"
namespace apollo {
namespace drivers {
namespace gnss {
// convert gps time (base on Jan 6 1980) to system time (base on Jan 1 1970)
// notice: Jan 6 1980
//
// linux shell:
// time1 = date +%s -d"Jan 6, 1980 00:00:01"
// time2 = date +%s -d"Jan 1, 1970 00:00:01"
// dif_tick = time1-time2
// 315964800 = 315993601 - 28801
#define EPOCH_AND_SYSTEM_DIFF_SECONDS 315964800
// A helper function that returns a pointer to a protobuf message of type T.
template <class T>
inline T *As(::google::protobuf::Message *message_ptr) {
return dynamic_cast<T *>(message_ptr);
}
// An abstract class of Parser.
// One should use the create_xxx() functions to create a Parser object.
class Parser {
public:
// A general pointer to a protobuf message.
using MessagePtr = ::google::protobuf::Message *;
// Return a pointer to a NovAtel parser. The caller should take ownership.
static Parser *CreateNovatel(const config::Config &config);
// Return a pointer to rtcm v3 parser. The caller should take ownership.
static Parser *CreateRtcmV3(bool is_base_station = false);
virtual ~Parser() {}
// Updates the parser with new data. The caller must keep the data valid until
// GetMessage()
// returns NONE.
void Update(const uint8_t *data, size_t length) {
data_ = data;
data_end_ = data + length;
}
void Update(const std::string &data) {
Update(reinterpret_cast<const uint8_t *>(data.data()), data.size());
}
enum class MessageType {
NONE,
GNSS,
GNSS_RANGE,
IMU,
INS,
INS_STAT,
WHEEL,
EPHEMERIDES,
OBSERVATION,
GPGGA,
BDSEPHEMERIDES,
RAWIMU,
GPSEPHEMERIDES,
GLOEPHEMERIDES,
BEST_GNSS_POS,
HEADING,
};
// Gets a parsed protobuf message. The caller must consume the message before
// calling another
// GetMessage() or Update();
virtual MessageType GetMessage(MessagePtr *message_ptr) = 0;
protected:
Parser() {}
// Point to the beginning and end of data. Do not take ownership.
const uint8_t *data_ = nullptr;
const uint8_t *data_end_ = nullptr;
private:
DISABLE_COPY_AND_ASSIGN(Parser);
};
} // namespace gnss
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/gnss
|
apollo_public_repos/apollo/modules/drivers/gnss/parser/data_parser.h
|
/******************************************************************************
* Copyright 2017 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#pragma once
#include <memory>
#include <string>
#define ACCEPT_USE_OF_DEPRECATED_PROJ_API_H
#include <proj_api.h>
#include "cyber/cyber.h"
#include "modules/transform/transform_broadcaster.h"
#include "modules/drivers/gnss/proto/config.pb.h"
#include "modules/common_msgs/sensor_msgs/gnss.pb.h"
#include "modules/common_msgs/sensor_msgs/gnss_best_pose.pb.h"
#include "modules/common_msgs/sensor_msgs/gnss_raw_observation.pb.h"
#include "modules/drivers/gnss/proto/gnss_status.pb.h"
#include "modules/common_msgs/sensor_msgs/heading.pb.h"
#include "modules/common_msgs/sensor_msgs/imu.pb.h"
#include "modules/common_msgs/sensor_msgs/ins.pb.h"
#include "modules/common_msgs/localization_msgs/gps.pb.h"
#include "modules/common_msgs/localization_msgs/imu.pb.h"
#include "modules/drivers/gnss/parser/parser.h"
namespace apollo {
namespace drivers {
namespace gnss {
class DataParser {
public:
using MessagePtr = ::google::protobuf::Message *;
DataParser(const config::Config &config,
const std::shared_ptr<apollo::cyber::Node> &node);
~DataParser() {}
bool Init();
void ParseRawData(const std::string &msg);
private:
void DispatchMessage(Parser::MessageType type, MessagePtr message);
void PublishInsStat(const MessagePtr message);
void PublishOdometry(const MessagePtr message);
void PublishCorrimu(const MessagePtr message);
void PublishImu(const MessagePtr message);
void PublishBestpos(const MessagePtr message);
void PublishEphemeris(const MessagePtr message);
void PublishObservation(const MessagePtr message);
void PublishHeading(const MessagePtr message);
void CheckInsStatus(Ins *ins);
void CheckGnssStatus(Gnss *gnss);
void GpsToTransformStamped(
const std::shared_ptr<apollo::localization::Gps> &gps,
apollo::transform::TransformStamped *transform);
bool init_flag_ = false;
config::Config config_;
std::unique_ptr<Parser> data_parser_;
apollo::transform::TransformBroadcaster tf_broadcaster_;
GnssStatus gnss_status_;
InsStatus ins_status_;
uint32_t ins_status_record_ = static_cast<uint32_t>(0);
projPJ wgs84pj_source_;
projPJ utm_target_;
std::shared_ptr<apollo::cyber::Node> node_ = nullptr;
std::shared_ptr<apollo::cyber::Writer<GnssStatus>> gnssstatus_writer_ =
nullptr;
std::shared_ptr<apollo::cyber::Writer<InsStatus>> insstatus_writer_ = nullptr;
std::shared_ptr<apollo::cyber::Writer<GnssBestPose>> gnssbestpose_writer_ =
nullptr;
std::shared_ptr<apollo::cyber::Writer<apollo::localization::CorrectedImu>>
corrimu_writer_ = nullptr;
std::shared_ptr<apollo::cyber::Writer<Imu>> rawimu_writer_ = nullptr;
std::shared_ptr<apollo::cyber::Writer<apollo::localization::Gps>>
gps_writer_ = nullptr;
std::shared_ptr<apollo::cyber::Writer<InsStat>> insstat_writer_ = nullptr;
std::shared_ptr<apollo::cyber::Writer<GnssEphemeris>> gnssephemeris_writer_ =
nullptr;
std::shared_ptr<apollo::cyber::Writer<EpochObservation>>
epochobservation_writer_ = nullptr;
std::shared_ptr<apollo::cyber::Writer<Heading>> heading_writer_ = nullptr;
};
} // namespace gnss
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/gnss
|
apollo_public_repos/apollo/modules/drivers/gnss/parser/novatel_messages.h
|
/******************************************************************************
* Copyright 2017 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
// This defines enums and structures for parsing NovAtel binary messages. Please
// refer to NovAtel's
// documents for details about these messages.
// http://www.novatel.com/assets/Documents/Manuals/om-20000129.pdf
// http://www.novatel.com/assets/Documents/Manuals/OM-20000144UM.pdf
#pragma once
#include <cstdint>
#include <limits>
#include "modules/drivers/gnss/proto/config.pb.h"
namespace apollo {
namespace drivers {
namespace gnss {
namespace novatel {
enum MessageId : uint16_t {
BESTGNSSPOS = 1429,
BESTGNSSVEL = 1430,
BESTPOS = 42,
BESTVEL = 99,
CORRIMUDATA = 812,
CORRIMUDATAS = 813,
INSCOV = 264,
INSCOVS = 320,
INSPVA = 507,
INSPVAS = 508,
INSPVAX = 1465,
PSRPOS = 47,
PSRVEL = 100,
RAWIMU = 268,
RAWIMUS = 325,
RAWIMUX = 1461,
RAWIMUSX = 1462,
MARK1PVA = 1067,
GPGGA = 218,
BDSEPHEMERIS = 1696,
GLOEPHEMERIS = 723,
GPSEPHEMERIS = 7,
RANGE = 43,
HEADING = 971,
IMURATECORRIMUS = 1362,
};
// Every binary message has 32-bit CRC performed on all data including the
// header.
constexpr uint16_t CRC_LENGTH = 4;
#pragma pack(push, 1) // Turn off struct padding.
enum SyncByte : uint8_t {
SYNC_0 = 0xAA,
SYNC_1 = 0x44,
SYNC_2_LONG_HEADER = 0x12,
SYNC_2_SHORT_HEADER = 0x13,
};
struct MessageType {
enum MessageFormat {
BINARY = 0b00,
ASCII = 0b01,
ABREVIATED_ASCII = 0b10,
NMEA = 0b11,
};
enum ResponseBit {
ORIGINAL_MESSAGE = 0b0,
RESPONSE_MESSAGE = 0b1,
};
uint8_t reserved : 5;
MessageFormat format : 2;
ResponseBit response : 1;
};
struct LongHeader {
SyncByte sync[3];
uint8_t header_length;
MessageId message_id;
MessageType message_type;
uint8_t port_address; // Address of the data port the log was received on.
uint16_t
message_length; // Message length (not including the header nor the CRC).
uint16_t sequence; // Counts down from N-1 to 0 for multiple related logs.
uint8_t idle; // Time the processor was idle in last second between logs with
// same ID.
uint8_t time_status; // Indicates the quality of the GPS time.
uint16_t gps_week; // GPS Week number.
uint32_t gps_millisecs; // Milliseconds of week.
uint32_t status; // Receiver status.
uint16_t reserved;
uint16_t version; // Receiver software build number.
};
static_assert(sizeof(LongHeader) == 28, "Incorrect size of LongHeader");
struct ShortHeader {
SyncByte sync[3];
uint8_t
message_length; // Message length (not including the header nor the CRC).
MessageId message_id;
uint16_t gps_week; // GPS Week number.
uint32_t gps_millisecs; // Milliseconds of week.
};
static_assert(sizeof(ShortHeader) == 12, "Incorrect size of ShortHeader");
enum class SolutionStatus : uint32_t {
SOL_COMPUTED = 0, // solution computed
INSUFFICIENT_OBS, // insufficient observations
NO_CONVERGENCE, // no convergence
SINGULARITY, // singularity at parameters matrix
COV_TRACE, // covariance trace exceeds maximum (trace > 1000 m)
TEST_DIST, // test distance exceeded (max of 3 rejections if distance > 10
// km)
COLD_START, // not yet converged from cold start
V_H_LIMIT, // height or velocity limits exceeded
VARIANCE, // variance exceeds limits
RESIDUALS, // residuals are too large
INTEGRITY_WARNING = 13, // large residuals make position questionable
PENDING = 18, // receiver computes its position and determines if the fixed
// position is valid
INVALID_FIX = 19, // the fixed position entered using the fix position
// command is invalid
UNAUTHORIZED = 20, // position type is unauthorized
INVALID_RATE =
22, // selected logging rate is not supported for this solution type
NONE = std::numeric_limits<uint32_t>::max(),
};
enum class SolutionType : uint32_t {
NONE = 0,
FIXEDPOS = 1,
FIXEDHEIGHT = 2,
FLOATCONV = 4,
WIDELANE = 5,
NARROWLANE = 6,
DOPPLER_VELOCITY = 8,
SINGLE = 16,
PSRDIFF = 17,
WAAS = 18,
PROPOGATED = 19,
OMNISTAR = 20,
L1_FLOAT = 32,
IONOFREE_FLOAT = 33,
NARROW_FLOAT = 34,
L1_INT = 48,
WIDE_INT = 49,
NARROW_INT = 50,
RTK_DIRECT_INS = 51, // RTK filter is directly initialized
// from the INS filter.
INS_SBAS = 52,
INS_PSRSP = 53,
INS_PSRDIFF = 54,
INS_RTKFLOAT = 55,
INS_RTKFIXED = 56,
INS_OMNISTAR = 57,
INS_OMNISTAR_HP = 58,
INS_OMNISTAR_XP = 59,
OMNISTAR_HP = 64,
OMNISTAR_XP = 65,
PPP_CONVERGING = 68,
PPP = 69,
INS_PPP_CONVERGING = 73,
INS_PPP = 74,
};
enum class DatumId : uint32_t {
// We only use WGS-84.
WGS84 = 61,
};
struct BDS_Ephemeris {
uint32_t satellite_id; // ID/ranging code
uint32_t week; // week number
double ura; // user range accuracy(meters).
// This is the evaluated URAI/URA lookup-table value
uint32_t health1; // Autonomous satellite health flag.
// 0 means broadcasting satellite is good, 1 means not
double tdg1; // Equipment group delay differential for the B1 signal(seconds)
double tdg2; // Equipment group delay differential for the B2 signal(seconds)
uint32_t aodc; // Age of data, clock
uint32_t toc; // Reference time of clock parameters
double a0; // Constant term of clock correction polynomial(seconds)
double a1; // Linear term of clock correction polynomial (seconds/seconds)
double a2; // Quadratic term of clock correction polynomial
// (second/seconds^2)
uint32_t aode; // Age of data, ephemeris
uint32_t toe; // Reference time of ephemeris parameters
double rootA; // Square root of semi-major axis (sqrt(meters))
double ecc; // Eccentricity (sqrt(meters))
double omega; // Argument of perigee
double delta_N; // Mean motion difference from computed value
// (radians/second)
double M0; // Mean anomaly at reference time (radians)
double omega0; // Longitude of ascending node of orbital of plane computed
// according to reference time(radians)
double rra; // Rate of right ascension(radians/second)
double inc_angle; // inclination angle at reference time(radians)
double idot; // Rate of inclination angle(radians/second)
double cuc; // Amplitude of cosine harmonic correction term to the argument
// of latitude(radians)
double cus; // Amplitude of sine harmonic correction term to the argument
// of latitude(radians)
double crc; // Amplitude of cosine harmonic correction term to
// the orbit radius(meters)
double crs; // Amplitude of sine harmonic correction term to
// the orbit radius(meters)
double cic; // Amplitude of cosine harmonic correction term to the angle of
// inclination(radians)
double cis; // Amplitude of sine harmonic correction term to the angle of
// inclination(radians)
};
static_assert(sizeof(BDS_Ephemeris) == 196, "Incorrect size of BDS_Ephemeris.");
struct GLO_Ephemeris {
uint16_t sloto; // Slot information offset-PRNidentification(Slot+37).
uint16_t freqo; // frequency channel offset for satellite
// in the range 0 to 20
uint8_t sat_type; // Satellite type where(0=GLO_SAT, 1=GLO_SAT_M,
// 2=GLO_SAT_K)
uint8_t reserved_1; // Reserved
uint16_t e_week; // reference week of ephemeris(GPS reference time)
uint32_t e_time; // reference time of ephemeris(GPS reference time) in ms
uint32_t t_offset; // integer seconds between GPS and GLONASS time.
// A positive value implies GLONASS is ahead
// of GPS reference time.
uint16_t Nt; // Calendar number of day within 4 year interval starting at
// Jan 1 of leap year
uint8_t reserved_2; // Reserved
uint8_t reserved_3; // Reserved
uint32_t issue; // 15 minute interval number corresponding to ephemeris
// reference time
uint32_t health; // Ephemeris health where 0-3=GOOD, 4-15=BAD
double pos_x; // X coordinate for satellite at reference time (PZ-90.02),
// in meters
double pos_y; // Y coordinate for satellite at reference time (PZ-90.02),
// in meters
double pos_z; // Z coordinate for satellite at reference time (PZ-90.02),
// in meters
double vel_x; // X coordinate for satellite velocity at reference
// time(PZ-90.02), in meters/s
double vel_y; // Y coordinate for satellite velocity at reference
// time(PZ-90.02), in meters/s
double vel_z; // Z coordinate for satellite velocity at reference
// time(PZ-90.02), in meters/s
double acc_x; // X coordinate for lunisolar acceleration at reference
// time(PZ-90.02), in meters/s/s
double acc_y; // Y coordinate for lunisolar acceleration at reference
// time(PZ-90.02), in meters/s/s
double acc_z; // Z coordinate for lunisolar acceleration at reference
// time(PZ-90.02), in meters/s/s
double tau_n; // Correction to the nth satellite time t_n relative to
// GLONASS time_t, in seconds
double delta_tau_n; // Time difference between navigation RF signal
// transmitted in L2 sub-band and
// navigation RF signal transmitted in
// L1 sub-band by nth satellite , in seconds
double gamma; // frequency correction , in seconds/second
uint32_t Tk; // Time of frame start(since start of GLONASS day), in seconds
uint32_t P; // technological parameter
uint32_t Ft; // User range
uint32_t age; // age of data, in days
uint32_t Flags; // information flags
};
static_assert(sizeof(GLO_Ephemeris) == 144, "Incorrect size of GLO_Ephemeris.");
struct GPS_Ephemeris {
uint32_t prn; // Satellite prn number
double tow; // Time stamp of subframe 0
uint32_t health; // Health status -a 6-bit health code as defined in
// ICD-GPS-200
uint32_t iode1; // issue of ephemeris data 1
uint32_t iode2; // issue of ephemeris data 2
uint32_t week; // GPS reference week number
uint32_t z_week; // Z count week number
double toe; // reference time for ephemeris, seconds
double A; // semi-major axis, metres
double delta_A; // Mean motion difference, radians/second
double M_0; // Mean anomaly of reference time, radians
double ecc; // Eccentricity. dimensionless-quantity defined for
// a conic section where e=0 is a circle, e=1 is a parabola
// 0<e<1 os an ellipse and e>1 is a hyperbola
double omega; // Argument of perigee, radians -measurement along the
// orbital path from the ascending node to the point where
// the SV os closest to the earth, in the direction of
// the SV's motion
double cuc; // Argument of latitude
double cus; // Argument of latitude
double crc; // Orbit radius
double crs; // Orbit radius
double cic; // Inclination
double cis; // Inclination
double I_0; // Inclination angle at reference time, radians
double dot_I; // Rate of inclination angle, radians/second
double omega_0; // right ascension, radians
double dot_omega; // rate of right ascension, radians/second
uint32_t iodc; // issue of data clock
double toc; // SV clock correction term, seconds
double tgd; // Estimated group delay difference seconds
double af0; // Clock aging parameter. seconds
double af1; // Clock aging parameter
double af2; // Clock aging parameter
uint32_t AS; // Anti-spoofing on : 0=false, 1=true
double N; // Corrected mean motion, radians/second
double ura; // User Range Acceracy variance.
};
static_assert(sizeof(GPS_Ephemeris) == 224, "Incorrect size of GPS_Ephemeris.");
struct BestPos {
SolutionStatus solution_status;
SolutionType position_type;
double latitude; // in degrees
double longitude; // in degrees
double height_msl; // height above mean sea level in meters
float undulation; // undulation = height_wgs84 - height_msl
DatumId datum_id; // datum id number
float latitude_std_dev; // latitude standard deviation (m)
float longitude_std_dev; // longitude standard deviation (m)
float height_std_dev; // height standard deviation (m)
char base_station_id[4]; // base station id
float differential_age; // differential position age (sec)
float solution_age; // solution age (sec)
uint8_t num_sats_tracked; // number of satellites tracked
uint8_t num_sats_in_solution; // number of satellites used in solution
uint8_t num_sats_l1; // number of L1/E1/B1 satellites used in solution
uint8_t
num_sats_multi; // number of multi-frequency satellites used in solution
uint8_t reserved; // reserved
uint8_t extended_solution_status; // extended solution status - OEMV and
// greater only
uint8_t galileo_beidou_used_mask;
uint8_t gps_glonass_used_mask;
};
static_assert(sizeof(BestPos) == 72, "Incorrect size of BestPos");
struct BestVel {
SolutionStatus solution_status; // Solution status
SolutionType velocity_type;
float latency; // measure of the latency of the velocity time tag in seconds
float age; // differential age in seconds
double horizontal_speed; // horizontal speed in m/s
double track_over_ground; // direction of travel in degrees
double vertical_speed; // vertical speed in m/s
float reserved;
};
static_assert(sizeof(BestVel) == 44, "Incorrect size of BestVel");
// IMU data corrected for gravity, the earth's rotation and estimated sensor
// errors.
struct CorrImuData {
uint32_t gps_week;
double gps_seconds; // seconds of week
// All the measurements are in the SPAN computational frame: right, forward,
// up.
double x_angle_change; // change in angle around x axis in radians
double y_angle_change; // change in angle around y axis in radians
double z_angle_change; // change in angle around z axis in radians
double x_velocity_change; // change in velocity along x axis in m/s
double y_velocity_change; // change in velocity along y axis in m/s
double z_velocity_change; // change in velocity along z axis in m/s
};
static_assert(sizeof(CorrImuData) == 60, "Incorrect size of CorrImuData");
struct InsCov {
uint32_t gps_week;
double gps_seconds; // seconds of week
double position_covariance[9]; // Position covariance matrix [m^2]
// (xx,xy,xz,yz,yy,...)
double attitude_covariance[9]; // Attitude covariance matrix [deg^2]
// (xx,xy,xz,yz,yy,...)
double velocity_covariance[9]; // Velocity covariance matrix [(m/s)^2]
// (xx,xy,xz,yz,yy,...)
};
static_assert(sizeof(InsCov) == 228, "Incorrect size of InsCov");
enum class InsStatus : uint32_t {
INACTIVE = 0,
ALIGNING,
HIGH_VARIANCE,
SOLUTION_GOOD,
SOLUTION_FREE = 6,
ALIGNMENT_COMPLETE,
DETERMINING_ORIENTATION,
WAITING_INITIAL_POS,
NONE = std::numeric_limits<uint32_t>::max(),
};
struct InsPva {
uint32_t gps_week;
double gps_seconds; // seconds of week
double latitude; // in degrees
double longitude; // in degrees
double height; // Ellipsoidal height - WGS84 (m)
double north_velocity; // velocity in a northerly direction (m/s)
double east_velocity; // velocity in an easterly direction (m/s)
double up_velocity; // velocity in an up direction
double roll; // right handed rotation around y-axis (degrees)
double pitch; // right handed rotation around x-axis (degrees)
double azimuth; // left handed rotation around z-axis (degrees)
InsStatus status; // status of the INS system
};
static_assert(sizeof(InsPva) == 88, "Incorrect size of InsPva");
struct InsPvaX {
uint32_t ins_status;
uint32_t pos_type;
double latitude; // in degrees
double longitude; // in degrees
double height; // Ellipsoidal height - WGS84 (m)
float undulation;
double north_velocity; // velocity in a northerly direction (m/s)
double east_velocity; // velocity in an easterly direction (m/s)
double up_velocity; // velocity in an up direction
double roll; // right handed rotation around y-axis (degrees)
double pitch; // right handed rotation around x-axis (degrees)
double azimuth; // left handed rotation around z-axis (degrees)
float latitude_std;
float longitude_std;
float height_std;
float north_velocity_std;
float east_velocity_std;
float up_velocity_std;
float roll_std;
float pitch_std;
float azimuth_std;
uint32_t ext_slo_stat;
uint16_t elapsed_time;
};
static_assert(sizeof(InsPvaX) == 126, "Incorrect size of InsPvaX");
// enum class ImuType : uint8_t {
// // We currently use the following IMUs. We'll extend this list when a new
// IMU
// // is introduced.
// IMAR_FSAS = 13, // iMAR iIMU-FSAS
// ISA100C = 26, // Northrop Grumman Litef ISA-100C
// ADIS16488 = 31, // Analog Devices ADIS16488
// STIM300 = 32, // Sensonor STIM300
// ISA100 = 34, // Northrop Grumman Litef ISA-100
// ISA100_400HZ = 38, // Northrop Grumman Litef ISA-100
// ISA100C_400HZ = 39, // Northrop Grumman Litef ISA-100
// G320N = 40, // EPSON G320N
// CPT_X25651 = 41, // IMU@SPAN-CPT, and XingWangYuda 5651
// BMI055 = 42 // BOSCH BMI055 IMU
// };
struct RawImuX {
uint8_t imu_error; // Simple IMU error flag. 0 means IMU okay.
uint8_t imu_type;
uint16_t gps_week;
double gps_seconds; // Seconds of week.
uint32_t imuStatus; // Status of the IMU. The content varies with IMU type.
// All the measurements are in the IMU reference frame. Scale factors varies
// with IMU type.
int32_t z_velocity_change; // change in velocity along z axis.
int32_t y_velocity_change_neg; // -change in velocity along y axis.
int32_t x_velocity_change; // change in velocity along x axis.
int32_t z_angle_change; // change in angle around z axis.
int32_t y_angle_change_neg; // -change in angle around y axis.
int32_t x_angle_change; // change in angle around x axis.
};
static_assert(sizeof(RawImuX) == 40, "Incorrect size of RawImuX");
struct RawImu {
uint32_t gps_week;
double gps_seconds; // Seconds of week.
uint32_t imuStatus; // Status of the IMU. The content varies with IMU type.
int32_t z_velocity_change; // change in velocity along z axis.
int32_t y_velocity_change_neg; // -change in velocity along y axis.
int32_t x_velocity_change; // change in velocity along x axis.
int32_t z_angle_change; // change in angle around z axis.
int32_t y_angle_change_neg; // -change in angle around y axis.
int32_t x_angle_change; // change in angle around x axis.
};
static_assert(sizeof(RawImu) == 40, "Incorrect size of RawImu");
struct Heading {
SolutionStatus solution_status;
SolutionType position_type;
float length;
float heading;
float pitch;
float reserved;
float heading_std_dev;
float pitch_std_dev;
char station_id[4]; // station id
uint8_t num_sats_tracked; // number of satellites tracked
uint8_t num_sats_in_solution; // number of satellites used in solution
uint8_t num_sats_ele;
uint8_t num_sats_l2;
uint8_t solution_source;
uint8_t extended_solution_status;
uint8_t galileo_beidou_sig_mask;
uint8_t gps_glonass_sig_mask;
};
static_assert(sizeof(Heading) == 44, "Incorrect size of Heading");
#pragma pack(pop) // Back to whatever the previous packing mode was.
struct ImuParameter {
double gyro_scale;
double accel_scale;
double sampling_rate_hz;
};
using ::apollo::drivers::gnss::config::ImuType;
inline ImuParameter GetImuParameter(ImuType type) {
switch (type) {
case ImuType::IMAR_FSAS:
// 0.1 * (2 ** -8) * (math.pi / 180 / 3600), (0.05 * (2 ** -15)
return {1.893803441835e-9, 1.52587890625e-6, 200.0};
case ImuType::ADIS16488:
// 720/2**31 deg/LSB, 200/2**31 m/s/LSB
return {5.8516723170686385e-09, 9.31322574615478515625e-8, 200.0};
case ImuType::STIM300:
// 2**-21 deg/LSB, 2**-22 m/s/LSB
return {8.32237840649762e-09, 2.384185791015625e-07, 125.0};
case ImuType::ISA100:
case ImuType::ISA100C:
// 1.0e-9 rad/LSB, 2.0e-8 m/s/LSB
return {1.0e-9, 2.0e-8, 200.0};
case ImuType::ISA100_400HZ:
case ImuType::ISA100C_400HZ:
return {1.0e-9, 2.0e-8, 400.0};
case ImuType::G320N:
return {1.7044230976507124e-11, 2.3929443359375006e-10, 125.0};
case ImuType::CPT_XW5651:
return {1.0850694444444445e-07, 1.52587890625e-06, 100.0};
case ImuType::UM442:
return {6.6581059144655048e-6, 2.99127170628e-5, 20.0};
case ImuType::IAM20680:
// (1.0/65.5)/125.0 deg/LSB (1.0/8192.0)*9.80665/125.0 m/s/LSB
return {0.0001221374045, 9.57680664e-06, 125};
default:
return {0.0, 0.0, 0.0};
}
}
} // namespace novatel
} // namespace gnss
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/gnss
|
apollo_public_repos/apollo/modules/drivers/gnss/parser/rtcm_parser.h
|
/******************************************************************************
* Copyright 2017 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#pragma once
#include <memory>
#include <string>
#include "cyber/cyber.h"
#include "modules/drivers/gnss/parser/parser.h"
#include "modules/common_msgs/sensor_msgs/gnss_raw_observation.pb.h"
namespace apollo {
namespace drivers {
namespace gnss {
class RtcmParser {
public:
using MessagePtr = ::google::protobuf::Message*;
RtcmParser(const config::Config& config,
const std::shared_ptr<apollo::cyber::Node>& node);
~RtcmParser() {}
bool Init();
void ParseRtcmData(const std::string& msg);
private:
void DispatchMessage(Parser::MessageType type, MessagePtr message);
void PublishEphemeris(const MessagePtr& message);
void PublishObservation(const MessagePtr& message);
config::Config config_;
std::shared_ptr<apollo::cyber::Node> node_ = nullptr;
std::shared_ptr<apollo::cyber::Writer<GnssEphemeris>> gnssephemeris_writer_ =
nullptr;
std::shared_ptr<apollo::cyber::Writer<EpochObservation>>
epochobservation_writer_ = nullptr;
bool init_flag_ = false;
std::unique_ptr<Parser> rtcm_parser_ = nullptr;
};
} // namespace gnss
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/gnss
|
apollo_public_repos/apollo/modules/drivers/gnss/parser/novatel_parser.cc
|
/******************************************************************************
* Copyright 2017 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
// An parser for decoding binary messages from a NovAtel receiver. The following
// messages must be
// logged in order for this parser to work properly.
//
#include <cmath>
#include <iostream>
#include <limits>
#include <memory>
#include <vector>
#include "cyber/cyber.h"
#include "modules/drivers/gnss/parser/novatel_messages.h"
#include "modules/drivers/gnss/parser/parser.h"
#include "modules/drivers/gnss/parser/rtcm_decode.h"
#include "modules/common_msgs/sensor_msgs/gnss.pb.h"
#include "modules/common_msgs/sensor_msgs/gnss_best_pose.pb.h"
#include "modules/common_msgs/sensor_msgs/gnss_raw_observation.pb.h"
#include "modules/common_msgs/sensor_msgs/heading.pb.h"
#include "modules/common_msgs/sensor_msgs/imu.pb.h"
#include "modules/common_msgs/sensor_msgs/ins.pb.h"
#include "modules/drivers/gnss/util/time_conversion.h"
namespace apollo {
namespace drivers {
namespace gnss {
// Anonymous namespace that contains helper constants and functions.
namespace {
constexpr size_t BUFFER_SIZE = 256;
constexpr int SECONDS_PER_WEEK = 60 * 60 * 24 * 7;
constexpr double DEG_TO_RAD = M_PI / 180.0;
constexpr float FLOAT_NAN = std::numeric_limits<float>::quiet_NaN();
// The NovAtel's orientation covariance matrix is pitch, roll, and yaw. We use
// the index array below
// to convert it to the orientation covariance matrix with order roll, pitch,
// and yaw.
constexpr int INDEX[] = {4, 3, 5, 1, 0, 2, 7, 6, 8};
static_assert(sizeof(INDEX) == 9 * sizeof(int), "Incorrect size of INDEX");
template <typename T>
constexpr bool is_zero(T value) {
return value == static_cast<T>(0);
}
// CRC algorithm from the NovAtel document.
inline uint32_t crc32_word(uint32_t word) {
for (int j = 0; j < 8; ++j) {
if (word & 1) {
word = (word >> 1) ^ 0xEDB88320;
} else {
word >>= 1;
}
}
return word;
}
inline uint32_t crc32_block(const uint8_t* buffer, size_t length) {
uint32_t word = 0;
while (length--) {
uint32_t t1 = (word >> 8) & 0xFFFFFF;
uint32_t t2 = crc32_word((word ^ *buffer++) & 0xFF);
word = t1 ^ t2;
}
return word;
}
// Converts NovAtel's azimuth (north = 0, east = 90) to FLU yaw (east = 0, north
// = pi/2).
constexpr double azimuth_deg_to_yaw_rad(double azimuth) {
return (90.0 - azimuth) * DEG_TO_RAD;
}
// A helper that fills an Point3D object (which uses the FLU frame) using RFU
// measurements.
inline void rfu_to_flu(double r, double f, double u,
::apollo::common::Point3D* flu) {
flu->set_x(f);
flu->set_y(-r);
flu->set_z(u);
}
} // namespace
class NovatelParser : public Parser {
public:
NovatelParser();
explicit NovatelParser(const config::Config& config);
virtual MessageType GetMessage(MessagePtr* message_ptr);
private:
bool check_crc();
Parser::MessageType PrepareMessage(MessagePtr* message_ptr);
// The handle_xxx functions return whether a message is ready.
bool HandleBestPos(const novatel::BestPos* pos, uint16_t gps_week,
uint32_t gps_millisecs);
bool HandleGnssBestpos(const novatel::BestPos* pos, uint16_t gps_week,
uint32_t gps_millisecs);
bool HandleBestVel(const novatel::BestVel* vel, uint16_t gps_week,
uint32_t gps_millisecs);
bool HandleCorrImuData(const novatel::CorrImuData* imu);
bool HandleInsCov(const novatel::InsCov* cov);
bool HandleInsPva(const novatel::InsPva* pva);
bool HandleInsPvax(const novatel::InsPvaX* pvax, uint16_t gps_week,
uint32_t gps_millisecs);
bool HandleRawImuX(const novatel::RawImuX* imu);
bool HandleRawImu(const novatel::RawImu* imu);
bool HandleBdsEph(const novatel::BDS_Ephemeris* bds_emph);
bool HandleGpsEph(const novatel::GPS_Ephemeris* gps_emph);
bool HandleGloEph(const novatel::GLO_Ephemeris* glo_emph);
void SetObservationTime();
bool DecodeGnssObservation(const uint8_t* obs_data,
const uint8_t* obs_data_end);
bool HandleHeading(const novatel::Heading* heading, uint16_t gps_week,
uint32_t gps_millisecs);
double gyro_scale_ = 0.0;
double accel_scale_ = 0.0;
float imu_measurement_span_ = 1.0f / 200.0f;
float imu_measurement_hz_ = 200.0f;
int imu_frame_mapping_ = 5;
double imu_measurement_time_previous_ = -1.0;
std::vector<uint8_t> buffer_;
size_t header_length_ = 0;
size_t total_length_ = 0;
config::ImuType imu_type_ = config::ImuType::ADIS16488;
// -1 is an unused value.
novatel::SolutionStatus solution_status_ =
static_cast<novatel::SolutionStatus>(novatel::SolutionStatus::NONE);
novatel::SolutionType position_type_ =
static_cast<novatel::SolutionType>(novatel::SolutionType::NONE);
novatel::SolutionType velocity_type_ =
static_cast<novatel::SolutionType>(novatel::SolutionType::NONE);
novatel::InsStatus ins_status_ =
static_cast<novatel::InsStatus>(novatel::InsStatus::NONE);
raw_t raw_; // used for observation data
::apollo::drivers::gnss::Gnss gnss_;
::apollo::drivers::gnss::GnssBestPose bestpos_;
::apollo::drivers::gnss::Imu imu_;
::apollo::drivers::gnss::Ins ins_;
::apollo::drivers::gnss::InsStat ins_stat_;
::apollo::drivers::gnss::GnssEphemeris gnss_ephemeris_;
::apollo::drivers::gnss::EpochObservation gnss_observation_;
::apollo::drivers::gnss::Heading heading_;
};
Parser* Parser::CreateNovatel(const config::Config& config) {
return new NovatelParser(config);
}
NovatelParser::NovatelParser() {
buffer_.reserve(BUFFER_SIZE);
ins_.mutable_position_covariance()->Resize(9, FLOAT_NAN);
ins_.mutable_euler_angles_covariance()->Resize(9, FLOAT_NAN);
ins_.mutable_linear_velocity_covariance()->Resize(9, FLOAT_NAN);
if (1 != init_raw(&raw_)) {
AFATAL << "memory allocation error for observation data structure.";
}
}
NovatelParser::NovatelParser(const config::Config& config) {
buffer_.reserve(BUFFER_SIZE);
ins_.mutable_position_covariance()->Resize(9, FLOAT_NAN);
ins_.mutable_euler_angles_covariance()->Resize(9, FLOAT_NAN);
ins_.mutable_linear_velocity_covariance()->Resize(9, FLOAT_NAN);
if (config.has_imu_type()) {
imu_type_ = config.imu_type();
}
if (1 != init_raw(&raw_)) {
AFATAL << "memory allocation error for observation data structure.";
}
}
Parser::MessageType NovatelParser::GetMessage(MessagePtr* message_ptr) {
if (data_ == nullptr) {
return MessageType::NONE;
}
while (data_ < data_end_) {
if (buffer_.empty()) { // Looking for SYNC0
if (*data_ == novatel::SYNC_0) {
buffer_.push_back(*data_);
}
++data_;
} else if (buffer_.size() == 1) { // Looking for SYNC1
if (*data_ == novatel::SYNC_1) {
buffer_.push_back(*data_++);
} else {
buffer_.clear();
}
} else if (buffer_.size() == 2) { // Looking for SYNC2
switch (*data_) {
case novatel::SYNC_2_LONG_HEADER:
buffer_.push_back(*data_++);
header_length_ = sizeof(novatel::LongHeader);
break;
case novatel::SYNC_2_SHORT_HEADER:
buffer_.push_back(*data_++);
header_length_ = sizeof(novatel::ShortHeader);
break;
default:
buffer_.clear();
}
} else if (header_length_ > 0) { // Working on header.
if (buffer_.size() < header_length_) {
buffer_.push_back(*data_++);
} else {
if (header_length_ == sizeof(novatel::LongHeader)) {
total_length_ = header_length_ + novatel::CRC_LENGTH +
reinterpret_cast<novatel::LongHeader*>(buffer_.data())
->message_length;
} else if (header_length_ == sizeof(novatel::ShortHeader)) {
total_length_ =
header_length_ + novatel::CRC_LENGTH +
reinterpret_cast<novatel::ShortHeader*>(buffer_.data())
->message_length;
} else {
AERROR << "Incorrect header_length_. Should never reach here.";
buffer_.clear();
}
header_length_ = 0;
}
} else if (total_length_ > 0) {
if (buffer_.size() < total_length_) { // Working on body.
buffer_.push_back(*data_++);
continue;
}
MessageType type = PrepareMessage(message_ptr);
buffer_.clear();
total_length_ = 0;
if (type != MessageType::NONE) {
return type;
}
}
}
return MessageType::NONE;
}
bool NovatelParser::check_crc() {
size_t l = buffer_.size() - novatel::CRC_LENGTH;
return crc32_block(buffer_.data(), l) ==
*reinterpret_cast<uint32_t*>(buffer_.data() + l);
}
Parser::MessageType NovatelParser::PrepareMessage(MessagePtr* message_ptr) {
if (!check_crc()) {
AERROR << "CRC check failed.";
return MessageType::NONE;
}
uint8_t* message = nullptr;
novatel::MessageId message_id;
uint16_t message_length;
uint16_t gps_week;
uint32_t gps_millisecs;
if (buffer_[2] == novatel::SYNC_2_LONG_HEADER) {
auto header = reinterpret_cast<const novatel::LongHeader*>(buffer_.data());
message = buffer_.data() + sizeof(novatel::LongHeader);
gps_week = header->gps_week;
gps_millisecs = header->gps_millisecs;
message_id = header->message_id;
message_length = header->message_length;
} else {
auto header = reinterpret_cast<const novatel::ShortHeader*>(buffer_.data());
message = buffer_.data() + sizeof(novatel::ShortHeader);
gps_week = header->gps_week;
gps_millisecs = header->gps_millisecs;
message_id = header->message_id;
message_length = header->message_length;
}
switch (message_id) {
case novatel::BESTGNSSPOS:
if (message_length != sizeof(novatel::BestPos)) {
AERROR << "Incorrect message_length";
break;
}
if (HandleGnssBestpos(reinterpret_cast<novatel::BestPos*>(message),
gps_week, gps_millisecs)) {
*message_ptr = &bestpos_;
return MessageType::BEST_GNSS_POS;
}
break;
case novatel::BESTPOS:
case novatel::PSRPOS:
if (message_length != sizeof(novatel::BestPos)) {
AERROR << "Incorrect message_length";
break;
}
if (HandleBestPos(reinterpret_cast<novatel::BestPos*>(message), gps_week,
gps_millisecs)) {
*message_ptr = &gnss_;
return MessageType::GNSS;
}
break;
case novatel::BESTGNSSVEL:
case novatel::BESTVEL:
case novatel::PSRVEL:
if (message_length != sizeof(novatel::BestVel)) {
AERROR << "Incorrect message_length";
break;
}
if (HandleBestVel(reinterpret_cast<novatel::BestVel*>(message), gps_week,
gps_millisecs)) {
*message_ptr = &gnss_;
return MessageType::GNSS;
}
break;
case novatel::CORRIMUDATA:
case novatel::CORRIMUDATAS:
case novatel::IMURATECORRIMUS:
if (message_length != sizeof(novatel::CorrImuData)) {
AERROR << "Incorrect message_length";
break;
}
if (HandleCorrImuData(reinterpret_cast<novatel::CorrImuData*>(message))) {
*message_ptr = &ins_;
return MessageType::INS;
}
break;
case novatel::INSCOV:
case novatel::INSCOVS:
if (message_length != sizeof(novatel::InsCov)) {
AERROR << "Incorrect message_length";
break;
}
if (HandleInsCov(reinterpret_cast<novatel::InsCov*>(message))) {
*message_ptr = &ins_;
return MessageType::INS;
}
break;
case novatel::INSPVA:
case novatel::INSPVAS:
if (message_length != sizeof(novatel::InsPva)) {
AERROR << "Incorrect message_length";
break;
}
if (HandleInsPva(reinterpret_cast<novatel::InsPva*>(message))) {
*message_ptr = &ins_;
return MessageType::INS;
}
break;
case novatel::RAWIMUX:
case novatel::RAWIMUSX:
if (message_length != sizeof(novatel::RawImuX)) {
AERROR << "Incorrect message_length";
break;
}
if (HandleRawImuX(reinterpret_cast<novatel::RawImuX*>(message))) {
*message_ptr = &imu_;
return MessageType::IMU;
}
break;
case novatel::RAWIMU:
case novatel::RAWIMUS:
if (message_length != sizeof(novatel::RawImu)) {
AERROR << "Incorrect message_length";
break;
}
if (HandleRawImu(reinterpret_cast<novatel::RawImu*>(message))) {
*message_ptr = &imu_;
return MessageType::IMU;
}
break;
case novatel::INSPVAX:
if (message_length != sizeof(novatel::InsPvaX)) {
AERROR << "Incorrect message_length";
break;
}
if (HandleInsPvax(reinterpret_cast<novatel::InsPvaX*>(message), gps_week,
gps_millisecs)) {
*message_ptr = &ins_stat_;
return MessageType::INS_STAT;
}
break;
case novatel::BDSEPHEMERIS:
if (message_length != sizeof(novatel::BDS_Ephemeris)) {
AERROR << "Incorrect BDSEPHEMERIS message_length";
break;
}
if (HandleBdsEph(reinterpret_cast<novatel::BDS_Ephemeris*>(message))) {
*message_ptr = &gnss_ephemeris_;
return MessageType::BDSEPHEMERIDES;
}
break;
case novatel::GPSEPHEMERIS:
if (message_length != sizeof(novatel::GPS_Ephemeris)) {
AERROR << "Incorrect GPSEPHEMERIS message_length";
break;
}
if (HandleGpsEph(reinterpret_cast<novatel::GPS_Ephemeris*>(message))) {
*message_ptr = &gnss_ephemeris_;
return MessageType::GPSEPHEMERIDES;
}
break;
case novatel::GLOEPHEMERIS:
if (message_length != sizeof(novatel::GLO_Ephemeris)) {
AERROR << "Incorrect GLOEPHEMERIS message length";
break;
}
if (HandleGloEph(reinterpret_cast<novatel::GLO_Ephemeris*>(message))) {
*message_ptr = &gnss_ephemeris_;
return MessageType::GLOEPHEMERIDES;
}
break;
case novatel::RANGE:
if (DecodeGnssObservation(buffer_.data(),
buffer_.data() + buffer_.size())) {
*message_ptr = &gnss_observation_;
return MessageType::OBSERVATION;
}
break;
case novatel::HEADING:
if (message_length != sizeof(novatel::Heading)) {
AERROR << "Incorrect message_length";
break;
}
if (HandleHeading(reinterpret_cast<novatel::Heading*>(message), gps_week,
gps_millisecs)) {
*message_ptr = &heading_;
return MessageType::HEADING;
}
break;
default:
break;
}
return MessageType::NONE;
}
bool NovatelParser::HandleGnssBestpos(const novatel::BestPos* pos,
uint16_t gps_week,
uint32_t gps_millisecs) {
bestpos_.set_sol_status(
static_cast<apollo::drivers::gnss::SolutionStatus>(pos->solution_status));
bestpos_.set_sol_type(
static_cast<apollo::drivers::gnss::SolutionType>(pos->position_type));
bestpos_.set_latitude(pos->latitude);
bestpos_.set_longitude(pos->longitude);
bestpos_.set_height_msl(pos->height_msl);
bestpos_.set_undulation(pos->undulation);
bestpos_.set_datum_id(
static_cast<apollo::drivers::gnss::DatumId>(pos->datum_id));
bestpos_.set_latitude_std_dev(pos->latitude_std_dev);
bestpos_.set_longitude_std_dev(pos->longitude_std_dev);
bestpos_.set_height_std_dev(pos->height_std_dev);
bestpos_.set_base_station_id(pos->base_station_id);
bestpos_.set_differential_age(pos->differential_age);
bestpos_.set_solution_age(pos->solution_age);
bestpos_.set_num_sats_tracked(pos->num_sats_tracked);
bestpos_.set_num_sats_in_solution(pos->num_sats_in_solution);
bestpos_.set_num_sats_l1(pos->num_sats_l1);
bestpos_.set_num_sats_multi(pos->num_sats_multi);
bestpos_.set_extended_solution_status(pos->extended_solution_status);
bestpos_.set_galileo_beidou_used_mask(pos->galileo_beidou_used_mask);
bestpos_.set_gps_glonass_used_mask(pos->gps_glonass_used_mask);
double seconds = gps_week * SECONDS_PER_WEEK + gps_millisecs * 1e-3;
bestpos_.set_measurement_time(seconds);
// AINFO << "Best gnss pose:\r\n" << bestpos_.DebugString();
return true;
}
bool NovatelParser::HandleBestPos(const novatel::BestPos* pos,
uint16_t gps_week, uint32_t gps_millisecs) {
gnss_.mutable_position()->set_lon(pos->longitude);
gnss_.mutable_position()->set_lat(pos->latitude);
gnss_.mutable_position()->set_height(pos->height_msl + pos->undulation);
gnss_.mutable_position_std_dev()->set_x(pos->longitude_std_dev);
gnss_.mutable_position_std_dev()->set_y(pos->latitude_std_dev);
gnss_.mutable_position_std_dev()->set_z(pos->height_std_dev);
gnss_.set_num_sats(pos->num_sats_in_solution);
if (solution_status_ != pos->solution_status) {
solution_status_ = pos->solution_status;
AINFO << "Solution status: " << static_cast<int>(solution_status_);
}
if (position_type_ != pos->position_type) {
position_type_ = pos->position_type;
AINFO << "Position type: " << static_cast<int>(position_type_);
}
gnss_.set_solution_status(static_cast<uint32_t>(pos->solution_status));
if (pos->solution_status == novatel::SolutionStatus::SOL_COMPUTED) {
gnss_.set_position_type(static_cast<uint32_t>(pos->position_type));
switch (pos->position_type) {
case novatel::SolutionType::SINGLE:
case novatel::SolutionType::INS_PSRSP:
gnss_.set_type(apollo::drivers::gnss::Gnss::SINGLE);
break;
case novatel::SolutionType::PSRDIFF:
case novatel::SolutionType::WAAS:
case novatel::SolutionType::INS_SBAS:
gnss_.set_type(apollo::drivers::gnss::Gnss::PSRDIFF);
break;
case novatel::SolutionType::FLOATCONV:
case novatel::SolutionType::L1_FLOAT:
case novatel::SolutionType::IONOFREE_FLOAT:
case novatel::SolutionType::NARROW_FLOAT:
case novatel::SolutionType::RTK_DIRECT_INS:
case novatel::SolutionType::INS_RTKFLOAT:
gnss_.set_type(apollo::drivers::gnss::Gnss::RTK_FLOAT);
break;
case novatel::SolutionType::WIDELANE:
case novatel::SolutionType::NARROWLANE:
case novatel::SolutionType::L1_INT:
case novatel::SolutionType::WIDE_INT:
case novatel::SolutionType::NARROW_INT:
case novatel::SolutionType::INS_RTKFIXED:
gnss_.set_type(apollo::drivers::gnss::Gnss::RTK_INTEGER);
break;
case novatel::SolutionType::OMNISTAR:
case novatel::SolutionType::INS_OMNISTAR:
case novatel::SolutionType::INS_OMNISTAR_HP:
case novatel::SolutionType::INS_OMNISTAR_XP:
case novatel::SolutionType::OMNISTAR_HP:
case novatel::SolutionType::OMNISTAR_XP:
case novatel::SolutionType::PPP_CONVERGING:
case novatel::SolutionType::PPP:
case novatel::SolutionType::INS_PPP_CONVERGING:
case novatel::SolutionType::INS_PPP:
gnss_.set_type(apollo::drivers::gnss::Gnss::PPP);
break;
case novatel::SolutionType::PROPOGATED:
gnss_.set_type(apollo::drivers::gnss::Gnss::PROPAGATED);
break;
default:
gnss_.set_type(apollo::drivers::gnss::Gnss::INVALID);
}
} else {
gnss_.set_type(apollo::drivers::gnss::Gnss::INVALID);
gnss_.set_position_type(0);
}
if (pos->datum_id != novatel::DatumId::WGS84) {
AERROR_EVERY(5) << "Unexpected Datum Id: "
<< static_cast<int>(pos->datum_id);
}
double seconds = gps_week * SECONDS_PER_WEEK + gps_millisecs * 1e-3;
if (gnss_.measurement_time() != seconds) {
gnss_.set_measurement_time(seconds);
return false;
}
return true;
}
bool NovatelParser::HandleBestVel(const novatel::BestVel* vel,
uint16_t gps_week, uint32_t gps_millisecs) {
if (velocity_type_ != vel->velocity_type) {
velocity_type_ = vel->velocity_type;
AINFO << "Velocity type: " << static_cast<int>(velocity_type_);
}
if (!gnss_.has_velocity_latency() ||
gnss_.velocity_latency() != vel->latency) {
AINFO << "Velocity latency: " << static_cast<int>(vel->latency);
gnss_.set_velocity_latency(vel->latency);
}
double yaw = azimuth_deg_to_yaw_rad(vel->track_over_ground);
gnss_.mutable_linear_velocity()->set_x(vel->horizontal_speed * cos(yaw));
gnss_.mutable_linear_velocity()->set_y(vel->horizontal_speed * sin(yaw));
gnss_.mutable_linear_velocity()->set_z(vel->vertical_speed);
double seconds = gps_week * SECONDS_PER_WEEK + gps_millisecs * 1e-3;
if (gnss_.measurement_time() != seconds) {
gnss_.set_measurement_time(seconds);
return false;
}
return true;
}
bool NovatelParser::HandleCorrImuData(const novatel::CorrImuData* imu) {
rfu_to_flu(imu->x_velocity_change * imu_measurement_hz_,
imu->y_velocity_change * imu_measurement_hz_,
imu->z_velocity_change * imu_measurement_hz_,
ins_.mutable_linear_acceleration());
rfu_to_flu(imu->x_angle_change * imu_measurement_hz_,
imu->y_angle_change * imu_measurement_hz_,
imu->z_angle_change * imu_measurement_hz_,
ins_.mutable_angular_velocity());
double seconds = imu->gps_week * SECONDS_PER_WEEK + imu->gps_seconds;
if (ins_.measurement_time() != seconds) {
ins_.set_measurement_time(seconds);
return false;
}
ins_.mutable_header()->set_timestamp_sec(cyber::Time::Now().ToSecond());
return true;
}
bool NovatelParser::HandleInsCov(const novatel::InsCov* cov) {
for (int i = 0; i < 9; ++i) {
ins_.set_position_covariance(
i, static_cast<float>(cov->position_covariance[i]));
ins_.set_euler_angles_covariance(
INDEX[i], static_cast<float>((DEG_TO_RAD * DEG_TO_RAD) *
cov->attitude_covariance[i]));
ins_.set_linear_velocity_covariance(
i, static_cast<float>(cov->velocity_covariance[i]));
}
return false;
}
bool NovatelParser::HandleInsPva(const novatel::InsPva* pva) {
if (ins_status_ != pva->status) {
ins_status_ = pva->status;
AINFO << "INS status: " << static_cast<int>(ins_status_);
}
ins_.mutable_position()->set_lon(pva->longitude);
ins_.mutable_position()->set_lat(pva->latitude);
ins_.mutable_position()->set_height(pva->height);
ins_.mutable_euler_angles()->set_x(pva->roll * DEG_TO_RAD);
ins_.mutable_euler_angles()->set_y(-pva->pitch * DEG_TO_RAD);
ins_.mutable_euler_angles()->set_z(azimuth_deg_to_yaw_rad(pva->azimuth));
ins_.mutable_linear_velocity()->set_x(pva->east_velocity);
ins_.mutable_linear_velocity()->set_y(pva->north_velocity);
ins_.mutable_linear_velocity()->set_z(pva->up_velocity);
switch (pva->status) {
case novatel::InsStatus::ALIGNMENT_COMPLETE:
case novatel::InsStatus::SOLUTION_GOOD:
ins_.set_type(apollo::drivers::gnss::Ins::GOOD);
break;
case novatel::InsStatus::ALIGNING:
case novatel::InsStatus::HIGH_VARIANCE:
case novatel::InsStatus::SOLUTION_FREE:
ins_.set_type(apollo::drivers::gnss::Ins::CONVERGING);
break;
default:
ins_.set_type(apollo::drivers::gnss::Ins::INVALID);
}
double seconds = pva->gps_week * SECONDS_PER_WEEK + pva->gps_seconds;
if (ins_.measurement_time() != seconds) {
ins_.set_measurement_time(seconds);
return false;
}
ins_.mutable_header()->set_timestamp_sec(cyber::Time::Now().ToSecond());
return true;
}
bool NovatelParser::HandleInsPvax(const novatel::InsPvaX* pvax,
uint16_t gps_week, uint32_t gps_millisecs) {
double seconds = gps_week * SECONDS_PER_WEEK + gps_millisecs * 1e-3;
double unix_sec = apollo::drivers::util::gps2unix(seconds);
ins_stat_.mutable_header()->set_timestamp_sec(unix_sec);
ins_stat_.set_ins_status(pvax->ins_status);
ins_stat_.set_pos_type(pvax->pos_type);
return true;
}
bool NovatelParser::HandleRawImuX(const novatel::RawImuX* imu) {
if (imu->imu_error != 0) {
AWARN << "IMU error. Status: " << std::hex << std::showbase
<< imu->imuStatus;
}
if (is_zero(gyro_scale_)) {
config::ImuType imu_type = imu_type_;
novatel::ImuParameter param = novatel::GetImuParameter(imu_type);
AINFO << "IMU type: " << config::ImuType_Name(imu_type) << "; "
<< "Gyro scale: " << param.gyro_scale << "; "
<< "Accel scale: " << param.accel_scale << "; "
<< "Sampling rate: " << param.sampling_rate_hz << ".";
if (is_zero(param.sampling_rate_hz)) {
AERROR_EVERY(5) << "Unsupported IMU type: "
<< config::ImuType_Name(imu_type);
return false;
}
gyro_scale_ = param.gyro_scale * param.sampling_rate_hz;
accel_scale_ = param.accel_scale * param.sampling_rate_hz;
imu_measurement_hz_ = static_cast<float>(param.sampling_rate_hz);
imu_measurement_span_ = static_cast<float>(1.0 / param.sampling_rate_hz);
imu_.set_measurement_span(imu_measurement_span_);
}
double time = imu->gps_week * SECONDS_PER_WEEK + imu->gps_seconds;
if (imu_measurement_time_previous_ > 0.0 &&
fabs(time - imu_measurement_time_previous_ - imu_measurement_span_) >
1e-4) {
AWARN_EVERY(5) << "Unexpected delay between two IMU measurements at: "
<< time - imu_measurement_time_previous_;
}
imu_.set_measurement_time(time);
switch (imu_frame_mapping_) {
case 5: // Default mapping.
rfu_to_flu(imu->x_velocity_change * accel_scale_,
-imu->y_velocity_change_neg * accel_scale_,
imu->z_velocity_change * accel_scale_,
imu_.mutable_linear_acceleration());
rfu_to_flu(imu->x_angle_change * gyro_scale_,
-imu->y_angle_change_neg * gyro_scale_,
imu->z_angle_change * gyro_scale_,
imu_.mutable_angular_velocity());
break;
case 6:
rfu_to_flu(-imu->y_velocity_change_neg * accel_scale_,
imu->x_velocity_change * accel_scale_,
-imu->z_velocity_change * accel_scale_,
imu_.mutable_linear_acceleration());
rfu_to_flu(-imu->y_angle_change_neg * gyro_scale_,
imu->x_angle_change * gyro_scale_,
-imu->z_angle_change * gyro_scale_,
imu_.mutable_angular_velocity());
break;
default:
AERROR_EVERY(5) << "Unsupported IMU frame mapping: "
<< imu_frame_mapping_;
}
imu_measurement_time_previous_ = time;
return true;
}
bool NovatelParser::HandleRawImu(const novatel::RawImu* imu) {
double gyro_scale = 0.0;
double accel_scale = 0.0;
float imu_measurement_span = 1.0f / 200.0f;
if (is_zero(gyro_scale_)) {
novatel::ImuParameter param = novatel::GetImuParameter(imu_type_);
if (is_zero(param.sampling_rate_hz)) {
AERROR_EVERY(5) << "Unsupported IMU type ADUS16488.";
return false;
}
gyro_scale = param.gyro_scale * param.sampling_rate_hz;
accel_scale = param.accel_scale * param.sampling_rate_hz;
imu_measurement_span = static_cast<float>(1.0 / param.sampling_rate_hz);
imu_.set_measurement_span(imu_measurement_span);
} else {
gyro_scale = gyro_scale_;
accel_scale = accel_scale_;
imu_measurement_span = imu_measurement_span_;
imu_.set_measurement_span(imu_measurement_span);
}
double time = imu->gps_week * SECONDS_PER_WEEK + imu->gps_seconds;
if (imu_measurement_time_previous_ > 0.0 &&
fabs(time - imu_measurement_time_previous_ - imu_measurement_span) >
1e-4) {
AWARN << "Unexpected delay between two IMU measurements at: "
<< time - imu_measurement_time_previous_;
}
imu_.set_measurement_time(time);
switch (imu_frame_mapping_) {
case 5: // Default mapping.
rfu_to_flu(imu->x_velocity_change * accel_scale,
-imu->y_velocity_change_neg * accel_scale,
imu->z_velocity_change * accel_scale,
imu_.mutable_linear_acceleration());
rfu_to_flu(imu->x_angle_change * gyro_scale,
-imu->y_angle_change_neg * gyro_scale,
imu->z_angle_change * gyro_scale,
imu_.mutable_angular_velocity());
break;
case 6:
rfu_to_flu(-imu->y_velocity_change_neg * accel_scale,
imu->x_velocity_change * accel_scale,
-imu->z_velocity_change * accel_scale,
imu_.mutable_linear_acceleration());
rfu_to_flu(-imu->y_angle_change_neg * gyro_scale,
imu->x_angle_change * gyro_scale,
-imu->z_angle_change * gyro_scale,
imu_.mutable_angular_velocity());
break;
default:
AERROR_EVERY(5) << "Unsupported IMU frame mapping: "
<< imu_frame_mapping_;
}
imu_measurement_time_previous_ = time;
return true;
}
bool NovatelParser::HandleGpsEph(const novatel::GPS_Ephemeris* gps_emph) {
gnss_ephemeris_.set_gnss_type(apollo::drivers::gnss::GnssType::GPS_SYS);
apollo::drivers::gnss::KepplerOrbit* keppler_orbit =
gnss_ephemeris_.mutable_keppler_orbit();
keppler_orbit->set_gnss_type(apollo::drivers::gnss::GnssType::GPS_SYS);
keppler_orbit->set_gnss_time_type(
apollo::drivers::gnss::GnssTimeType::GPS_TIME);
keppler_orbit->set_sat_prn(gps_emph->prn);
keppler_orbit->set_week_num(gps_emph->week);
keppler_orbit->set_af0(gps_emph->af0);
keppler_orbit->set_af1(gps_emph->af1);
keppler_orbit->set_af2(gps_emph->af2);
keppler_orbit->set_iode(gps_emph->iode1);
keppler_orbit->set_deltan(gps_emph->delta_A);
keppler_orbit->set_m0(gps_emph->M_0);
keppler_orbit->set_e(gps_emph->ecc);
keppler_orbit->set_roota(sqrt(gps_emph->A));
keppler_orbit->set_toe(gps_emph->toe);
keppler_orbit->set_toc(gps_emph->toc);
keppler_orbit->set_cic(gps_emph->cic);
keppler_orbit->set_crc(gps_emph->crc);
keppler_orbit->set_cis(gps_emph->cis);
keppler_orbit->set_crs(gps_emph->crs);
keppler_orbit->set_cuc(gps_emph->cuc);
keppler_orbit->set_cus(gps_emph->cus);
keppler_orbit->set_omega0(gps_emph->omega_0);
keppler_orbit->set_omega(gps_emph->omega);
keppler_orbit->set_i0(gps_emph->I_0);
keppler_orbit->set_omegadot(gps_emph->dot_omega);
keppler_orbit->set_idot(gps_emph->dot_I);
keppler_orbit->set_accuracy(static_cast<unsigned int>(sqrt(gps_emph->ura)));
keppler_orbit->set_health(gps_emph->health);
keppler_orbit->set_tgd(gps_emph->tgd);
keppler_orbit->set_iodc(gps_emph->iodc);
return true;
}
bool NovatelParser::HandleBdsEph(const novatel::BDS_Ephemeris* bds_emph) {
gnss_ephemeris_.set_gnss_type(apollo::drivers::gnss::GnssType::BDS_SYS);
apollo::drivers::gnss::KepplerOrbit* keppler_orbit =
gnss_ephemeris_.mutable_keppler_orbit();
keppler_orbit->set_gnss_type(apollo::drivers::gnss::GnssType::BDS_SYS);
keppler_orbit->set_gnss_time_type(
apollo::drivers::gnss::GnssTimeType::BDS_TIME);
keppler_orbit->set_sat_prn(bds_emph->satellite_id);
keppler_orbit->set_week_num(bds_emph->week);
keppler_orbit->set_af0(bds_emph->a0);
keppler_orbit->set_af1(bds_emph->a1);
keppler_orbit->set_af2(bds_emph->a2);
keppler_orbit->set_iode(bds_emph->aode);
keppler_orbit->set_deltan(bds_emph->delta_N);
keppler_orbit->set_m0(bds_emph->M0);
keppler_orbit->set_e(bds_emph->ecc);
keppler_orbit->set_roota(bds_emph->rootA);
keppler_orbit->set_toe(bds_emph->toe);
keppler_orbit->set_toc(bds_emph->toc);
keppler_orbit->set_cic(bds_emph->cic);
keppler_orbit->set_crc(bds_emph->crc);
keppler_orbit->set_cis(bds_emph->cis);
keppler_orbit->set_crs(bds_emph->crs);
keppler_orbit->set_cuc(bds_emph->cuc);
keppler_orbit->set_cus(bds_emph->cus);
keppler_orbit->set_omega0(bds_emph->omega0);
keppler_orbit->set_omega(bds_emph->omega);
keppler_orbit->set_i0(bds_emph->inc_angle);
keppler_orbit->set_omegadot(bds_emph->rra);
keppler_orbit->set_idot(bds_emph->idot);
keppler_orbit->set_accuracy(static_cast<unsigned int>(bds_emph->ura));
keppler_orbit->set_health(bds_emph->health1);
keppler_orbit->set_tgd(bds_emph->tdg1);
keppler_orbit->set_iodc(bds_emph->aodc);
return true;
}
bool NovatelParser::HandleGloEph(const novatel::GLO_Ephemeris* glo_emph) {
gnss_ephemeris_.set_gnss_type(apollo::drivers::gnss::GnssType::GLO_SYS);
apollo::drivers::gnss::GlonassOrbit* glonass_orbit =
gnss_ephemeris_.mutable_glonass_orbit();
glonass_orbit->set_gnss_type(apollo::drivers::gnss::GnssType::GLO_SYS);
glonass_orbit->set_gnss_time_type(
apollo::drivers::gnss::GnssTimeType::GLO_TIME);
glonass_orbit->set_slot_prn(glo_emph->sloto - 37);
glonass_orbit->set_toe(glo_emph->e_time / 1000);
glonass_orbit->set_frequency_no(glo_emph->freqo - 7);
glonass_orbit->set_week_num(glo_emph->e_week);
glonass_orbit->set_week_second_s(glo_emph->e_time / 1000);
glonass_orbit->set_tk(glo_emph->Tk);
glonass_orbit->set_clock_offset(-glo_emph->tau_n);
glonass_orbit->set_clock_drift(glo_emph->gamma);
if (glo_emph->health <= 3) {
glonass_orbit->set_health(0); // 0 means good.
} else {
glonass_orbit->set_health(1); // 1 means bad.
}
glonass_orbit->set_position_x(glo_emph->pos_x);
glonass_orbit->set_position_y(glo_emph->pos_y);
glonass_orbit->set_position_z(glo_emph->pos_z);
glonass_orbit->set_velocity_x(glo_emph->vel_x);
glonass_orbit->set_velocity_y(glo_emph->vel_y);
glonass_orbit->set_velocity_z(glo_emph->vel_z);
glonass_orbit->set_accelerate_x(glo_emph->acc_x);
glonass_orbit->set_accelerate_y(glo_emph->acc_y);
glonass_orbit->set_accelerate_z(glo_emph->acc_z);
glonass_orbit->set_infor_age(glo_emph->age);
return true;
}
bool NovatelParser::HandleHeading(const novatel::Heading* heading,
uint16_t gps_week, uint32_t gps_millisecs) {
heading_.set_solution_status(static_cast<uint32_t>(heading->solution_status));
heading_.set_position_type(static_cast<uint32_t>(heading->position_type));
heading_.set_baseline_length(heading->length);
heading_.set_heading(heading->heading);
heading_.set_pitch(heading->pitch);
heading_.set_reserved(heading->reserved);
heading_.set_heading_std_dev(heading->heading_std_dev);
heading_.set_pitch_std_dev(heading->pitch_std_dev);
heading_.set_station_id(heading->station_id);
heading_.set_satellite_tracked_number(heading->num_sats_tracked);
heading_.set_satellite_soulution_number(heading->num_sats_in_solution);
heading_.set_satellite_number_obs(heading->num_sats_ele);
heading_.set_satellite_number_multi(heading->num_sats_l2);
heading_.set_solution_source(heading->solution_source);
heading_.set_extended_solution_status(heading->extended_solution_status);
heading_.set_galileo_beidou_sig_mask(heading->galileo_beidou_sig_mask);
heading_.set_gps_glonass_sig_mask(heading->gps_glonass_sig_mask);
double seconds = gps_week * SECONDS_PER_WEEK + gps_millisecs * 1e-3;
heading_.set_measurement_time(seconds);
return true;
}
void NovatelParser::SetObservationTime() {
int week = 0;
double second = time2gpst(raw_.time, &week);
gnss_observation_.set_gnss_time_type(apollo::drivers::gnss::GPS_TIME);
gnss_observation_.set_gnss_week(week);
gnss_observation_.set_gnss_second_s(second);
}
bool NovatelParser::DecodeGnssObservation(const uint8_t* obs_data,
const uint8_t* obs_data_end) {
while (obs_data < obs_data_end) {
const int status = input_oem4(&raw_, *obs_data++);
switch (status) {
case 1: // observation data
if (raw_.obs.n == 0) {
AWARN << "Obs is zero";
}
gnss_observation_.Clear();
gnss_observation_.set_receiver_id(0);
SetObservationTime();
gnss_observation_.set_sat_obs_num(raw_.obs.n);
for (int i = 0; i < raw_.obs.n; ++i) {
int prn = 0;
int sys = 0;
sys = satsys(raw_.obs.data[i].sat, &prn);
apollo::drivers::gnss::GnssType gnss_type;
if (!gnss_sys_type(sys, &gnss_type)) {
break;
}
auto sat_obs = gnss_observation_.add_sat_obs(); // create obj
sat_obs->set_sat_prn(prn);
sat_obs->set_sat_sys(gnss_type);
int j = 0;
for (j = 0; j < NFREQ + NEXOBS; ++j) {
if (is_zero(raw_.obs.data[i].L[j])) {
break;
}
apollo::drivers::gnss::GnssBandID baud_id;
if (!gnss_baud_id(gnss_type, j, &baud_id)) {
break;
}
auto band_obs = sat_obs->add_band_obs();
if (raw_.obs.data[i].code[i] == CODE_L1C) {
band_obs->set_pseudo_type(
apollo::drivers::gnss::PseudoType::CORSE_CODE);
} else if (raw_.obs.data[i].code[i] == CODE_L1P) {
band_obs->set_pseudo_type(
apollo::drivers::gnss::PseudoType::PRECISION_CODE);
} else {
AINFO << "Code " << raw_.obs.data[i].code[i] << ", in seq " << j
<< ", gnss type " << static_cast<int>(gnss_type);
}
band_obs->set_band_id(baud_id);
band_obs->set_pseudo_range(raw_.obs.data[i].P[j]);
band_obs->set_carrier_phase(raw_.obs.data[i].L[j]);
band_obs->set_loss_lock_index(raw_.obs.data[i].SNR[j]);
band_obs->set_doppler(raw_.obs.data[i].D[j]);
band_obs->set_snr(raw_.obs.data[i].SNR[j]);
band_obs->set_snr(raw_.obs.data[i].SNR[j]);
}
sat_obs->set_band_obs_num(j);
}
return true;
default:
break;
}
}
return false;
}
} // namespace gnss
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/gnss
|
apollo_public_repos/apollo/modules/drivers/gnss/parser/data_parser.cc
|
/******************************************************************************
* Copyright 2017 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/drivers/gnss/parser/data_parser.h"
#include <cmath>
#include <memory>
#include <string>
#include "Eigen/Geometry"
#include "boost/array.hpp"
#include "cyber/cyber.h"
#include "modules/common/adapters/adapter_gflags.h"
#include "modules/common/util/message_util.h"
#include "modules/common_msgs/sensor_msgs/gnss_best_pose.pb.h"
#include "modules/common_msgs/sensor_msgs/gnss_raw_observation.pb.h"
#include "modules/common_msgs/sensor_msgs/heading.pb.h"
#include "modules/common_msgs/localization_msgs/imu.pb.h"
#include "modules/drivers/gnss/parser/parser.h"
#include "modules/drivers/gnss/util/time_conversion.h"
namespace apollo {
namespace drivers {
namespace gnss {
using ::apollo::localization::CorrectedImu;
using ::apollo::localization::Gps;
using apollo::transform::TransformStamped;
namespace {
constexpr double DEG_TO_RAD_LOCAL = M_PI / 180.0;
const char *WGS84_TEXT = "+proj=latlong +ellps=WGS84";
// covariance data for pose if can not get from novatel inscov topic
static const boost::array<double, 36> POSE_COVAR = {
2, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0,
0, 0, 0, 0.01, 0, 0, 0, 0, 0, 0, 0.01, 0, 0, 0, 0, 0, 0, 0.01};
Parser *CreateParser(config::Config config, bool is_base_station = false) {
switch (config.data().format()) {
case config::Stream::NOVATEL_BINARY:
return Parser::CreateNovatel(config);
default:
return nullptr;
}
}
} // namespace
DataParser::DataParser(const config::Config &config,
const std::shared_ptr<apollo::cyber::Node> &node)
: config_(config), tf_broadcaster_(node), node_(node) {
std::string utm_target_param;
wgs84pj_source_ = pj_init_plus(WGS84_TEXT);
utm_target_ = pj_init_plus(config_.proj4_text().c_str());
gnss_status_.set_solution_status(0);
gnss_status_.set_num_sats(0);
gnss_status_.set_position_type(0);
gnss_status_.set_solution_completed(false);
ins_status_.set_type(InsStatus::INVALID);
}
bool DataParser::Init() {
ins_status_.mutable_header()->set_timestamp_sec(
cyber::Time::Now().ToSecond());
gnss_status_.mutable_header()->set_timestamp_sec(
cyber::Time::Now().ToSecond());
gnssstatus_writer_ = node_->CreateWriter<GnssStatus>(FLAGS_gnss_status_topic);
insstatus_writer_ = node_->CreateWriter<InsStatus>(FLAGS_ins_status_topic);
gnssbestpose_writer_ =
node_->CreateWriter<GnssBestPose>(FLAGS_gnss_best_pose_topic);
corrimu_writer_ = node_->CreateWriter<CorrectedImu>(FLAGS_imu_topic);
insstat_writer_ = node_->CreateWriter<InsStat>(FLAGS_ins_stat_topic);
gnssephemeris_writer_ =
node_->CreateWriter<GnssEphemeris>(FLAGS_gnss_rtk_eph_topic);
epochobservation_writer_ =
node_->CreateWriter<EpochObservation>(FLAGS_gnss_rtk_obs_topic);
heading_writer_ = node_->CreateWriter<Heading>(FLAGS_heading_topic);
rawimu_writer_ = node_->CreateWriter<Imu>(FLAGS_raw_imu_topic);
gps_writer_ = node_->CreateWriter<Gps>(FLAGS_gps_topic);
common::util::FillHeader("gnss", &ins_status_);
insstatus_writer_->Write(ins_status_);
common::util::FillHeader("gnss", &gnss_status_);
gnssstatus_writer_->Write(gnss_status_);
AINFO << "Creating data parser of format: " << config_.data().format();
data_parser_.reset(CreateParser(config_, false));
if (!data_parser_) {
AFATAL << "Failed to create data parser.";
return false;
}
init_flag_ = true;
return true;
}
void DataParser::ParseRawData(const std::string &msg) {
if (!init_flag_) {
AERROR << "Data parser not init.";
return;
}
data_parser_->Update(msg);
Parser::MessageType type;
MessagePtr msg_ptr;
while (cyber::OK()) {
type = data_parser_->GetMessage(&msg_ptr);
if (type == Parser::MessageType::NONE) {
break;
}
DispatchMessage(type, msg_ptr);
}
}
void DataParser::CheckInsStatus(::apollo::drivers::gnss::Ins *ins) {
static double last_notify = cyber::Time().Now().ToSecond();
double now = cyber::Time().Now().ToSecond();
if (ins_status_record_ != static_cast<uint32_t>(ins->type()) ||
(now - last_notify) > 1.0) {
last_notify = now;
ins_status_record_ = static_cast<uint32_t>(ins->type());
switch (ins->type()) {
case apollo::drivers::gnss::Ins::GOOD:
ins_status_.set_type(apollo::drivers::gnss::InsStatus::GOOD);
break;
case apollo::drivers::gnss::Ins::CONVERGING:
ins_status_.set_type(apollo::drivers::gnss::InsStatus::CONVERGING);
break;
case apollo::drivers::gnss::Ins::INVALID:
default:
ins_status_.set_type(apollo::drivers::gnss::InsStatus::INVALID);
break;
}
common::util::FillHeader("gnss", &ins_status_);
insstatus_writer_->Write(ins_status_);
}
}
void DataParser::CheckGnssStatus(::apollo::drivers::gnss::Gnss *gnss) {
gnss_status_.set_solution_status(
static_cast<uint32_t>(gnss->solution_status()));
gnss_status_.set_num_sats(static_cast<uint32_t>(gnss->num_sats()));
gnss_status_.set_position_type(static_cast<uint32_t>(gnss->position_type()));
if (static_cast<uint32_t>(gnss->solution_status()) == 0) {
gnss_status_.set_solution_completed(true);
} else {
gnss_status_.set_solution_completed(false);
}
common::util::FillHeader("gnss", &gnss_status_);
gnssstatus_writer_->Write(gnss_status_);
}
void DataParser::DispatchMessage(Parser::MessageType type, MessagePtr message) {
switch (type) {
case Parser::MessageType::GNSS:
CheckGnssStatus(As<::apollo::drivers::gnss::Gnss>(message));
break;
case Parser::MessageType::BEST_GNSS_POS:
PublishBestpos(message);
break;
case Parser::MessageType::IMU:
PublishImu(message);
break;
case Parser::MessageType::INS:
CheckInsStatus(As<::apollo::drivers::gnss::Ins>(message));
PublishCorrimu(message);
PublishOdometry(message);
break;
case Parser::MessageType::INS_STAT:
PublishInsStat(message);
break;
case Parser::MessageType::BDSEPHEMERIDES:
case Parser::MessageType::GPSEPHEMERIDES:
case Parser::MessageType::GLOEPHEMERIDES:
PublishEphemeris(message);
break;
case Parser::MessageType::OBSERVATION:
PublishObservation(message);
break;
case Parser::MessageType::HEADING:
PublishHeading(message);
break;
default:
break;
}
}
void DataParser::PublishInsStat(const MessagePtr message) {
auto ins_stat = std::make_shared<InsStat>(*As<InsStat>(message));
common::util::FillHeader("gnss", ins_stat.get());
insstat_writer_->Write(ins_stat);
}
void DataParser::PublishBestpos(const MessagePtr message) {
auto bestpos = std::make_shared<GnssBestPose>(*As<GnssBestPose>(message));
common::util::FillHeader("gnss", bestpos.get());
gnssbestpose_writer_->Write(bestpos);
}
void DataParser::PublishImu(const MessagePtr message) {
auto raw_imu = std::make_shared<Imu>(*As<Imu>(message));
Imu *imu = As<Imu>(message);
raw_imu->mutable_linear_acceleration()->set_x(
-imu->linear_acceleration().y());
raw_imu->mutable_linear_acceleration()->set_y(imu->linear_acceleration().x());
raw_imu->mutable_linear_acceleration()->set_z(imu->linear_acceleration().z());
raw_imu->mutable_angular_velocity()->set_x(-imu->angular_velocity().y());
raw_imu->mutable_angular_velocity()->set_y(imu->angular_velocity().x());
raw_imu->mutable_angular_velocity()->set_z(imu->angular_velocity().z());
common::util::FillHeader("gnss", raw_imu.get());
rawimu_writer_->Write(raw_imu);
}
void DataParser::PublishOdometry(const MessagePtr message) {
Ins *ins = As<Ins>(message);
auto gps = std::make_shared<Gps>();
double unix_sec = apollo::drivers::util::gps2unix(ins->measurement_time());
gps->mutable_header()->set_timestamp_sec(unix_sec);
auto *gps_msg = gps->mutable_localization();
// 1. pose xyz
double x = ins->position().lon();
double y = ins->position().lat();
x *= DEG_TO_RAD_LOCAL;
y *= DEG_TO_RAD_LOCAL;
pj_transform(wgs84pj_source_, utm_target_, 1, 1, &x, &y, NULL);
gps_msg->mutable_position()->set_x(x);
gps_msg->mutable_position()->set_y(y);
gps_msg->mutable_position()->set_z(ins->position().height());
// 2. orientation
Eigen::Quaterniond q =
Eigen::AngleAxisd(ins->euler_angles().z() - 90 * DEG_TO_RAD_LOCAL,
Eigen::Vector3d::UnitZ()) *
Eigen::AngleAxisd(-ins->euler_angles().y(), Eigen::Vector3d::UnitX()) *
Eigen::AngleAxisd(ins->euler_angles().x(), Eigen::Vector3d::UnitY());
gps_msg->mutable_orientation()->set_qx(q.x());
gps_msg->mutable_orientation()->set_qy(q.y());
gps_msg->mutable_orientation()->set_qz(q.z());
gps_msg->mutable_orientation()->set_qw(q.w());
gps_msg->mutable_linear_velocity()->set_x(ins->linear_velocity().x());
gps_msg->mutable_linear_velocity()->set_y(ins->linear_velocity().y());
gps_msg->mutable_linear_velocity()->set_z(ins->linear_velocity().z());
gps_writer_->Write(gps);
if (config_.tf().enable()) {
TransformStamped transform;
GpsToTransformStamped(gps, &transform);
tf_broadcaster_.SendTransform(transform);
}
}
void DataParser::PublishCorrimu(const MessagePtr message) {
Ins *ins = As<Ins>(message);
auto imu = std::make_shared<CorrectedImu>();
double unix_sec = apollo::drivers::util::gps2unix(ins->measurement_time());
imu->mutable_header()->set_timestamp_sec(unix_sec);
auto *imu_msg = imu->mutable_imu();
imu_msg->mutable_linear_acceleration()->set_x(
-ins->linear_acceleration().y());
imu_msg->mutable_linear_acceleration()->set_y(ins->linear_acceleration().x());
imu_msg->mutable_linear_acceleration()->set_z(ins->linear_acceleration().z());
imu_msg->mutable_angular_velocity()->set_x(-ins->angular_velocity().y());
imu_msg->mutable_angular_velocity()->set_y(ins->angular_velocity().x());
imu_msg->mutable_angular_velocity()->set_z(ins->angular_velocity().z());
imu_msg->mutable_euler_angles()->set_x(ins->euler_angles().x());
imu_msg->mutable_euler_angles()->set_y(-ins->euler_angles().y());
imu_msg->mutable_euler_angles()->set_z(ins->euler_angles().z() -
90 * DEG_TO_RAD_LOCAL);
corrimu_writer_->Write(imu);
}
void DataParser::PublishEphemeris(const MessagePtr message) {
auto eph = std::make_shared<GnssEphemeris>(*As<GnssEphemeris>(message));
gnssephemeris_writer_->Write(eph);
}
void DataParser::PublishObservation(const MessagePtr message) {
auto observation =
std::make_shared<EpochObservation>(*As<EpochObservation>(message));
epochobservation_writer_->Write(observation);
}
void DataParser::PublishHeading(const MessagePtr message) {
auto heading = std::make_shared<Heading>(*As<Heading>(message));
heading_writer_->Write(heading);
}
void DataParser::GpsToTransformStamped(const std::shared_ptr<Gps> &gps,
TransformStamped *transform) {
transform->mutable_header()->set_timestamp_sec(gps->header().timestamp_sec());
transform->mutable_header()->set_frame_id(config_.tf().frame_id());
transform->set_child_frame_id(config_.tf().child_frame_id());
auto translation = transform->mutable_transform()->mutable_translation();
translation->set_x(gps->localization().position().x());
translation->set_y(gps->localization().position().y());
translation->set_z(gps->localization().position().z());
auto rotation = transform->mutable_transform()->mutable_rotation();
rotation->set_qx(gps->localization().orientation().qx());
rotation->set_qy(gps->localization().orientation().qy());
rotation->set_qz(gps->localization().orientation().qz());
rotation->set_qw(gps->localization().orientation().qw());
}
} // namespace gnss
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/gnss
|
apollo_public_repos/apollo/modules/drivers/gnss/parser/rtcm_parser.cc
|
/******************************************************************************
* Copyright 2017 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/drivers/gnss/parser/rtcm_parser.h"
#include <memory>
#include "cyber/cyber.h"
#include "modules/common/adapters/adapter_gflags.h"
#include "modules/drivers/gnss/parser/parser.h"
#include "modules/drivers/gnss/parser/rtcm3_parser.h"
#include "modules/common_msgs/sensor_msgs/gnss_raw_observation.pb.h"
namespace apollo {
namespace drivers {
namespace gnss {
using ::apollo::drivers::gnss::EpochObservation;
using ::apollo::drivers::gnss::GnssEphemeris;
RtcmParser::RtcmParser(const config::Config& config,
const std::shared_ptr<apollo::cyber::Node>& node)
: config_(config), node_(node) {}
bool RtcmParser::Init() {
rtcm_parser_.reset(new Rtcm3Parser(true));
if (!rtcm_parser_) {
AERROR << "Failed to create rtcm parser.";
return false;
}
gnssephemeris_writer_ =
node_->CreateWriter<GnssEphemeris>(FLAGS_gnss_rtk_eph_topic);
epochobservation_writer_ =
node_->CreateWriter<EpochObservation>(FLAGS_gnss_rtk_obs_topic);
init_flag_ = true;
return true;
}
void RtcmParser::ParseRtcmData(const std::string& msg) {
if (!init_flag_) {
return;
}
rtcm_parser_->Update(msg);
Parser::MessageType type;
MessagePtr msg_ptr;
while (cyber::OK()) {
type = rtcm_parser_->GetMessage(&msg_ptr);
if (type == Parser::MessageType::NONE) {
break;
}
DispatchMessage(type, msg_ptr);
}
}
void RtcmParser::DispatchMessage(Parser::MessageType type, MessagePtr message) {
switch (type) {
case Parser::MessageType::EPHEMERIDES:
PublishEphemeris(message);
break;
case Parser::MessageType::OBSERVATION:
PublishObservation(message);
break;
default:
break;
}
}
void RtcmParser::PublishEphemeris(const MessagePtr& message) {
auto eph = std::make_shared<GnssEphemeris>(*As<GnssEphemeris>(message));
gnssephemeris_writer_->Write(eph);
}
void RtcmParser::PublishObservation(const MessagePtr& message) {
auto observation =
std::make_shared<EpochObservation>(*As<EpochObservation>(message));
epochobservation_writer_->Write(observation);
}
} // namespace gnss
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/gnss
|
apollo_public_repos/apollo/modules/drivers/gnss/parser/BUILD
|
load("@rules_cc//cc:defs.bzl", "cc_library")
load("//tools:cpplint.bzl", "cpplint")
package(default_visibility = ["//visibility:public"])
cc_library(
name = "gnss_parser",
deps = [
":data_parser",
":novatel_parser",
":rtcm_parsers",
],
)
cc_library(
name = "data_parser",
srcs = ["data_parser.cc"],
hdrs = [
"data_parser.h",
"parser.h",
],
copts = ["-Ithird_party/rtklib"],
deps = [
":novatel_parser",
"//cyber",
"//modules/common/adapters:adapter_gflags",
"//modules/common/util:util_tool",
"//modules/common_msgs/sensor_msgs:gnss_best_pose_cc_proto",
"//modules/common_msgs/sensor_msgs:gnss_cc_proto",
"//modules/drivers/gnss/proto:gnss_status_cc_proto",
"//modules/drivers/gnss/util:gnss_util",
"//modules/common_msgs/localization_msgs:gps_cc_proto",
"//modules/common_msgs/localization_msgs:imu_cc_proto",
"//modules/transform:transform_broadcaster",
"@eigen",
"@proj",
],
)
cc_library(
name = "novatel_parser",
srcs = ["novatel_parser.cc"],
hdrs = [
"novatel_messages.h",
"parser.h",
"rtcm_decode.h",
],
copts = ["-Ithird_party/rtklib"],
deps = [
"//cyber",
"//modules/common/adapters:adapter_gflags",
"//modules/common_msgs/basic_msgs:error_code_cc_proto",
"//modules/common_msgs/basic_msgs:geometry_cc_proto",
"//modules/common_msgs/basic_msgs:header_cc_proto",
"//modules/drivers/gnss/proto:config_cc_proto",
"//modules/common_msgs/sensor_msgs:gnss_best_pose_cc_proto",
"//modules/common_msgs/sensor_msgs:gnss_cc_proto",
"//modules/common_msgs/sensor_msgs:gnss_raw_observation_cc_proto",
"//modules/common_msgs/sensor_msgs:heading_cc_proto",
"//modules/common_msgs/sensor_msgs:imu_cc_proto",
"//modules/common_msgs/sensor_msgs:ins_cc_proto",
"//modules/drivers/gnss/util:gnss_util",
"//third_party/rtklib",
],
)
cc_library(
name = "rtcm_parsers",
srcs = [
"rtcm3_parser.cc",
"rtcm_parser.cc",
],
hdrs = [
"parser.h",
"rtcm3_parser.h",
"rtcm_decode.h",
"rtcm_parser.h",
],
copts = ["-Ithird_party/rtklib"],
deps = [
"//cyber",
"//modules/common/adapters:adapter_gflags",
"//modules/drivers/gnss/proto:config_cc_proto",
"//modules/common_msgs/sensor_msgs:gnss_raw_observation_cc_proto",
"//modules/drivers/gnss/util:gnss_util",
"//third_party/rtklib",
],
)
cpplint()
| 0
|
apollo_public_repos/apollo/modules/drivers/gnss
|
apollo_public_repos/apollo/modules/drivers/gnss/parser/rtcm3_parser.h
|
/******************************************************************************
* Copyright 2017 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#pragma once
#include <cmath>
#include <iostream>
#include <limits>
#include <map>
#include <memory>
#include <vector>
#include "modules/common_msgs/sensor_msgs/gnss_raw_observation.pb.h"
#include "cyber/cyber.h"
#include "modules/drivers/gnss/parser/parser.h"
#include "modules/drivers/gnss/parser/rtcm_decode.h"
namespace apollo {
namespace drivers {
namespace gnss {
class Rtcm3Parser : public Parser {
public:
explicit Rtcm3Parser(bool is_base_satation);
virtual MessageType GetMessage(MessagePtr *message_ptr);
private:
void SetObservationTime();
bool SetStationPosition();
void FillKepplerOrbit(const eph_t &eph,
apollo::drivers::gnss::KepplerOrbit *keppler_orbit);
void FillGlonassOrbit(const geph_t &eph,
apollo::drivers::gnss::GlonassOrbit *keppler_orbit);
bool ProcessObservation();
bool ProcessEphemerides();
bool ProcessStationParameters();
bool init_flag_;
std::vector<uint8_t> buffer_;
rtcm_t rtcm_;
bool is_base_station_ = false;
apollo::drivers::gnss::GnssEphemeris ephemeris_;
apollo::drivers::gnss::EpochObservation observation_;
struct Point3D {
double x;
double y;
double z;
};
std::map<int, Point3D> station_location_;
};
} // namespace gnss
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/gnss
|
apollo_public_repos/apollo/modules/drivers/gnss/parser/rtcm_decode.h
|
/******************************************************************************
* Copyright 2017 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#pragma once
#include <rtklib.h>
#include "modules/common_msgs/sensor_msgs/gnss_raw_observation.pb.h"
namespace apollo {
namespace drivers {
namespace gnss {
static inline int baud_obs_num(int type) {
switch (type) {
case 1002: // gps L1 only
return 1;
case 1004: // gps L1/L1
return 2;
case 1010: // glonass L1 only
return 0;
case 1012: // glonass L1 & L2
return 2;
case 1125:
case 1005: // station arp, for pose, no antenna height
case 1006: // station arp, with antenna height
case 1007: // antenna descriptor
case 1008: // antenna descriptor& serial number
case 1019: // gps ephemerides
case 1020: // glonass ephemerides
case 1033: // receiver and antenna descriptor, for station
case 1044: // qzss ephemerides
case 1045: // galileo
default:
return 0;
}
}
static inline bool gnss_sys(int message_type,
apollo::drivers::gnss::GnssType* gnss_type) {
switch (message_type) {
case 1019: // gps ephemerides
*gnss_type = apollo::drivers::gnss::GnssType::GPS_SYS;
break;
case 1020: // glonass ephemerides
*gnss_type = apollo::drivers::gnss::GnssType::GLO_SYS;
break;
case 1045: // galileo ephemerides
*gnss_type = apollo::drivers::gnss::GnssType::GAL_SYS;
break;
case 1047: // beidou ephemerides
*gnss_type = apollo::drivers::gnss::GnssType::BDS_SYS;
break;
case 1044: // qzss ephemerides
default:
return false;
}
return true;
}
static inline bool gnss_sys_type(int sys_id,
apollo::drivers::gnss::GnssType* gnss_type) {
switch (sys_id) {
case SYS_GPS:
*gnss_type = apollo::drivers::gnss::GnssType::GPS_SYS;
break;
case SYS_CMP:
*gnss_type = apollo::drivers::gnss::GnssType::BDS_SYS;
break;
case SYS_GLO:
*gnss_type = apollo::drivers::gnss::GnssType::GLO_SYS;
break;
case SYS_GAL:
*gnss_type = apollo::drivers::gnss::GnssType::GAL_SYS;
break;
default:
AINFO << "Not support sys id: " << sys_id;
return false;
}
return true;
}
static inline bool gnss_baud_id(apollo::drivers::gnss::GnssType sys_type,
int seq,
apollo::drivers::gnss::GnssBandID* baud_id) {
switch (sys_type) {
case apollo::drivers::gnss::GnssType::GPS_SYS:
if (seq == 0) {
*baud_id = apollo::drivers::gnss::GnssBandID::GPS_L1;
} else if (seq == 1) {
*baud_id = apollo::drivers::gnss::GnssBandID::GPS_L2;
} else if (seq == 2) {
*baud_id = apollo::drivers::gnss::GnssBandID::GPS_L5;
} else {
AINFO << "Not support gps baud seq : " << seq;
return false;
}
break;
case apollo::drivers::gnss::GnssType::BDS_SYS:
if (seq == 0) {
*baud_id = apollo::drivers::gnss::GnssBandID::BDS_B1;
} else if (seq == 1) {
*baud_id = apollo::drivers::gnss::GnssBandID::BDS_B2;
} else if (seq == 2) {
*baud_id = apollo::drivers::gnss::GnssBandID::BDS_B3;
} else {
AINFO << "Not support beidou baud seq : " << seq;
return false;
}
break;
case apollo::drivers::gnss::GnssType::GLO_SYS:
if (seq == 0) {
*baud_id = apollo::drivers::gnss::GnssBandID::GLO_G1;
} else if (seq == 1) {
*baud_id = apollo::drivers::gnss::GnssBandID::GLO_G2;
} else {
AINFO << "Not support beidou glonass seq : " << seq;
return false;
}
break;
default:
AINFO << "Not support sys " << static_cast<int>(sys_type) << ", seq "
<< seq;
return false;
}
return true;
}
static inline bool gnss_time_type(
apollo::drivers::gnss::GnssType sys_type,
apollo::drivers::gnss::GnssTimeType* time_type) {
switch (sys_type) {
case apollo::drivers::gnss::GnssType::GPS_SYS:
*time_type = apollo::drivers::gnss::GnssTimeType::GPS_TIME;
break;
case apollo::drivers::gnss::GnssType::BDS_SYS:
*time_type = apollo::drivers::gnss::GnssTimeType::BDS_TIME;
break;
case apollo::drivers::gnss::GnssType::GLO_SYS:
*time_type = apollo::drivers::gnss::GnssTimeType::GLO_TIME;
break;
case apollo::drivers::gnss::GnssType::GAL_SYS:
*time_type = apollo::drivers::gnss::GnssTimeType::GAL_TIME;
break;
default:
AINFO << "Not support sys " << static_cast<int>(sys_type);
return false;
}
return true;
}
} // namespace gnss
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/gnss
|
apollo_public_repos/apollo/modules/drivers/gnss/parser/rtcm3_parser.cc
|
/******************************************************************************
* Copyright 2017 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/drivers/gnss/parser/rtcm3_parser.h"
#include <utility>
namespace apollo {
namespace drivers {
namespace gnss {
// Anonymous namespace that contains helper constants and functions.
namespace {
template <typename T>
constexpr bool is_zero(T value) {
return value == static_cast<T>(0);
}
} // namespace
Parser *Parser::CreateRtcmV3(bool is_base_station) {
return new Rtcm3Parser(is_base_station);
}
Rtcm3Parser::Rtcm3Parser(bool is_base_station) {
if (1 != init_rtcm(&rtcm_)) {
init_flag_ = true;
} else {
init_flag_ = false;
}
ephemeris_.Clear();
observation_.Clear();
is_base_station_ = is_base_station;
}
bool Rtcm3Parser::SetStationPosition() {
auto iter = station_location_.find(rtcm_.staid);
if (iter == station_location_.end()) {
AWARN << "Station " << rtcm_.staid << " has no location info.";
return false;
}
observation_.set_position_x(iter->second.x);
observation_.set_position_y(iter->second.y);
observation_.set_position_z(iter->second.z);
return true;
}
void Rtcm3Parser::FillKepplerOrbit(
const eph_t &eph, apollo::drivers::gnss::KepplerOrbit *keppler_orbit) {
keppler_orbit->set_week_num(eph.week);
keppler_orbit->set_af0(eph.f0);
keppler_orbit->set_af1(eph.f1);
keppler_orbit->set_af2(eph.f2);
keppler_orbit->set_iode(eph.iode);
keppler_orbit->set_deltan(eph.deln);
keppler_orbit->set_m0(eph.M0);
keppler_orbit->set_e(eph.e);
keppler_orbit->set_roota(std::sqrt(eph.A));
keppler_orbit->set_toe(eph.toes);
keppler_orbit->set_toc(eph.tocs);
keppler_orbit->set_cic(eph.cic);
keppler_orbit->set_crc(eph.crc);
keppler_orbit->set_cis(eph.cis);
keppler_orbit->set_crs(eph.crs);
keppler_orbit->set_cuc(eph.cuc);
keppler_orbit->set_cus(eph.cus);
keppler_orbit->set_omega0(eph.OMG0);
keppler_orbit->set_omega(eph.omg);
keppler_orbit->set_i0(eph.i0);
keppler_orbit->set_omegadot(eph.OMGd);
keppler_orbit->set_idot(eph.idot);
// keppler_orbit->set_codesonL2channel(eph.);
keppler_orbit->set_l2pdataflag(eph.flag);
keppler_orbit->set_accuracy(eph.sva);
keppler_orbit->set_health(eph.svh);
keppler_orbit->set_tgd(eph.tgd[0]);
keppler_orbit->set_iodc(eph.iodc);
int prn = 0;
satsys(eph.sat, &prn);
keppler_orbit->set_sat_prn(prn);
}
void Rtcm3Parser::FillGlonassOrbit(const geph_t &eph,
apollo::drivers::gnss::GlonassOrbit *orbit) {
orbit->set_position_x(eph.pos[0]);
orbit->set_position_y(eph.pos[1]);
orbit->set_position_z(eph.pos[2]);
orbit->set_velocity_x(eph.vel[0]);
orbit->set_velocity_y(eph.vel[1]);
orbit->set_velocity_z(eph.vel[2]);
orbit->set_accelerate_x(eph.acc[0]);
orbit->set_accelerate_y(eph.acc[1]);
orbit->set_accelerate_z(eph.acc[2]);
orbit->set_health(eph.svh);
orbit->set_clock_offset(-eph.taun);
orbit->set_clock_drift(eph.gamn);
orbit->set_infor_age(eph.age);
orbit->set_frequency_no(eph.frq);
// orbit->set_toe(eph.toe.time + eph.toe.sec);
// orbit->set_tk(eph.tof.time + eph.tof.sec);
int week = 0;
double second = time2gpst(eph.toe, &week);
orbit->set_week_num(week);
orbit->set_week_second_s(second);
orbit->set_toe(second);
second = time2gpst(eph.tof, &week);
orbit->set_tk(second);
orbit->set_gnss_time_type(apollo::drivers::gnss::GnssTimeType::GPS_TIME);
int prn = 0;
satsys(eph.sat, &prn);
orbit->set_slot_prn(prn);
}
void Rtcm3Parser::SetObservationTime() {
int week = 0;
double second = time2gpst(rtcm_.time, &week);
observation_.set_gnss_time_type(apollo::drivers::gnss::GPS_TIME);
observation_.set_gnss_week(week);
observation_.set_gnss_second_s(second);
}
Parser::MessageType Rtcm3Parser::GetMessage(MessagePtr *message_ptr) {
if (data_ == nullptr) {
return MessageType::NONE;
}
while (data_ < data_end_) {
const int status = input_rtcm3(&rtcm_, *data_++); // parse data use rtklib
switch (status) {
case 1: // observation data
if (ProcessObservation()) {
*message_ptr = &observation_;
return MessageType::OBSERVATION;
}
break;
case 2: // ephemeris
if (ProcessEphemerides()) {
*message_ptr = &ephemeris_;
return MessageType::EPHEMERIDES;
}
break;
case 5:
ProcessStationParameters();
break;
case 10: // ssr messages
default:
break;
}
}
return MessageType::NONE;
}
bool Rtcm3Parser::ProcessObservation() {
if (rtcm_.obs.n == 0) {
AWARN << "Obs is zero.";
}
observation_.Clear();
SetStationPosition();
if (!is_base_station_) {
observation_.set_receiver_id(0);
} else {
observation_.set_receiver_id(rtcm_.staid + 0x80000000);
}
// set time
SetObservationTime();
// set satellite obs
observation_.set_sat_obs_num(rtcm_.obs.n);
observation_.set_health_flag(rtcm_.stah);
for (int i = 0; i < rtcm_.obs.n; ++i) {
int prn = 0;
int sys = 0;
sys = satsys(rtcm_.obs.data[i].sat, &prn);
apollo::drivers::gnss::GnssType gnss_type;
// transform sys to local sys type
if (!gnss_sys_type(sys, &gnss_type)) {
return false;
}
auto sat_obs = observation_.add_sat_obs(); // create obj
sat_obs->set_sat_prn(prn);
sat_obs->set_sat_sys(gnss_type);
int j = 0;
for (j = 0; j < NFREQ + NEXOBS; ++j) {
if (is_zero(rtcm_.obs.data[i].L[j])) {
break;
}
apollo::drivers::gnss::GnssBandID baud_id;
if (!gnss_baud_id(gnss_type, j, &baud_id)) {
break;
}
auto band_obs = sat_obs->add_band_obs();
if (rtcm_.obs.data[i].code[i] == CODE_L1C) {
band_obs->set_pseudo_type(
apollo::drivers::gnss::PseudoType::CORSE_CODE);
} else if (rtcm_.obs.data[i].code[i] == CODE_L1P) {
band_obs->set_pseudo_type(
apollo::drivers::gnss::PseudoType::PRECISION_CODE);
} else {
// AINFO << "Message type " << rtcm_.message_type;
}
band_obs->set_band_id(baud_id);
band_obs->set_pseudo_range(rtcm_.obs.data[i].P[j]);
band_obs->set_carrier_phase(rtcm_.obs.data[i].L[j]);
band_obs->set_loss_lock_index(rtcm_.obs.data[i].SNR[j]);
band_obs->set_doppler(rtcm_.obs.data[i].D[j]);
band_obs->set_snr(rtcm_.obs.data[i].SNR[j]);
}
sat_obs->set_band_obs_num(j);
}
return true;
}
bool Rtcm3Parser::ProcessEphemerides() {
apollo::drivers::gnss::GnssType gnss_type;
if (!gnss_sys(rtcm_.message_type, &gnss_type)) {
AINFO << "Failed get gnss type from message type " << rtcm_.message_type;
return false;
}
apollo::drivers::gnss::GnssTimeType time_type;
gnss_time_type(gnss_type, &time_type);
AINFO << "Gnss sys " << static_cast<int>(gnss_type) << "ephemeris info.";
ephemeris_.Clear();
ephemeris_.set_gnss_type(gnss_type);
if (gnss_type == apollo::drivers::gnss::GnssType::GLO_SYS) {
auto obit = ephemeris_.mutable_glonass_orbit();
obit->set_gnss_type(gnss_type);
obit->set_gnss_time_type(time_type);
FillGlonassOrbit(rtcm_.nav.geph[rtcm_.ephsat - 1], obit);
} else {
auto obit = ephemeris_.mutable_keppler_orbit();
obit->set_gnss_type(gnss_type);
obit->set_gnss_time_type(time_type);
FillKepplerOrbit(rtcm_.nav.eph[rtcm_.ephsat - 1], obit);
}
return true;
}
bool Rtcm3Parser::ProcessStationParameters() {
// station pose/ant parameters, set pose.
// update station location
auto iter = station_location_.find(rtcm_.staid);
if (iter == station_location_.end()) {
Point3D point;
AINFO << "Add pose for station id: " << rtcm_.staid;
point.x = rtcm_.sta.pos[0];
point.y = rtcm_.sta.pos[1];
point.z = rtcm_.sta.pos[2];
station_location_.insert(std::make_pair(rtcm_.staid, point));
} else {
iter->second.x = rtcm_.sta.pos[0];
iter->second.y = rtcm_.sta.pos[1];
iter->second.z = rtcm_.sta.pos[2];
}
return true;
}
} // namespace gnss
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/gnss
|
apollo_public_repos/apollo/modules/drivers/gnss/conf/gnss_conf.pb.txt
|
data {
format: NOVATEL_BINARY
serial {
device: "/dev/novatel0"
baud_rate: 115200
}
}
#rtk_from {
# format: RTCM_V3
# ntrip {
#address: "111.111.111.11"
#port: 0000
#mount_point: "yourport"
#user: "username"
#password: "password"
#timeout_s: 5
# }
# push_location: true
#}
rtk_to {
format: NOVATEL_BINARY
serial {
device: "/dev/novatel1"
baud_rate: 115200
}
}
command {
format: NOVATEL_BINARY
serial {
device: "/dev/novatel2"
baud_rate: 115200
}
}
rtk_solution_type: RTK_RECEIVER_SOLUTION
imu_type: ADIS16488
proj4_text: "+proj=utm +zone=10 +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs"
tf {
frame_id: "world"
child_frame_id: "novatel"
enable: true
}
# If given, the driver will send velocity info into novatel one time per second
wheel_parameters: "SETWHEELPARAMETERS 100 1 1\r\n"
gpsbin_folder: "/apollo/data/gpsbin"
#########################################################################
# notice: only for debug, won't configure device through driver online!!!
#########################################################################
# login_commands: "UNLOGALL THISPORT\r\n"
# login_commands: "LOG COM2 GPRMC ONTIME 1.0 0.25\r\n"
# login_commands: "EVENTOUTCONTROL MARK2 ENABLE POSITIVE 999999990 10\r\n"
# login_commands: "EVENTOUTCONTROL MARK1 ENABLE POSITIVE 500000000 500000000\r\n"
# login_commands: "LOG GPGGA ONTIME 1.0\r\n"
# login_commands: "log bestgnssposb ontime 1\r\n"
# login_commands: "log bestgnssvelb ontime 1\r\n"
# login_commands: "log bestposb ontime 1\r\n"
# login_commands: "log INSPVAXB ontime 0.5\r\n"
# login_commands: "log INSPVASB ontime 0.01\r\n"
# login_commands: "log CORRIMUDATASB ontime 0.01\r\n"
# login_commands: "log RAWIMUSXB onnew 0 0\r\n"
# login_commands: "log INSCOVSB ontime 1\r\n"
# login_commands: "log mark1pvab onnew\r\n"
# login_commands: "log rangeb ontime 0.2\r\n"
# login_commands: "log bdsephemerisb\r\n"
# login_commands: "log gpsephemb\r\n"
# login_commands: "log gloephemerisb\r\n"
# login_commands: "log bdsephemerisb ontime 15\r\n"
# login_commands: "log gpsephemb ontime 15\r\n"
# login_commands: "log gloephemerisb ontime 15\r\n"
# login_commands: "log imutoantoffsetsb once\r\n"
# login_commands: "log vehiclebodyrotationb onchanged\r\n"
logout_commands: "EVENTOUTCONTROL MARK2 DISABLE\r\n"
logout_commands: "EVENTOUTCONTROL MARK1 DISABLE\r\n"
| 0
|
apollo_public_repos/apollo/modules/drivers/gnss
|
apollo_public_repos/apollo/modules/drivers/gnss/conf/readme.txt
|
first check imutoantoffset saved in device, method below:
screen /dev/ttyUSB2
log imutoantoffsets
| 0
|
apollo_public_repos/apollo/modules/drivers
|
apollo_public_repos/apollo/modules/drivers/canbus/sensor_gflags.cc
|
/******************************************************************************
* Copyright 2017 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/drivers/canbus/sensor_gflags.h"
// System gflags
DEFINE_string(node_name, "chassis", "The chassis module name in proto");
DEFINE_string(canbus_driver_name, "canbus", "Driver name.");
// data file
DEFINE_string(sensor_conf_file, "", "Sensor conf file");
// Canbus gflags
DEFINE_double(sensor_freq, 100,
"Sensor feedback timer frequency -- 0 means event trigger.");
// System gflags
DEFINE_string(sensor_node_name, "", "Sensor node name.");
// esd can extended frame gflags
DEFINE_bool(esd_can_extended_frame, false,
"check esd can exdended frame enabled or not");
| 0
|
apollo_public_repos/apollo/modules/drivers
|
apollo_public_repos/apollo/modules/drivers/canbus/sensor_canbus.h
|
/******************************************************************************
* Copyright 2017 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
/**
* @file
*/
#pragma once
#include <condition_variable>
#include <memory>
#include <mutex>
#include <string>
#include <thread>
#include <utility>
#include <vector>
#include "cyber/common/file.h"
#include "cyber/component/component.h"
#include "cyber/time/time.h"
#include "modules/common/monitor_log/monitor_log_buffer.h"
#include "modules/common/util/util.h"
#include "modules/drivers/canbus/can_client/can_client.h"
#include "modules/drivers/canbus/can_client/can_client_factory.h"
#include "modules/drivers/canbus/can_comm/can_receiver.h"
#include "modules/drivers/canbus/can_comm/message_manager.h"
#include "modules/common_msgs/drivers_msgs/can_card_parameter.pb.h"
#include "modules/drivers/canbus/proto/sensor_canbus_conf.pb.h"
#include "modules/drivers/canbus/sensor_gflags.h"
/**
* @namespace apollo::drivers
* @brief apollo::drivers
*/
namespace apollo {
namespace drivers {
/**
* @class SensorCanbus
*
* @brief template of canbus-based sensor module main class (e.g., mobileye).
*/
using apollo::common::ErrorCode;
// using apollo::common::Status;
using apollo::common::monitor::MonitorMessageItem;
using apollo::cyber::Time;
using apollo::drivers::canbus::CanClient;
using apollo::drivers::canbus::CanClientFactory;
using apollo::drivers::canbus::CanReceiver;
using apollo::drivers::canbus::SensorCanbusConf;
template <typename T>
using Writer = apollo::cyber::Writer<T>;
template <typename SensorType>
class SensorCanbus : public apollo::cyber::Component<> {
public:
// TODO(lizh): check whether we need a new msg item, say
// MonitorMessageItem::SENSORCANBUS
SensorCanbus()
: monitor_logger_buffer_(
apollo::common::monitor::MonitorMessageItem::CANBUS) {}
~SensorCanbus();
/**
* @brief module initialization function
* @return initialization status
*/
bool Init() override;
private:
bool Start();
void PublishSensorData();
void OnTimer();
void DataTrigger();
bool OnError(const std::string &error_msg);
void RegisterCanClients();
SensorCanbusConf canbus_conf_;
std::unique_ptr<CanClient> can_client_;
CanReceiver<SensorType> can_receiver_;
std::unique_ptr<canbus::MessageManager<SensorType>> sensor_message_manager_;
std::unique_ptr<std::thread> thread_;
int64_t last_timestamp_ = 0;
std::unique_ptr<cyber::Timer> timer_;
common::monitor::MonitorLogBuffer monitor_logger_buffer_;
std::mutex mutex_;
volatile bool data_trigger_running_ = false;
std::shared_ptr<Writer<SensorType>> sensor_writer_;
};
// method implementations
template <typename SensorType>
bool SensorCanbus<SensorType>::Init() {
// load conf
if (!cyber::common::GetProtoFromFile(config_file_path_, &canbus_conf_)) {
return OnError("Unable to load canbus conf file: " + config_file_path_);
}
AINFO << "The canbus conf file is loaded: " << config_file_path_;
ADEBUG << "Canbus_conf:" << canbus_conf_.ShortDebugString();
// Init can client
auto *can_factory = CanClientFactory::Instance();
can_factory->RegisterCanClients();
can_client_ = can_factory->CreateCANClient(canbus_conf_.can_card_parameter());
if (!can_client_) {
return OnError("Failed to create can client.");
}
AINFO << "Can client is successfully created.";
sensor_message_manager_.reset(new canbus::MessageManager<SensorType>());
if (sensor_message_manager_ == nullptr) {
return OnError("Failed to create message manager.");
}
AINFO << "Sensor message manager is successfully created.";
if (can_receiver_.Init(can_client_.get(), sensor_message_manager_.get(),
canbus_conf_.enable_receiver_log()) != ErrorCode::OK) {
return OnError("Failed to init can receiver.");
}
AINFO << "The can receiver is successfully initialized.";
sensor_writer_ = node_->CreateWriter<SensorType>(FLAGS_sensor_node_name);
return Start();
}
template <typename SensorType>
bool SensorCanbus<SensorType>::Start() {
// 1. init and start the can card hardware
if (can_client_->Start() != ErrorCode::OK) {
return OnError("Failed to start can client");
}
AINFO << "Can client is started.";
// 2. start receive first then send
if (can_receiver_.Start() != ErrorCode::OK) {
return OnError("Failed to start can receiver.");
}
AINFO << "Can receiver is started.";
// 3. set timer to trigger publish info periodically
// if sensor_freq == 0, then it is event-triggered publishment.
// no need for timer.
if (FLAGS_sensor_freq > 0) {
double duration_ms = 1000.0 / FLAGS_sensor_freq;
timer_.reset(new cyber::Timer(static_cast<uint32_t>(duration_ms),
[this]() { this->OnTimer(); }, false));
timer_->Start();
} else {
data_trigger_running_ = true;
thread_.reset(new std::thread([this] { DataTrigger(); }));
if (thread_ == nullptr) {
AERROR << "Unable to create data trigger thread.";
return OnError("Failed to start data trigger thread.");
}
}
// last step: publish monitor messages
monitor_logger_buffer_.INFO("Canbus is started.");
return true;
}
template <typename SensorType>
void SensorCanbus<SensorType>::OnTimer() {
PublishSensorData();
}
template <typename SensorType>
void SensorCanbus<SensorType>::DataTrigger() {
std::condition_variable *cvar = sensor_message_manager_->GetMutableCVar();
while (data_trigger_running_) {
std::unique_lock<std::mutex> lock(mutex_);
cvar->wait(lock);
PublishSensorData();
sensor_message_manager_->ClearSensorData();
}
}
template <typename SensorType>
SensorCanbus<SensorType>::~SensorCanbus() {
if (FLAGS_sensor_freq > 0) {
timer_->Stop();
}
can_receiver_.Stop();
can_client_->Stop();
if (data_trigger_running_) {
data_trigger_running_ = false;
if (thread_ != nullptr && thread_->joinable()) {
sensor_message_manager_->GetMutableCVar()->notify_all();
thread_->join();
}
thread_.reset();
}
AINFO << "Data trigger stopped [ok].";
}
// Send the error to monitor and return it
template <typename SensorType>
bool SensorCanbus<SensorType>::OnError(const std::string &error_msg) {
monitor_logger_buffer_.ERROR(error_msg);
return false;
}
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers
|
apollo_public_repos/apollo/modules/drivers/canbus/BUILD
|
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_binary")
load("//tools:cpplint.bzl", "cpplint")
load("//tools/install:install.bzl", "install")
package(default_visibility = ["//visibility:public"])
install(
name = "install",
library_dest = "drivers/lib",
targets = [
":libsensor_gflags.so",
":libsensor_canbus.so"
],
visibility = ["//visibility:public"],
)
cc_binary(
name = "libsensor_gflags.so",
srcs = ["sensor_gflags.cc", "sensor_gflags.h"],
linkshared = True,
linkstatic = True,
deps = [
"@com_github_gflags_gflags//:gflags",
],
)
cc_library(
name = "sensor_gflags",
srcs = ["libsensor_gflags.so"],
hdrs = ["sensor_gflags.h"],
alwayslink = True,
deps = [
"@com_github_gflags_gflags//:gflags",
],
)
cc_library(
name = "sensor_canbus_lib",
srcs = ["libsensor_canbus.so"],
alwayslink = True,
deps = [
":sensor_gflags",
"//modules/common/monitor_log",
"//modules/drivers/canbus/can_client:can_client_factory",
"//modules/drivers/canbus/can_comm:can_receiver",
"//modules/drivers/canbus/can_comm:can_sender",
"//modules/drivers/canbus/can_comm:message_manager_base",
],
)
cc_binary(
name = "libsensor_canbus.so",
srcs = ["sensor_canbus.h"],
linkshared = True,
linkstatic = True,
deps = [
":sensor_gflags",
"//modules/common/monitor_log",
"//modules/drivers/canbus/can_client:can_client_factory",
"//modules/drivers/canbus/can_comm:can_receiver",
"//modules/drivers/canbus/can_comm:can_sender",
"//modules/drivers/canbus/can_comm:message_manager_base",
],
)
cpplint()
| 0
|
apollo_public_repos/apollo/modules/drivers
|
apollo_public_repos/apollo/modules/drivers/canbus/sensor_gflags.h
|
/******************************************************************************
* Copyright 2017 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#pragma once
#include "gflags/gflags.h"
// System gflags
DECLARE_string(node_name);
DECLARE_string(canbus_driver_name);
// data file
DECLARE_string(sensor_conf_file);
// Sensor gflags
DECLARE_double(sensor_freq);
// System gflags
DECLARE_string(sensor_node_name);
// esd Can Extended frame supported or not
DECLARE_bool(esd_can_extended_frame);
| 0
|
apollo_public_repos/apollo/modules/drivers/canbus
|
apollo_public_repos/apollo/modules/drivers/canbus/can_comm/message_manager_test.cc
|
/******************************************************************************
* Copyright 2017 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/drivers/canbus/can_comm/message_manager.h"
#include <memory>
#include <set>
#include "gtest/gtest.h"
#include "modules/common_msgs/chassis_msgs/chassis_detail.pb.h"
#include "modules/drivers/canbus/can_comm/protocol_data.h"
namespace apollo {
namespace drivers {
namespace canbus {
using apollo::common::ErrorCode;
class MockProtocolData : public ProtocolData<::apollo::canbus::ChassisDetail> {
public:
static const int32_t ID = 0x111;
MockProtocolData() {}
};
class MockMessageManager
: public MessageManager<::apollo::canbus::ChassisDetail> {
public:
MockMessageManager() {
AddRecvProtocolData<MockProtocolData, true>();
AddSendProtocolData<MockProtocolData, true>();
}
};
TEST(MessageManagerTest, GetMutableProtocolDataById) {
uint8_t mock_data = 1;
MockMessageManager manager;
manager.Parse(MockProtocolData::ID, &mock_data, 8);
manager.ResetSendMessages();
EXPECT_NE(manager.GetMutableProtocolDataById(MockProtocolData::ID), nullptr);
::apollo::canbus::ChassisDetail chassis_detail;
chassis_detail.set_car_type(::apollo::canbus::ChassisDetail::QIRUI_EQ_15);
EXPECT_EQ(manager.GetSensorData(&chassis_detail), ErrorCode::OK);
EXPECT_EQ(manager.GetSensorData(nullptr), ErrorCode::CANBUS_ERROR);
}
} // namespace canbus
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/canbus
|
apollo_public_repos/apollo/modules/drivers/canbus/can_comm/message_manager.h
|
/******************************************************************************
* Copyright 2017 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
/**
* @file message_manager.h
* @brief The class of MessageManager
*/
#pragma once
#include <condition_variable>
#include <memory>
#include <mutex>
#include <set>
#include <thread>
#include <unordered_map>
#include <vector>
#include "cyber/common/log.h"
#include "cyber/time/time.h"
#include "modules/common_msgs/basic_msgs/error_code.pb.h"
#include "modules/drivers/canbus/can_comm/protocol_data.h"
#include "modules/drivers/canbus/common/byte.h"
/**
* @namespace apollo::drivers::canbus
* @brief apollo::drivers::canbus
*/
namespace apollo {
namespace drivers {
namespace canbus {
using apollo::common::ErrorCode;
using apollo::cyber::Time;
using micros = std::chrono::microseconds;
/**
* @struct CheckIdArg
*
* @brief this struct include data for check ids.
*/
struct CheckIdArg {
int64_t period = 0;
int64_t real_period = 0;
int64_t last_time = 0;
int32_t error_count = 0;
};
/**
* @class MessageManager
*
* @brief message manager manages protocols. It supports parse and can get
* protocol data by message id.
*/
template <typename SensorType>
class MessageManager {
public:
/*
* @brief constructor function
*/
MessageManager() {}
/*
* @brief destructor function
*/
virtual ~MessageManager() = default;
/**
* @brief parse data and store parsed info in protocol data
* @param message_id the id of the message
* @param data a pointer to the data array to be parsed
* @param length the length of data array
*/
virtual void Parse(const uint32_t message_id, const uint8_t *data,
int32_t length);
void ClearSensorData();
std::condition_variable *GetMutableCVar();
/**
* @brief get mutable protocol data by message id
* @param message_id the id of the message
* @return a pointer to the protocol data
*/
ProtocolData<SensorType> *GetMutableProtocolDataById(
const uint32_t message_id);
/**
* @brief get chassis detail. used lock_guard in this function to avoid
* concurrent read/write issue.
* @param chassis_detail chassis_detail to be filled.
*/
common::ErrorCode GetSensorData(SensorType *const sensor_data);
/*
* @brief reset send messages
*/
void ResetSendMessages();
protected:
template <class T, bool need_check>
void AddRecvProtocolData();
template <class T, bool need_check>
void AddSendProtocolData();
std::vector<std::unique_ptr<ProtocolData<SensorType>>> send_protocol_data_;
std::vector<std::unique_ptr<ProtocolData<SensorType>>> recv_protocol_data_;
std::unordered_map<uint32_t, ProtocolData<SensorType> *> protocol_data_map_;
std::unordered_map<uint32_t, CheckIdArg> check_ids_;
std::set<uint32_t> received_ids_;
std::mutex sensor_data_mutex_;
SensorType sensor_data_;
bool is_received_on_time_ = false;
std::condition_variable cvar_;
};
template <typename SensorType>
template <class T, bool need_check>
void MessageManager<SensorType>::AddRecvProtocolData() {
recv_protocol_data_.emplace_back(new T());
auto *dt = recv_protocol_data_.back().get();
if (dt == nullptr) {
return;
}
protocol_data_map_[T::ID] = dt;
if (need_check) {
check_ids_[T::ID].period = dt->GetPeriod();
check_ids_[T::ID].real_period = 0;
check_ids_[T::ID].last_time = 0;
check_ids_[T::ID].error_count = 0;
}
}
template <typename SensorType>
template <class T, bool need_check>
void MessageManager<SensorType>::AddSendProtocolData() {
send_protocol_data_.emplace_back(new T());
auto *dt = send_protocol_data_.back().get();
if (dt == nullptr) {
return;
}
protocol_data_map_[T::ID] = dt;
if (need_check) {
check_ids_[T::ID].period = dt->GetPeriod();
check_ids_[T::ID].real_period = 0;
check_ids_[T::ID].last_time = 0;
check_ids_[T::ID].error_count = 0;
}
}
template <typename SensorType>
ProtocolData<SensorType>
*MessageManager<SensorType>::GetMutableProtocolDataById(
const uint32_t message_id) {
if (protocol_data_map_.find(message_id) == protocol_data_map_.end()) {
ADEBUG << "Unable to get protocol data because of invalid message_id:"
<< Byte::byte_to_hex(message_id);
return nullptr;
}
return protocol_data_map_[message_id];
}
template <typename SensorType>
void MessageManager<SensorType>::Parse(const uint32_t message_id,
const uint8_t *data, int32_t length) {
ProtocolData<SensorType> *protocol_data =
GetMutableProtocolDataById(message_id);
if (protocol_data == nullptr) {
return;
}
{
std::lock_guard<std::mutex> lock(sensor_data_mutex_);
protocol_data->Parse(data, length, &sensor_data_);
}
received_ids_.insert(message_id);
// check if need to check period
const auto it = check_ids_.find(message_id);
if (it != check_ids_.end()) {
const int64_t time = Time::Now().ToNanosecond() / 1e3;
it->second.real_period = time - it->second.last_time;
// if period 1.5 large than base period, inc error_count
const double period_multiplier = 1.5;
if (static_cast<double>(it->second.real_period) >
(static_cast<double>(it->second.period) * period_multiplier)) {
it->second.error_count += 1;
} else {
it->second.error_count = 0;
}
it->second.last_time = time;
}
}
template <typename SensorType>
void MessageManager<SensorType>::ClearSensorData() {
std::lock_guard<std::mutex> lock(sensor_data_mutex_);
sensor_data_.Clear();
}
template <typename SensorType>
std::condition_variable *MessageManager<SensorType>::GetMutableCVar() {
return &cvar_;
}
template <typename SensorType>
ErrorCode MessageManager<SensorType>::GetSensorData(
SensorType *const sensor_data) {
if (sensor_data == nullptr) {
AERROR << "Failed to get sensor_data due to nullptr.";
return ErrorCode::CANBUS_ERROR;
}
std::lock_guard<std::mutex> lock(sensor_data_mutex_);
sensor_data->CopyFrom(sensor_data_);
return ErrorCode::OK;
}
template <typename SensorType>
void MessageManager<SensorType>::ResetSendMessages() {
for (auto &protocol_data : send_protocol_data_) {
if (protocol_data == nullptr) {
AERROR << "Invalid protocol data.";
} else {
protocol_data->Reset();
}
}
}
} // namespace canbus
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/canbus
|
apollo_public_repos/apollo/modules/drivers/canbus/can_comm/can_receiver_test.cc
|
/******************************************************************************
* Copyright 2017 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/drivers/canbus/can_comm/can_receiver.h"
#include "gtest/gtest.h"
#include "modules/common_msgs/chassis_msgs/chassis_detail.pb.h"
#include "modules/common_msgs/basic_msgs/error_code.pb.h"
#include "modules/drivers/canbus/can_client/fake/fake_can_client.h"
#include "modules/drivers/canbus/can_comm/message_manager.h"
namespace apollo {
namespace drivers {
namespace canbus {
TEST(CanReceiverTest, ReceiveOne) {
cyber::Init("can_receiver_test");
can::FakeCanClient can_client;
MessageManager<::apollo::canbus::ChassisDetail> pm;
CanReceiver<::apollo::canbus::ChassisDetail> receiver;
receiver.Init(&can_client, &pm, false);
EXPECT_EQ(receiver.Start(), common::ErrorCode::OK);
EXPECT_TRUE(receiver.IsRunning());
receiver.Stop();
EXPECT_FALSE(receiver.IsRunning());
// cyber::Clear();
}
} // namespace canbus
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/canbus
|
apollo_public_repos/apollo/modules/drivers/canbus/can_comm/protocol_data.h
|
/******************************************************************************
* Copyright 2017 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
/**
* @file
* @brief The class of ProtocolData
*/
#pragma once
#include <cmath>
#include <numeric>
#include "cyber/common/log.h"
#include "modules/drivers/canbus/common/canbus_consts.h"
/**
* @namespace apollo::drivers::canbus
* @brief apollo::drivers::canbus
*/
namespace apollo {
namespace drivers {
namespace canbus {
/**
* @class ProtocolData
*
* @brief This is the base class of protocol data.
*/
template <typename SensorType>
class ProtocolData {
public:
/**
* @brief static function, used to calculate the checksum of input array.
* @param input the pointer to the start position of input array
* @param length the length of the input array
* @return the value of checksum
*/
static std::uint8_t CalculateCheckSum(const uint8_t *input,
const uint32_t length);
/**
* @brief construct protocol data.
*/
ProtocolData() = default;
/**
* @brief destruct protocol data.
*/
virtual ~ProtocolData() = default;
/*
* @brief get interval period for canbus messages
* @return the interval period in us (1e-6s)
*/
virtual uint32_t GetPeriod() const;
/*
* @brief get the length of protocol data. The length is usually 8.
* @return the length of protocol data.
*/
virtual int32_t GetLength() const;
/*
* @brief parse received data
* @param bytes a pointer to the input bytes
* @param length the length of the input bytes
* @param sensor_data the parsed sensor_data
*/
virtual void Parse(const uint8_t *bytes, int32_t length,
SensorType *sensor_data) const;
/*
* @brief update the data
*/
virtual void UpdateData(uint8_t *data);
/*
* @brief update the heartbeat data
*/
virtual void UpdateData_Heartbeat(uint8_t *data);
/*
* @brief reset the protocol data
*/
virtual void Reset();
/*
* @brief check if the value is in [lower, upper], if not , round it to bound
*/
template <typename T>
static T BoundedValue(T lower, T upper, T val);
private:
const int32_t data_length_ = CANBUS_MESSAGE_LENGTH;
};
template <typename SensorType>
template <typename T>
T ProtocolData<SensorType>::BoundedValue(T lower, T upper, T val) {
if (lower > upper) {
return val;
}
if (val < lower) {
return lower;
}
if (val > upper) {
return upper;
}
return val;
}
// (SUM(input))^0xFF
template <typename SensorType>
uint8_t ProtocolData<SensorType>::CalculateCheckSum(const uint8_t *input,
const uint32_t length) {
return static_cast<uint8_t>(std::accumulate(input, input + length, 0) ^ 0xFF);
}
template <typename SensorType>
uint32_t ProtocolData<SensorType>::GetPeriod() const {
const uint32_t CONST_PERIOD = 100 * 1000;
return CONST_PERIOD;
}
template <typename SensorType>
int32_t ProtocolData<SensorType>::GetLength() const {
return data_length_;
}
template <typename SensorType>
void ProtocolData<SensorType>::Parse(const uint8_t *bytes, int32_t length,
SensorType *sensor_data) const {}
template <typename SensorType>
void ProtocolData<SensorType>::UpdateData(uint8_t * /*data*/) {}
template <typename SensorType>
void ProtocolData<SensorType>::UpdateData_Heartbeat(uint8_t * /*data*/) {}
template <typename SensorType>
void ProtocolData<SensorType>::Reset() {}
} // namespace canbus
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/canbus
|
apollo_public_repos/apollo/modules/drivers/canbus/can_comm/can_sender_test.cc
|
/******************************************************************************
* Copyright 2017 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/drivers/canbus/can_comm/can_sender.h"
#include "gtest/gtest.h"
#include "modules/common_msgs/chassis_msgs/chassis_detail.pb.h"
#include "modules/common_msgs/basic_msgs/error_code.pb.h"
#include "modules/drivers/canbus/can_client/fake/fake_can_client.h"
#include "modules/drivers/canbus/can_comm/protocol_data.h"
namespace apollo {
namespace drivers {
namespace canbus {
TEST(CanSenderTest, OneRunCase) {
CanSender<::apollo::canbus::ChassisDetail> sender;
MessageManager<::apollo::canbus::ChassisDetail> pm;
can::FakeCanClient can_client;
sender.Init(&can_client, &pm, true);
ProtocolData<::apollo::canbus::ChassisDetail> mpd;
SenderMessage<::apollo::canbus::ChassisDetail> msg(1, &mpd);
EXPECT_FALSE(sender.NeedSend(msg, 1));
EXPECT_EQ(msg.message_id(), 1);
int32_t period = msg.curr_period();
msg.UpdateCurrPeriod(-50);
EXPECT_EQ(msg.curr_period(), period + 50);
EXPECT_EQ(msg.CanFrame().id, 1);
sender.AddMessage(1, &mpd);
EXPECT_EQ(sender.Start(), common::ErrorCode::OK);
EXPECT_TRUE(sender.IsRunning());
EXPECT_TRUE(sender.enable_log());
sender.Update();
sender.Stop();
EXPECT_FALSE(sender.IsRunning());
}
} // namespace canbus
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/canbus
|
apollo_public_repos/apollo/modules/drivers/canbus/can_comm/can_sender.h
|
/******************************************************************************
* Copyright 2017 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
/**
* @file
* @brief Defines SenderMessage class and CanSender class.
*/
#pragma once
#include <algorithm>
#include <array>
#include <memory>
#include <mutex>
#include <thread>
#include <unordered_map>
#include <vector>
#include "gtest/gtest_prod.h"
#include "cyber/common/macros.h"
#include "cyber/common/log.h"
#include "cyber/time/time.h"
#include "modules/common_msgs/basic_msgs/error_code.pb.h"
#include "modules/drivers/canbus/can_client/can_client.h"
#include "modules/drivers/canbus/can_comm/message_manager.h"
#include "modules/drivers/canbus/can_comm/protocol_data.h"
/**
* @namespace apollo::drivers::canbus
* @brief apollo::drivers::canbus
*/
namespace apollo {
namespace drivers {
namespace canbus {
/**
* @class SenderMessage
* @brief This class defines the message to send.
*/
template <typename SensorType>
class SenderMessage {
public:
/**
* @brief Constructor which takes message ID and protocol data.
* @param message_id The message ID.
* @param protocol_data A pointer of ProtocolData
* which contains the content to send.
*/
SenderMessage(const uint32_t message_id,
ProtocolData<SensorType> *protocol_data);
/**
* @brief Constructor which takes message ID and protocol data and
* and indicator whether to initialize all bits of the .
* @param message_id The message ID.
* @param protocol_data A pointer of ProtocolData
* which contains the content to send.
* @param init_with_one If it is true, then initialize all bits in
* the protocol data as one.
*/
SenderMessage(const uint32_t message_id,
ProtocolData<SensorType> *protocol_data, bool init_with_one);
/**
* @brief Destructor.
*/
virtual ~SenderMessage() = default;
/**
* @brief Update the current period for sending messages by a difference.
* @param delta_period Update the current period by reducing delta_period.
*/
void UpdateCurrPeriod(const int32_t delta_period);
/**
* @brief Update the protocol data. But the updating process depends on
* the real type of protocol data which inherites ProtocolData.
*/
void Update();
/**
* @brief Always update the protocol data. But the updating process depends on
* the real type of protocol data which inherites ProtocolData.
*/
void Update_Heartbeat();
/**
* @brief Get the CAN frame to send.
* @return The CAN frame to send.
*/
struct CanFrame CanFrame();
/**
* @brief Get the message ID.
* @return The message ID.
*/
uint32_t message_id() const;
/**
* @brief Get the current period to send messages. It may be different from
* the period from protocol data by updating.
* @return The current period.
*/
int32_t curr_period() const;
private:
uint32_t message_id_ = 0;
ProtocolData<SensorType> *protocol_data_ = nullptr;
int32_t period_ = 0;
int32_t curr_period_ = 0;
private:
static std::mutex mutex_;
struct CanFrame can_frame_to_send_;
struct CanFrame can_frame_to_update_;
};
/**
* @class CanSender
* @brief CAN sender.
*/
template <typename SensorType>
class CanSender {
public:
/**
* @brief Constructor.
*/
CanSender() = default;
/**
* @brief Destructor.
*/
virtual ~CanSender() = default;
/**
* @brief Initialize by a CAN client based on its brand.
* @param can_client The CAN client to use for sending messages.
* @param enable_log whether enable record the send can frame log
* @return An error code indicating the status of this initialization.
*/
common::ErrorCode Init(CanClient *can_client,
MessageManager<SensorType> *pt_manager,
bool enable_log);
/**
* @brief Add a message with its ID, protocol data.
* @param message_id The message ID.
* @param protocol_data A pointer of ProtocolData
* which contains the content to send.
* @param init_with_one If it is true, then initialize all bits in
* the protocol data as one. By default, it is false.
*/
void AddMessage(uint32_t message_id, ProtocolData<SensorType> *protocol_data,
bool init_with_one = false);
/**
* @brief Start the CAN sender.
* @return The error code indicating the status of this action.
*/
apollo::common::ErrorCode Start();
/*
* @brief Update the protocol data based the types.
*/
void Update();
/*
* @brief Update the heartbeat protocol data based the types.
*/
void Update_Heartbeat();
/**
* @brief Stop the CAN sender.
*/
void Stop();
/**
* @brief Get the working status of this CAN sender.
* To check if it is running.
* @return If this CAN sender is running.
*/
bool IsRunning() const;
bool enable_log() const;
FRIEND_TEST(CanSenderTest, OneRunCase);
private:
void PowerSendThreadFunc();
bool NeedSend(const SenderMessage<SensorType> &msg,
const int32_t delta_period);
bool is_init_ = false;
bool is_running_ = false;
CanClient *can_client_ = nullptr; // Owned by global canbus.cc
MessageManager<SensorType> *pt_manager_ = nullptr;
std::vector<SenderMessage<SensorType>> send_messages_;
std::unique_ptr<std::thread> thread_;
bool enable_log_ = false;
DISALLOW_COPY_AND_ASSIGN(CanSender);
};
const uint32_t kSenderInterval = 6000;
template <typename SensorType>
std::mutex SenderMessage<SensorType>::mutex_;
template <typename SensorType>
SenderMessage<SensorType>::SenderMessage(
const uint32_t message_id, ProtocolData<SensorType> *protocol_data)
: SenderMessage(message_id, protocol_data, false) {}
template <typename SensorType>
SenderMessage<SensorType>::SenderMessage(
const uint32_t message_id, ProtocolData<SensorType> *protocol_data,
bool init_with_one)
: message_id_(message_id), protocol_data_(protocol_data) {
if (init_with_one) {
for (int32_t i = 0; i < protocol_data->GetLength(); ++i) {
can_frame_to_update_.data[i] = 0xFF;
}
}
int32_t len = protocol_data_->GetLength();
can_frame_to_update_.id = message_id_;
can_frame_to_update_.len = static_cast<uint8_t>(len);
period_ = protocol_data_->GetPeriod();
curr_period_ = period_;
Update();
}
template <typename SensorType>
void SenderMessage<SensorType>::UpdateCurrPeriod(const int32_t period_delta) {
curr_period_ -= period_delta;
if (curr_period_ <= 0) {
curr_period_ = period_;
}
}
template <typename SensorType>
void SenderMessage<SensorType>::Update() {
if (protocol_data_ == nullptr) {
AERROR << "Attention: ProtocolData is nullptr!";
return;
}
protocol_data_->UpdateData(can_frame_to_update_.data);
std::lock_guard<std::mutex> lock(mutex_);
can_frame_to_send_ = can_frame_to_update_;
}
template <typename SensorType>
void SenderMessage<SensorType>::Update_Heartbeat() {
if (protocol_data_ == nullptr) {
AERROR << "Attention: ProtocolData is nullptr!";
return;
}
protocol_data_->UpdateData_Heartbeat(can_frame_to_update_.data);
std::lock_guard<std::mutex> lock(mutex_);
can_frame_to_send_ = can_frame_to_update_;
}
template <typename SensorType>
uint32_t SenderMessage<SensorType>::message_id() const {
return message_id_;
}
template <typename SensorType>
struct CanFrame SenderMessage<SensorType>::CanFrame() {
std::lock_guard<std::mutex> lock(mutex_);
return can_frame_to_send_;
}
template <typename SensorType>
int32_t SenderMessage<SensorType>::curr_period() const {
return curr_period_;
}
template <typename SensorType>
void CanSender<SensorType>::PowerSendThreadFunc() {
CHECK_NOTNULL(can_client_);
sched_param sch;
sch.sched_priority = 99;
pthread_setschedparam(pthread_self(), SCHED_FIFO, &sch);
const int32_t INIT_PERIOD = 5000; // 5ms
int32_t delta_period = INIT_PERIOD;
int32_t new_delta_period = INIT_PERIOD;
int64_t tm_start = 0;
int64_t tm_end = 0;
int64_t sleep_interval = 0;
AINFO << "Can client sender thread starts.";
while (is_running_) {
tm_start = cyber::Time::Now().ToNanosecond() / 1e3;
new_delta_period = INIT_PERIOD;
for (auto &message : send_messages_) {
bool need_send = NeedSend(message, delta_period);
message.UpdateCurrPeriod(delta_period);
new_delta_period = std::min(new_delta_period, message.curr_period());
if (!need_send) {
continue;
}
std::vector<CanFrame> can_frames;
CanFrame can_frame = message.CanFrame();
can_frames.push_back(can_frame);
if (can_client_->SendSingleFrame(can_frames) != common::ErrorCode::OK) {
AERROR << "Send msg failed:" << can_frame.CanFrameString();
}
if (enable_log()) {
ADEBUG << "send_can_frame#" << can_frame.CanFrameString()
<< "echo send_can_frame# in chssis_detail.";
uint32_t uid = can_frame.id;
const uint8_t *data = can_frame.data;
uint8_t len = can_frame.len;
pt_manager_->Parse(uid, data, len);
}
}
delta_period = new_delta_period;
tm_end = cyber::Time::Now().ToNanosecond() / 1e3;
sleep_interval = delta_period - (tm_end - tm_start);
if (sleep_interval > 0) {
std::this_thread::sleep_for(std::chrono::microseconds(sleep_interval));
} else {
// do not sleep
AWARN << "Too much time for calculation: " << tm_end - tm_start
<< "us is more than minimum period: " << delta_period << "us";
}
}
AINFO << "Can client sender thread stopped!";
}
template <typename SensorType>
common::ErrorCode CanSender<SensorType>::Init(
CanClient *can_client, MessageManager<SensorType> *pt_manager,
bool enable_log) {
if (is_init_) {
AERROR << "Duplicated Init request.";
return common::ErrorCode::CANBUS_ERROR;
}
if (can_client == nullptr) {
AERROR << "Invalid can client.";
return common::ErrorCode::CANBUS_ERROR;
}
is_init_ = true;
can_client_ = can_client;
pt_manager_ = pt_manager;
enable_log_ = enable_log;
return common::ErrorCode::OK;
}
template <typename SensorType>
void CanSender<SensorType>::AddMessage(uint32_t message_id,
ProtocolData<SensorType> *protocol_data,
bool init_with_one) {
if (protocol_data == nullptr) {
AERROR << "invalid protocol data.";
return;
}
send_messages_.emplace_back(
SenderMessage<SensorType>(message_id, protocol_data, init_with_one));
AINFO << "Add send message:" << std::hex << message_id;
}
template <typename SensorType>
common::ErrorCode CanSender<SensorType>::Start() {
if (is_running_) {
AERROR << "Cansender has already started.";
return common::ErrorCode::CANBUS_ERROR;
}
is_running_ = true;
thread_.reset(new std::thread([this] { PowerSendThreadFunc(); }));
return common::ErrorCode::OK;
}
// cansender -> Update_Heartbeat()
template <typename SensorType>
void CanSender<SensorType>::Update_Heartbeat() {
for (auto &message : send_messages_) {
message.Update_Heartbeat();
}
}
template <typename SensorType>
void CanSender<SensorType>::Update() {
for (auto &message : send_messages_) {
message.Update();
}
}
template <typename SensorType>
void CanSender<SensorType>::Stop() {
if (is_running_) {
AINFO << "Stopping can sender ...";
is_running_ = false;
if (thread_ != nullptr && thread_->joinable()) {
thread_->join();
}
thread_.reset();
} else {
AERROR << "CanSender is not running.";
}
AINFO << "Can client sender stopped [ok].";
}
template <typename SensorType>
bool CanSender<SensorType>::IsRunning() const {
return is_running_;
}
template <typename SensorType>
bool CanSender<SensorType>::enable_log() const {
return enable_log_;
}
template <typename SensorType>
bool CanSender<SensorType>::NeedSend(const SenderMessage<SensorType> &msg,
const int32_t delta_period) {
return msg.curr_period() <= delta_period;
}
} // namespace canbus
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/canbus
|
apollo_public_repos/apollo/modules/drivers/canbus/can_comm/protocol_data_test.cc
|
/******************************************************************************
* Copyright 2017 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/drivers/canbus/can_comm/protocol_data.h"
#include "gtest/gtest.h"
#include "modules/common_msgs/chassis_msgs/chassis_detail.pb.h"
namespace apollo {
namespace drivers {
namespace canbus {
using ::apollo::canbus::ChassisDetail;
TEST(ProtocolDataTest, CheckSum) {
const uint8_t INPUT[] = {0x00, 0x12, 0x00, 0x13, 0x00, 0xF3, 0x00, 0x00};
const uint8_t result =
ProtocolData<apollo::canbus::ChassisDetail>::CalculateCheckSum(INPUT, 8);
EXPECT_EQ(0xE7, result);
}
TEST(ProtocolDataTest, BoundedValue) {
const double_t input = 5.0;
const double_t min_bound = 0.0;
const double_t max_bound = M_PI;
const double_t result =
ProtocolData<apollo::canbus::ChassisDetail>::BoundedValue(
min_bound, max_bound, input);
EXPECT_EQ(M_PI, result);
}
} // namespace canbus
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/canbus
|
apollo_public_repos/apollo/modules/drivers/canbus/can_comm/can_receiver.h
|
/******************************************************************************
* Copyright 2017 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
/**
* @file
* @brief Defines CanReceiver class.
*/
#pragma once
#include <atomic>
#include <cmath>
#include <future>
#include <iostream>
#include <memory>
#include <sstream>
#include <thread>
#include <vector>
#include "cyber/common/macros.h"
#include "cyber/cyber.h"
#include "modules/common_msgs/basic_msgs/error_code.pb.h"
#include "modules/drivers/canbus/can_client/can_client.h"
#include "modules/drivers/canbus/can_comm/message_manager.h"
#include "modules/drivers/canbus/common/canbus_consts.h"
/**
* @namespace apollo::drivers::canbus
* @brief apollo::drivers::canbus
*/
namespace apollo {
namespace drivers {
namespace canbus {
/**
* @class CanReceiver
* @brief CAN receiver.
*/
template <typename SensorType>
class CanReceiver {
public:
/**
* @brief Constructor.
*/
CanReceiver() = default;
/**
* @brief Destructor.
*/
virtual ~CanReceiver() = default;
/**
* @brief Initialize by a CAN client, message manager.
* @param can_client The CAN client to use for receiving messages.
* @param pt_manager The message manager which can parse and
* get protocol data by message id.
* @param enable_log If log the essential information during running.
* @return An error code indicating the status of this initialization.
*/
common::ErrorCode Init(CanClient *can_client,
MessageManager<SensorType> *pt_manager,
bool enable_log);
/**
* @brief Get the working status of this CAN receiver.
* To check if it is running.
* @return If this CAN receiver is running.
*/
bool IsRunning() const;
/**
* @brief Start the CAN receiver.
* @return The error code indicating the status of this action.
*/
::apollo::common::ErrorCode Start();
/**
* @brief Stop the CAN receiver.
*/
void Stop();
private:
void RecvThreadFunc();
int32_t Start(bool is_blocked);
private:
std::atomic<bool> is_running_ = {false};
// CanClient, MessageManager pointer life is managed by outer program
CanClient *can_client_ = nullptr;
MessageManager<SensorType> *pt_manager_ = nullptr;
bool enable_log_ = false;
bool is_init_ = false;
std::future<void> async_result_;
DISALLOW_COPY_AND_ASSIGN(CanReceiver);
};
template <typename SensorType>
::apollo::common::ErrorCode CanReceiver<SensorType>::Init(
CanClient *can_client, MessageManager<SensorType> *pt_manager,
bool enable_log) {
can_client_ = can_client;
pt_manager_ = pt_manager;
enable_log_ = enable_log;
if (can_client_ == nullptr) {
AERROR << "Invalid can client.";
return ::apollo::common::ErrorCode::CANBUS_ERROR;
}
if (pt_manager_ == nullptr) {
AERROR << "Invalid protocol manager.";
return ::apollo::common::ErrorCode::CANBUS_ERROR;
}
is_init_ = true;
return ::apollo::common::ErrorCode::OK;
}
template <typename SensorType>
void CanReceiver<SensorType>::RecvThreadFunc() {
AINFO << "Can client receiver thread starts.";
CHECK_NOTNULL(can_client_);
CHECK_NOTNULL(pt_manager_);
int32_t receive_error_count = 0;
int32_t receive_none_count = 0;
const int32_t ERROR_COUNT_MAX = 10;
auto default_period = 10 * 1000;
while (IsRunning()) {
std::vector<CanFrame> buf;
int32_t frame_num = MAX_CAN_RECV_FRAME_LEN;
if (can_client_->Receive(&buf, &frame_num) !=
::apollo::common::ErrorCode::OK) {
LOG_IF_EVERY_N(ERROR, receive_error_count++ > ERROR_COUNT_MAX,
ERROR_COUNT_MAX)
<< "Received " << receive_error_count << " error messages.";
cyber::USleep(default_period);
continue;
}
receive_error_count = 0;
if (buf.size() != static_cast<size_t>(frame_num)) {
AERROR_EVERY(100) << "Receiver buf size [" << buf.size()
<< "] does not match can_client returned length["
<< frame_num << "].";
}
if (frame_num == 0) {
LOG_IF_EVERY_N(ERROR, receive_none_count++ > ERROR_COUNT_MAX,
ERROR_COUNT_MAX)
<< "Received " << receive_none_count << " empty messages.";
cyber::USleep(default_period);
continue;
}
receive_none_count = 0;
for (const auto &frame : buf) {
uint8_t len = frame.len;
uint32_t uid = frame.id;
const uint8_t *data = frame.data;
pt_manager_->Parse(uid, data, len);
if (enable_log_) {
ADEBUG << "recv_can_frame#" << frame.CanFrameString();
}
}
cyber::Yield();
}
AINFO << "Can client receiver thread stopped.";
}
template <typename SensorType>
bool CanReceiver<SensorType>::IsRunning() const {
return is_running_.load();
}
template <typename SensorType>
::apollo::common::ErrorCode CanReceiver<SensorType>::Start() {
if (is_init_ == false) {
return ::apollo::common::ErrorCode::CANBUS_ERROR;
}
is_running_.exchange(true);
async_result_ = cyber::Async(&CanReceiver<SensorType>::RecvThreadFunc, this);
return ::apollo::common::ErrorCode::OK;
}
template <typename SensorType>
void CanReceiver<SensorType>::Stop() {
if (IsRunning()) {
AINFO << "Stopping can client receiver ...";
is_running_.exchange(false);
async_result_.wait();
} else {
AINFO << "Can client receiver is not running.";
}
AINFO << "Can client receiver stopped [ok].";
}
} // namespace canbus
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/canbus
|
apollo_public_repos/apollo/modules/drivers/canbus/can_comm/BUILD
|
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test")
load("//tools:cpplint.bzl", "cpplint")
package(default_visibility = ["//visibility:public"])
cc_library(
name = "can_receiver",
hdrs = ["can_receiver.h"],
deps = [
"//modules/common_msgs/basic_msgs:error_code_cc_proto",
"//modules/drivers/canbus/can_client",
"//modules/drivers/canbus/can_comm:message_manager_base",
],
)
cc_library(
name = "can_sender",
hdrs = ["can_sender.h"],
deps = [
"//modules/common_msgs/basic_msgs:error_code_cc_proto",
"//modules/drivers/canbus/can_client",
"//modules/drivers/canbus/can_comm:message_manager_base",
"@com_google_googletest//:gtest",
],
)
cc_library(
name = "message_manager_base",
hdrs = [
"message_manager.h",
"protocol_data.h",
],
deps = [
"//cyber",
"//modules/common_msgs/basic_msgs:error_code_cc_proto",
"//modules/drivers/canbus/common:canbus_common",
],
)
cc_test(
name = "can_sender_test",
size = "small",
srcs = ["can_sender_test.cc"],
deps = [
"//cyber",
"//modules/common_msgs/chassis_msgs:chassis_cc_proto",
"//modules/common_msgs/chassis_msgs:chassis_detail_cc_proto",
"//modules/drivers/canbus/can_client/fake:fake_can_client",
"//modules/drivers/canbus/can_comm:can_sender",
"//modules/drivers/canbus/common:canbus_common",
"@com_google_googletest//:gtest_main",
],
)
cc_test(
name = "can_receiver_test",
size = "small",
srcs = ["can_receiver_test.cc"],
deps = [
"//cyber",
"//modules/common_msgs/chassis_msgs:chassis_cc_proto",
"//modules/common_msgs/chassis_msgs:chassis_detail_cc_proto",
"//modules/common_msgs/config_msgs:vehicle_config_cc_proto",
"//modules/common_msgs/basic_msgs:drive_state_cc_proto",
"//modules/common_msgs/basic_msgs:header_cc_proto",
"//modules/common_msgs/basic_msgs:vehicle_signal_cc_proto",
"//modules/drivers/canbus/can_client/fake:fake_can_client",
"//modules/drivers/canbus/can_comm:can_receiver",
"//modules/drivers/canbus/common:canbus_common",
"@com_google_googletest//:gtest_main",
],
linkstatic = True,
)
cc_test(
name = "protocol_data_test",
size = "small",
srcs = ["protocol_data_test.cc"],
deps = [
"//modules/common_msgs/chassis_msgs:chassis_cc_proto",
"//modules/common_msgs/chassis_msgs:chassis_detail_cc_proto",
"//modules/drivers/canbus/can_comm:message_manager_base",
"@com_google_googletest//:gtest_main",
],
linkstatic = True,
)
cc_test(
name = "message_manager_test",
size = "small",
srcs = ["message_manager_test.cc"],
deps = [
"//cyber",
"//modules/common_msgs/chassis_msgs:chassis_detail_cc_proto",
"//modules/drivers/canbus/can_comm:message_manager_base",
"@com_google_googletest//:gtest_main",
],
)
cpplint()
| 0
|
apollo_public_repos/apollo/modules/drivers/canbus
|
apollo_public_repos/apollo/modules/drivers/canbus/proto/sensor_canbus_conf.proto
|
syntax = "proto2";
package apollo.drivers.canbus;
import "modules/common_msgs/drivers_msgs/can_card_parameter.proto";
message SensorCanbusConf {
optional apollo.drivers.canbus.CANCardParameter can_card_parameter = 1;
optional bool enable_debug_mode = 2 [default = false];
optional bool enable_receiver_log = 3 [default = false];
}
| 0
|
apollo_public_repos/apollo/modules/drivers/canbus
|
apollo_public_repos/apollo/modules/drivers/canbus/proto/BUILD
|
## Auto generated by `proto_build_generator.py`
load("@rules_proto//proto:defs.bzl", "proto_library")
load("@rules_cc//cc:defs.bzl", "cc_proto_library")
load("//tools:python_rules.bzl", "py_proto_library")
package(default_visibility = ["//visibility:public"])
cc_proto_library(
name = "sensor_canbus_conf_cc_proto",
deps = [
":sensor_canbus_conf_proto",
],
)
proto_library(
name = "sensor_canbus_conf_proto",
srcs = ["sensor_canbus_conf.proto"],
deps = [
"//modules/common_msgs/drivers_msgs:can_card_parameter_proto",
],
)
py_proto_library(
name = "sensor_canbus_conf_py_pb2",
deps = [
":sensor_canbus_conf_proto",
"//modules/common_msgs/drivers_msgs:can_card_parameter_py_pb2",
],
)
| 0
|
apollo_public_repos/apollo/modules/drivers/canbus
|
apollo_public_repos/apollo/modules/drivers/canbus/common/byte.cc
|
/******************************************************************************
* Copyright 2017 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/drivers/canbus/common/byte.h"
#include <algorithm>
#include <bitset>
#include "modules/drivers/canbus/sensor_gflags.h"
namespace apollo {
namespace drivers {
namespace canbus {
namespace {
constexpr int32_t BYTE_LENGTH = static_cast<int32_t>(sizeof(int8_t) * 8);
const uint8_t RANG_MASK_1_L[] = {0x01, 0x03, 0x07, 0x0F,
0x1F, 0x3F, 0x7F, 0xFF};
const uint8_t RANG_MASK_0_L[] = {0xFE, 0XFC, 0xF8, 0xF0,
0xE0, 0xC0, 0x80, 0x00};
} // namespace
Byte::Byte(const uint8_t *value) : value_(const_cast<uint8_t *>(value)) {}
Byte::Byte(const Byte &value) : value_(value.value_) {}
std::string Byte::byte_to_hex(const uint8_t value) {
static const char HEX[] = "0123456789ABCDEF";
uint8_t high = static_cast<uint8_t>(value >> 4);
uint8_t low = static_cast<uint8_t>(value & 0x0F);
return {HEX[high], HEX[low]};
}
std::string Byte::byte_to_hex(const uint32_t value) {
uint8_t high;
uint8_t low;
std::string result = "";
if (FLAGS_esd_can_extended_frame && value >= 65536) {
high = static_cast<uint8_t>((value >> 24) & 0xFF);
low = static_cast<uint8_t>((value >> 16) & 0xFF);
result += byte_to_hex(high);
result += byte_to_hex(low);
}
high = static_cast<uint8_t>((value >> 8) & 0xFF);
low = static_cast<uint8_t>(value & 0xFF);
result += byte_to_hex(high);
result += byte_to_hex(low);
return result;
}
std::string Byte::byte_to_binary(const uint8_t value) {
return std::bitset<8 * sizeof(uint8_t)>(value).to_string();
}
void Byte::set_bit_1(const int32_t pos) {
static const uint8_t BIT_MASK_1[] = {0x01, 0x02, 0x04, 0x08,
0x10, 0x20, 0x40, 0x80};
if (pos >= 0 && pos < BYTE_LENGTH) {
*value_ |= BIT_MASK_1[pos];
}
}
void Byte::set_bit_0(const int32_t pos) {
static const uint8_t BIT_MASK_0[] = {0xFE, 0xFD, 0xFB, 0xF7,
0xEF, 0xDF, 0xBF, 0x7F};
if (pos >= 0 && pos < BYTE_LENGTH) {
*value_ &= BIT_MASK_0[pos];
}
}
bool Byte::is_bit_1(const int32_t pos) const {
return pos >= 0 && pos < BYTE_LENGTH && ((*value_ >> pos) % 2 == 1);
}
void Byte::set_value(const uint8_t value) {
if (value_ != nullptr) {
*value_ = value;
}
}
void Byte::set_value_high_4_bits(const uint8_t value) {
set_value(value, 4, 4);
}
void Byte::set_value_low_4_bits(const uint8_t value) { set_value(value, 0, 4); }
void Byte::set_value(const uint8_t value, const int32_t start_pos,
const int32_t length) {
if (start_pos > BYTE_LENGTH - 1 || start_pos < 0 || length < 1) {
return;
}
int32_t end_pos = std::min(start_pos + length - 1, BYTE_LENGTH - 1);
int32_t real_len = end_pos + 1 - start_pos;
uint8_t current_value_low = 0x00;
if (start_pos > 0) {
current_value_low = *value_ & RANG_MASK_1_L[start_pos - 1];
}
uint8_t current_value_high = *value_ & RANG_MASK_0_L[end_pos];
uint8_t middle_value = value & RANG_MASK_1_L[real_len - 1];
middle_value = static_cast<uint8_t>(middle_value << start_pos);
*value_ = static_cast<uint8_t>(current_value_high + middle_value +
current_value_low);
}
uint8_t Byte::get_byte() const { return *value_; }
uint8_t Byte::get_byte_high_4_bits() const { return get_byte(4, 4); }
uint8_t Byte::get_byte_low_4_bits() const { return get_byte(0, 4); }
uint8_t Byte::get_byte(const int32_t start_pos, const int32_t length) const {
if (start_pos > BYTE_LENGTH - 1 || start_pos < 0 || length < 1) {
return 0x00;
}
int32_t end_pos = std::min(start_pos + length - 1, BYTE_LENGTH - 1);
int32_t real_len = end_pos + 1 - start_pos;
uint8_t result = static_cast<uint8_t>(*value_ >> start_pos);
result &= RANG_MASK_1_L[real_len - 1];
return result;
}
std::string Byte::to_hex_string() const { return byte_to_hex(*value_); }
std::string Byte::to_binary_string() const { return byte_to_binary(*value_); }
} // namespace canbus
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/canbus
|
apollo_public_repos/apollo/modules/drivers/canbus/common/canbus_consts.h
|
/******************************************************************************
* Copyright 2017 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
/**
* @file
*/
#pragma once
#include <cstdint>
/**
* @namespace apollo::drivers::canbus
* @brief apollo::drivers::canbus
*/
namespace apollo {
namespace drivers {
namespace canbus {
const int32_t CAN_FRAME_SIZE = 8;
const int32_t MAX_CAN_SEND_FRAME_LEN = 1;
const int32_t MAX_CAN_RECV_FRAME_LEN = 10;
const int32_t CANBUS_MESSAGE_LENGTH = 8; // according to ISO-11891-1
} // namespace canbus
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/canbus
|
apollo_public_repos/apollo/modules/drivers/canbus/common/byte_test.cc
|
/******************************************************************************
* Copyright 2017 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/drivers/canbus/common/byte.h"
#include <string>
#include "gtest/gtest.h"
namespace apollo {
namespace drivers {
namespace canbus {
TEST(ByteTest, CopyConstructor) {
unsigned char byte_value = 0xFF;
Byte value(&byte_value);
Byte another_value(value);
EXPECT_EQ(another_value.to_hex_string(), value.to_hex_string());
EXPECT_EQ(another_value.to_binary_string(), value.to_binary_string());
}
TEST(ByteTest, SetBit) {
unsigned char byte_value = 0xFF;
Byte value(&byte_value);
value.set_bit_0(1);
EXPECT_EQ(0xFD, value.get_byte());
value.set_bit_0(7);
EXPECT_EQ(0x7D, value.get_byte());
value.set_bit_1(7);
EXPECT_EQ(0xFD, value.get_byte());
value.set_value(0x77);
value.set_bit_1(0);
EXPECT_EQ(0x77, value.get_byte());
EXPECT_TRUE(value.is_bit_1(0));
EXPECT_TRUE(value.is_bit_1(1));
EXPECT_FALSE(value.is_bit_1(3));
EXPECT_TRUE(value.is_bit_1(6));
EXPECT_FALSE(value.is_bit_1(7));
}
TEST(ByteTest, SetValue) {
unsigned char byte_value = 0x1A;
Byte value(&byte_value);
value.set_value(0x06, 3, 3);
EXPECT_EQ(0x32, value.get_byte());
value.set_value(0x1A);
value.set_value(0x06, 0, 8);
EXPECT_EQ(0x06, value.get_byte());
value.set_value(0x1A);
value.set_value(0x06, 0, 10);
EXPECT_EQ(0x06, value.get_byte());
value.set_value(0x1A);
value.set_value(0x06, 1, 7);
EXPECT_EQ(0x0C, value.get_byte());
value.set_value(0x1A);
value.set_value(0x07, 1, 1);
EXPECT_EQ(0x1A, value.get_byte());
value.set_value(0x1A);
value.set_value(0x07, -1, 1);
EXPECT_EQ(0x1A, value.get_byte());
}
TEST(ByteTest, GetValue) {
unsigned char byte_value = 0x1A;
Byte value(&byte_value);
EXPECT_EQ(0x05, value.get_byte(1, 3));
EXPECT_EQ(0x01, value.get_byte(1, 1));
EXPECT_EQ(0x00, value.get_byte(8, 1));
EXPECT_EQ(0x00, value.get_byte(-1, 1));
EXPECT_EQ(0x1A, value.get_byte(0, 10));
}
TEST(ByteTest, SetGetHighLowBit) {
unsigned char byte_value = 0x37;
Byte value(&byte_value);
value.set_value_high_4_bits(0x0B);
EXPECT_EQ(0x0B, value.get_byte_high_4_bits());
EXPECT_EQ(0x07, value.get_byte_low_4_bits());
value.set_value_low_4_bits(0x0B);
EXPECT_EQ(0x0B, value.get_byte_high_4_bits());
EXPECT_EQ(0x0B, value.get_byte_low_4_bits());
}
TEST(ByteTest, ByteToString) {
unsigned char value = 0x34;
EXPECT_EQ("34", Byte::byte_to_hex(value));
EXPECT_EQ("00110100", Byte::byte_to_binary(value));
uint32_t int_value = 0xE13A;
EXPECT_EQ("E13A", Byte::byte_to_hex(int_value));
}
} // namespace canbus
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/canbus
|
apollo_public_repos/apollo/modules/drivers/canbus/common/BUILD
|
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test")
load("//tools:cpplint.bzl", "cpplint")
load("//tools/install:install.bzl", "install")
package(default_visibility = ["//visibility:public"])
install(
name = "install",
library_dest = "drivers/lib",
targets = [
":libcanbus_common.so",
],
)
cc_binary(
name = "libcanbus_common.so",
srcs = [
"byte.cc",
"byte.h",
"canbus_consts.h",
],
linkshared = True,
linkstatic = True,
deps = [
"//modules/drivers/canbus:sensor_gflags",
],
)
cc_library(
name = "canbus_common",
srcs = ["libcanbus_common.so"],
hdrs = [
"byte.cc",
"byte.h",
"canbus_consts.h",
],
deps = [
"//modules/drivers/canbus:sensor_gflags",
],
)
cc_test(
name = "byte_test",
size = "small",
srcs = ["byte_test.cc"],
deps = [
":canbus_common",
"@com_google_googletest//:gtest_main",
],
)
cpplint()
| 0
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.