Apollo 10.0
自动驾驶开放平台
apollo::external_command::MotionCommandProcessorBase< T > 模板类 参考abstract

#include <motion_command_processor_base.h>

类 apollo::external_command::MotionCommandProcessorBase< T > 继承关系图:
apollo::external_command::MotionCommandProcessorBase< T > 的协作图:

Public 成员函数

 MotionCommandProcessorBase ()
 
 ~MotionCommandProcessorBase () override=default
 
bool Init (const std::shared_ptr< cyber::Node > &node) override
 
bool GetCommandStatus (int64_t command_id, CommandStatus *status) const override
 Get the command status.
 
- Public 成员函数 继承自 apollo::external_command::CommandProcessorBase
 CommandProcessorBase ()
 
virtual ~CommandProcessorBase ()=default
 

Protected 成员函数

const std::shared_ptr< apollo::external_command::LaneWayTool > & GetLaneWayTool () const
 
virtual bool Convert (const std::shared_ptr< T > &command, std::shared_ptr< apollo::routing::RoutingRequest > &routing_request) const =0
 Convert moving command to RoutingRequest.
 
bool SetStartPose (std::vector< apollo::routing::LaneWaypoint > *lane_way_points) const
 Set the start pose of lane_way_points with current vehicle pose.
 
bool SetStartPose (std::shared_ptr< apollo::routing::RoutingRequest > &routing_request) const
 Set the start pose of RoutingRequest with current vehicle pose.
 
void OnCommand (const std::shared_ptr< T > &command, std::shared_ptr< CommandStatus > &status)
 Process the incoming lane follow command.
 
virtual bool ProcessSpecialCommand (const std::shared_ptr< T > &command, const std::shared_ptr< apollo::planning::PlanningCommand > &planning_command) const =0
 Process special command except RoutingRequest.
 
- Protected 成员函数 继承自 apollo::external_command::CommandProcessorBase
const CommandProcessorConfigGetProcessorConfig () const
 
const std::shared_ptr< cyber::Node > & Node () const
 

Protected 属性

std::shared_ptr< cyber::Service< T, CommandStatus > > command_service_
 
std::shared_ptr< WriterHandleplanning_command_writer_
 
std::shared_ptr< WriterHandlerouting_response_writer_
 
std::shared_ptr< apollo::routing::Routingrouting_
 
std::shared_ptr< apollo::external_command::LaneWayToollane_way_tool_
 
last_received_command_
 
MessageReadermessage_reader_
 
std::string planning_command_status_name_
 

详细描述

template<typename T>
class apollo::external_command::MotionCommandProcessorBase< T >

在文件 motion_command_processor_base.h54 行定义.

构造及析构函数说明

◆ MotionCommandProcessorBase()

template<typename T >
apollo::external_command::MotionCommandProcessorBase< T >::MotionCommandProcessorBase ( )

在文件 motion_command_processor_base.h132 行定义.

133 : command_service_(nullptr),
135 routing_(std::make_shared<apollo::routing::Routing>()),
136 lane_way_tool_(nullptr),
137 message_reader_(MessageReader::Instance()) {
138 last_received_command_.set_command_id(-1);
139}
std::shared_ptr< cyber::Service< T, CommandStatus > > command_service_
std::shared_ptr< apollo::external_command::LaneWayTool > lane_way_tool_

◆ ~MotionCommandProcessorBase()

template<typename T >
apollo::external_command::MotionCommandProcessorBase< T >::~MotionCommandProcessorBase ( )
overridedefault

成员函数说明

◆ Convert()

template<typename T >
virtual bool apollo::external_command::MotionCommandProcessorBase< T >::Convert ( const std::shared_ptr< T > &  command,
std::shared_ptr< apollo::routing::RoutingRequest > &  routing_request 
) const
protectedpure virtual

Convert moving command to RoutingRequest.

参数
commandmoving command to be converted.
routing_requestConvert result of RoutingRequest. If there is no LaneFollow action in moving command, the convert result can be nullptr.
返回
Return true if there is error occurs for converting.

◆ GetCommandStatus()

template<typename T >
bool apollo::external_command::MotionCommandProcessorBase< T >::GetCommandStatus ( int64_t  command_id,
CommandStatus status 
) const
overridevirtual

Get the command status.

参数
command_idId of the command.
statusOutput command status.

实现了 apollo::external_command::CommandProcessorBase.

在文件 motion_command_processor_base.h187 行定义.

