29 "UNKOWN",
"ROD",
"FENCE",
"ADVERTISING",
"TELESCOPIC",
"OTHER"
35 AERROR <<
"Get BarrierRecognitionComponent file failed";
38 AINFO <<
"BarrierRecognitionComponent Component Configs: " << barrier_comp_config.DebugString();
40 tf2_frame_id_ = barrier_comp_config.
frame_id();
45 barrier_bank_init_options.
config_path = recognizer_param.config_path();
46 barrier_bank_init_options.
config_file = recognizer_param.config_file();
47 ACHECK(barrier_bank_.
Init(barrier_bank_init_options));
51 status_tracker_init_options.
config_path = tracker_param.config_path();
52 status_tracker_init_options.
config_file = tracker_param.config_file();
53 ACHECK(status_tracker_.
Init(status_tracker_init_options));
56 hd_map_ = map::HDMapInput::Instance();
57 if (hd_map_ ==
nullptr) {
58 AERROR <<
"BarrierRecognitionComponent get hdmap failed.";
62 if (!hd_map_->
Init()) {
63 AERROR <<
"BarrierRecognitionComponent init hd-map failed.";
66 AINFO <<
"Successfully init barrier recognition component.";
77 std::vector<BarrieGate> gates;
78 bool status = InternalProc(message, gates);
80 std::shared_ptr<PerceptionBarrierGate> out_message(
new (std::nothrow)
82 if (!MakeProtobufMsg(message->timestamp_, seq_num_, gates,
84 AERROR <<
"MakeProtobufMsg failed ts: " << message->timestamp_;
88 writer_->Write(out_message);
89 AINFO <<
"Send peception barrier gate message.";
94bool BarrierRecognitionComponent::InternalProc(
95 const std::shared_ptr<LidarFrameMessage>& message,
96 std::vector<BarrieGate>& gates) {
97 const double timestamp = message->timestamp_;
98 auto frame = message->lidar_frame_.get();
100 std::vector<apollo::hdmap::BarrierGate> hdmap_gates;
102 QueryPoseAndGates(timestamp, frame->lidar2world_pose, &hdmap_gates);
105 for (auto& hdmap_gate : hdmap_gates) {
106 std::vector<double> world_polygon;
107 GetGatesPolygon(hdmap_gate, world_polygon);
109 detector_options.
name =
"StraightPoleRecognizer";
112 float open_percent = 0.;
113 if (!barrier_bank_.
Recognize(detector_options, frame, open_percent)) {
114 AINFO <<
"barrier recognize error.";
118 if (!status_tracker_.
Track(timestamp, open_percent, status_id)) {
119 AINFO <<
"barrier track error.";
123 BarrieGate obj = {status_id, hdmap_gate.id().id(),
126 gates.emplace_back(obj);
133bool BarrierRecognitionComponent::QueryPoseAndGates(
134 const double ts,
const Eigen::Affine3d& pose,
135 std::vector<apollo::hdmap::BarrierGate>* gates) {
137 AERROR <<
"hd_map_ not init.";
142 Eigen::Vector3d global_tranlation = pose.translation();
144 forward_distance_to_queries_,
146 if (ts - last_gates_ts_ < valid_hdmap_interval_) {
147 *gates = last_gates_;
148 AWARN <<
"query pose and gates failed to get gates info. "
149 <<
"Now use last info. ts:" << ts
150 <<
" pose:" << global_tranlation
151 <<
" gates.size(): " << gates->size();
153 AERROR <<
"query pose and gates failed to get gates info. "
154 <<
"ts:" << ts <<
" pose:" << global_tranlation;
158 AINFO <<
"query pose and gates succeeded, gates.size(): "
161 last_gates_ = *gates;
166void BarrierRecognitionComponent::GetGatesPolygon(
168 std::vector<double>& world_polygon) {
169 world_polygon.clear();
170 for (
int i = 0; i < barrier_gate.
polygon().point_size(); i+=2) {
171 world_polygon.push_back(barrier_gate.
polygon().
point(i).
x());
172 world_polygon.push_back(barrier_gate.
polygon().
point(i).
y());
176bool BarrierRecognitionComponent::MakeProtobufMsg(
177 double msg_timestamp,
int seq_num,
178 std::vector<BarrieGate> gates,
179 PerceptionBarrierGate *msg) {
181 auto header = msg->mutable_header();
182 header->set_timestamp_sec(publish_time);
183 header->set_module_name(
"perception_lidar");
184 header->set_sequence_num(seq_num);
187 header->set_lidar_timestamp(
static_cast<uint64_t
>(msg_timestamp * 1e9));
188 header->set_camera_timestamp(
static_cast<uint64_t
>(msg_timestamp * 1e9));
190 for (
const auto &obj : gates) {
193 gate->set_id(obj.id);
194 gate->set_type(obj.type);
195 gate->set_is_useable(
true);
196 gate->set_open_percent(obj.open_percent);