Apollo 10.0
自动驾驶开放平台
ExternalCommandWrapperDemo类 参考final

#include <external_command_wrapper_demo.h>

类 ExternalCommandWrapperDemo 继承关系图:
ExternalCommandWrapperDemo 的协作图:

Public 成员函数

 ExternalCommandWrapperDemo ()
 
bool Init () override
 
bool Proc () override
 The Proc logic of the component, which called by the CyberRT frame.
 
- Public 成员函数 继承自 apollo::cyber::TimerComponent
 TimerComponent ()
 
 ~TimerComponent () override
 
bool Initialize (const TimerComponentConfig &config) override
 init the component by protobuf object.
 
void Clear () override
 
bool Process ()
 
uint32_t GetInterval () const
 
- Public 成员函数 继承自 apollo::cyber::ComponentBase
virtual ~ComponentBase ()
 
virtual bool Initialize (const ComponentConfig &config)
 
virtual void Shutdown ()
 
template<typename T >
bool GetProtoConfig (T *config) const
 

额外继承的成员函数

- Public 类型 继承自 apollo::cyber::ComponentBase
template<typename M >
using Reader = cyber::Reader< M >
 
- Protected 成员函数 继承自 apollo::cyber::ComponentBase
const std::string & ConfigFilePath () const
 
void LoadConfigFiles (const ComponentConfig &config)
 
void LoadConfigFiles (const TimerComponentConfig &config)
 
- Protected 属性 继承自 apollo::cyber::ComponentBase
std::atomic< bool > is_shutdown_ = {false}
 
std::shared_ptr< Node > node_ = nullptr
 
std::string config_file_path_ = ""
 
std::vector< std::shared_ptr< ReaderBase > > readers_
 

详细描述

在文件 external_command_wrapper_demo.h 第 39 行定义.

构造及析构函数说明

◆ ExternalCommandWrapperDemo()

ExternalCommandWrapperDemo::ExternalCommandWrapperDemo ( )

在文件 external_command_wrapper_demo.cc 第 31 行定义.

32 : command_id_(0), module_name_("demo") {}

成员函数说明

◆ Init()

bool ExternalCommandWrapperDemo::Init ( )
overridevirtual

实现了 apollo::cyber::ComponentBase.

在文件 external_command_wrapper_demo.cc 第 34 行定义.

34 {
35 action_command_client_ = std::make_shared<apollo::common::ClientWrapper<
37 node_, "/apollo/external_command/action");
38 chassis_command_client_ = std::make_shared<apollo::common::ClientWrapper<
40 node_, "/apollo/external_command/chassis");
41 free_space_command_client_ = std::make_shared<apollo::common::ClientWrapper<
43 node_, "/apollo/external_command/free_space");
44 zone_cover_command_client_ = std::make_shared<apollo::common::ClientWrapper<
46 node_, "/apollo/external_command/zone_cover");
47 lane_follow_command_client_ = std::make_shared<apollo::common::ClientWrapper<
49 node_, "/apollo/external_command/lane_follow");
50 path_follow_command_client_ = std::make_shared<apollo::common::ClientWrapper<
52 node_, "/apollo/external_command/path_follow");
53 speed_command_client_ = std::make_shared<apollo::common::ClientWrapper<
55 node_, "/apollo/external_command/speed");
56 valet_parking_command_client_ =
57 std::make_shared<apollo::common::ClientWrapper<
59 node_, "/apollo/external_command/valet_parking");
60 status_client_ = std::make_shared<apollo::common::ClientWrapper<
62 node_, "/apollo/external_command/command_status");
64 "modules/external_command/external_command_demo/conf/"
65 "demo_config.pb.txt",
66 &demo_config_);
67 return true;
68}
Wrapper of cyber::Client which sends a topic with service name when SendRequst is invoked.
std::shared_ptr< Node > node_
bool GetProtoFromFile(const std::string &file_name, google::protobuf::Message *message)
Parses the content of the file specified by the file_name as a representation of protobufs,...
Definition file.cc:132

◆ Proc()

bool ExternalCommandWrapperDemo::Proc ( )
overridevirtual

The Proc logic of the component, which called by the CyberRT frame.

返回
returns true if successful, otherwise returns false

实现了 apollo::cyber::TimerComponent.

在文件 external_command_wrapper_demo.cc 第 70 行定义.

