CARLA
CarlaRecorder.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 
9 // #include "GameFramework/Actor.h"
10 #include <fstream>
11 
13 
23 #include "CarlaRecorderCollision.h"
24 #include "CarlaRecorderEventAdd.h"
25 #include "CarlaRecorderEventDel.h"
27 #include "CarlaRecorderFrames.h"
28 #include "CarlaRecorderInfo.h"
29 #include "CarlaRecorderPosition.h"
30 #include "CarlaRecorderQuery.h"
31 #include "CarlaRecorderState.h"
34 #include "CarlaReplayer.h"
35 
36 #include "CarlaRecorder.generated.h"
37 
38 class AActor;
39 class UCarlaEpisode;
41 class UCarlaLight;
42 class ATrafficSignBase;
43 class ATrafficLightBase;
44 
45 enum class CarlaRecorderPacketId : uint8_t
46 {
47  FrameStart = 0,
48  FrameEnd,
49  EventAdd,
50  EventDel,
52  Collision,
53  Position,
54  State,
56  AnimWalker,
58  SceneLight,
59  Kinematics,
68 };
69 
70 /// Recorder for the simulation
71 UCLASS()
72 class CARLA_API ACarlaRecorder : public AActor
73 {
74  GENERATED_BODY()
75 
76 public:
77 
78  ACarlaRecorder(void);
79  ACarlaRecorder(const FObjectInitializer &InObjectInitializer);
80 
81  // enable / disable
82  bool IsEnabled(void)
83  {
84  return Enabled;
85  }
86  void Enable(void);
87 
88  void Disable(void);
89 
90  // start / stop
91  std::string Start(std::string Name, FString MapName, bool AdditionalData = false);
92 
93  void Stop(void);
94 
95  void Clear(void);
96 
97  void Write(double DeltaSeconds);
98 
99  // events
100  void AddEvent(const CarlaRecorderEventAdd &Event);
101 
102  void AddEvent(const CarlaRecorderEventDel &Event);
103 
104  void AddEvent(const CarlaRecorderEventParent &Event);
105 
106  void AddCollision(AActor *Actor1, AActor *Actor2);
107 
108  void AddPosition(const CarlaRecorderPosition &Position);
109 
110  void AddState(const CarlaRecorderStateTrafficLight &State);
111 
112  void AddAnimVehicle(const CarlaRecorderAnimVehicle &Vehicle);
113 
114  void AddAnimWalker(const CarlaRecorderAnimWalker &Walker);
115 
116  void AddLightVehicle(const CarlaRecorderLightVehicle &LightVehicle);
117 
118  void AddEventLightSceneChanged(const UCarlaLight* Light);
119 
120  void AddKinematics(const CarlaRecorderKinematics &ActorKinematics);
121 
122  void AddBoundingBox(const CarlaRecorderActorBoundingBox &ActorBoundingBox);
123 
124  void AddTriggerVolume(const ATrafficSignBase &TrafficSign);
125 
126  void AddPhysicsControl(const ACarlaWheeledVehicle& Vehicle);
127 
128  void AddTrafficLightTime(const ATrafficLightBase& TrafficLight);
129 
130  void AddActorBones(FCarlaActor *CarlaActor);
131 
132  // set episode
133  void SetEpisode(UCarlaEpisode *ThisEpisode)
134  {
135  Episode = ThisEpisode;
136  Replayer.SetEpisode(ThisEpisode);
137  }
138 
139  void CreateRecorderEventAdd(
140  uint32_t DatabaseId,
141  uint8_t Type,
142  const FTransform &Transform,
143  FActorDescription ActorDescription);
144 
145  // replayer
147  {
148  return &Replayer;
149  }
150 
151  // queries
152  std::string ShowFileInfo(std::string Name, bool bShowAll = false);
153  std::string ShowFileCollisions(std::string Name, char Type1, char Type2);
154  std::string ShowFileActorsBlocked(std::string Name, double MinTime = 30, double MinDistance = 10);
155 
156  // replayer
157  std::string ReplayFile(std::string Name, double TimeStart, double Duration,
158  uint32_t FollowId, bool ReplaySensors);
159  void SetReplayerTimeFactor(double TimeFactor);
160  void SetReplayerIgnoreHero(bool IgnoreHero);
161  void StopReplayer(bool KeepActors = false);
162 
163  void Ticking(float DeltaSeconds);
164 
165 private:
166 
167  bool Enabled; // enabled or not
168 
169  // enabling this records additional data (kinematics, bounding boxes, etc)
170  bool bAdditionalData = false;
171 
172  uint32_t NextCollisionId = 0;
173 
174  // files
175  std::ofstream File;
176 
177  UCarlaEpisode *Episode = nullptr;
178 
179  // structures
200 
201  // replayer
203 
204  // query tools
206 
207  void AddExistingActors(void);
208  void AddActorPosition(FCarlaActor *CarlaActor);
209  void AddWalkerAnimation(FCarlaActor *CarlaActor);
210  void AddVehicleAnimation(FCarlaActor *CarlaActor);
211  void AddTrafficLightState(FCarlaActor *CarlaActor);
212  void AddVehicleLight(FCarlaActor *CarlaActor);
213  void AddActorKinematics(FCarlaActor *CarlaActor);
214  void AddActorBoundingBox(FCarlaActor *CarlaActor);
215 };
CarlaRecorderTrafficLightTimes TrafficLightTimes
CarlaRecorderFrames Frames
CarlaRecorderQuery Query
CarlaRecorderAnimVehicles Vehicles
CarlaRecorderInfo Info
CarlaRecorderPlatformTime PlatformTime
void SetEpisode(UCarlaEpisode *ThisEpisode)
CarlaReplayer Replayer
CarlaRecorderLightScenes LightScenes
CarlaRecorderAnimWalkers Walkers
CarlaRecorderVisualTime VisualTime
CarlaReplayer * GetReplayer(void)
CarlaRecorderWalkersBones WalkersBones
CarlaRecorderActorBoundingBoxes BoundingBoxes
CarlaRecorderPhysicsControls PhysicsControls
CarlaRecorderLightVehicles LightVehicles
CarlaRecorderEventsParent EventsParent
A simulation episode.
Definition: CarlaEpisode.h:37
Recorder for the simulation.
Definition: CarlaRecorder.h:72
std::ofstream File
CarlaRecorderEventsAdd EventsAdd
CarlaRecorderCollisions Collisions
A description of a Carla Actor with all its variation.
bool IsEnabled(void)
Definition: CarlaRecorder.h:82
CarlaRecorderPacketId
Definition: CarlaRecorder.h:45
CarlaRecorderActorsKinematics Kinematics
CarlaRecorderPositions Positions
CarlaRecorderActorTriggerVolumes TriggerVolumes
CarlaRecorderEventsDel EventsDel
Base class for CARLA wheeled vehicles.
CarlaRecorderStates States
geom::Transform Transform
Definition: rpc/Transform.h:16
A view over an actor and its properties.
Definition: CarlaActor.h:23