Apollo 11.0
自动驾驶开放平台
parser_common.h
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2017 The Apollo Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
16
17#pragma once
18
19#include <cmath>
20#include <deque>
21#include <limits>
22#include <string>
23#include <vector>
24
25#include "modules/common_msgs/basic_msgs/geometry.pb.h"
26
27#include "cyber/cyber.h"
28
29namespace apollo {
30namespace drivers {
31namespace gnss {
32
33constexpr int SECONDS_PER_WEEK = 60 * 60 * 24 * 7;
34
35constexpr double DEG_TO_RAD = M_PI / 180.0;
36
37constexpr double EPS = 1e-8;
38
39constexpr float FLOAT_NAN = std::numeric_limits<float>::quiet_NaN();
40
41constexpr double azimuth_deg_to_yaw_rad(double azimuth) {
42 return (90.0 - azimuth) * DEG_TO_RAD;
43}
44
45// A helper that fills an Point3D object (which uses the FLU frame) using RFU
46// measurements.
47inline void rfu_to_flu(double r, double f, double u,
49 flu->set_x(f);
50 flu->set_y(-r);
51 flu->set_z(u);
52}
53
54constexpr uint64_t PERIOD_NS_1HZ = 900 * 1e6;
56 public:
57 explicit RateControl(uint64_t period_ns) : period_ns_(period_ns) {}
58 bool check() {
59 auto now = cyber::Time::Now().ToNanosecond();
60 if (now - latest_ns_ > period_ns_) {
61 latest_ns_ = now;
62 return true;
63 }
64 return false;
65 }
66
67 private:
68 uint64_t period_ns_;
69 uint64_t latest_ns_ = 0;
70};
71
73 public:
75
76 void Add(const uint8_t *data_start, const uint8_t *data_end,
77 const uint8_t channel = 0) {
78 message_.clear();
79 std::string &message = channel_messages_[channel];
80 // merge message
81 message.append(reinterpret_cast<const char *>(data_start),
82 std::distance(data_start, data_end));
83 std::string::iterator it_s = message.begin();
84 for (auto it = message.begin(); it != message.end(); ++it) {
85 if (*it == '$' || *it == '#') {
86 it_s = it;
87 continue;
88 }
89 if (*it == 0x0A) {
90 if (*it_s == '$' || *it_s == '#') {
91 message_.assign(it_s, it);
92 } else {
93 AERROR << "invalid ascii message: " << message;
94 }
95 it_s = it + 1;
96 }
97 }
98 if (it_s != message.end()) {
99 message.assign(it_s, message.end());
100 } else {
101 message.clear();
102 }
103 }
104
105 const std::string &GetMessage() { return message_; }
106
107 private:
108 std::vector<std::string> channel_messages_{5};
109 std::string message_;
110};
111
112} // namespace gnss
113} // namespace drivers
114} // namespace apollo
double f
uint64_t ToNanosecond() const
convert time to nanosecond.
Definition time.cc:83
static Time Now()
get the current time.
Definition time.cc:57
void Add(const uint8_t *data_start, const uint8_t *data_end, const uint8_t channel=0)
#define AERROR
Definition log.h:44
constexpr double DEG_TO_RAD
constexpr double EPS
void rfu_to_flu(double r, double f, double u, ::apollo::common::Point3D *flu)
constexpr int SECONDS_PER_WEEK
constexpr uint64_t PERIOD_NS_1HZ
constexpr double azimuth_deg_to_yaw_rad(double azimuth)
constexpr float FLOAT_NAN
class register implement
Definition arena_queue.h:37