70 {
71 int8_t revent = 0; // short
72 struct pollfd fd = {STDIN_FILENO, POLLIN, revent};
73 switch (poll(&fd, 1, 100)) {
74 case -1:
75 std::cout << "Failed to read keyboard" << std::endl;
76 return false;
77 case 0:
78 return true;
79 default:
80 char data[50];
81 std::cin.getline(data, 50);
82 std::string input_command_string = data;
83 if (input_command_string == "pull_over") {
84 // Pull over.
85 SendActionCommand(
87 } else if (input_command_string == "stop") {
88 // Stop planning.
90 } else if (input_command_string == "start") {
91 // Start planning.
93 } else if (input_command_string == "clear") {
94 // Start planning.
95 SendActionCommand(
97 } else if (input_command_string == "manual") {
98 // Switch manual mode.
99 SendActionCommand(
101 } else if (input_command_string == "auto") {
102 // Switch auto mode.
103 SendActionCommand(
105 } else if (input_command_string == "vin") {
106 // Send vin validation.
108 } else if (input_command_string == "enter_mission") {
109 // Enter mission model.
110 SendActionCommand(
112 } else if (input_command_string == "exit_mission") {
113 // Exit mission model.
114 SendActionCommand(
116 } else if (input_command_string == "chassis") {
117 SendVehicleSignalCommand();
118 } else if (input_command_string == "custom_chassis") {
119 SendCustomChassisCommand();
120 } else if (input_command_string.find("set_speed") != std::string::npos) {
121 auto index = input_command_string.find("set_speed");
122 std::string speed_value_string = input_command_string.substr(
123 index + std::string("set_speed").length(),
124 input_command_string.length());
125 if (!speed_value_string.empty()) {
126 double speed_value = std::atof(speed_value_string.c_str());
127 SendSpeedCommand(speed_value);
128 } else {
129 AWARN << "Input format is invalid, please input format like: "
130 "set_speed 1.5";
131 }
132 } else if (input_command_string == "increase_speed") {
133 double speed_factor = 1.2;
134 SendSpeedFactorCommand(speed_factor);
135 } else if (input_command_string == "decrease_speed") {
136 double speed_factor = 0.8;
137 SendSpeedFactorCommand(speed_factor);
138 } else if (input_command_string == "restore_speed") {
139 RestoreSpeed();
140 } else if (input_command_string == "lane") {
141 // Modify way point as needed.
143 way_point.set_x(0.0);
144 way_point.set_y(0.0);
145 way_point.set_heading(0.0);
146 std::vector<apollo::external_command::Pose> way_points;
147 way_points.emplace_back(way_point);
149 end_pose.set_x(10.0);
150 end_pose.set_y(0.0);
151 end_pose.set_heading(0.0);
152 SendLaneFollowCommand(way_points, end_pose,
153 demo_config_.target_speed());
154 } else if (input_command_string == "path_loc") {
155 SendPathFollowCommandWithLocationRecord(
157 } else if (input_command_string == "path_path") {
158 SendPathFollowCommandWithPathRecord(
160 } else if (input_command_string == "valet_parking") {
161 std::string parking_spot_id = "451089045";
162 SendValetParkingCommand(parking_spot_id, demo_config_.target_speed());
163 } else if (input_command_string.find("command_status") !=
164 std::string::npos) {
165 // Input command with format: command_status=XX, where XX is the
166 // command_id
167 const size_t start_pos = std::string("command_status=").length();
168 const size_t end_pos = input_command_string.length();
169 if (end_pos <= start_pos) {
170 std::cout
171 << "Please check command status with format: command_status=XX!"
172 << std::endl;
173 break;
174 }
175 std::string command_id_string =
176 input_command_string.substr(start_pos, end_pos);
177 command_id_string.erase(
178 std::remove_if(command_id_string.begin(), command_id_string.end(),
179 ::isspace),
180 command_id_string.end());
181 uint64_t id = std::atoi(command_id_string.c_str());
182 CheckCommandStatus(id);
183 } else if (input_command_string == "free1") {
185 end_pose.set_x(demo_config_.end_pose_x());
186 end_pose.set_y(demo_config_.end_pose_y());
187 end_pose.set_heading(demo_config_.end_pose_heading());
188 std::vector<apollo::external_command::Point> way_points;
193 point1.set_x(demo_config_.point1_x());
194 point1.set_y(demo_config_.point1_y());
195 point2.set_x(demo_config_.point2_x());
196 point2.set_y(demo_config_.point2_y());
197 point3.set_x(demo_config_.point3_x());
198 point3.set_y(demo_config_.point3_y());
199 point4.set_x(demo_config_.point4_x());
200 point4.set_y(demo_config_.point4_y());
201 way_points.emplace_back(point1);
202 way_points.emplace_back(point2);
203 way_points.emplace_back(point3);
204 way_points.emplace_back(point4);
205
206 SendFreespaceCommand(way_points, end_pose);
207 } else if (input_command_string == "zone_cover") {
208 std::string overlap_id = demo_config_.overlap_id();
209 SendZoneCoverCommand(overlap_id);
210 } else {
211 std::cout << "Invalid input!" << input_command_string << std::endl;
212 }
213 }
214 return true;
215}
#define AWARN
Definition log.h:43

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