Apollo 10.0
自动驾驶开放平台
pose_container.cc
浏览该文件的文档.
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
18
19#include "cyber/common/log.h"
22
23namespace apollo {
24namespace prediction {
25
29
30void PoseContainer::Insert(const ::google::protobuf::Message& message) {
32 localization.CopyFrom(dynamic_cast<const LocalizationEstimate&>(message));
33 Update(localization);
34}
35
36void PoseContainer::Update(
37 const localization::LocalizationEstimate& localization) {
38 if (!localization.has_header() ||
39 !localization.header().has_timestamp_sec()) {
40 AERROR << "Localization message has no timestamp ["
41 << localization.ShortDebugString() << "].";
42 return;
43 } else if (!localization.has_pose()) {
44 AERROR << "Localization message has no pose ["
45 << localization.ShortDebugString() << "].";
46 return;
47 } else if (!localization.pose().has_position() ||
48 !localization.pose().has_linear_velocity()) {
49 AERROR << "Localization message has no position or linear velocity ["
50 << localization.ShortDebugString() << "].";
51 return;
52 }
53
54 if (obstacle_ptr_.get() == nullptr) {
55 obstacle_ptr_.reset(new PerceptionObstacle());
56 }
57 obstacle_ptr_->Clear();
58
59 obstacle_ptr_->set_id(FLAGS_ego_vehicle_id);
60 Point position;
61 position.set_x(localization.pose().position().x());
62 position.set_y(localization.pose().position().y());
63 position.set_z(localization.pose().position().z());
64 obstacle_ptr_->mutable_position()->CopyFrom(position);
65
66 double theta = 0.0;
67 if (localization.pose().has_orientation() &&
68 localization.pose().orientation().has_qx() &&
69 localization.pose().orientation().has_qy() &&
70 localization.pose().orientation().has_qz() &&
71 localization.pose().orientation().has_qw()) {
72 double qw = localization.pose().orientation().qw();
73 double qx = localization.pose().orientation().qx();
74 double qy = localization.pose().orientation().qy();
75 double qz = localization.pose().orientation().qz();
76 theta = common::math::QuaternionToHeading(qw, qx, qy, qz);
77 }
78 obstacle_ptr_->set_theta(theta);
79
80 Point velocity;
81 velocity.set_x(localization.pose().linear_velocity().x());
82 velocity.set_y(localization.pose().linear_velocity().y());
83 velocity.set_z(localization.pose().linear_velocity().z());
84 obstacle_ptr_->mutable_velocity()->CopyFrom(velocity);
85
86 obstacle_ptr_->set_type(type_);
87 obstacle_ptr_->set_timestamp(localization.header().timestamp_sec());
88
89 ADEBUG << "ADC obstacle [" << obstacle_ptr_->ShortDebugString() << "].";
90}
91
93 if (obstacle_ptr_ != nullptr) {
94 return obstacle_ptr_->timestamp();
95 } else {
96 return 0.0;
97 }
98}
99
101 return obstacle_ptr_.get();
102}
103
104} // namespace prediction
105} // namespace apollo
void Insert(const ::google::protobuf::Message &message) override
Insert a data message into the container
const perception::PerceptionObstacle * ToPerceptionObstacle()
Transform pose to a perception obstacle.
static const perception::PerceptionObstacle::Type type_
double GetTimestamp()
Get timestamp
#define ADEBUG
Definition log.h:41
#define AERROR
Definition log.h:44
double QuaternionToHeading(const double qw, const double qx, const double qy, const double qz)
Definition quaternion.h:56
apollo::common::Point3D Point
class register implement
Definition arena_queue.h:37
Obstacles container
Contains a number of helper functions related to quaternions.
optional double timestamp_sec
Definition header.proto:9
optional apollo::localization::Pose pose
optional apollo::common::Header header
optional apollo::common::Point3D linear_velocity
Definition pose.proto:35
optional apollo::common::Quaternion orientation
Definition pose.proto:31
optional apollo::common::PointENU position
Definition pose.proto:26