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 <memory>
9 #include <mutex>
10 #include <vector>
11 #include "carla/client/Sensor.h"
12 
13 namespace ad {
14 namespace rss {
15 namespace world {
16 
17 /// forward declaration of the RssDynamics struct
18 struct RssDynamics;
19 
20 } // namespace world
21 } // namespace rss
22 } // namespace ad
23 
24 namespace carla {
25 
26 namespace rss {
27 
28 /// forward declaration of the RoadBoundariesMode
29 enum class RoadBoundariesMode;
30 /// forward declaration of the RssCheck class
31 class RssCheck;
32 /// forward declaration of the ActorContellationResult struct
33 struct ActorConstellationResult;
34 /// forward declaration of the ActorContellationData struct
35 struct ActorConstellationData;
36 } // namespace rss
37 
38 namespace client {
39 
40 /// The RSS Sensor class implementing the carla::client::Sensor interface
41 /// This class is a proxy to the RssCheck class
42 class RssSensor : public Sensor {
43 public:
44  using Sensor::Sensor;
45 
47  std::function<::carla::rss::ActorConstellationResult(carla::SharedPtr<::carla::rss::ActorConstellationData>)>;
48 
49  /// @brief constructor
50  explicit RssSensor(ActorInitializer init);
51 
52  /// @brief destructor
53  ~RssSensor();
54 
55  /// Register a @a callback to be executed for each actor within each measurement to be processed
56  /// to decide on the operation of the RSS sensor in respect to the ego vehicle to actor constellation
57  void RegisterActorConstellationCallback(ActorConstellationCallbackFunctionType callback);
58 
59  /// Register a @a callback to be executed each time a new measurement is
60  /// received.
61  ///
62  /// @warning Calling this function on a sensor that is already listening
63  /// steals the data stream from the previously set callback. Note that
64  /// several instances of Sensor (even in different processes) may point to
65  /// the same sensor in the simulator.
66  void Listen(CallbackFunctionType callback) override;
67 
68  /// Stop listening for new measurements.
69  void Stop() override;
70 
71  /// Return whether this Sensor instance is currently listening to the
72  /// associated sensor in the simulator.
73  bool IsListening() const override {
74  return _on_tick_register_id != 0u;
75  }
76 
77  /// @brief sets the current log level
78  void SetLogLevel(const uint8_t &log_level);
79 
80  /// @brief sets the current map log level
81  void SetMapLogLevel(const uint8_t &map_log_level);
82 
83  /// @returns the currently used dynamics of the ego vehicle (@see also
84  /// RssCheck::GetEgoVehicleDynamics())
85  const ::ad::rss::world::RssDynamics &GetEgoVehicleDynamics() const;
86  /// @brief sets the ego vehicle dynamics to be used by the ego vehicle (@see
87  /// also RssCheck::SetEgoVehicleDynamics())
88  void SetEgoVehicleDynamics(const ::ad::rss::world::RssDynamics &ego_dynamics);
89 
90  /// @returns the currently used dynamics of other vehicles (@see also
91  /// RssCheck::GetOtherVehicleDynamics())
92  const ::ad::rss::world::RssDynamics &GetOtherVehicleDynamics() const;
93  /// @brief sets the ego vehicle dynamics to be used by other vehicles (@see
94  /// also RssCheck::SetOtherVehicleDynamics())
95  void SetOtherVehicleDynamics(const ::ad::rss::world::RssDynamics &other_vehicle_dynamics);
96 
97  /// @returns the currently used dynamics of pedestrians (@see also
98  /// RssCheck::GetPedestrianDynamics())
99  const ::ad::rss::world::RssDynamics &GetPedestrianDynamics() const;
100  /// @brief sets the ego vehicle dynamics to be used by pedestrians (@see
101  /// also RssCheck::SetPedestrianDynamics())
102  void SetPedestrianDynamics(const ::ad::rss::world::RssDynamics &pedestrian_dynamics);
103 
104  /// @returns the current mode for respecting the road boundaries (@see also
105  /// RssCheck::GetRoadBoundariesMode())
106  const ::carla::rss::RoadBoundariesMode &GetRoadBoundariesMode() const;
107  /// @brief sets the current mode for respecting the road boundaries (@see also
108  /// RssCheck::SetRoadBoundariesMode())
109  void SetRoadBoundariesMode(const ::carla::rss::RoadBoundariesMode &road_boundaries_mode);
110 
111  /// @returns the current routing targets (@see also
112  /// RssCheck::GetRoutingTargets())
113  const std::vector<::carla::geom::Transform> GetRoutingTargets() const;
114  /// @brief appends a routing target to the current routing target list (@see
115  /// also RssCheck::AppendRoutingTarget())
116  void AppendRoutingTarget(const ::carla::geom::Transform &routing_target);
117  /// @brief resets the current routing target (@see also
118  /// RssCheck::ResetRoutingTargets())
119  void ResetRoutingTargets();
120 
121  /// @brief drop the current route (@see also RssCheck::DropRoute())
122  void DropRoute();
123 
124 private:
125  /// the acutal sensor tick callback function
126  SharedPtr<sensor::SensorData> TickRssSensor(const Timestamp &timestamp);
127 
128  /// the id got when registering for the on tick event
129  std::size_t _on_tick_register_id;
130 
131  /// the mutex to protect the actual RSS processing and in case it takes too long to process ever frame
132  std::mutex _processing_lock;
133 
134  //// the object actually performing the RSS processing
135  std::shared_ptr<::carla::rss::RssCheck> _rss_check;
136 
137  //// the rss actor constellation callback function
139 
140  /// reqired to store DropRoute() requests until next sensor tick
142 
143  /// last processed frame
145 };
146 
147 } // namespace client
148 } // namespace carla
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:99
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.
Definition: ActorState.h:93
RoadBoundariesMode
struct defining the different supported handling of road boundaries
Definition: RssCheck.h:28
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
ActorConstellationCallbackFunctionType _rss_actor_constellation_callback
geom::Transform Transform
Definition: rpc/Transform.h:16