Apollo 10.0
自动驾驶开放平台
convert_apollo_quadruple.h
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2024 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
17#ifndef CYBER_APOLLO_ROS_SINGLE_H_
18#define CYBER_APOLLO_ROS_SINGLE_H_
19
20#include <memory>
21#include <string>
22#include <utility>
23
25
26#include "cyber/cyber.h"
29
30namespace apollo {
31namespace cyber {
32
33template <typename InType0, typename InType1, typename InType2,
34 typename InType3, typename OutType0>
36 InputTypes<std::shared_ptr<InType0>, std::shared_ptr<InType1>,
37 std::shared_ptr<InType2>, std::shared_ptr<InType3>>,
38 OutputTypes<std::shared_ptr<OutType0>>> : public MessageConverter {
39 public:
42
43 bool Init() {
45 if (!init_.load()) {
46 return false;
47 }
49 return false;
50 }
51
52 apollo::cyber::ReaderConfig reader_cfg_0;
54
55 apollo::cyber::ReaderConfig reader_cfg_1;
57 auto apollo_reader_1 =
58 cyber_node_->template CreateReader<InType1>(reader_cfg_1);
59
60 apollo::cyber::ReaderConfig reader_cfg_2;
62 auto apollo_reader_2 =
63 cyber_node_->template CreateReader<InType2>(reader_cfg_2);
64
65 apollo::cyber::ReaderConfig reader_cfg_3;
67 auto apollo_reader_3 =
68 cyber_node_->template CreateReader<InType3>(reader_cfg_3);
69
70 std::string ros_topic_name_0 = converter_conf_.ros_topic_name_0();
71
72 auto apollo_blocker_1 =
73 blocker::BlockerManager::Instance()->GetBlocker<InType1>(
74 reader_cfg_1.channel_name);
75 auto apollo_blocker_2 =
76 blocker::BlockerManager::Instance()->GetBlocker<InType2>(
77 reader_cfg_2.channel_name);
78 auto apollo_blocker_3 =
79 blocker::BlockerManager::Instance()->GetBlocker<InType3>(
80 reader_cfg_3.channel_name);
81#ifdef RCLCPP__RCLCPP_HPP_
82 auto ros_publisher_0 =
83 ros_node_->create_publisher<OutType0>(ros_topic_name_0, 10);
84 ros_publishers_.push_back(std::move(ros_publisher_0));
85 auto func = [this, ros_publisher_0, apollo_blocker_1, apollo_blocker_2,
86 apollo_blocker_3](const std::shared_ptr<InType0> in) {
87#else
88 auto func = [this, apollo_blocker_1, apollo_blocker_2,
89 apollo_blocker_3](const std::shared_ptr<InType0> in) {
90#endif
91 auto out = std::make_shared<OutType0>();
92 if (!apollo_blocker_1->IsPublishedEmpty() &&
93 !apollo_blocker_2->IsPublishedEmpty() &&
94 !apollo_blocker_3->IsPublishedEmpty()) {
95 auto msg1 = apollo_blocker_1->GetLatestPublishedPtr();
96 auto msg2 = apollo_blocker_2->GetLatestPublishedPtr();
97 auto msg3 = apollo_blocker_3->GetLatestPublishedPtr();
98 auto in_container =
99 InputTypes<std::shared_ptr<InType0>, std::shared_ptr<InType1>,
100 std::shared_ptr<InType2>, std::shared_ptr<InType3>>{
101 std::make_tuple(in, msg1, msg2, msg3)};
102 auto out_container =
103 OutputTypes<std::shared_ptr<OutType0>>{std::make_tuple(out)};
104 this->ConvertMsg(in_container, out_container);
105#ifdef RCLCPP__RCLCPP_HPP_
106 ros_publisher_0->publish(*out);
107#endif
108 }
109 };
110 auto apollo_reader_0 =
111 cyber_node_->template CreateReader<InType0>(reader_cfg_0, func);
112 apollo_readers_.push_back(std::move(apollo_reader_0));
113 apollo_readers_.push_back(std::move(apollo_reader_1));
114 apollo_readers_.push_back(std::move(apollo_reader_2));
115 apollo_readers_.push_back(std::move(apollo_reader_3));
116
117 return true;
118 }
119
120 protected:
121 virtual bool ConvertMsg(
122 InputTypes<std::shared_ptr<InType0>, std::shared_ptr<InType1>,
123 std::shared_ptr<InType2>, std::shared_ptr<InType3>>& input,
124 OutputTypes<std::shared_ptr<OutType0>>& output) = 0;
125}; // NOLINT
126
127// template <typename InType0, typename InType1, typename InType2,
128// typename InType3, typename OutType0>
129// bool ApolloRosMessageConverter<InputTypes<
130// std::shared_ptr<InType0>,
131// std::shared_ptr<InType1>,
132// std::shared_ptr<InType2>,
133// std::shared_ptr<InType3>>,
134// OutputTypes<std::shared_ptr<OutType0>>>::Init()
135
136template <typename InType0, typename InType1, typename InType2,
137 typename InType3, typename OutType0, typename OutType1>
139 InputTypes<std::shared_ptr<InType0>, std::shared_ptr<InType1>,
140 std::shared_ptr<InType2>, std::shared_ptr<InType3>>,
141 OutputTypes<std::shared_ptr<OutType0>, std::shared_ptr<OutType1>>>
142 : public MessageConverter {
143 public:
146
147 bool Init() override;
148
149 protected:
150 virtual bool ConvertMsg(
151 InputTypes<std::shared_ptr<InType0>, std::shared_ptr<InType1>,
152 std::shared_ptr<InType2>, std::shared_ptr<InType3>>& input,
153 OutputTypes<std::shared_ptr<OutType0>, std::shared_ptr<OutType1>>&
154 output) = 0;
155};
156
157template <typename InType0, typename InType1, typename InType2,
158 typename InType3, typename OutType0, typename OutType1>
160 InputTypes<std::shared_ptr<InType0>, std::shared_ptr<InType1>,
161 std::shared_ptr<InType2>, std::shared_ptr<InType3>>,
162 OutputTypes<std::shared_ptr<OutType0>, std::shared_ptr<OutType1>>>::Init() {
164 if (!init_.load()) {
165 return false;
166 }
168 return false;
169 }
170
171 apollo::cyber::ReaderConfig reader_cfg_0;
173
174 apollo::cyber::ReaderConfig reader_cfg_1;
176 auto apollo_reader_1 =
177 cyber_node_->template CreateReader<InType1>(reader_cfg_1);
178
179 apollo::cyber::ReaderConfig reader_cfg_2;
181 auto apollo_reader_2 =
182 cyber_node_->template CreateReader<InType2>(reader_cfg_2);
183
184 apollo::cyber::ReaderConfig reader_cfg_3;
186 auto apollo_reader_3 =
187 cyber_node_->template CreateReader<InType3>(reader_cfg_3);
188
189 std::string ros_topic_name_0 = converter_conf_.ros_topic_name_0();
190 std::string ros_topic_name_1 = converter_conf_.ros_topic_name_1();
191
192 auto apollo_blocker_1 =
193 blocker::BlockerManager::Instance()->GetBlocker<InType1>(
194 reader_cfg_1.channel_name);
195 auto apollo_blocker_2 =
196 blocker::BlockerManager::Instance()->GetBlocker<InType2>(
197 reader_cfg_2.channel_name);
198 auto apollo_blocker_3 =
199 blocker::BlockerManager::Instance()->GetBlocker<InType3>(
200 reader_cfg_3.channel_name);
201
202#ifdef RCLCPP__RCLCPP_HPP_
203 auto ros_publisher_0 =
204 ros_node_->create_publisher<OutType0>(ros_topic_name_0, 10);
205 auto ros_publisher_1 =
206 ros_node_->create_publisher<OutType1>(ros_topic_name_1, 10);
207 ros_publishers_.push_back(std::move(ros_publisher_0));
208 ros_publishers_.push_back(std::move(ros_publisher_1));
209 auto func = [this, apollo_blocker_1, apollo_blocker_2, apollo_blocker_3,
210 ros_publisher_0,
211 ros_publisher_1](const std::shared_ptr<InType0> in) {
212#else
213 auto func = [this, apollo_blocker_1, apollo_blocker_2,
214 apollo_blocker_3](const std::shared_ptr<InType0> in) {
215#endif
216 if (!apollo_blocker_1->IsPublishedEmpty() &&
217 !apollo_blocker_2->IsPublishedEmpty() &&
218 !apollo_blocker_3->IsPublishedEmpty()) {
219 auto msg1 = apollo_blocker_1->GetLatestPublishedPtr();
220 auto msg2 = apollo_blocker_2->GetLatestPublishedPtr();
221 auto msg3 = apollo_blocker_3->GetLatestPublishedPtr();
222 auto out_0 = std::make_shared<OutType0>();
223 auto out_1 = std::make_shared<OutType1>();
224 auto in_container =
225 InputTypes<std::shared_ptr<InType0>, std::shared_ptr<InType1>,
226 std::shared_ptr<InType2>, std::shared_ptr<InType3>>{
227 std::make_tuple(in, msg1, msg2, msg3)};
228 auto out_container =
229 OutputTypes<std::shared_ptr<OutType0>, std::shared_ptr<OutType1>>{
230 std::make_tuple(out_0, out_1)};
231 this->ConvertMsg(in_container, out_container);
232#ifdef RCLCPP__RCLCPP_HPP_
233 ros_publisher_0->publish(*out_0);
234 ros_publisher_1->publish(*out_1);
235#endif
236 }
237 };
238 auto apollo_reader_0 =
239 cyber_node_->template CreateReader<InType0>(reader_cfg_0, func);
240 apollo_readers_.push_back(std::move(apollo_reader_0));
241 apollo_readers_.push_back(std::move(apollo_reader_1));
242 apollo_readers_.push_back(std::move(apollo_reader_2));
243 apollo_readers_.push_back(std::move(apollo_reader_3));
244
245 return true;
246}
247
248template <typename InType0, typename InType1, typename InType2,
249 typename InType3, typename OutType0, typename OutType1,
250 typename OutType2>
252 InputTypes<std::shared_ptr<InType0>, std::shared_ptr<InType1>,
253 std::shared_ptr<InType2>, std::shared_ptr<InType3>>,
254 OutputTypes<std::shared_ptr<OutType0>, std::shared_ptr<OutType1>,
255 std::shared_ptr<OutType2>>> : public MessageConverter {
256 public:
259
260 bool Init() override;
261
262 protected:
263 virtual bool ConvertMsg(
264 InputTypes<std::shared_ptr<InType0>, std::shared_ptr<InType1>,
265 std::shared_ptr<InType2>, std::shared_ptr<InType3>>& input,
266 OutputTypes<std::shared_ptr<OutType0>, std::shared_ptr<OutType1>,
267 std::shared_ptr<OutType2>>& output) = 0;
268};
269
270template <typename InType0, typename InType1, typename InType2,
271 typename InType3, typename OutType0, typename OutType1,
272 typename OutType2>
274 InputTypes<std::shared_ptr<InType0>, std::shared_ptr<InType1>,
275 std::shared_ptr<InType2>, std::shared_ptr<InType3>>,
276 OutputTypes<std::shared_ptr<OutType0>, std::shared_ptr<OutType1>,
277 std::shared_ptr<OutType2>>>::Init() {
279 if (!init_.load()) {
280 return false;
281 }
283 return false;
284 }
285
286 apollo::cyber::ReaderConfig reader_cfg_0;
288
289 apollo::cyber::ReaderConfig reader_cfg_1;
291 auto apollo_reader_1 =
292 cyber_node_->template CreateReader<InType1>(reader_cfg_1);
293
294 apollo::cyber::ReaderConfig reader_cfg_2;
296 auto apollo_reader_2 =
297 cyber_node_->template CreateReader<InType2>(reader_cfg_2);
298
299 apollo::cyber::ReaderConfig reader_cfg_3;
301 auto apollo_reader_3 =
302 cyber_node_->template CreateReader<InType3>(reader_cfg_3);
303
304 auto apollo_blocker_1 =
305 blocker::BlockerManager::Instance()->GetBlocker<InType1>(
306 reader_cfg_1.channel_name);
307 auto apollo_blocker_2 =
308 blocker::BlockerManager::Instance()->GetBlocker<InType2>(
309 reader_cfg_2.channel_name);
310 auto apollo_blocker_3 =
311 blocker::BlockerManager::Instance()->GetBlocker<InType3>(
312 reader_cfg_3.channel_name);
313
314 std::string ros_topic_name_0 = converter_conf_.ros_topic_name_0();
315 std::string ros_topic_name_1 = converter_conf_.ros_topic_name_1();
316 std::string ros_topic_name_2 = converter_conf_.ros_topic_name_2();
317
318#ifdef RCLCPP__RCLCPP_HPP_
319 auto ros_publisher_0 =
320 ros_node_->create_publisher<OutType0>(ros_topic_name_0, 10);
321 auto ros_publisher_1 =
322 ros_node_->create_publisher<OutType1>(ros_topic_name_1, 10);
323 auto ros_publisher_2 =
324 ros_node_->create_publisher<OutType2>(ros_topic_name_2, 10);
325 ros_publishers_.push_back(std::move(ros_publisher_0));
326 ros_publishers_.push_back(std::move(ros_publisher_1));
327 ros_publishers_.push_back(std::move(ros_publisher_2));
328 auto func = [this, apollo_blocker_1, apollo_blocker_2, apollo_blocker_3,
329 ros_publisher_0, ros_publisher_1,
330 ros_publisher_2](const std::shared_ptr<InType0> in) {
331#else
332 auto func = [this, apollo_blocker_1, apollo_blocker_2,
333 apollo_blocker_3](const std::shared_ptr<InType0> in) {
334#endif
335 if (!apollo_blocker_1->IsPublishedEmpty() &&
336 !apollo_blocker_1->IsPublishedEmpty() &&
337 !apollo_blocker_1->IsPublishedEmpty()) {
338 auto msg1 = apollo_blocker_1->GetLatestPublishedPtr();
339 auto msg2 = apollo_blocker_2->GetLatestPublishedPtr();
340 auto msg3 = apollo_blocker_3->GetLatestPublishedPtr();
341 auto out_0 = std::make_shared<OutType0>();
342 auto out_1 = std::make_shared<OutType1>();
343 auto out_2 = std::make_shared<OutType2>();
344 auto in_container =
345 InputTypes<std::shared_ptr<InType0>, std::shared_ptr<InType1>,
346 std::shared_ptr<InType2>, std::shared_ptr<InType3>>{
347 std::make_tuple(in, msg1, msg2, msg3)};
348 auto out_container =
349 OutputTypes<std::shared_ptr<OutType0>, std::shared_ptr<OutType1>,
350 std::shared_ptr<OutType2>>{
351 std::make_tuple(out_0, out_1, out_2)};
352 this->ConvertMsg(in_container, out_container);
353#ifdef RCLCPP__RCLCPP_HPP_
354 ros_publisher_0->publish(*out_0);
355 ros_publisher_1->publish(*out_1);
356 ros_publisher_2->publish(*out_2);
357#endif
358 }
359 };
360 auto apollo_reader_0 =
361 cyber_node_->template CreateReader<InType0>(reader_cfg_0, func);
362 apollo_readers_.push_back(std::move(apollo_reader_0));
363 apollo_readers_.push_back(std::move(apollo_reader_1));
364 apollo_readers_.push_back(std::move(apollo_reader_2));
365 apollo_readers_.push_back(std::move(apollo_reader_3));
366
367 return true;
368}
369
370template <typename InType0, typename InType1, typename InType2,
371 typename InType3, typename OutType0, typename OutType1,
372 typename OutType2, typename OutType3>
374 InputTypes<std::shared_ptr<InType0>, std::shared_ptr<InType1>,
375 std::shared_ptr<InType2>, std::shared_ptr<InType3>>,
376 OutputTypes<std::shared_ptr<OutType0>, std::shared_ptr<OutType1>,
377 std::shared_ptr<OutType2>, std::shared_ptr<OutType3>>>
378 : public MessageConverter {
379 public:
382
383 bool Init() override;
384
385 protected:
386 virtual bool ConvertMsg(
387 InputTypes<std::shared_ptr<InType0>, std::shared_ptr<InType1>,
388 std::shared_ptr<InType2>, std::shared_ptr<InType3>>& input,
389 OutputTypes<std::shared_ptr<OutType0>, std::shared_ptr<OutType1>,
390 std::shared_ptr<OutType2>, std::shared_ptr<OutType3>>&
391 output) = 0;
392};
393
394template <typename InType0, typename InType1, typename InType2,
395 typename InType3, typename OutType0, typename OutType1,
396 typename OutType2, typename OutType3>
398 InputTypes<std::shared_ptr<InType0>, std::shared_ptr<InType1>,
399 std::shared_ptr<InType2>, std::shared_ptr<InType3>>,
400 OutputTypes<std::shared_ptr<OutType0>, std::shared_ptr<OutType1>,
401 std::shared_ptr<OutType2>, std::shared_ptr<OutType3>>>::Init() {
403 if (!init_.load()) {
404 return false;
405 }
407 return false;
408 }
409
410 apollo::cyber::ReaderConfig reader_cfg_0;
412
413 apollo::cyber::ReaderConfig reader_cfg_1;
415 auto apollo_reader_1 =
416 cyber_node_->template CreateReader<InType1>(reader_cfg_1);
417
418 apollo::cyber::ReaderConfig reader_cfg_2;
420 auto apollo_reader_2 =
421 cyber_node_->template CreateReader<InType2>(reader_cfg_2);
422
423 apollo::cyber::ReaderConfig reader_cfg_3;
425 auto apollo_reader_3 =
426 cyber_node_->template CreateReader<InType3>(reader_cfg_3);
427
428 auto apollo_blocker_1 =
429 blocker::BlockerManager::Instance()->GetBlocker<InType1>(
430 reader_cfg_1.channel_name);
431 auto apollo_blocker_2 =
432 blocker::BlockerManager::Instance()->GetBlocker<InType2>(
433 reader_cfg_2.channel_name);
434 auto apollo_blocker_3 =
435 blocker::BlockerManager::Instance()->GetBlocker<InType3>(
436 reader_cfg_3.channel_name);
437
438 std::string ros_topic_name_0 = converter_conf_.ros_topic_name_0();
439 std::string ros_topic_name_1 = converter_conf_.ros_topic_name_1();
440 std::string ros_topic_name_2 = converter_conf_.ros_topic_name_2();
441 std::string ros_topic_name_3 = converter_conf_.ros_topic_name_3();
442
443#ifdef RCLCPP__RCLCPP_HPP_
444 auto ros_publisher_0 =
445 ros_node_->create_publisher<OutType0>(ros_topic_name_0, 10);
446 auto ros_publisher_1 =
447 ros_node_->create_publisher<OutType1>(ros_topic_name_1, 10);
448 auto ros_publisher_2 =
449 ros_node_->create_publisher<OutType2>(ros_topic_name_2, 10);
450 auto ros_publisher_3 =
451 ros_node_->create_publisher<OutType2>(ros_topic_name_3, 10);
452 ros_publishers_.push_back(std::move(ros_publisher_0));
453 ros_publishers_.push_back(std::move(ros_publisher_1));
454 ros_publishers_.push_back(std::move(ros_publisher_2));
455 ros_publishers_.push_back(std::move(ros_publisher_3));
456 auto func = [this, apollo_blocker_1, apollo_blocker_2, apollo_blocker_3,
457 ros_publisher_0, ros_publisher_1, ros_publisher_2,
458 ros_publisher_3](const std::shared_ptr<InType0> in) {
459#else
460 auto func = [this, apollo_blocker_1, apollo_blocker_2,
461 apollo_blocker_3](const std::shared_ptr<InType0> in) {
462#endif
463 if (!apollo_blocker_1->IsPublishedEmpty() &&
464 !apollo_blocker_2->IsPublishedEmpty() &&
465 !apollo_blocker_3->IsPublishedEmpty()) {
466 auto msg1 = apollo_blocker_1->GetLatestPublishedPtr();
467 auto msg2 = apollo_blocker_2->GetLatestPublishedPtr();
468 auto msg3 = apollo_blocker_3->GetLatestPublishedPtr();
469 auto out_0 = std::make_shared<OutType0>();
470 auto out_1 = std::make_shared<OutType1>();
471 auto out_2 = std::make_shared<OutType2>();
472 auto out_3 = std::make_shared<OutType3>();
473 auto in_container =
474 InputTypes<std::shared_ptr<InType0>, std::shared_ptr<InType1>,
475 std::shared_ptr<InType2>, std::shared_ptr<InType3>>{
476 std::make_tuple(in, msg1, msg2, msg3)};
477 auto out_container =
478 OutputTypes<std::shared_ptr<OutType0>, std::shared_ptr<OutType1>,
479 std::shared_ptr<OutType2>, std::shared_ptr<OutType3>>{
480 std::make_tuple(out_0, out_1, out_2, out_3)};
481 this->ConvertMsg(in_container, out_container);
482#ifdef RCLCPP__RCLCPP_HPP_
483 ros_publisher_0->publish(*out_0);
484 ros_publisher_1->publish(*out_1);
485 ros_publisher_2->publish(*out_2);
486 ros_publisher_3->publish(*out_2);
487#endif
488 }
489 };
490 auto apollo_reader_0 =
491 cyber_node_->template CreateReader<InType0>(reader_cfg_0, func);
492 apollo_readers_.push_back(std::move(apollo_reader_0));
493 apollo_readers_.push_back(std::move(apollo_reader_1));
494 apollo_readers_.push_back(std::move(apollo_reader_2));
495 apollo_readers_.push_back(std::move(apollo_reader_3));
496
497 return true;
498}
499
500} // namespace cyber
501} // namespace apollo
502
503#endif // CYBER_APOLLO_ROS_MESSAGE_CONVERTER_H_
virtual bool ConvertMsg(InputTypes< std::shared_ptr< InType0 >, std::shared_ptr< InType1 >, std::shared_ptr< InType2 >, std::shared_ptr< InType3 > > &input, OutputTypes< std::shared_ptr< OutType0 >, std::shared_ptr< OutType1 > > &output)=0
virtual bool ConvertMsg(InputTypes< std::shared_ptr< InType0 >, std::shared_ptr< InType1 >, std::shared_ptr< InType2 >, std::shared_ptr< InType3 > > &input, OutputTypes< std::shared_ptr< OutType0 >, std::shared_ptr< OutType1 >, std::shared_ptr< OutType2 > > &output)=0
virtual bool ConvertMsg(InputTypes< std::shared_ptr< InType0 >, std::shared_ptr< InType1 >, std::shared_ptr< InType2 >, std::shared_ptr< InType3 > > &input, OutputTypes< std::shared_ptr< OutType0 > > &output)=0
virtual bool ConvertMsg(InputTypes< std::shared_ptr< InType0 >, std::shared_ptr< InType1 >, std::shared_ptr< InType2 >, std::shared_ptr< InType3 > > &input, OutputTypes< std::shared_ptr< OutType0 >, std::shared_ptr< OutType1 >, std::shared_ptr< OutType2 >, std::shared_ptr< OutType3 > > &output)=0
virtual bool ConvertMsg(InputTypes &input, OutputTypes &output)=0
std::unique_ptr< apollo::cyber::Node > cyber_node_
std::vector< std::shared_ptr< apollo::cyber::ReaderBase > > apollo_readers_
bool LoadConfig(ConverterConf *config)
static const std::shared_ptr< BlockerManager > & Instance()
class register implement
Definition arena_queue.h:37
Definition future.h:29