24#include "modules/common_msgs/chassis_msgs/chassis.pb.h"
25#include "modules/common_msgs/control_msgs/control_cmd.pb.h"
26#include "modules/control/control_component/proto/calibration_debug.pb.h"
27#include "modules/control/control_component/proto/calibration_table.pb.h"
43 "/apollo/modules/control/control_component/conf/"
44 "calibration_table.pb.txt",
45 "calibration table file");
64 AERROR <<
"Already running.";
68 chassis_reader_ = node_->CreateReader<
Chassis>(
69 FLAGS_chassis_topic, [
this](
const std::shared_ptr<Chassis> &chassis) {
74 FLAGS_control_command_topic,
75 [
this](
const std::shared_ptr<ControlCommand> &cmd) {
on_debug(*cmd); });
78 "/apollo/control/calibration_debug");
80 keyboard_thread_.reset(
82 if (keyboard_thread_ ==
nullptr) {
83 AERROR <<
"Unable to create can client receiver thread.";
88 AERROR <<
"failed to load calibration table";
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();
104 std::string calibration_table_path = FLAGS_calibration_table_debug_file;
107 calibration_table_conf)) {
108 AERROR <<
"Load calibration table failed!";
111 AINFO <<
"Load the calibraiton table file successfully, file path: "
112 << calibration_table_path;
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()));
126 ACHECK(control_interpolation_->Init(xyz))
127 <<
"Fail to load control calibration table";
131 chassis_reader_->Observe();
132 const auto &chassis_msg = chassis_reader_->GetLatestObserved();
133 if (chassis_msg ==
nullptr) {
134 AERROR <<
"Chassis msg is not ready!";
138 double current_speed = 0.0;
140 double input_acc_lookup = 0.0;
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;
150 current_speed = chassis_msg->speed_mps();
152 input_calibration_value =
155 output_calibration_value = control_interpolation_->Interpolate(
156 std::make_pair(std::fabs(current_speed), input_acc_lookup));
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;
170 ADEBUG <<
"Received chassis data: run chassis callback.";
171 std::lock_guard<std::mutex> lock(mutex_);
172 latest_chassis_.CopyFrom(chassis);
179 if (read(kfd_, &c, 1) < 0) {
191 if (keyboard_thread_ !=
nullptr && keyboard_thread_->joinable()) {
192 keyboard_thread_->join();
193 keyboard_thread_.reset();
194 AINFO <<
"keyboard stopped [ok].";
200 std::unique_ptr<std::thread> keyboard_thread_;
201 std::shared_ptr<Reader<Chassis>> chassis_reader_;
202 std::shared_ptr<Reader<ControlCommand>> control_reader_;
203 std::shared_ptr<Writer<CalibrationDebug>> calibration_debug_writer_;
204 std::shared_ptr<Node> node_;
212 std::unique_ptr<Interpolation2D> control_interpolation_;
213 bool is_running_ =
false;
218int main(
int argc,
char **argv) {
220 FLAGS_alsologtostderr =
true;
222 google::ParseCommandLineFlags(&argc, &argv,
true);
224 if (calibration_debug.
init() != 0) {
225 AERROR <<
"Fail to init calibration_debug";
229 calibration_debug.
stop();
int main(int argc, char **argv)
DEFINE_string(calibration_table_debug_file, "/apollo/modules/control/control_component/conf/" "calibration_table.pb.txt", "calibration table file")
linear interpolation from key (double, double) to one double value.
std::vector< std::tuple< double, double, double > > DataType
void on_debug(const control::ControlCommand &cmd)
void KeyboardLoopThreadFunc()
void InitControlCalibrationTable()
VehicleCalibrationDebug()
bool LoadCalibrationTable(calibration_table *calibration_table_conf)
void on_chassis(const Chassis &chassis)
a singleton clock that can be used to get the current timestamp.
Node is the fundamental building block of Cyber RT.
Reader subscribes a channel, it has two main functions:
Some string util functions.
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,...
bool Init(const char *binary_name, const std::string &dag_info)
std::unique_ptr< Node > CreateNode(const std::string &node_name, const std::string &name_space)
optional SimpleLongitudinalDebug simple_lon_debug
optional double calibration_value
optional double acceleration_lookup
repeated ControlCalibrationInfo calibration