Apollo 11.0
自动驾驶开放平台
replan_control_task.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2024 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
18
19#include "cyber/common/log.h"
22
23namespace apollo {
24namespace control {
25
32
33ReplanControlTask::ReplanControlTask() : name_("Replan Control Task") {
34 AINFO << "Using " << name_;
35}
36
37Status ReplanControlTask::Init(std::shared_ptr<DependencyInjector> injector) {
38 // hook: Apollo License Verification: v_apollo_park
39 injector_ = injector;
40 node_ = ::apollo::cyber::CreateNode("replan_control");
41
42 if (!ControlTask::LoadConfig<ReplanTaskConf>(&replan_task_conf_)) {
43 AERROR << "Failed to replan control task config";
44 return Status(ErrorCode::CONTROL_INIT_ERROR, "Failed to load replan control task conf");
45 }
46
47 cyber::ReaderConfig safety_decision_reader_config;
48 safety_decision_reader_config.channel_name = replan_task_conf_.guardian_decision_topic();
49 safety_decision_reader_config.pending_queue_size = replan_task_conf_.guardian_decision_msg_pending_queue_size();
50
51 safety_decision_reader_ = node_->CreateReader<SafetyDecision>(safety_decision_reader_config, nullptr);
52
53 return Status::OK();
54}
55
56void ReplanControlTask::OnSafetyDecision(const std::shared_ptr<SafetyDecision> &safety_decision_msg) {
57 ADEBUG << "Received safety decision data: run SafetyDecision callback.";
58 std::lock_guard<std::mutex> lock(mutex_);
59 decision_.CopyFrom(*safety_decision_msg);
60}
61
63 const localization::LocalizationEstimate *localization,
64 const canbus::Chassis *chassis,
65 const planning::ADCTrajectory *planning_published_trajectory,
66 ControlCommand *cmd) {
67 auto replan_debug_info = injector_->mutable_control_debug_info()->mutable_replan_debug();
68 replan_debug_info->set_control_task_name(name_);
69 replan_debug_info->set_trajectory_replan(planning_published_trajectory->is_replan());
70
71 bool replan_request = false;
72 ReplanRequestReasonCode replan_req_reason_code;
73 std::string replan_request_reason = "";
74 if (safety_decision_reader_ != nullptr) {
75 ADEBUG << "Received safety decision data.";
76 // get safety decision
77 safety_decision_reader_->Observe();
78 const auto &safety_decision_msg = safety_decision_reader_->GetLatestObserved();
79 if (safety_decision_msg == nullptr) {
80 AERROR << "safety decision msg is not ready!";
81 } else {
82 ADEBUG << "safety_decision_msg is " << safety_decision_msg->ShortDebugString();
83 OnSafetyDecision(safety_decision_msg);
84 }
85 if (decision_.has_safety_mode_trigger_time()) {
86 ADEBUG << "Safety mode triggered, need to replan.";
87 replan_request = true;
89 replan_request_reason = "Safety function mode triggered, need to replan.";
90 }
91 } else {
92 AERROR << "safety decision reader is not ready!";
93 }
94
95 if (chassis->error_code() == Chassis::CMD_NOT_IN_PERIOD) {
96 ADEBUG << "chassis safety triggered, need to replan.";
97 replan_request = true;
99 replan_request_reason = "Chassis safety mode triggered, need to replan.";
100 }
101
102 auto control_interactive_info = injector_->mutable_control_interactive_info();
103 control_interactive_info->set_replan_request(replan_request);
104
105 if (replan_request) {
106 control_interactive_info->set_replan_req_reason_code(replan_req_reason_code);
107 control_interactive_info->set_replan_request_reason(replan_request_reason);
108 } else {
109 control_interactive_info->set_replan_req_reason_code(ReplanRequestReasonCode::NONE_REPLAN);
110 control_interactive_info->set_replan_request_reason("No triggered, do not need to replan");
111 }
112
113 replan_debug_info->set_is_need_replan(replan_request);
114
115 return Status::OK();
116}
117
119
123
124std::string ReplanControlTask::Name() const {
125 return name_;
126}
127
128} // namespace control
129} // 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
std::shared_ptr< DependencyInjector > injector_
void Stop() override
stop ReplanControlTask
common::Status ComputeControlCommand(const localization::LocalizationEstimate *localization, const canbus::Chassis *chassis, const planning::ADCTrajectory *trajectory, control::ControlCommand *cmd) override
compute brake / throttle values based on current vehicle status and target trajectory
common::Status Init(std::shared_ptr< DependencyInjector > injector) override
initialize ReplanControlTask
std::string Name() const override
ReplanControlTask name
common::Status Reset() override
reset demo control task
#define ADEBUG
Definition log.h:41
#define AERROR
Definition log.h:44
#define AINFO
Definition log.h:42
std::unique_ptr< Node > CreateNode(const std::string &node_name, const std::string &name_space)
Definition cyber.cc:33
class register implement
Definition arena_queue.h:37
Defines the ReplanControlTask class.
optional ErrorCode error_code
uint32_t pending_queue_size
configuration for responding ChannelBuffer.