Apollo 11.0
自动驾驶开放平台
cycle_routing_manager.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2020 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 *****************************************************************************/
17
19
20namespace apollo {
21namespace task_manager {
22
23using common::math::Vec2d;
24
26 common::PointENU ego, double distance) {
27 AINFO << ego.x() << " " << ego.y() << " " << target.x() << " " << target.y();
28 Vec2d tar2ego(ego.x() - target.x(), ego.y() - target.y());
29 Vec2d unit = Vec2d::CreateUnitVec2d(target.heading());
30 double dis = unit.InnerProd(tar2ego);
31 return dis < 1e-6 && std::fabs(dis) < distance && tar2ego.Length() < distance;
32}
33
35 const localization::Pose& pose,
36 const CycleRoutingTask& cycle_routing_task) {
37 cycle_ = cycle_routing_task.cycle_num();
38 auto waypoints = cycle_routing_task.lane_follow_command().way_point();
39 begin_point_.set_x(pose.position().x());
40 begin_point_.set_y(pose.position().y());
41 begin_point_.set_heading(pose.heading());
42 end_point_ = cycle_routing_task.lane_follow_command().end_pose();
43 is_allowed_to_route_ = true;
44 original_lane_follow_command_ = cycle_routing_task.lane_follow_command();
45 map_service_.reset(new apollo::dreamview::MapService());
46
47 AINFO << "New cycle routing task: cycle " << cycle_ << ", begin point "
48 << begin_point_.x() << " " << begin_point_.y() << ", end point "
49 << end_point_.x() << " " << end_point_.y();
50
51 return common::Status::OK();
52}
53
55 const localization::Pose& pose,
56 external_command::LaneFollowCommand* lane_follow_command) {
57 AINFO << "GetNewRouting: localization_pose: " << pose.position().x() << " "
58 << pose.position().y() << ", begin point " << begin_point_.x() << " "
59 << begin_point_.y() << ", end point " << end_point_.x() << " "
60 << end_point_.y() << ", threshold "
61 << FLAGS_task_manager_threshold_for_destination_check
62 << ", allowed_to_send_routing_request " << is_allowed_to_route_;
63
64 if (is_allowed_to_route_) {
66 begin_point_, pose.position(),
67 FLAGS_task_manager_threshold_for_destination_check)) {
68 AINFO << "GetNewRouting: reach begin point."
69 << "Remaining cycles: " << cycle_;
70 lane_follow_command->CopyFrom(original_lane_follow_command_);
71 auto cur_point = lane_follow_command->mutable_way_point(0);
72 is_allowed_to_route_ = false;
73 return true;
74 }
75 } else {
77 end_point_, pose.position(),
78 FLAGS_task_manager_threshold_for_destination_check)) {
79 AINFO << "GetNewRouting: reach end point. "
80 << "Remaining cycles: " << cycle_;
81 lane_follow_command->clear_way_point();
82 auto cur_point = lane_follow_command->add_way_point();
83 cur_point->Clear();
84 cur_point->set_x(pose.position().x());
85 cur_point->set_y(pose.position().y());
86 cur_point->set_heading(pose.heading());
87 auto end_pose = lane_follow_command->mutable_end_pose();
88 end_pose->CopyFrom(begin_point_);
89 --cycle_;
90 is_allowed_to_route_ = true;
91 return true;
92 }
93 }
94
95 return false;
96}
97
98} // namespace task_manager
99} // namespace apollo
A general class to denote the return status of an API call.
Definition status.h:43
static Status OK()
generate a success status.
Definition status.h:60
Implements a class of 2-dimensional vectors.
Definition vec2d.h:42
static Vec2d CreateUnitVec2d(const double angle)
Creates a unit-vector with a given angle to the positive x semi-axis
Definition vec2d.cc:29
double InnerProd(const Vec2d &other) const
Returns the inner product between these two Vec2d.
Definition vec2d.cc:61
double Length() const
Gets the length of the vector
Definition vec2d.cc:33
common::Status Init(const localization::Pose &pose, const task_manager::CycleRoutingTask &cycle_routing_task)
module initialization function
bool GetNewRouting(const localization::Pose &pose, external_command::LaneFollowCommand *lane_follow_command)
Get new routing if the vehicle reaches the begin/end point
#define AINFO
Definition log.h:42
bool CheckPointDistanceInThreshold(external_command::Pose target, common::PointENU ego, double distance)
class register implement
Definition arena_queue.h:37
optional double heading
Definition pose.proto:48
optional apollo::common::PointENU position
Definition pose.proto:26
optional apollo::external_command::LaneFollowCommand lane_follow_command