Apollo 10.0
自动驾驶开放平台
object_general_info_60b.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2021 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
18
19#include "glog/logging.h"
20
21#include "cyber/time/time.h"
25
26namespace apollo {
27namespace drivers {
28namespace nano_radar {
29
31
33const uint32_t ObjectGeneralInfo60B::ID = 0x60B;
34
35void ObjectGeneralInfo60B::Parse(const std::uint8_t* bytes, int32_t length,
36 NanoRadar* nano_radar) const {
37 int obj_id = object_id(bytes, length);
38 auto conti_obs = nano_radar->add_contiobs();
39 conti_obs->set_clusterortrack(false);
40 conti_obs->set_obstacle_id(obj_id);
41 conti_obs->set_longitude_dist(longitude_dist(bytes, length));
42 conti_obs->set_lateral_dist(lateral_dist(bytes, length));
43 conti_obs->set_longitude_vel(longitude_vel(bytes, length));
44 conti_obs->set_lateral_vel(lateral_vel(bytes, length));
45 conti_obs->set_rcs(rcs(bytes, length));
46 conti_obs->set_dynprop(dynprop(bytes, length));
47 // double long_dist = longitude_dist(bytes, length);
48 // double lat_dist = lateral_dist(bytes, length);
49 double obs_range = obstacle_range(longitude_dist(bytes, length),
50 lateral_dist(bytes, length));
51 double obs_angle = obstacle_angle(longitude_dist(bytes, length),
52 lateral_dist(bytes, length));
53 double obs_vel = obstacle_velocity(longitude_vel(bytes, length),
54 lateral_vel(bytes, length), obs_angle);
55 // conti_obs->set_obstacle_range(obstacle_range(longitude_dist(bytes,
56 // length),lateral_dist(bytes, length))); double obs_angle =
57 // obstacle_angle(longitude_dist(),lateral_dist()); double long_vel =
58 // longitude_vel(bytes, length); double lat_vel = lateral_vel(bytes, length);
59 // double obs_vel = obstacle_velocity(longitude_dist(),lat_dist,obs_angle);
60 conti_obs->set_obstacle_range(obs_range);
61 conti_obs->set_obstacle_vel(obs_vel);
62 conti_obs->set_obstacle_angle(obs_angle);
63 double timestamp = apollo::cyber::Time::Now().ToSecond();
64 auto header = conti_obs->mutable_header();
65 header->CopyFrom(nano_radar->header());
66 header->set_timestamp_sec(timestamp);
67}
68
69int ObjectGeneralInfo60B::object_id(const std::uint8_t* bytes,
70 int32_t length) const {
71 Byte t0(bytes);
72 int32_t x = t0.get_byte(0, 8);
73
74 int ret = x;
75 return ret;
76}
77
78double ObjectGeneralInfo60B::longitude_dist(const std::uint8_t* bytes,
79 int32_t length) const {
80 Byte t0(bytes + 1);
81 int32_t x = t0.get_byte(0, 8);
82
83 Byte t1(bytes + 2);
84 int32_t t = t1.get_byte(3, 5);
85
86 x <<= 5;
87 x |= t;
88
89 double ret = x * OBJECT_DIST_RES + OBJECT_DIST_LONG_MIN;
90 return ret;
91}
92
93double ObjectGeneralInfo60B::lateral_dist(const std::uint8_t* bytes,
94 int32_t length) const {
95 Byte t0(bytes + 2);
96 int32_t x = t0.get_byte(0, 3);
97
98 Byte t1(bytes + 3);
99 int32_t t = t1.get_byte(0, 8);
100
101 x <<= 8;
102 x |= t;
103
104 double ret = x * OBJECT_DIST_RES + OBJECT_DIST_LAT_MIN;
105 return ret;
106}
107
108double ObjectGeneralInfo60B::longitude_vel(const std::uint8_t* bytes,
109 int32_t length) const {
110 Byte t0(bytes + 4);
111 int32_t x = t0.get_byte(0, 8);
112 Byte t1(bytes + 5);
113 int32_t t = t1.get_byte(6, 2);
114
115 x <<= 2;
116 x |= t;
117 double ret = x * OBJECT_VREL_RES + OBJECT_VREL_LONG_MIN;
118 return ret;
119}
120
121double ObjectGeneralInfo60B::lateral_vel(const std::uint8_t* bytes,
122 int32_t length) const {
123 Byte t0(bytes + 5);
124 int32_t x = t0.get_byte(0, 6);
125
126 Byte t1(bytes + 6);
127 int32_t t = t1.get_byte(5, 3);
128
129 x <<= 3;
130 x |= t;
131
132 double ret = x * OBJECT_VREL_RES + OBJECT_VREL_LAT_MIN;
133 return ret;
134}
135
136double ObjectGeneralInfo60B::rcs(const std::uint8_t* bytes,
137 int32_t length) const {
138 Byte t0(bytes + 7);
139 int32_t x = t0.get_byte(0, 8);
140
141 double ret = x * OBJECT_RCS_RES + OBJECT_RCS_MIN;
142 return ret;
143}
144
145int ObjectGeneralInfo60B::dynprop(const std::uint8_t* bytes,
146 int32_t length) const {
147 Byte t0(bytes + 6);
148 int32_t x = t0.get_byte(0, 3);
149
150 int ret = x;
151 return ret;
152}
153
154double ObjectGeneralInfo60B::obstacle_range(double long_dist,
155 double lat_dist) const {
156 double ret = sqrt(long_dist * long_dist + lat_dist * lat_dist);
157
158 return ret;
159}
160
161double ObjectGeneralInfo60B::obstacle_velocity(double long_vel, double lat_vel,
162 double obj_angle) const {
163 double ret = long_vel * cos(obj_angle) + lat_vel * sin(obj_angle);
164
165 return ret;
166}
167
168double ObjectGeneralInfo60B::obstacle_angle(double long_dist,
169 double lat_dist) const {
170 double angle = atan(lat_dist / long_dist);
171
172 double ret = angle / M_PI * 180;
173 return ret;
174}
175
176} // namespace nano_radar
177} // namespace drivers
178} // namespace apollo
Defines the Byte class.
static Time Now()
get the current time.
Definition time.cc:57
double ToSecond() const
convert time to second.
Definition time.cc:77
The class of one byte, which is 8 bits.
Definition byte.h:39
void Parse(const std::uint8_t *bytes, int32_t length, NanoRadar *nano_radar) const override
float cos(Angle16 a)
Definition angle.cc:42
float sin(Angle16 a)
Definition angle.cc:25
const double OBJECT_DIST_LAT_MIN
Definition const_vars.h:41
const double OBJECT_DIST_LONG_MIN
Definition const_vars.h:40
const double OBJECT_VREL_LAT_MIN
Definition const_vars.h:44
const double OBJECT_VREL_LONG_MIN
Definition const_vars.h:43
class register implement
Definition arena_queue.h:37
optional apollo::common::Header header