188 {
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 =
193 message_reader_->GetMessage<CommandStatus>(
195 if (nullptr == latest_planning_command_status) {
197 status->set_message("Cannot get planning command status!");
198 return true;
199 }
200 status->CopyFrom(*latest_planning_command_status);
201 return true;
202 }
203 return false;
204}
const T * GetMessage(const std::string &channel_name) const
Get the message with the channel name.

◆ GetLaneWayTool()

template<typename T >
const std::shared_ptr< apollo::external_command::LaneWayTool > & apollo::external_command::MotionCommandProcessorBase< T >::GetLaneWayTool ( ) const
inlineprotected

在文件 motion_command_processor_base.h70 行定义.

71 {
72 return lane_way_tool_;
73 }

◆ Init()

template<typename T >
bool apollo::external_command::MotionCommandProcessorBase< T >::Init ( const std::shared_ptr< cyber::Node > &  node)
overridevirtual

重载 apollo::external_command::CommandProcessorBase .

在文件 motion_command_processor_base.h142 行定义.

143 {
144 // Init function of base class should be invoked first.
145 if (!CommandProcessorBase::Init(node)) {
146 AERROR << "MotionCommandProcessorBase init failed!";
147 return false;
148 }
150 std::make_shared<apollo::external_command::LaneWayTool>(node);
151 routing_->Init();
152 // Create service for input command.
153 const auto& config = GetProcessorConfig();
154 command_service_ = node->CreateService<T, CommandStatus>(
155 config.input_command_name(),
156 [this](const std::shared_ptr<T>& command,
157 std::shared_ptr<CommandStatus>& status) {
158 this->OnCommand(command, status);
159 });
160
161 CHECK_GT(config.output_command_name().size(), 0);
162 // Create writer for output command.
164 attr.set_channel_name(config.output_command_name().Get(0));
165 auto qos = attr.mutable_qos_profile();
167 qos->set_reliability(
169 qos->set_durability(
171 auto message_writer = MessageWriter::Instance();
173 message_writer->RegisterMessage<apollo::planning::PlanningCommand>(
174 attr, config.planning_command_history_name());
176 message_writer->RegisterMessage<apollo::routing::RoutingResponse>(
177 FLAGS_routing_response_topic);
178 // Create reader for input command status.
179 CHECK_GT(config.input_command_status_name().size(), 0);
180 planning_command_status_name_ = config.input_command_status_name().Get(0);
181 message_reader_->RegisterMessage<CommandStatus>(
183 return true;
184}
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.
void OnCommand(const std::shared_ptr< T > &command, std::shared_ptr< CommandStatus > &status)
Process the incoming lane follow command.
#define AERROR
Definition log.h:44

◆ OnCommand()

template<typename T >
void apollo::external_command::MotionCommandProcessorBase< T >::OnCommand ( const std::shared_ptr< T > &  command,
std::shared_ptr< CommandStatus > &  status 
)
protected

Process the incoming lane follow command.

Search the routing to end point and send to planning module.

参数
commandIncoming lane follow command.
statusThe command process result before sending to planning module.

在文件 motion_command_processor_base.h207 行定义.

208 {
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";
218 return;
219 }
220 }
221 last_received_command_.CopyFrom(*command);
222 status->set_command_id(command->command_id());
223 // Convert command to RoutingRequest.
224 std::shared_ptr<apollo::routing::RoutingRequest> routing_request = nullptr;
225 bool convert_result = Convert(command, routing_request);
226 if (!convert_result) {
227 status->set_status(CommandStatusType::ERROR);
228 status->set_message("Cannot convert command to RoutingRequest: " +
229 command->DebugString());
230 return;
231 }
232 // Search routing.
233 std::string module_name = "UNKNOWN";
234 if (command->has_header()) {
235 module_name = command->header().module_name();
236 }
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())) {
245 status->set_status(CommandStatusType::ERROR);
246 status->set_message("Cannot get routing of command: " +
247 command->DebugString());
248 AERROR << "Routing process failed! ";
249 return;
250 }
251 planning_command->mutable_lane_follow_command()->CopyFrom(
252 *routing_response);
253 // Publish routing response to display on HMI.
254 routing_response_writer_->Write(routing_response);
255 }
256 // Process command except RoutingRequest.
257 if (!ProcessSpecialCommand(command, planning_command)) {
258 AERROR << "Process special command failed!";
259 return;
260 }
261 planning_command->set_command_id(command->command_id());
262 // Set target_speed.
263 if (command->has_target_speed()) {
264 planning_command->set_target_speed(command->target_speed());
265 }
266 planning_command->set_is_motion_command(true);
267 // Send routing response to planning module.
268 planning_command_writer_->Write(planning_command);
269 AINFO << "publish: " << planning_command->DebugString();
270 status->set_status(CommandStatusType::RUNNING);
271}
static double NowInSeconds()
gets the current time in second.
Definition clock.cc:56
virtual bool Convert(const std::shared_ptr< T > &command, std::shared_ptr< apollo::routing::RoutingRequest > &routing_request) const =0
Convert moving command to RoutingRequest.
virtual bool ProcessSpecialCommand(const std::shared_ptr< T > &command, const std::shared_ptr< apollo::planning::PlanningCommand > &planning_command) const =0
Process special command except RoutingRequest.
#define AINFO
Definition log.h:42

