17#include "modules/common_msgs/chassis_msgs/chassis.pb.h"
18#include "modules/common_msgs/control_msgs/pad_msg.pb.h"
43 PadTerminal() : node_(
CreateNode(
"pad_terminal")) {}
45 chassis_reader_ = node_->CreateReader<Chassis>(
46 FLAGS_chassis_topic, [
this](
const std::shared_ptr<Chassis> &chassis) {
50 pad_writer_ = node_->CreateWriter<PadMessage>(FLAGS_pad_topic);
51 terminal_thread_.reset(
new std::thread([
this] { terminal_thread_func(); }));
54 AINFO <<
"COMMAND:\n";
55 AINFO <<
"\t0: reset to manual drive mode.";
56 AINFO <<
"\t1: auto drive mode.";
57 AINFO <<
"\tctrl + c: exit.";
58 AINFO <<
"\tother: print help.";
60 void send(
int cmd_type) {
62 if (cmd_type == RESET_COMMAND) {
63 pad.set_action(DrivingAction::RESET);
64 AINFO <<
"sending reset action command.";
65 }
else if (cmd_type == AUTO_DRIVE_COMMAND) {
66 pad.set_action(DrivingAction::START);
67 AINFO <<
"sending start action command.";
69 apollo::common::util::FillHeader(
"terminal", &pad);
70 pad_writer_->Write(pad);
71 AINFO <<
"send pad_message OK";
74 void on_chassis(
const Chassis &chassis) {
75 static bool is_first_emergency_mode =
true;
76 static int64_t count_start = 0;
77 static bool waiting_reset =
false;
81 if (chassis.driving_mode() == Chassis::EMERGENCY_MODE) {
82 if (is_first_emergency_mode) {
84 is_first_emergency_mode =
false;
85 AINFO <<
"detect emergency mode.";
88 if (diff > EMERGENCY_MODE_HOLD_TIME) {
93 AINFO <<
"trigger to reset emergency mode to manual mode.";
98 }
else if (chassis.driving_mode() == Chassis::COMPLETE_MANUAL) {
100 is_first_emergency_mode =
true;
101 waiting_reset =
false;
102 AINFO <<
"emergency mode reset to manual ok.";
107 void terminal_thread_func() {
109 bool should_exit =
false;
110 while (std::cin >> mode) {
116 send(AUTO_DRIVE_COMMAND);
131 void stop() { terminal_thread_->join(); }
134 std::unique_ptr<std::thread> terminal_thread_;
135 const int ROS_QUEUE_SIZE = 1;
136 const int RESET_COMMAND = 1;
137 const int AUTO_DRIVE_COMMAND = 2;
138 const int EMERGENCY_MODE_HOLD_TIME = 4 * 1000000;
139 std::shared_ptr<Reader<Chassis>> chassis_reader_;
140 std::shared_ptr<Writer<PadMessage>> pad_writer_;
141 std::shared_ptr<Node> node_;
145int main(
int argc,
char **argv) {
147 FLAGS_alsologtostderr =
true;
149 google::ParseCommandLineFlags(&argc, &argv,
true);
150 PadTerminal pad_terminal;
a singleton clock that can be used to get the current timestamp.
static Time Now()
PRECISION >= 1000000 means the precision is at least 1us.
Node is the fundamental building block of Cyber RT.
Reader subscribes a channel, it has two main functions:
uint64_t ToNanosecond() const
convert time to nanosecond.
Some string util functions.
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)