143 const std::shared_ptr<cyber::Node>& node) {
146 AERROR <<
"MotionCommandProcessorBase init failed!";
150 std::make_shared<apollo::external_command::LaneWayTool>(node);
153 const auto& config = GetProcessorConfig();
155 config.input_command_name(),
156 [
this](
const std::shared_ptr<T>& command,
157 std::shared_ptr<CommandStatus>& status) {
158 this->OnCommand(command, status);
161 CHECK_GT(config.output_command_name().size(), 0);
164 attr.set_channel_name(config.output_command_name().Get(0));
165 auto qos = attr.mutable_qos_profile();
167 qos->set_reliability(
171 auto message_writer = MessageWriter::Instance();
172 planning_command_writer_ =
174 attr, config.planning_command_history_name());
175 routing_response_writer_ =
177 FLAGS_routing_response_topic);
179 CHECK_GT(config.input_command_status_name().size(), 0);
180 planning_command_status_name_ = config.input_command_status_name().Get(0);
182 planning_command_status_name_);
189 CHECK_NOTNULL(status);
190 if (last_received_command_.command_id() == command_id) {
191 status->set_command_id(command_id);
192 auto* latest_planning_command_status =
194 planning_command_status_name_);
195 if (
nullptr == latest_planning_command_status) {
197 status->set_message(
"Cannot get planning command status!");
200 status->CopyFrom(*latest_planning_command_status);
208 const std::shared_ptr<T>& command, std::shared_ptr<CommandStatus>& status) {
209 CHECK_NOTNULL(command);
210 CHECK_NOTNULL(status);
211 if (command->has_header()) {
213 AINFO << std::setprecision(12) <<
"timestamp: " << timestamp <<
" "
214 <<
"request for " << command->header().timestamp_sec();
215 if (timestamp - command->header().timestamp_sec() > 2.0) {
216 AINFO <<
"request for " << command->header().module_name()
217 <<
" has been timeouted";
221 last_received_command_.CopyFrom(*command);
222 status->set_command_id(command->command_id());
224 std::shared_ptr<apollo::routing::RoutingRequest> routing_request =
nullptr;
225 bool convert_result = Convert(command, routing_request);
226 if (!convert_result) {
228 status->set_message(
"Cannot convert command to RoutingRequest: " +
229 command->DebugString());
233 std::string module_name =
"UNKNOWN";
234 if (command->has_header()) {
235 module_name = command->header().module_name();
237 std::lock_guard<std::mutex> guard(this->mutex_);
238 auto planning_command = std::make_shared<apollo::planning::PlanningCommand>();
239 common::util::FillHeader(module_name, planning_command.get());
240 if (
nullptr != routing_request) {
241 AINFO <<
"Process routing: " << routing_request->DebugString();
242 auto routing_response =
243 std::make_shared<apollo::routing::RoutingResponse>();
244 if (!routing_->Process(routing_request, routing_response.get())) {
246 status->set_message(
"Cannot get routing of command: " +
247 command->DebugString());
248 AERROR <<
"Routing process failed! ";
251 planning_command->mutable_lane_follow_command()->CopyFrom(
254 routing_response_writer_->Write(routing_response);
257 if (!ProcessSpecialCommand(command, planning_command)) {
258 AERROR <<
"Process special command failed!";
261 planning_command->set_command_id(command->command_id());
263 if (command->has_target_speed()) {
264 planning_command->set_target_speed(command->target_speed());
266 planning_command->set_is_motion_command(
true);
268 planning_command_writer_->Write(planning_command);
269 AINFO <<
"publish: " << planning_command->DebugString();