Apollo 10.0
自动驾驶开放平台
pose_collection_agent.cc
浏览该文件的文档.
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 *****************************************************************************/
17
18#include <vector>
19
22
23namespace apollo {
24namespace hdmap {
25
26PoseCollectionAgent::PoseCollectionAgent(std::shared_ptr<JsonConf> sp_conf) {
27 sp_pj_transformer_ = std::make_shared<PJTransformer>(50);
28 sp_conf_ = sp_conf;
29 Reset();
30}
31
32void PoseCollectionAgent::Reset() {
33 sp_pose_collection_ = std::make_shared<PoseCollection>(sp_conf_);
34}
35
37 const std::shared_ptr<const apollo::drivers::gnss::GnssBestPose>
38 &bestgnsspos) {
39 if (sp_pose_collection_ == nullptr) {
40 sp_pose_collection_ = std::make_shared<PoseCollection>(sp_conf_);
41 }
42
44 bestgnsspos->measurement_time()); // in seconds
45 FramePose pose;
46 if (sp_conf_->use_system_time) {
47 pose.time_stamp = UnixNow();
48 AINFO << "system time: " << pose.time_stamp;
49 } else {
50 pose.time_stamp = time_stamp;
51 }
52 pose.latitude = bestgnsspos->latitude();
53 pose.longitude = bestgnsspos->longitude();
54 pose.altitude = bestgnsspos->height_msl();
55 pose.solution_status = bestgnsspos->sol_status();
56 pose.position_type = bestgnsspos->sol_type();
57 pose.diff_age = bestgnsspos->differential_age();
58 double latitude_std = bestgnsspos->latitude_std_dev();
59 double longitude_std = bestgnsspos->longitude_std_dev();
60 double altitude_std = bestgnsspos->height_std_dev();
61 pose.local_std =
62 std::sqrt(latitude_std * latitude_std + longitude_std * longitude_std +
63 altitude_std * altitude_std);
64 pose.tx = pose.longitude * kDEGRESS_TO_RADIANS;
65 pose.ty = pose.latitude * kDEGRESS_TO_RADIANS;
66 pose.tz = pose.altitude;
67 sp_pj_transformer_->LatlongToUtm(1, 1, &pose.tx, &pose.ty, &pose.tz);
68
69 std::lock_guard<std::mutex> mutex_locker(mutex_);
70 if (pose_file == nullptr) pose_file = fopen("poses.txt", "w");
71 if (pose_file == nullptr) {
72 AERROR << "open poses.txt failed";
73 return;
74 }
75 static int count = 0;
76 fprintf(stderr, "%d:%lf %lf %lf %lf 0.0 0.0 0.0 0.0\n", ++count,
77 pose.time_stamp, pose.tx, pose.ty, pose.tz);
78 fprintf(pose_file, "%lf %lf %lf %lf 0.0 0.0 0.0 0.0\n", pose.time_stamp,
79 pose.tx, pose.ty, pose.tz);
80 fflush(pose_file);
81 sp_pose_collection_->Collect(pose);
82}
83
84std::shared_ptr<std::vector<FramePose>> PoseCollectionAgent::GetPoses() const {
85 if (sp_pose_collection_ == nullptr) {
86 return nullptr;
87 }
88 return sp_pose_collection_->GetPoses();
89}
90
92 if (pose_file != nullptr) {
93 fclose(pose_file);
94 pose_file = nullptr;
95 }
96}
97
98} // namespace hdmap
99} // namespace apollo
PoseCollectionAgent(std::shared_ptr< JsonConf > sp_conf)
std::shared_ptr< std::vector< FramePose > > GetPoses() const
void OnBestgnssposCallback(const std::shared_ptr< const apollo::drivers::gnss::GnssBestPose > &bestgnsspos)
#define AERROR
Definition log.h:44
#define AINFO
Definition log.h:42
T GpsToUnixSeconds(T gps_seconds)
double UnixNow()
constexpr double kDEGRESS_TO_RADIANS
Definition common.h:38
class register implement
Definition arena_queue.h:37
unsigned int position_type
Definition common.h:51
unsigned int solution_status
Definition common.h:50