Apollo 10.0
自动驾驶开放平台
refresh_default_end_way_point.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
17// A tool to refresh default_end_way_point.txt file after the map is updated.
18//
19// Usage:
20// bazel-bin/modules/map/tools/refresh_default_end_way_point --map_dir=</yours>
21//
22// How it works:
23// Assuming that the lanes information is changed while our end point's
24// absolute (x,y,z) is still correct. Then we can find the nearest point on
25// the new map as the new end point.
26
27#include "cyber/common/file.h"
28#include "cyber/common/log.h"
30#include "modules/common_msgs/routing_msgs/poi.pb.h"
31#include "modules/common_msgs/routing_msgs/routing.pb.h"
32
33namespace apollo {
34namespace hdmap {
35
36apollo::common::PointENU SLToXYZ(const std::string& lane_id, const double s,
37 const double l) {
38 const auto lane_info = HDMapUtil::BaseMap().GetLaneById(MakeMapId(lane_id));
39 ACHECK(lane_info);
40 return lane_info->GetSmoothPoint(s);
41}
42
43void XYZToSL(const apollo::common::PointENU& point, std::string* lane_id,
44 double* s, double* l) {
45 ACHECK(lane_id);
46 ACHECK(s);
47 ACHECK(l);
48 LaneInfoConstPtr lane = nullptr;
49
50 CHECK_EQ(HDMapUtil::BaseMap().GetNearestLane(point, &lane, s, l), 0);
51 *lane_id = lane->id().id();
52}
53
55 const apollo::common::PointENU& p2) {
56 const double x_diff = p1.x() - p2.x();
57 const double y_diff = p1.y() - p2.y();
58 const double z_diff = p1.z() - p2.z();
59 return std::sqrt(x_diff * x_diff + y_diff * y_diff + z_diff * z_diff);
60}
61
65
67 for (const auto& old_landmark : old_poi.landmark()) {
68 apollo::routing::Landmark* new_landmark = new_poi.add_landmark();
69 new_landmark->set_name(old_landmark.name());
70 AINFO << "Refreshed point of interest: " << old_landmark.name();
71 // Read xyz from old point.
72 for (const auto& old_end_point : old_landmark.waypoint()) {
74 old_xyz.set_x(old_end_point.pose().x());
75 old_xyz.set_y(old_end_point.pose().y());
76 old_xyz.set_z(old_end_point.pose().z());
77
78 // Get new lane info from xyz.
79 std::string new_lane;
80 double new_s;
81 double new_l;
82 XYZToSL(old_xyz, &new_lane, &new_s, &new_l);
83
84 // Get new xyz from lane info.
85 const auto new_xyz = SLToXYZ(new_lane, new_s, new_l);
86
87 // Update default end way point.
89 new_end_point.set_id(new_lane);
90 new_end_point.set_s(new_s);
91 auto* pose = new_end_point.mutable_pose();
92 pose->set_x(new_xyz.x());
93 pose->set_y(new_xyz.y());
94 pose->set_z(new_xyz.z());
95 *new_landmark->add_waypoint() = new_end_point;
96
97 AINFO << "\n ============ from ============ \n"
98 << old_end_point.DebugString()
99 << "\n ============ to ============ \n"
100 << new_end_point.DebugString() << "XYZ distance is "
101 << XYZDistance(old_xyz, new_xyz);
102 }
103 }
105}
106
107} // namespace hdmap
108} // namespace apollo
109
110int main(int argc, char* argv[]) {
111 google::InitGoogleLogging(argv[0]);
112 google::ParseCommandLineFlags(&argc, &argv, true);
113 FLAGS_logtostderr = true;
114
116 return 0;
117}
static const HDMap & BaseMap()
LaneInfoConstPtr GetLaneById(const Id &id) const
Definition hdmap.cc:34
#define ACHECK(cond)
Definition log.h:80
#define AINFO
Definition log.h:42
bool GetProtoFromASCIIFile(const std::string &file_name, google::protobuf::Message *message)
Parses the content of the file specified by the file_name as ascii representation of protobufs,...
Definition file.cc:89
bool SetProtoToASCIIFile(const google::protobuf::Message &message, int file_descriptor)
Definition file.cc:43
std::string EndWayPointFile()
get end way point file path from flags.
Definition hdmap_util.h:56
apollo::hdmap::Id MakeMapId(const std::string &id)
create a Map ID given a string.
Definition hdmap_util.h:85
std::shared_ptr< const LaneInfo > LaneInfoConstPtr
void XYZToSL(const apollo::common::PointENU &point, std::string *lane_id, double *s, double *l)
double XYZDistance(const apollo::common::PointENU &p1, const apollo::common::PointENU &p2)
apollo::common::PointENU SLToXYZ(const std::string &lane_id, const double s, const double l)
class register implement
Definition arena_queue.h:37
int main(int argc, char *argv[])
optional string name
Definition poi.proto:23
repeated Landmark landmark
Definition poi.proto:31