Apollo 10.0
自动驾驶开放平台
postprocessor_submodule.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2019 The Apollo Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
16
22
23#include <string>
24
25#include "cyber/time/clock.h"
29
30namespace apollo {
31namespace control {
32
37
38std::string PostprocessorSubmodule::Name() const {
39 return FLAGS_postprocessor_submodule_name;
40}
41
43 postprocessor_writer_ =
44 node_->CreateWriter<ControlCommand>(FLAGS_control_command_topic);
45 ACHECK(postprocessor_writer_ != nullptr);
46 return true;
47}
48
50 const std::shared_ptr<ControlCommand>& control_core_command) {
51 const auto start_time = Clock::Instance()->Now();
52 ControlCommand control_command;
53 // get all fields from control_core_command for now
54 control_command = *control_core_command;
55
56 // estop handling
57 if (control_core_command->header().status().error_code() != ErrorCode::OK) {
58 AWARN_EVERY(100) << "Estop triggered! No control core method executed!";
59 control_command.set_speed(0);
60 control_command.set_throttle(0);
61 control_command.set_brake(FLAGS_soft_estop_brake);
62 control_command.set_gear_location(Chassis::GEAR_DRIVE);
63 }
64
65 // set header
66 control_command.mutable_header()->set_lidar_timestamp(
67 control_core_command->header().lidar_timestamp());
68 control_command.mutable_header()->set_camera_timestamp(
69 control_core_command->header().camera_timestamp());
70 control_command.mutable_header()->set_radar_timestamp(
71 control_core_command->header().radar_timestamp());
72
73 common::util::FillHeader(Name(), &control_command);
74 const auto end_time = Clock::Instance()->Now();
75
76 // measure latency
77 static apollo::common::LatencyRecorder latency_recorder(
78 FLAGS_control_command_topic);
79 latency_recorder.AppendLatencyRecord(
80 control_command.header().lidar_timestamp(), start_time, end_time);
81
82 postprocessor_writer_->Write(control_command);
83
84 return true;
85}
86
87} // namespace control
88} // namespace apollo
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.
Definition status.h:43
bool Proc(const std::shared_ptr< ControlCommand > &control_command) override
bool Init() override
Initialize the submodule
std::string Name() const
Get name of the node
a singleton clock that can be used to get the current timestamp.
Definition clock.h:39
std::shared_ptr< Node > node_
#define ACHECK(cond)
Definition log.h:80
#define AWARN_EVERY(freq)
Definition log.h:84
class register implement
Definition arena_queue.h:37
optional uint64 lidar_timestamp
Definition header.proto:19
optional apollo::common::Header header