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