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" 36 template <
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";
71 response->set_code(ErrorCode::ERROR_REQUEST);
72 response->set_progress(sp_alignment_->GetProgress());
75 AINFO <<
"AlignmentAgent progress: " << response->progress();
81 AINFO <<
"AlignmentAgent is running. do need start again";
82 response->set_code(ErrorCode::ERROR_REPEATED_START);
83 response->set_progress(0.0);
88 response->set_code(ErrorCode::SUCCESS);
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();
106 if (code == ErrorCode::ERROR_VERIFY_NO_GNSSPOS ||
107 code == ErrorCode::ERROR_GNSS_SIGNAL_FAIL) {
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";
138 response->set_code(ErrorCode::ERROR_CHECK_BEFORE_START);
139 response->set_progress(0.0);
142 if (sp_alignment_ ==
nullptr) {
143 AINFO <<
"sp_alignment_ is null, check later";
144 response->set_code(ErrorCode::SUCCESS);
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);
153 if (code == ErrorCode::ERROR_VERIFY_NO_GNSSPOS ||
154 code == ErrorCode::ERROR_GNSS_SIGNAL_FAIL) {
163 response->set_code(ErrorCode::SUCCESS);
164 if (sp_alignment_ ==
nullptr) {
165 response->set_progress(0.0);
167 response->set_progress(sp_alignment_->GetProgress());
174 void SetState(AlignmentAgentState state) { state_ = state; }
175 AlignmentAgentState
GetState()
const {
return state_; }
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;
181 AlignmentAgentState state_;
void SetState(AlignmentAgentState state)
Definition: alignment_agent.h:174
int AlignmentStop(REQUEST_TYPE *request, RESPONSE_TYPE *response)
Definition: alignment_agent.h:162
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
int AsyncStartAlignment()
Definition: alignment_agent.h:93
std::shared_ptr< std::vector< FramePose > > GetPoses() const
Definition: alignment_agent.h:128
AlignmentAgent(std::shared_ptr< JsonConf > sp_conf, std::shared_ptr< PoseCollectionAgent > sp_pose_collection_agent)
Definition: alignment_agent.h:40
bool IsShutdown()
Definition: state.h:46
int AlignmentStart(REQUEST_TYPE *request, RESPONSE_TYPE *response)
Definition: alignment_agent.h:79
int AlignmentCheck(REQUEST_TYPE *request, RESPONSE_TYPE *response)
Definition: alignment_agent.h:135
void Reset()
Definition: alignment_agent.h:47
State AlignmentAgentState
Definition: alignment_agent.h:34
State
Definition: common.h:56
grpc::Status ProcessGrpcRequest(grpc::ServerContext *context, REQUEST_TYPE *request, RESPONSE_TYPE *response)
Definition: alignment_agent.h:53
AlignmentAgentState GetState() const
Definition: alignment_agent.h:175
#define AERROR
Definition: log.h:44
bool OK()
Definition: state.h:44
#define AINFO
Definition: log.h:42
double UnixNow()
Definition: client_common.h:37
Definition: alignment_agent.h:38