43 : monitor_logger_buffer_(common::monitor::MonitorMessageItem::CONTROL) {}
48 return FLAGS_preprocessor_submodule_name;
52 injector_ = std::make_shared<DependencyInjector>();
55 preprocessor_writer_ =
58 ACHECK(preprocessor_writer_ !=
nullptr);
63 ADEBUG <<
"Preprocessor started ....";
68 auto *preprocessor_status =
69 control_preprocessor.mutable_header()->mutable_status();
71 control_preprocessor.mutable_local_view()->CopyFrom(*
local_view);
73 Status status = ProducePreprocessorStatus(&control_preprocessor);
74 AERROR_IF(!status.
ok()) <<
"Failed to produce control preprocessor:"
77 if (status.
ok() && !estop_) {
78 preprocessor_status->set_error_code(ErrorCode::OK);
81 preprocessor_status->set_error_code(status.
code());
85 if (control_preprocessor.
local_view().has_pad_msg()) {
88 AINFO <<
"Control received RESET action!";
90 preprocessor_status->set_error_code(ErrorCode::OK);
91 preprocessor_status->set_msg(
"");
93 control_preprocessor.set_received_pad_msg(
true);
96 control_preprocessor.mutable_header()->set_lidar_timestamp(
98 control_preprocessor.mutable_header()->set_camera_timestamp(
99 local_view->trajectory().header().camera_timestamp());
100 control_preprocessor.mutable_header()->set_radar_timestamp(
101 local_view->trajectory().header().radar_timestamp());
102 common::util::FillHeader(
Name(), &control_preprocessor);
107 FLAGS_control_preprocessor_topic);
111 preprocessor_writer_->Write(control_preprocessor);
112 ADEBUG <<
"Preprocessor finished.";
117Status PreprocessorSubmodule::ProducePreprocessorStatus(
121 Status status = CheckInput(control_preprocessor->mutable_local_view());
126 auto mutable_engage_advice = control_preprocessor->mutable_engage_advice();
127 mutable_engage_advice->set_advice(
134 Status status_ts = CheckTimestamp(control_preprocessor->
local_view());
136 if (!status_ts.ok()) {
137 AERROR <<
"Input messages timeout";
141 control_preprocessor->mutable_engage_advice()->set_advice(
143 control_preprocessor->mutable_engage_advice()->set_reason(
148 control_preprocessor->mutable_engage_advice()->set_advice(
152 FLAGS_enable_persistent_estop
153 ? estop_ || control_preprocessor->
local_view()
161 ErrorCode::CONTROL_ESTOP_ERROR,
163 "estop from planning : ",
167 if (FLAGS_enable_gear_drive_negative_speed_protection) {
168 const double kEpsilon = 0.001;
169 auto first_trajectory_point =
173 first_trajectory_point.v() < -1 * kEpsilon) {
175 ErrorCode::CONTROL_ESTOP_ERROR,
177 "estop for empty planning trajectory, planning headers: ",
181 .ShortDebugString()));
185 auto input_debug = control_preprocessor->mutable_input_debug();
186 input_debug->mutable_localization_header()->CopyFrom(
188 input_debug->mutable_canbus_header()->CopyFrom(
190 input_debug->mutable_trajectory_header()->CopyFrom(
194 latest_replan_trajectory_header_.CopyFrom(
198 if (latest_replan_trajectory_header_.has_sequence_num()) {
199 input_debug->mutable_latest_replan_trajectory_header()->CopyFrom(
200 latest_replan_trajectory_header_);
207 ADEBUG <<
"Received localization:"
208 <<
local_view->localization().ShortDebugString();
211 if (!
local_view->trajectory().estop().is_estop() &&
212 local_view->trajectory().trajectory_point().empty()) {
213 AWARN_EVERY(100) <<
"planning has no trajectory point. ";
214 const std::string msg =
215 absl::StrCat(
"planning has no trajectory point. planning_seq_num: ",
216 local_view->trajectory().header().sequence_num());
217 return Status(ErrorCode::CONTROL_COMPUTE_ERROR, msg);
220 std::lock_guard<std::mutex> lock(mutex_);
221 for (
auto trajectory_point :
local_view->trajectory().trajectory_point()) {
222 if (std::abs(trajectory_point.v()) < FLAGS_minimum_speed_resolution &&
223 std::abs(trajectory_point.a()) <
224 FLAGS_max_acceleration_when_stopped) {
225 trajectory_point.set_v(0.0);
226 trajectory_point.set_a(0.0);
230 injector_->vehicle_state()->Update(
local_view->localization(),
237 if (!FLAGS_enable_input_timestamp_check || FLAGS_is_control_test_mode) {
238 ADEBUG <<
"Skip input timestamp check by gflags.";
243 double localization_diff =
244 current_timestamp -
local_view.localization().header().timestamp_sec();
246 if (localization_diff >
247 (FLAGS_max_localization_miss_num * FLAGS_localization_period)) {
248 AERROR <<
"Localization msg lost for " << std::setprecision(6)
249 << localization_diff <<
"s";
250 monitor_logger_buffer_.ERROR(
"Localization msg lost");
251 return Status(ErrorCode::CONTROL_COMPUTE_ERROR,
"Localization msg timeout");
254 double chassis_diff =
255 current_timestamp -
local_view.chassis().header().timestamp_sec();
257 if (chassis_diff > (FLAGS_max_chassis_miss_num * FLAGS_chassis_period)) {
258 AERROR <<
"Chassis msg lost for " << std::setprecision(6) << chassis_diff
260 monitor_logger_buffer_.ERROR(
"Chassis msg lost");
261 return Status(ErrorCode::CONTROL_COMPUTE_ERROR,
"Chassis msg timeout");
264 double trajectory_diff =
265 current_timestamp -
local_view.trajectory().header().timestamp_sec();
267 if (trajectory_diff >
268 (FLAGS_max_planning_miss_num * FLAGS_trajectory_period)) {
269 AERROR <<
"Trajectory msg lost for " << std::setprecision(6)
270 << trajectory_diff <<
"s";
271 monitor_logger_buffer_.ERROR(
"Trajectory msg lost");
272 return Status(ErrorCode::CONTROL_COMPUTE_ERROR,
"Trajectory msg timeout");
void AppendLatencyRecord(const uint64_t message_id, const apollo::cyber::Time &begin_time, const apollo::cyber::Time &end_time)
A general class to denote the return status of an API call.
bool ok() const
check whether the return status is OK.
ErrorCode code() const
get the error code
const std::string & error_message() const
returns the error message of the status, empty if the status is OK.
static Status OK()
generate a success status.
The class of vehicle state.
std::string Name() const
Get name of the node
bool Init() override
Initialize the submodule
PreprocessorSubmodule()
Construct a new Preprocessor Submodule object
bool Proc(const std::shared_ptr< LocalView > &local_view) override
~PreprocessorSubmodule()
Destructor
a singleton clock that can be used to get the current timestamp.
static double NowInSeconds()
gets the current time in second.
static Time Now()
PRECISION >= 1000000 means the precision is at least 1us.
std::shared_ptr< Node > node_
#define AERROR_EVERY(freq)
#define AWARN_EVERY(freq)
optional GearPosition gear_location
optional apollo::common::Header header
optional DrivingMode driving_mode
optional apollo::planning::ADCTrajectory trajectory
optional PadMessage pad_msg
optional apollo::canbus::Chassis chassis
optional apollo::localization::LocalizationEstimate localization
optional LocalView local_view
optional apollo::common::Header header
optional apollo::common::Header header
repeated apollo::common::TrajectoryPoint trajectory_point
optional apollo::common::Header header
LocalView contains all necessary data as planning input