CARLA
CarlaEngine.h
Go to the documentation of this file.
1 // Copyright (c) 2017 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 
13 #include "Carla/Util/NonCopyable.h"
14 #include "Carla/Game/FrameData.h"
15 
16 #include "Misc/CoreDelegates.h"
17 
19 #include <carla/multigpu/router.h>
23 #include <carla/ros2/ROS2.h>
25 
26 #include <mutex>
27 
28 class UCarlaSettings;
29 struct FEpisodeSettings;
30 
31 class FCarlaEngine : private NonCopyable
32 {
33 public:
34 
35  static uint64_t FrameCounter;
36 
37  ~FCarlaEngine();
38 
39  void NotifyInitGame(const UCarlaSettings &Settings);
40 
41  void NotifyBeginEpisode(UCarlaEpisode &Episode);
42 
43  void NotifyEndEpisode();
44 
45  const FCarlaServer &GetServer() const
46  {
47  return Server;
48  }
49 
51  {
52  return Server;
53  }
54 
56  {
57  return CurrentEpisode;
58  }
59 
60  void SetRecorder(ACarlaRecorder *InRecorder)
61  {
62  Recorder = InRecorder;
63  }
64 
65  static uint64_t GetFrameCounter()
66  {
68  }
69 
70  static uint64_t UpdateFrameCounter()
71  {
73  #if defined(WITH_ROS2)
74  auto ROS2 = carla::ros2::ROS2::GetInstance();
75  if (ROS2->IsEnabled())
76  ROS2->SetFrame(FCarlaEngine::FrameCounter);
77  #endif
79  }
80 
81  static void ResetFrameCounter(uint64_t Value = 0)
82  {
84  #if defined(WITH_ROS2)
85  auto ROS2 = carla::ros2::ROS2::GetInstance();
86  if (ROS2->IsEnabled())
87  ROS2->SetFrame(FCarlaEngine::FrameCounter);
88  #endif
89  }
90 
91  std::shared_ptr<carla::multigpu::Router> GetSecondaryServer()
92  {
93  return SecondaryServer;
94  }
95 
96 private:
97 
98  void OnPreTick(UWorld *World, ELevelTick TickType, float DeltaSeconds);
99 
100  void OnPostTick(UWorld *World, ELevelTick TickType, float DeltaSeconds);
101 
102  void OnEpisodeSettingsChanged(const FEpisodeSettings &Settings);
103 
104  void ResetSimulationState();
105 
106  bool bIsRunning = false;
107 
108  bool bSynchronousMode = false;
109 
110  bool bMapChanged = false;
111 
113 
115 
117 
119 
121 
122  FDelegateHandle OnPreTickHandle;
123 
124  FDelegateHandle OnPostTickHandle;
125 
127 
128  bool bIsPrimaryServer = true;
129  bool bNewConnection = false;
130 
131  std::unordered_map<uint32_t, uint32_t> MappedId;
132 
133  std::shared_ptr<carla::multigpu::Router> SecondaryServer;
134  std::shared_ptr<carla::multigpu::Secondary> Secondary;
135 
136  std::vector<FFrameData> FramesToProcess;
138 };
139 
140 // Note: this has a circular dependency with FCarlaEngine; it must be included late.
UCarlaEpisode * GetCurrentEpisode()
Definition: CarlaEngine.h:55
bool bMapChanged
Definition: CarlaEngine.h:110
void OnEpisodeSettingsChanged(const FEpisodeSettings &Settings)
FDelegateHandle OnEpisodeSettingsChangeHandle
Definition: CarlaEngine.h:126
std::shared_ptr< carla::multigpu::Router > SecondaryServer
Definition: CarlaEngine.h:133
FCarlaServer Server
Definition: CarlaEngine.h:112
FCarlaServer & GetServer()
Definition: CarlaEngine.h:50
Serializes and sends all the actors in the current UCarlaEpisode.
Definition: WorldObserver.h:14
std::vector< FFrameData > FramesToProcess
Definition: CarlaEngine.h:136
static uint64_t UpdateFrameCounter()
Definition: CarlaEngine.h:70
FDelegateHandle OnPostTickHandle
Definition: CarlaEngine.h:124
std::shared_ptr< carla::multigpu::Router > GetSecondaryServer()
Definition: CarlaEngine.h:91
FWorldObserver WorldObserver
Definition: CarlaEngine.h:114
void SetRecorder(ACarlaRecorder *InRecorder)
Definition: CarlaEngine.h:60
static void ResetFrameCounter(uint64_t Value=0)
Definition: CarlaEngine.h:81
static uint64_t GetFrameCounter()
Definition: CarlaEngine.h:65
void NotifyInitGame(const UCarlaSettings &Settings)
Definition: CarlaEngine.cpp:77
void OnPostTick(UWorld *World, ELevelTick TickType, float DeltaSeconds)
static uint64_t FrameCounter
Definition: CarlaEngine.h:35
A simulation episode.
Definition: CarlaEpisode.h:38
std::mutex FrameToProcessMutex
Definition: CarlaEngine.h:137
void NotifyBeginEpisode(UCarlaEpisode &Episode)
Recorder for the simulation.
Definition: CarlaRecorder.h:76
ACarlaRecorder * Recorder
Definition: CarlaEngine.h:120
bool bNewConnection
Definition: CarlaEngine.h:129
void NotifyEndEpisode()
std::unordered_map< uint32_t, uint32_t > MappedId
Definition: CarlaEngine.h:131
FEpisodeSettings CurrentSettings
Definition: CarlaEngine.h:118
Global settings for CARLA.
Definition: CarlaSettings.h:21
UCarlaEpisode * CurrentEpisode
Definition: CarlaEngine.h:116
void ResetSimulationState()
void OnPreTick(UWorld *World, ELevelTick TickType, float DeltaSeconds)
bool bSynchronousMode
Definition: CarlaEngine.h:108
bool bIsPrimaryServer
Definition: CarlaEngine.h:128
static std::shared_ptr< ROS2 > GetInstance()
Definition: ROS2.h:51
std::shared_ptr< carla::multigpu::Secondary > Secondary
Definition: CarlaEngine.h:134
FDelegateHandle OnPreTickHandle
Definition: CarlaEngine.h:122
const FCarlaServer & GetServer() const
Definition: CarlaEngine.h:45