CARLA
LibCarla/source/carla/rss/RssSensor.h
Go to the documentation of this file.
1 // Copyright (c) 2019-2020 Intel Corporation
2 //
3 // This work is licensed under the terms of the MIT license.
4 // For a copy, see <https://opensource.org/licenses/MIT>.
5 
6 #pragma once
7 
8 #include <atomic>
9 #include <future>
10 #include <list>
11 #include <memory>
12 #include <mutex>
13 #include <vector>
14 #include "carla/client/Sensor.h"
15 
16 namespace ad {
17 namespace rss {
18 namespace world {
19 
20 /// forward declaration of the RssDynamics struct
21 struct RssDynamics;
22 
23 } // namespace world
24 } // namespace rss
25 } // namespace ad
26 
27 namespace carla {
28 
29 namespace rss {
30 
31 /// forward declaration of the RoadBoundariesMode
32 enum class RoadBoundariesMode;
33 /// forward declaration of the RssCheck class
34 class RssCheck;
35 /// forward declaration of the ActorContellationResult struct
36 struct ActorConstellationResult;
37 /// forward declaration of the ActorContellationData struct
38 struct ActorConstellationData;
39 } // namespace rss
40 
41 namespace client {
42 
43 /// The RSS Sensor class implementing the carla::client::Sensor interface
44 /// This class is a proxy to the RssCheck class
45 class RssSensor : public Sensor {
46 public:
47  using Sensor::Sensor;
48 
50  std::function<::carla::rss::ActorConstellationResult(carla::SharedPtr<::carla::rss::ActorConstellationData>)>;
51 
52  /// @brief constructor
53  explicit RssSensor(ActorInitializer init);
54 
55  /// @brief destructor
56  ~RssSensor();
57 
58  /// Register a @a callback to be executed for each actor within each measurement to be processed
59  /// to decide on the operation of the RSS sensor in respect to the ego vehicle to actor constellation
60  void RegisterActorConstellationCallback(ActorConstellationCallbackFunctionType callback);
61 
62  /// Register a @a callback to be executed each time a new measurement is
63  /// received.
64  ///
65  /// @warning Calling this function on a sensor that is already listening
66  /// steals the data stream from the previously set callback. Note that
67  /// several instances of Sensor (even in different processes) may point to
68  /// the same sensor in the simulator.
69  void Listen(CallbackFunctionType callback) override;
70 
71  /// Stop listening for new measurements.
72  /// Be aware: GIL has to be unlocked to be able to wait for callbacks not active.
73  void Stop() override;
74 
75  /// Return whether this Sensor instance is currently listening to the
76  /// associated sensor in the simulator.
77  bool IsListening() const override {
78  return _on_tick_register_id != 0u;
79  }
80 
81  /// @brief sets the current log level
82  void SetLogLevel(const uint8_t &log_level);
83 
84  /// @brief sets the current map log level
85  void SetMapLogLevel(const uint8_t &map_log_level);
86 
87  /// @returns the currently used dynamics of the ego vehicle (@see also
88  /// RssCheck::GetEgoVehicleDynamics())
89  const ::ad::rss::world::RssDynamics &GetEgoVehicleDynamics() const;
90  /// @brief sets the ego vehicle dynamics to be used by the ego vehicle (@see
91  /// also RssCheck::SetEgoVehicleDynamics())
92  void SetEgoVehicleDynamics(const ::ad::rss::world::RssDynamics &ego_dynamics);
93 
94  /// @returns the currently used dynamics of other vehicles (@see also
95  /// RssCheck::GetOtherVehicleDynamics())
96  const ::ad::rss::world::RssDynamics &GetOtherVehicleDynamics() const;
97  /// @brief sets the ego vehicle dynamics to be used by other vehicles (@see
98  /// also RssCheck::SetOtherVehicleDynamics())
99  void SetOtherVehicleDynamics(const ::ad::rss::world::RssDynamics &other_vehicle_dynamics);
100 
101  /// @returns the currently used dynamics of pedestrians (@see also
102  /// RssCheck::GetPedestrianDynamics())
103  const ::ad::rss::world::RssDynamics &GetPedestrianDynamics() const;
104  /// @brief sets the ego vehicle dynamics to be used by pedestrians (@see
105  /// also RssCheck::SetPedestrianDynamics())
106  void SetPedestrianDynamics(const ::ad::rss::world::RssDynamics &pedestrian_dynamics);
107 
108  /// @returns the current mode for respecting the road boundaries (@see also
109  /// RssCheck::GetRoadBoundariesMode())
110  const ::carla::rss::RoadBoundariesMode &GetRoadBoundariesMode() const;
111  /// @brief sets the current mode for respecting the road boundaries (@see also
112  /// RssCheck::SetRoadBoundariesMode())
113  void SetRoadBoundariesMode(const ::carla::rss::RoadBoundariesMode &road_boundaries_mode);
114 
115  /// @returns the current routing targets (@see also
116  /// RssCheck::GetRoutingTargets())
117  const std::vector<::carla::geom::Transform> GetRoutingTargets() const;
118  /// @brief appends a routing target to the current routing target list (@see
119  /// also RssCheck::AppendRoutingTarget())
120  void AppendRoutingTarget(const ::carla::geom::Transform &routing_target);
121  /// @brief resets the current routing target (@see also
122  /// RssCheck::ResetRoutingTargets())
123  void ResetRoutingTargets();
124 
125  /// @brief drop the current route (@see also RssCheck::DropRoute())
126  void DropRoute();
127 
128 private:
129  /// the acutal sensor tick callback function
130  void TickRssSensor(const client::Timestamp &timestamp, CallbackFunctionType callback);
131  void TickRssSensorThreadLocked(const client::Timestamp &timestamp, SharedPtr<carla::client::ActorList> actors,
132  CallbackFunctionType callback);
133 
134  //// the object actually performing the RSS processing
135  std::shared_ptr<::carla::rss::RssCheck> _rss_check;
136 
137  /// the id got when registering for the on tick event
138  std::size_t _on_tick_register_id;
139 
140  /// the mutex to protect the actual RSS processing and in case it takes too long to process ever frame
141  std::mutex _processing_lock;
142 
143  /// the future for the async ticking thread
144  std::future<void> _tick_future;
145 
146  /// some debug timings
147  std::list<double> _rss_check_timings;
148 
149  //// the rss actor constellation callback function
151 
152  /// reqired to store DropRoute() requests until next sensor tick
154 
155  /// last processed frame
157 
158  static std::atomic_uint _global_map_initialization_counter_;
159 };
160 
161 } // namespace client
162 } // namespace carla
std::list< double > _rss_check_timings
some debug timings
std::function<::carla::rss::ActorConstellationResult(carla::SharedPtr<::carla::rss::ActorConstellationData >)> ActorConstellationCallbackFunctionType
std::shared_ptr<::carla::rss::RssCheck > _rss_check
std::mutex _processing_lock
the mutex to protect the actual RSS processing and in case it takes too long to process ever frame ...
boost::shared_ptr< T > SharedPtr
Use this SharedPtr (boost::shared_ptr) to keep compatibility with boost::python, but it would be nice...
Definition: Memory.h:20
This file contains definitions of common data structures used in traffic manager. ...
Definition: Carla.cpp:133
std::size_t _on_tick_register_id
the id got when registering for the on tick event
The RSS Sensor class implementing the carla::client::Sensor interface This class is a proxy to the Rs...
Used to initialize Actor classes.
RoadBoundariesMode
struct defining the different supported handling of road boundaries
Definition: RssCheck.h:28
static std::atomic_uint _global_map_initialization_counter_
std::function< void(SharedPtr< sensor::SensorData >)> CallbackFunctionType
std::size_t _last_processed_frame
last processed frame
bool IsListening() const override
Return whether this Sensor instance is currently listening to the associated sensor in the simulator...
bool _drop_route
reqired to store DropRoute() requests until next sensor tick
std::future< void > _tick_future
the future for the async ticking thread
ActorConstellationCallbackFunctionType _rss_actor_constellation_callback
geom::Transform Transform
Definition: rpc/Transform.h:16