190 std::shared_ptr<CarlaPublisher> publisher {};
191 std::shared_ptr<CarlaTransformPublisher> transform {};
193 publisher = it_publishers->second;
195 transform = it_transforms->second;
199 const std::string string_id = std::to_string(
id);
204 if (ros_name ==
"collision__") {
207 ros_name += string_id;
210 std::shared_ptr<CarlaCollisionPublisher> new_publisher = std::make_shared<CarlaCollisionPublisher>(ros_name.c_str(), parent_ros_name.c_str());
211 if (new_publisher->Init()) {
213 publisher = new_publisher;
215 std::shared_ptr<CarlaTransformPublisher> new_transform = std::make_shared<CarlaTransformPublisher>(ros_name.c_str(), parent_ros_name.c_str());
216 if (new_transform->Init()) {
218 transform = new_transform;
222 if (ros_name ==
"depth__") {
225 ros_name += string_id;
228 std::shared_ptr<CarlaDepthCameraPublisher> new_publisher = std::make_shared<CarlaDepthCameraPublisher>(ros_name.c_str(), parent_ros_name.c_str());
229 if (new_publisher->Init()) {
231 publisher = new_publisher;
233 std::shared_ptr<CarlaTransformPublisher> new_transform = std::make_shared<CarlaTransformPublisher>(ros_name.c_str(), parent_ros_name.c_str());
234 if (new_transform->Init()) {
236 transform = new_transform;
240 if (ros_name ==
"normals__") {
243 ros_name += string_id;
246 std::shared_ptr<CarlaNormalsCameraPublisher> new_publisher = std::make_shared<CarlaNormalsCameraPublisher>(ros_name.c_str(), parent_ros_name.c_str());
247 if (new_publisher->Init()) {
249 publisher = new_publisher;
251 std::shared_ptr<CarlaTransformPublisher> new_transform = std::make_shared<CarlaTransformPublisher>(ros_name.c_str(), parent_ros_name.c_str());
252 if (new_transform->Init()) {
254 transform = new_transform;
258 if (ros_name ==
"dvs__") {
261 ros_name += string_id;
264 std::shared_ptr<CarlaDVSCameraPublisher> new_publisher = std::make_shared<CarlaDVSCameraPublisher>(ros_name.c_str(), parent_ros_name.c_str());
265 if (new_publisher->Init()) {
267 publisher = new_publisher;
269 std::shared_ptr<CarlaTransformPublisher> new_transform = std::make_shared<CarlaTransformPublisher>(ros_name.c_str(), parent_ros_name.c_str());
270 if (new_transform->Init()) {
272 transform = new_transform;
276 if (ros_name ==
"gnss__") {
279 ros_name += string_id;
282 std::shared_ptr<CarlaGNSSPublisher> new_publisher = std::make_shared<CarlaGNSSPublisher>(ros_name.c_str(), parent_ros_name.c_str());
283 if (new_publisher->Init()) {
285 publisher = new_publisher;
287 std::shared_ptr<CarlaTransformPublisher> new_transform = std::make_shared<CarlaTransformPublisher>(ros_name.c_str(), parent_ros_name.c_str());
288 if (new_transform->Init()) {
290 transform = new_transform;
294 if (ros_name ==
"imu__") {
297 ros_name += string_id;
300 std::shared_ptr<CarlaIMUPublisher> new_publisher = std::make_shared<CarlaIMUPublisher>(ros_name.c_str(), parent_ros_name.c_str());
301 if (new_publisher->Init()) {
303 publisher = new_publisher;
305 std::shared_ptr<CarlaTransformPublisher> new_transform = std::make_shared<CarlaTransformPublisher>(ros_name.c_str(), parent_ros_name.c_str());
306 if (new_transform->Init()) {
308 transform = new_transform;
312 if (ros_name ==
"lane_invasion__") {
315 ros_name += string_id;
318 std::shared_ptr<CarlaLineInvasionPublisher> new_publisher = std::make_shared<CarlaLineInvasionPublisher>(ros_name.c_str(), parent_ros_name.c_str());
319 if (new_publisher->Init()) {
321 publisher = new_publisher;
323 std::shared_ptr<CarlaTransformPublisher> new_transform = std::make_shared<CarlaTransformPublisher>(ros_name.c_str(), parent_ros_name.c_str());
324 if (new_transform->Init()) {
326 transform = new_transform;
330 std::cerr <<
"Obstacle detection sensor does not have an available publisher" << std::endl;
333 if (ros_name ==
"optical_flow__") {
336 ros_name += string_id;
339 std::shared_ptr<CarlaOpticalFlowCameraPublisher> new_publisher = std::make_shared<CarlaOpticalFlowCameraPublisher>(ros_name.c_str(), parent_ros_name.c_str());
340 if (new_publisher->Init()) {
342 publisher = new_publisher;
344 std::shared_ptr<CarlaTransformPublisher> new_transform = std::make_shared<CarlaTransformPublisher>(ros_name.c_str(), parent_ros_name.c_str());
345 if (new_transform->Init()) {
347 transform = new_transform;
351 if (ros_name ==
"radar__") {
354 ros_name += string_id;
357 std::shared_ptr<CarlaRadarPublisher> new_publisher = std::make_shared<CarlaRadarPublisher>(ros_name.c_str(), parent_ros_name.c_str());
358 if (new_publisher->Init()) {
360 publisher = new_publisher;
362 std::shared_ptr<CarlaTransformPublisher> new_transform = std::make_shared<CarlaTransformPublisher>(ros_name.c_str(), parent_ros_name.c_str());
363 if (new_transform->Init()) {
365 transform = new_transform;
369 if (ros_name ==
"ray_cast_semantic__") {
372 ros_name += string_id;
375 std::shared_ptr<CarlaSemanticLidarPublisher> new_publisher = std::make_shared<CarlaSemanticLidarPublisher>(ros_name.c_str(), parent_ros_name.c_str());
376 if (new_publisher->Init()) {
378 publisher = new_publisher;
380 std::shared_ptr<CarlaTransformPublisher> new_transform = std::make_shared<CarlaTransformPublisher>(ros_name.c_str(), parent_ros_name.c_str());
381 if (new_transform->Init()) {
383 transform = new_transform;
387 if (ros_name ==
"ray_cast__") {
390 ros_name += string_id;
393 std::shared_ptr<CarlaLidarPublisher> new_publisher = std::make_shared<CarlaLidarPublisher>(ros_name.c_str(), parent_ros_name.c_str());
394 if (new_publisher->Init()) {
396 publisher = new_publisher;
398 std::shared_ptr<CarlaTransformPublisher> new_transform = std::make_shared<CarlaTransformPublisher>(ros_name.c_str(), parent_ros_name.c_str());
399 if (new_transform->Init()) {
401 transform = new_transform;
405 std::cerr <<
"RSS sensor does not have an available publisher" << std::endl;
408 if (ros_name ==
"rgb__") {
411 ros_name += string_id;
414 std::shared_ptr<CarlaRGBCameraPublisher> new_publisher = std::make_shared<CarlaRGBCameraPublisher>(ros_name.c_str(), parent_ros_name.c_str());
415 if (new_publisher->Init()) {
417 publisher = new_publisher;
419 std::shared_ptr<CarlaTransformPublisher> new_transform = std::make_shared<CarlaTransformPublisher>(ros_name.c_str(), parent_ros_name.c_str());
420 if (new_transform->Init()) {
422 transform = new_transform;
426 if (ros_name ==
"semantic_segmentation__") {
429 ros_name += string_id;
432 std::shared_ptr<CarlaSSCameraPublisher> new_publisher = std::make_shared<CarlaSSCameraPublisher>(ros_name.c_str(), parent_ros_name.c_str());
433 if (new_publisher->Init()) {
435 publisher = new_publisher;
437 std::shared_ptr<CarlaTransformPublisher> new_transform = std::make_shared<CarlaTransformPublisher>(ros_name.c_str(), parent_ros_name.c_str());
438 if (new_transform->Init()) {
440 transform = new_transform;
444 if (ros_name ==
"instance_segmentation__") {
447 ros_name += string_id;
450 std::shared_ptr<CarlaISCameraPublisher> new_publisher = std::make_shared<CarlaISCameraPublisher>(ros_name.c_str(), parent_ros_name.c_str());
451 if (new_publisher->Init()) {
453 publisher = new_publisher;
455 std::shared_ptr<CarlaTransformPublisher> new_transform = std::make_shared<CarlaTransformPublisher>(ros_name.c_str(), parent_ros_name.c_str());
456 if (new_transform->Init()) {
458 transform = new_transform;
462 std::cerr <<
"World obserser does not have an available publisher" << std::endl;
465 std::cerr <<
"Camera GBuffer uint8 does not have an available publisher" << std::endl;
468 std::cerr <<
"Camera GBuffer float does not have an available publisher" << std::endl;
471 std::cerr <<
"Unknown sensor type" << std::endl;
475 return { publisher, transform };
479 uint64_t sensor_type,
482 int W,
int H,
float Fov,
486 switch (sensor_type) {
488 log_info(
"Sensor Collision to ROS data: frame.",
_frame,
"sensor.", sensor_type,
"stream.", stream_id,
"buffer.", buffer->size());
492 log_info(
"Sensor DepthCamera to ROS data: frame.",
_frame,
"sensor.", sensor_type,
"stream.", stream_id,
"buffer.", buffer->size());
495 std::shared_ptr<CarlaDepthCameraPublisher> publisher = std::dynamic_pointer_cast<CarlaDepthCameraPublisher>(sensors.first);
500 if (!publisher->HasBeenInitialized())
501 publisher->InitInfoData(0, 0, H, W, Fov,
true);
504 publisher->Publish();
506 if (sensors.second) {
507 std::shared_ptr<CarlaTransformPublisher> publisher = std::dynamic_pointer_cast<CarlaTransformPublisher>(sensors.second);
509 publisher->Publish();
514 log_info(
"Sensor NormalsCamera to ROS data: frame.",
_frame,
"sensor.", sensor_type,
"stream.", stream_id,
"buffer.", buffer->size());
518 std::shared_ptr<CarlaNormalsCameraPublisher> publisher = std::dynamic_pointer_cast<CarlaNormalsCameraPublisher>(sensors.first);
523 if (!publisher->HasBeenInitialized())
524 publisher->InitInfoData(0, 0, H, W, Fov,
true);
527 publisher->Publish();
529 if (sensors.second) {
530 std::shared_ptr<CarlaTransformPublisher> publisher = std::dynamic_pointer_cast<CarlaTransformPublisher>(sensors.second);
532 publisher->Publish();
537 log_info(
"Sensor LaneInvasionSensor to ROS data: frame.",
_frame,
"sensor.", sensor_type,
"stream.", stream_id,
"buffer.", buffer->size());
541 std::shared_ptr<CarlaLineInvasionPublisher> publisher = std::dynamic_pointer_cast<CarlaLineInvasionPublisher>(sensors.first);
543 publisher->Publish();
545 if (sensors.second) {
546 std::shared_ptr<CarlaTransformPublisher> publisher = std::dynamic_pointer_cast<CarlaTransformPublisher>(sensors.second);
548 publisher->Publish();
553 log_info(
"Sensor OpticalFlowCamera to ROS data: frame.",
_frame,
"sensor.", sensor_type,
"stream.", stream_id,
"buffer.", buffer->size());
557 std::shared_ptr<CarlaOpticalFlowCameraPublisher> publisher = std::dynamic_pointer_cast<CarlaOpticalFlowCameraPublisher>(sensors.first);
562 if (!publisher->HasBeenInitialized())
563 publisher->InitInfoData(0, 0, H, W, Fov,
true);
566 publisher->Publish();
568 if (sensors.second) {
569 std::shared_ptr<CarlaTransformPublisher> publisher = std::dynamic_pointer_cast<CarlaTransformPublisher>(sensors.second);
571 publisher->Publish();
576 log_info(
"Sensor RssSensor to ROS data: frame.",
_frame,
"sensor.", sensor_type,
"stream.", stream_id,
"buffer.", buffer->size());
580 log_info(
"Sensor SceneCaptureCamera to ROS data: frame.",
_frame,
"sensor.", sensor_type,
"stream.", stream_id,
"buffer.", buffer->size());
584 std::shared_ptr<CarlaRGBCameraPublisher> publisher = std::dynamic_pointer_cast<CarlaRGBCameraPublisher>(sensors.first);
589 if (!publisher->HasBeenInitialized())
590 publisher->InitInfoData(0, 0, H, W, Fov,
true);
593 publisher->Publish();
595 if (sensors.second) {
596 std::shared_ptr<CarlaTransformPublisher> publisher = std::dynamic_pointer_cast<CarlaTransformPublisher>(sensors.second);
598 publisher->Publish();
604 log_info(
"Sensor SemanticSegmentationCamera to ROS data: frame.",
_frame,
"sensor.", sensor_type,
"stream.", stream_id,
"buffer.", buffer->size());
608 std::shared_ptr<CarlaSSCameraPublisher> publisher = std::dynamic_pointer_cast<CarlaSSCameraPublisher>(sensors.first);
613 if (!publisher->HasBeenInitialized())
614 publisher->InitInfoData(0, 0, H, W, Fov,
true);
617 publisher->Publish();
619 if (sensors.second) {
620 std::shared_ptr<CarlaTransformPublisher> publisher = std::dynamic_pointer_cast<CarlaTransformPublisher>(sensors.second);
622 publisher->Publish();
627 log_info(
"Sensor InstanceSegmentationCamera to ROS data: frame.",
_frame,
"sensor.", sensor_type,
"stream.", stream_id,
"buffer.", buffer->size());
631 std::shared_ptr<CarlaISCameraPublisher> publisher = std::dynamic_pointer_cast<CarlaISCameraPublisher>(sensors.first);
636 if (!publisher->HasBeenInitialized())
637 publisher->InitInfoData(0, 0, H, W, Fov,
true);
640 publisher->Publish();
642 if (sensors.second) {
643 std::shared_ptr<CarlaTransformPublisher> publisher = std::dynamic_pointer_cast<CarlaTransformPublisher>(sensors.second);
645 publisher->Publish();
650 log_info(
"Sensor WorldObserver to ROS data: frame.",
_frame,
"sensor.", sensor_type,
"stream.", stream_id,
"buffer.", buffer->size());
653 log_info(
"Sensor CameraGBufferUint8 to ROS data: frame.",
_frame,
"sensor.", sensor_type,
"stream.", stream_id,
"buffer.", buffer->size());
656 log_info(
"Sensor CameraGBufferFloat to ROS data: frame.",
_frame,
"sensor.", sensor_type,
"stream.", stream_id,
"buffer.", buffer->size());
659 log_info(
"Sensor to ROS data: frame.",
_frame,
"sensor.", sensor_type,
"stream.", stream_id,
"buffer.", buffer->size());