Apollo 11.0
自动驾驶开放平台
apollo::control::VehicleCalibrationDebug类 参考
apollo::control::VehicleCalibrationDebug 的协作图:

Public 成员函数

 VehicleCalibrationDebug ()
 
int32_t init ()
 
void Send ()
 
bool LoadCalibrationTable (calibration_table *calibration_table_conf)
 
void InitControlCalibrationTable ()
 
void on_debug (const control::ControlCommand &cmd)
 
void on_chassis (const Chassis &chassis)
 
void KeyboardLoopThreadFunc ()
 
bool IsRunning () const
 
void stop ()
 

详细描述

在文件 calibration_table_debug.cc 第 59 行定义.

构造及析构函数说明

◆ VehicleCalibrationDebug()

apollo::control::VehicleCalibrationDebug::VehicleCalibrationDebug ( )
inline

在文件 calibration_table_debug.cc 第 61 行定义.

61: node_(CreateNode("calibration_debug")) {}
std::unique_ptr< Node > CreateNode(const std::string &node_name, const std::string &name_space)
Definition cyber.cc:33

成员函数说明

◆ init()

int32_t apollo::control::VehicleCalibrationDebug::init ( )
inline

在文件 calibration_table_debug.cc 第 62 行定义.

62 {
63 if (is_running_) {
64 AERROR << "Already running.";
65 return -1;
66 }
67 is_running_ = true;
68 chassis_reader_ = node_->CreateReader<Chassis>(
69 FLAGS_chassis_topic, [this](const std::shared_ptr<Chassis> &chassis) {
70 on_chassis(*chassis);
71 });
72
73 control_reader_ = node_->CreateReader<ControlCommand>(
74 FLAGS_control_command_topic,
75 [this](const std::shared_ptr<ControlCommand> &cmd) { on_debug(*cmd); });
76
77 calibration_debug_writer_ = node_->CreateWriter<CalibrationDebug>(
78 "/apollo/control/calibration_debug");
79
80 keyboard_thread_.reset(
81 new std::thread([this] { KeyboardLoopThreadFunc(); }));
82 if (keyboard_thread_ == nullptr) {
83 AERROR << "Unable to create can client receiver thread.";
84 return -1;
85 }
86
87 if (!LoadCalibrationTable(&calibration_table_)) {
88 AERROR << "failed to load calibration table";
89 }
90
92
93 return 0;
94 }
void on_debug(const control::ControlCommand &cmd)
bool LoadCalibrationTable(calibration_table *calibration_table_conf)
#define AERROR
Definition log.h:44

◆ InitControlCalibrationTable()

void apollo::control::VehicleCalibrationDebug::InitControlCalibrationTable ( )
inline

在文件 calibration_table_debug.cc 第 116 行定义.

116 {
117 AINFO << "Control calibration table size is "
118 << calibration_table_.calibration_size();
120 for (const auto &calibration : calibration_table_.calibration()) {
121 xyz.push_back(std::make_tuple(calibration.speed(),
122 calibration.acceleration(),
123 calibration.command()));
124 }
125 control_interpolation_.reset(new Interpolation2D);
126 ACHECK(control_interpolation_->Init(xyz))
127 << "Fail to load control calibration table";
128 }
std::vector< std::tuple< double, double, double > > DataType
#define ACHECK(cond)
Definition log.h:80
#define AINFO
Definition log.h:42

◆ IsRunning()

bool apollo::control::VehicleCalibrationDebug::IsRunning ( ) const
inline

在文件 calibration_table_debug.cc 第 186 行定义.

186{ return is_running_; }

◆ KeyboardLoopThreadFunc()

void apollo::control::VehicleCalibrationDebug::KeyboardLoopThreadFunc ( )
inline

在文件 calibration_table_debug.cc 第 175 行定义.

175 {
176 char c = 0;
177 int32_t kfd_ = 0;
178 while (IsRunning()) {
179 if (read(kfd_, &c, 1) < 0) {
180 perror("read():");
181 exit(-1);
182 }
183 }
184 }

◆ LoadCalibrationTable()

bool apollo::control::VehicleCalibrationDebug::LoadCalibrationTable ( calibration_table *  calibration_table_conf)
inline

在文件 calibration_table_debug.cc 第 103 行定义.

103 {
104 std::string calibration_table_path = FLAGS_calibration_table_debug_file;
105
106 if (!apollo::cyber::common::GetProtoFromFile(calibration_table_path,
107 calibration_table_conf)) {
108 AERROR << "Load calibration table failed!";
109 return false;
110 }
111 AINFO << "Load the calibraiton table file successfully, file path: "
112 << calibration_table_path;
113 return true;
114 }
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

◆ on_chassis()

void apollo::control::VehicleCalibrationDebug::on_chassis ( const Chassis &  chassis)
inline

在文件 calibration_table_debug.cc 第 169 行定义.

169 {
170 ADEBUG << "Received chassis data: run chassis callback.";
171 std::lock_guard<std::mutex> lock(mutex_);
172 latest_chassis_.CopyFrom(chassis);
173 }
#define ADEBUG
Definition log.h:41

◆ on_debug()

void apollo::control::VehicleCalibrationDebug::on_debug ( const control::ControlCommand &  cmd)
inline

在文件 calibration_table_debug.cc 第 130 行定义.

130 {
131 chassis_reader_->Observe();
132 const auto &chassis_msg = chassis_reader_->GetLatestObserved();
133 if (chassis_msg == nullptr) {
134 AERROR << "Chassis msg is not ready!";
135 return;
136 }
137
138 double current_speed = 0.0;
139
140 double input_acc_lookup = 0.0;
141
142 double input_throttle_cmd = 0.0;
143 double output_throttle_cmd = 0.0;
144 double input_brake_cmd = 0.0;
145 double output_brake_cmd = 0.0;
146 double input_calibration_value = 0.0;
147 double output_calibration_value = 0.0;
148
149 if (cmd.debug().simple_lon_debug().has_acceleration_lookup()) {
150 current_speed = chassis_msg->speed_mps();
151 input_acc_lookup = cmd.debug().simple_lon_debug().acceleration_lookup();
152 input_calibration_value =
153 cmd.debug().simple_lon_debug().calibration_value();
154
155 output_calibration_value = control_interpolation_->Interpolate(
156 std::make_pair(std::fabs(current_speed), input_acc_lookup));
157
158 if (input_acc_lookup * input_calibration_value < 0.0) {
159 AINFO << "current_speed:" << current_speed
160 << ", input_acc_lookup:" << input_acc_lookup
161 << ", input_calibration_value:" << input_calibration_value
162 << ", output_calibration_value:" << output_calibration_value;
163 }
164 }
165
166 Send();
167 }

◆ Send()

void apollo::control::VehicleCalibrationDebug::Send ( )
inline

在文件 calibration_table_debug.cc 第 96 行定义.

96 {
97 apollo::common::util::FillHeader("calibration_debug", &calibration_debug_);
98 calibration_debug_writer_->Write(calibration_debug_);
99 ADEBUG << "Calibration Debug send OK:"
100 << calibration_debug_.ShortDebugString();
101 }

◆ stop()

void apollo::control::VehicleCalibrationDebug::stop ( )
inline

在文件 calibration_table_debug.cc 第 188 行定义.

188 {
189 if (is_running_) {
190 is_running_ = false;
191 if (keyboard_thread_ != nullptr && keyboard_thread_->joinable()) {
192 keyboard_thread_->join();
193 keyboard_thread_.reset();
194 AINFO << "keyboard stopped [ok].";
195 }
196 }
197 }

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