CARLA
 
载入中...
搜索中...
未找到
ROS2.h
浏览该文件的文档.
1// Copyright (c) 2023 Computer Vision Center (CVC) at the Universitat Autonoma
2// de Barcelona (UAB).
3//
4// This work is licensed under the terms of the MIT license.
5// For a copy, see <https://opensource.org/licenses/MIT>.
6
7#pragma once
8
9#include "carla/Buffer.h"
10#include "carla/BufferView.h"
14
15#include <unordered_set>
16#include <unordered_map>
17#include <memory>
18#include <vector>
19
20// 前置声明
21class AActor;
22namespace carla {
23 namespace geom {
24 class GeoLocation;
25 class Vector3D;
26 }
27 namespace sensor {
28 namespace data {
29 struct DVSEvent;
30 class LidarData;
32 class RadarData;
33 }
34 }
35}
36
37namespace carla {
38namespace ros2 {
39
40 class CarlaPublisher;
41 class CarlaTransformPublisher;
42 class CarlaClockPublisher;
43 class CarlaEgoVehicleControlSubscriber;
44
45class ROS2
46{
47 public:
48
49 // 删除单例的复制构造函数
50 ROS2(const ROS2& obj) = delete;
51 static std::shared_ptr<ROS2> GetInstance() {
52 if (!_instance)
53 _instance = std::shared_ptr<ROS2>(new ROS2);
54 return _instance;
55 }
56
57 // 通用函数
58 void Enable(bool enable);
59 void Shutdown();
60 bool IsEnabled() { return _enabled; }
61 void SetFrame(uint64_t frame);
62 void SetTimestamp(double timestamp);
63
64 // ros_name 管理函数
65 void AddActorRosName(void *actor, std::string ros_name);
66 void AddActorParentRosName(void *actor, void* parent);
67 void RemoveActorRosName(void *actor);
68 void UpdateActorRosName(void *actor, std::string ros_name);
69 std::string GetActorRosName(void *actor);
70 std::string GetActorParentRosName(void *actor);
71
72 // 回调函数
73 void AddActorCallback(void* actor, std::string ros_name, ActorCallback callback);
74 void RemoveActorCallback(void* actor);
75
76 // 允许流发布
79 void ResetStreams() { _publish_stream.clear(); }
80
81 // 接收要发布的数据
83 uint64_t sensor_type,
85 const carla::geom::Transform sensor_transform,
86 int W, int H, float Fov,
87 const carla::SharedBufferView buffer,
88 void *actor = nullptr);
90 uint64_t sensor_type,
92 const carla::geom::Transform sensor_transform,
93 const carla::geom::GeoLocation &data,
94 void *actor = nullptr);
96 uint64_t sensor_type,
98 const carla::geom::Transform sensor_transform,
99 carla::geom::Vector3D accelerometer,
100 carla::geom::Vector3D gyroscope,
101 float compass,
102 void *actor = nullptr);
104 uint64_t sensor_type,
106 const carla::geom::Transform sensor_transform,
107 const carla::SharedBufferView buffer,
108 int W, int H, float Fov,
109 void *actor = nullptr);
111 uint64_t sensor_type,
113 const carla::geom::Transform sensor_transform,
115 void *actor = nullptr);
117 uint64_t sensor_type,
119 const carla::geom::Transform sensor_transform,
121 void *actor = nullptr);
123 uint64_t sensor_type,
125 const carla::geom::Transform sensor_transform,
127 void *actor = nullptr);
129 uint64_t sensor_type,
131 const carla::geom::Transform sensor_transform,
132 AActor *first_actor,
133 AActor *second_actor,
134 float distance,
135 void *actor = nullptr);
137 uint64_t sensor_type,
139 const carla::geom::Transform sensor_transform,
140 uint32_t other_actor,
141 carla::geom::Vector3D impulse,
142 void* actor);
143
144 private:
145 std::pair<std::shared_ptr<CarlaPublisher>, std::shared_ptr<CarlaTransformPublisher>> GetOrCreateSensor(int type, carla::streaming::detail::stream_id_type id, void* actor);
146
147 // 单例
148 ROS2() {};
149
150 static std::shared_ptr<ROS2> _instance;
151
152 bool _enabled { false };
153 uint64_t _frame { 0 };
154 int32_t _seconds { 0 };
155 uint32_t _nanoseconds { 0 };
156 std::unordered_map<void *, std::string> _actor_ros_name;
157 std::unordered_map<void *, std::vector<void*> > _actor_parent_ros_name;
158 std::shared_ptr<CarlaEgoVehicleControlSubscriber> _controller;
159 std::shared_ptr<CarlaClockPublisher> _clock_publisher;
160 std::unordered_map<void *, std::shared_ptr<CarlaPublisher>> _publishers;
161 std::unordered_map<void *, std::shared_ptr<CarlaTransformPublisher>> _transforms;
162 std::unordered_set<carla::streaming::detail::stream_id_type> _publish_stream;
163 std::unordered_map<void *, ActorCallback> _actor_callbacks;
164};
165
166} // namespace ros2
167} // namespace carla
std::unordered_map< void *, std::shared_ptr< CarlaTransformPublisher > > _transforms
Definition ROS2.h:161
void ProcessDataFromRadar(uint64_t sensor_type, carla::streaming::detail::stream_id_type stream_id, const carla::geom::Transform sensor_transform, const carla::sensor::data::RadarData &data, void *actor=nullptr)
Definition ROS2.cpp:780
void ProcessDataFromDVS(uint64_t sensor_type, carla::streaming::detail::stream_id_type stream_id, const carla::geom::Transform sensor_transform, const carla::SharedBufferView buffer, int W, int H, float Fov, void *actor=nullptr)
Definition ROS2.cpp:705
static std::shared_ptr< ROS2 > _instance
Definition ROS2.h:150
std::string GetActorParentRosName(void *actor)
Definition ROS2.cpp:147
static std::shared_ptr< ROS2 > GetInstance()
Definition ROS2.h:51
std::unordered_set< carla::streaming::detail::stream_id_type > _publish_stream
Definition ROS2.h:162
void AddActorCallback(void *actor, std::string ros_name, ActorCallback callback)
Definition ROS2.cpp:174
void Enable(bool enable)
Definition ROS2.cpp:73
void RemoveActorRosName(void *actor)
Definition ROS2.cpp:123
void ProcessDataFromIMU(uint64_t sensor_type, carla::streaming::detail::stream_id_type stream_id, const carla::geom::Transform sensor_transform, carla::geom::Vector3D accelerometer, carla::geom::Vector3D gyroscope, float compass, void *actor=nullptr)
Definition ROS2.cpp:683
void Shutdown()
Definition ROS2.cpp:834
std::string GetActorRosName(void *actor)
Definition ROS2.cpp:138
void ProcessDataFromObstacleDetection(uint64_t sensor_type, carla::streaming::detail::stream_id_type stream_id, const carla::geom::Transform sensor_transform, AActor *first_actor, AActor *second_actor, float distance, void *actor=nullptr)
Definition ROS2.cpp:803
void ProcessDataFromCamera(uint64_t sensor_type, carla::streaming::detail::stream_id_type stream_id, const carla::geom::Transform sensor_transform, int W, int H, float Fov, const carla::SharedBufferView buffer, void *actor=nullptr)
Definition ROS2.cpp:478
std::unordered_map< void *, ActorCallback > _actor_callbacks
Definition ROS2.h:163
ROS2(const ROS2 &obj)=delete
void ProcessDataFromSemanticLidar(uint64_t sensor_type, carla::streaming::detail::stream_id_type stream_id, const carla::geom::Transform sensor_transform, carla::sensor::data::SemanticLidarData &data, void *actor=nullptr)
Definition ROS2.cpp:757
std::shared_ptr< CarlaClockPublisher > _clock_publisher
Definition ROS2.h:159
void ProcessDataFromCollisionSensor(uint64_t sensor_type, carla::streaming::detail::stream_id_type stream_id, const carla::geom::Transform sensor_transform, uint32_t other_actor, carla::geom::Vector3D impulse, void *actor)
Definition ROS2.cpp:814
std::shared_ptr< CarlaEgoVehicleControlSubscriber > _controller
Definition ROS2.h:158
void AddActorRosName(void *actor, std::string ros_name)
Definition ROS2.cpp:110
bool IsEnabled()
Definition ROS2.h:60
bool IsStreamEnabled(carla::streaming::detail::stream_id_type id)
Definition ROS2.h:78
void UpdateActorRosName(void *actor, std::string ros_name)
Definition ROS2.cpp:131
uint32_t _nanoseconds
Definition ROS2.h:155
std::unordered_map< void *, std::vector< void * > > _actor_parent_ros_name
Definition ROS2.h:157
void AddActorParentRosName(void *actor, void *parent)
Definition ROS2.cpp:114
void SetTimestamp(double timestamp)
Definition ROS2.cpp:99
void RemoveActorCallback(void *actor)
Definition ROS2.cpp:182
void ResetStreams()
Definition ROS2.h:79
void ProcessDataFromLidar(uint64_t sensor_type, carla::streaming::detail::stream_id_type stream_id, const carla::geom::Transform sensor_transform, carla::sensor::data::LidarData &data, void *actor=nullptr)
Definition ROS2.cpp:735
void SetFrame(uint64_t frame)
Definition ROS2.cpp:80
int32_t _seconds
Definition ROS2.h:154
std::pair< std::shared_ptr< CarlaPublisher >, std::shared_ptr< CarlaTransformPublisher > > GetOrCreateSensor(int type, carla::streaming::detail::stream_id_type id, void *actor)
Definition ROS2.cpp:187
void EnableStream(carla::streaming::detail::stream_id_type id)
Definition ROS2.h:77
std::unordered_map< void *, std::string > _actor_ros_name
Definition ROS2.h:156
std::unordered_map< void *, std::shared_ptr< CarlaPublisher > > _publishers
Definition ROS2.h:160
uint64_t _frame
Definition ROS2.h:153
void ProcessDataFromGNSS(uint64_t sensor_type, carla::streaming::detail::stream_id_type stream_id, const carla::geom::Transform sensor_transform, const carla::geom::GeoLocation &data, void *actor=nullptr)
Definition ROS2.cpp:663
std::function< void(void *actor, ROS2CallbackData data)> ActorCallback
geom::Vector3D Vector3D
uint32_t stream_id_type
Definition Types.h:18
This file contains definitions of common data structures used in traffic manager.
Definition Carla.cpp:133
std::shared_ptr< BufferView > SharedBufferView
Definition BufferView.h:151