◆ ProcessSpecialCommand()

template<typename T >
virtual bool apollo::external_command::MotionCommandProcessorBase< T >::ProcessSpecialCommand ( const std::shared_ptr< T > &  command,
const std::shared_ptr< apollo::planning::PlanningCommand > &  planning_command 
) const
protectedpure virtual

Process special command except RoutingRequest.

参数
commandRoutingCommand to be converted.
planning_commandOutput process result.
返回
True if no error occurs.

◆ SetStartPose() [1/2]

template<typename T >
bool apollo::external_command::MotionCommandProcessorBase< T >::SetStartPose ( std::shared_ptr< apollo::routing::RoutingRequest > &  routing_request) const
protected

Set the start pose of RoutingRequest with current vehicle pose.

参数
routing_requestRoutingRequest to be updated.
返回
Return true if there is error occurs.

在文件 motion_command_processor_base.h286 行定义.

287 {
288 CHECK_NOTNULL(routing_request);
289 // Get the current vehicle pose as start pose.
290 auto start_pose = routing_request->add_waypoint();
291 if (!lane_way_tool_->GetVehicleLaneWayPoint(start_pose)) {
292 AERROR << "Get lane near start pose failed!";
293 return false;
294 }
295 return true;
296}

◆ SetStartPose() [2/2]

template<typename T >
bool apollo::external_command::MotionCommandProcessorBase< T >::SetStartPose ( std::vector< apollo::routing::LaneWaypoint > *  lane_way_points) const
protected

Set the start pose of lane_way_points with current vehicle pose.

参数
lane_way_pointsstart pose to be updated.
返回
Return true if there is error occurs.

在文件 motion_command_processor_base.h274 行定义.

275 {
276 CHECK_NOTNULL(lane_way_points);
277 // Get the current vehicle pose as start pose.
278 if (!lane_way_tool_->GetVehicleLaneWayPoints(lane_way_points)) {
279 AERROR << "Get lane near start pose failed!";
280 return false;
281 }
282 return true;
283}

类成员变量说明

◆ command_service_

template<typename T >
std::shared_ptr<cyber::Service<T, CommandStatus> > apollo::external_command::MotionCommandProcessorBase< T >::command_service_
protected

在文件 motion_command_processor_base.h117 行定义.

◆ lane_way_tool_

template<typename T >
std::shared_ptr<apollo::external_command::LaneWayTool> apollo::external_command::MotionCommandProcessorBase< T >::lane_way_tool_
protected

在文件 motion_command_processor_base.h122 行定义.

◆ last_received_command_

template<typename T >
T apollo::external_command::MotionCommandProcessorBase< T >::last_received_command_
protected

在文件 motion_command_processor_base.h123 行定义.

◆ message_reader_

template<typename T >
MessageReader* apollo::external_command::MotionCommandProcessorBase< T >::message_reader_
protected

在文件 motion_command_processor_base.h124 行定义.

◆ planning_command_status_name_

template<typename T >
std::string apollo::external_command::MotionCommandProcessorBase< T >::planning_command_status_name_
protected

在文件 motion_command_processor_base.h125 行定义.

◆ planning_command_writer_

template<typename T >
std::shared_ptr<WriterHandle> apollo::external_command::MotionCommandProcessorBase< T >::planning_command_writer_
protected

在文件 motion_command_processor_base.h118 行定义.

◆ routing_

template<typename T >
std::shared_ptr<apollo::routing::Routing> apollo::external_command::MotionCommandProcessorBase< T >::routing_
protected

在文件 motion_command_processor_base.h121 行定义.

◆ routing_response_writer_

template<typename T >
std::shared_ptr<WriterHandle> apollo::external_command::MotionCommandProcessorBase< T >::routing_response_writer_
protected

在文件 motion_command_processor_base.h119 行定义.


该类的文档由以下文件生成: