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