23#include "modules/external_command/command_processor/command_processor_base/proto/command_processor_config.pb.h"
30namespace external_command {
37 last_received_command_.set_command_id(-1);
38 message_reader_ = MessageReader::Instance();
41 config.input_command_name(),
42 [
this](
const std::shared_ptr<SpeedCommand>& command, std::shared_ptr<CommandStatus>& status) {
43 this->OnCommand(command, status);
46 CHECK(config.output_command_name().size() > 0 && config.input_command_status_name().size() > 0);
47 auto message_writer = MessageWriter::Instance();
48 planning_command_writer_
50 planning_command_status_name_ = config.input_command_status_name().Get(0);
56 CHECK_NOTNULL(status);
57 if (command_id != last_received_command_.
command_id()) {
60 status->set_command_id(command_id);
66void SpeedCommandProcessor::OnCommand(
67 const std::shared_ptr<SpeedCommand>& command,
68 std::shared_ptr<CommandStatus>& status) {
69 auto planning_command = std::make_shared<apollo::planning::PlanningCommand>();
70 std::string module_name =
"UNKNOWN";
71 if (command->has_header()) {
72 module_name = command->header().module_name();
74 AINFO << std::setprecision(12) <<
"timestamp: " << timestamp <<
" " <<
"request for "
75 << command->header().timestamp_sec();
76 if (timestamp - command->header().timestamp_sec() > 2.0) {
77 AINFO <<
"request for " << command->header().module_name() <<
" has been timeouted";
81 common::util::FillHeader(module_name, planning_command.get());
82 auto custom_command = planning_command->mutable_custom_command();
83 custom_command->PackFrom(*command);
84 planning_command_writer_->Write(planning_command);
85 last_received_command_.CopyFrom(*command);
86 status->set_command_id(command->command_id());
static double NowInSeconds()
gets the current time in second.
virtual bool Init(const std::shared_ptr< cyber::Node > &node)
const CommandProcessorConfig & GetProcessorConfig() const
void RegisterMessage(const std::string &channel_name)
Register the message reader with the given channel name.
bool GetCommandStatus(int64_t command_id, CommandStatus *status) const override
Get the command status.
bool Init(const std::shared_ptr< cyber::Node > &node) override
Some string util functions.
optional int64 command_id