23#include "grpc++/grpc++.h"
25#include "modules/map/tools/map_datachecker/proto/collection_error_code.pb.h"
26#include "modules/map/tools/map_datachecker/proto/collection_service.pb.h"
36template <
typename ALIGNMENT_TYPE,
typename REQUEST_TYPE,
37 typename RESPONSE_TYPE>
41 std::shared_ptr<JsonConf> sp_conf,
42 std::shared_ptr<PoseCollectionAgent> sp_pose_collection_agent) {
44 sp_pose_collection_agent_ = sp_pose_collection_agent;
48 sp_alignment_ = std::make_shared<ALIGNMENT_TYPE>(sp_conf_);
54 REQUEST_TYPE *request,
55 RESPONSE_TYPE *response) {
56 AINFO <<
"AlignmentAgent request: " << request->DebugString();
57 switch (request->cmd()) {
59 AINFO <<
"AlignmentAgent start";
63 AINFO <<
"AlignmentAgent check";
67 AINFO <<
"AlignmentAgent stop";
72 response->set_progress(sp_alignment_->GetProgress());
75 AINFO <<
"AlignmentAgent progress: " << response->progress();
76 return grpc::Status::OK;
81 AINFO <<
"AlignmentAgent is running. do need start again";
83 response->set_progress(0.0);
89 response->set_progress(0.0);
95 std::thread alignment_thread([=]() {
96 sp_alignment_->SetStartTime(
UnixNow());
97 AINFO <<
"set state RUNNING";
99 std::shared_ptr<std::vector<FramePose>> sp_poses =
GetPoses();
100 if (sp_poses ==
nullptr) {
101 AINFO <<
"error, pose pointer is null";
104 sp_alignment_->Process(*sp_poses);
105 ErrorCode code = sp_alignment_->GetReturnState();
108 AERROR <<
"Some error occurred, while loop will exit";
111 AINFO <<
"get progress:" << sp_alignment_->GetProgress();
112 if (fabs(1 - sp_alignment_->GetProgress()) < 1e-8) {
113 AINFO <<
"alignment progress reached 1.0, thread exit";
116 AINFO <<
"sleep " << sp_conf_->alignment_featch_pose_sleep <<
" sec";
118 std::chrono::seconds(sp_conf_->alignment_featch_pose_sleep);
119 std::this_thread::sleep_for(seconds);
122 AINFO <<
"Align thread complete";
124 alignment_thread.detach();
128 std::shared_ptr<std::vector<FramePose>>
GetPoses()
const {
129 if (sp_pose_collection_agent_ ==
nullptr) {
132 return sp_pose_collection_agent_->GetPoses();
137 AINFO <<
"AlignmentAgent is idle. this call will be refused";
139 response->set_progress(0.0);
142 if (sp_alignment_ ==
nullptr) {
143 AINFO <<
"sp_alignment_ is null, check later";
145 response->set_progress(0.0);
149 ErrorCode code = sp_alignment_->GetReturnState();
150 double progress = sp_alignment_->GetProgress();
151 response->set_code(code);
152 response->set_progress(progress);
164 if (sp_alignment_ ==
nullptr) {
165 response->set_progress(0.0);
167 response->set_progress(sp_alignment_->GetProgress());
178 std::shared_ptr<JsonConf> sp_conf_ =
nullptr;
179 std::shared_ptr<ALIGNMENT_TYPE> sp_alignment_ =
nullptr;
180 std::shared_ptr<PoseCollectionAgent> sp_pose_collection_agent_ =
nullptr;
int AlignmentCheck(REQUEST_TYPE *request, RESPONSE_TYPE *response)
AlignmentAgentState GetState() const
int AsyncStartAlignment()
int AlignmentStart(REQUEST_TYPE *request, RESPONSE_TYPE *response)
std::shared_ptr< std::vector< FramePose > > GetPoses() const
int AlignmentStop(REQUEST_TYPE *request, RESPONSE_TYPE *response)
AlignmentAgent(std::shared_ptr< JsonConf > sp_conf, std::shared_ptr< PoseCollectionAgent > sp_pose_collection_agent)
grpc::Status ProcessGrpcRequest(grpc::ServerContext *context, REQUEST_TYPE *request, RESPONSE_TYPE *response)
void SetState(AlignmentAgentState state)
@ ERROR_VERIFY_NO_GNSSPOS
@ ERROR_CHECK_BEFORE_START
State AlignmentAgentState