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

#include <external_command_demo.h>

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

Public 成员函数

 ExternalCommandDemo ()
 
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_demo.h 第 37 行定义.

构造及析构函数说明

◆ ExternalCommandDemo()

ExternalCommandDemo::ExternalCommandDemo ( )

在文件 external_command_demo.cc 第 30 行定义.

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

成员函数说明

◆ Init()

bool ExternalCommandDemo::Init ( )
overridevirtual

实现了 apollo::cyber::ComponentBase.

在文件 external_command_demo.cc 第 33 行定义.

33 {
34 action_command_client_ =
36 CommandStatus>("/apollo/external_command/action");
37 chassis_command_client_ =
39 CommandStatus>("/apollo/external_command/chassis");
40 free_space_command_client_ =
42 CommandStatus>("/apollo/external_command/free_space");
43 lane_follow_command_client_ =
46 "/apollo/external_command/lane_follow");
47 path_follow_command_client_ =
50 "/apollo/external_command/path_follow");
51 speed_command_client_ =
52 node_
54 "/apollo/external_command/speed");
55 valet_parking_command_client_ =
58 "/apollo/external_command/valet_parking");
59 status_client_ =
62 "/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}
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 ExternalCommandDemo::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_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(437556.02);
186 end_pose.set_y(4432540.34);
187 end_pose.set_heading(1.8);
188 std::vector<apollo::external_command::Point> way_points;
193 point1.set_x(437536.29);
194 point1.set_y(4432560.69);
195 point2.set_x(437536.29);
196 point2.set_y(4432510.69);
197 point3.set_x(437576.29);
198 point3.set_y(4432510.69);
199 point4.set_x(437576.29);
200 point4.set_y(4432560.69);
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 {
208 std::cout << "Invalid input!" << input_command_string << std::endl;
209 }
210 }
211 return true;
212}
#define AWARN
Definition log.h:43

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