Apollo  6.0
Open source self driving car software
common.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2019 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 #pragma once
17 
18 #include <cmath>
19 #include <ctime>
20 
21 #include <iostream>
22 #include <memory>
23 #include <set>
24 #include <string>
25 #include <utility>
26 #include <vector>
27 
28 #include <boost/filesystem.hpp>
29 #include <boost/property_tree/json_parser.hpp>
30 #include <boost/property_tree/ptree.hpp>
31 
32 #include "cyber/cyber.h"
33 
34 namespace apollo {
35 namespace hdmap {
36 
37 constexpr double kRADIANS_TO_DEGREES = 180.0 / M_PI;
38 constexpr double kDEGRESS_TO_RADIANS = M_PI / 180.0;
39 
40 typedef unsigned char uchar;
41 
42 struct FramePose {
43  double time_stamp; // unix time
44  double tx, ty, tz;
45  double qx, qy, qz, qw;
47  double velx, vely, velz;
48  double roll, pitch, azimuth;
49  unsigned int ins_status;
50  unsigned int solution_status;
51  unsigned int position_type;
52  float diff_age;
53  double local_std;
54 };
55 
56 enum class State { IDLE, RUNNING };
57 
58 struct JsonConf {
59  std::vector<std::pair<std::string, double>> topic_list;
62 
63  unsigned int solution_status;
64  std::set<unsigned int> position_type_range;
65  std::pair<float, float> diff_age_range;
67 
68  /*Period of channel check trigger. The unit is seconds.*/
70  /*Period of alignment, The unit is seconds.
71  Eight route maneuver is also included in the alignment process.*/
73  /*the time that static alignment must last. The unit is seconds.*/
75  /*the maximum time that bad pose included in static alignment.
76  The unit is seconds.*/
78  /*Maximum Motion Distance Tolerated by Static Alignment*/
80 
81  /*Angle threshold between adjacent frames in eight route. The unit is degree*/
82  double eight_angle;
83  /*the time that eight route must last,The unit is seconds.*/
85  /*Minimum speed should be achieved in eight route*/
86  double eight_vel;
87  /*The tolerance of bad pose in eight route. The unit is frame*/
89 
90  /*Minimum frame number threshold for acquisition of multiple loops*/
92  /*The angle error of adjacent poses on the same trajectory should not be
93  greater than alpha_err_thresh. The unit is degree*/
95  /*The time stamp interval of adjacent poses on the same track should not be
96  greater than time_err_thresh. The unit is minutes.*/
98  /*The diameter of the searched square area*/
100  /*loops to check*/
101  size_t laps_number;
102  /*additional loops to check*/
104  /*Proportional thresholds for all required points
105  in acquisition cycle checking*/
107 };
108 
109 std::shared_ptr<JsonConf> ParseJson(std::string conf_path);
110 
111 inline double GetYaw(double from_x, double from_y, double to_x, double to_y) {
112  double vecx = to_x - from_x;
113  double vecy = to_y - from_y;
114  double alpha = acos(vecy / sqrt(vecx * vecx + vecy * vecy));
115  if (vecx < 0) {
116  alpha = 2 * M_PI - alpha;
117  }
118  return kRADIANS_TO_DEGREES * alpha;
119 }
120 
121 inline double UnixNow() { return apollo::cyber::Time::Now().ToSecond(); }
122 
123 } // namespace hdmap
124 } // namespace apollo
double ty
Definition: common.h:44
constexpr double kDEGRESS_TO_RADIANS
Definition: common.h:38
std::shared_ptr< JsonConf > ParseJson(std::string conf_path)
double static_align_duration
Definition: common.h:74
int eight_bad_pose_tolerance
Definition: common.h:88
double static_align_tolerance
Definition: common.h:77
Definition: common.h:58
double tx
Definition: common.h:44
double azimuth
Definition: common.h:48
float diff_age
Definition: common.h:52
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
std::pair< float, float > diff_age_range
Definition: common.h:65
double time_stamp
Definition: common.h:43
int channel_check_trigger_gap
Definition: common.h:69
double tz
Definition: common.h:44
double qy
Definition: common.h:45
std::set< unsigned int > position_type_range
Definition: common.h:64
double velx
Definition: common.h:47
unsigned int solution_status
Definition: common.h:63
int laps_search_diameter
Definition: common.h:99
double eight_angle
Definition: common.h:82
unsigned int ins_status
Definition: common.h:49
double laps_alpha_err_thresh
Definition: common.h:94
double pitch
Definition: common.h:48
double qz
Definition: common.h:45
double qw
Definition: common.h:45
double laps_rate_thresh
Definition: common.h:106
double eight_duration
Definition: common.h:84
double laps_time_err_thresh
Definition: common.h:97
double topic_rate_tolerance
Definition: common.h:61
int laps_frames_thresh
Definition: common.h:91
double altitude
Definition: common.h:46
double local_std_upper_limit
Definition: common.h:66
std::vector< std::pair< std::string, double > > topic_list
Definition: common.h:59
Definition: common.h:42
double longitude
Definition: common.h:46
unsigned char uchar
Definition: common.h:40
double vely
Definition: common.h:47
State
Definition: common.h:56
double local_std
Definition: common.h:53
unsigned int solution_status
Definition: common.h:50
double ToSecond() const
convert time to second.
size_t laps_number
Definition: common.h:101
int alignment_featch_pose_sleep
Definition: common.h:72
double static_align_dist_thresh
Definition: common.h:79
double qx
Definition: common.h:45
bool use_system_time
Definition: common.h:60
constexpr double kRADIANS_TO_DEGREES
Definition: common.h:37
double velz
Definition: common.h:47
static Time Now()
get the current time.
double GetYaw(double from_x, double from_y, double to_x, double to_y)
Definition: common.h:111
double roll
Definition: common.h:48
double eight_vel
Definition: common.h:86
double UnixNow()
Definition: client_common.h:37
unsigned int position_type
Definition: common.h:51
double latitude
Definition: common.h:46
int laps_number_additional
Definition: common.h:103