Added traffic light time events.
This commit is contained in:
parent
b1a475d2b4
commit
eb63a2aae8
|
@ -305,6 +305,21 @@ void ACarlaRecorder::AddPhysicsControl(const ACarlaWheeledVehicle& Vehicle)
|
|||
}
|
||||
}
|
||||
|
||||
void ACarlaRecorder::AddTrafficLightTime(const ATrafficLightBase& TrafficLight)
|
||||
{
|
||||
if (bAdditionalData)
|
||||
{
|
||||
auto DatabaseId = Episode->GetActorRegistry().Find(&TrafficLight).GetActorId();
|
||||
CarlaRecorderTrafficLightTime TrafficLightTime{
|
||||
DatabaseId,
|
||||
TrafficLight.GetGreenTime(),
|
||||
TrafficLight.GetYellowTime(),
|
||||
TrafficLight.GetRedTime()
|
||||
};
|
||||
TrafficLightTimes.Add(TrafficLightTime);
|
||||
}
|
||||
}
|
||||
|
||||
std::string ACarlaRecorder::Start(std::string Name, FString MapName, bool AdditionalData)
|
||||
{
|
||||
// stop replayer if any in course
|
||||
|
@ -376,6 +391,7 @@ void ACarlaRecorder::Clear(void)
|
|||
Kinematics.Clear();
|
||||
BoundingBoxes.Clear();
|
||||
PhysicsControls.Clear();
|
||||
TrafficLightTimes.Clear();
|
||||
}
|
||||
|
||||
void ACarlaRecorder::Write(double DeltaSeconds)
|
||||
|
@ -409,6 +425,7 @@ void ACarlaRecorder::Write(double DeltaSeconds)
|
|||
BoundingBoxes.Write(File);
|
||||
PlatformTime.Write(File);
|
||||
PhysicsControls.Write(File);
|
||||
TrafficLightTimes.Write(File);
|
||||
}
|
||||
|
||||
// end
|
||||
|
@ -602,10 +619,17 @@ void ACarlaRecorder::CreateRecorderEventAdd(
|
|||
};
|
||||
AddEvent(std::move(RecEvent));
|
||||
|
||||
// Other events related to spawning actors
|
||||
// check if it is a vehicle to get initial physics control
|
||||
ACarlaWheeledVehicle* Vehicle = Cast<ACarlaWheeledVehicle>(Episode->GetActorRegistry().Find(DatabaseId).GetActor());
|
||||
if (Vehicle)
|
||||
{
|
||||
AddPhysicsControl(*Vehicle);
|
||||
}
|
||||
|
||||
ATrafficLightBase* TrafficLight = Cast<ATrafficLightBase>(Episode->GetActorRegistry().Find(DatabaseId).GetActor());
|
||||
if (TrafficLight)
|
||||
{
|
||||
AddTrafficLightTime(*TrafficLight);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
#include "Carla/Actor/ActorDescription.h"
|
||||
|
||||
#include "CarlaRecorderTraficLightTime.h"
|
||||
#include "CarlaRecorderPhysicsControl.h"
|
||||
#include "CarlaRecorderPlatformTime.h"
|
||||
#include "CarlaRecorderBoundingBox.h"
|
||||
|
@ -36,6 +37,7 @@ class AActor;
|
|||
class UCarlaEpisode;
|
||||
class ACarlaWheeledVehicle;
|
||||
class UCarlaLight;
|
||||
class ATrafficLightBase;
|
||||
|
||||
enum class CarlaRecorderPacketId : uint8_t
|
||||
{
|
||||
|
@ -55,7 +57,7 @@ enum class CarlaRecorderPacketId : uint8_t
|
|||
BoundingBox,
|
||||
PlatformTime,
|
||||
PhysicsControl,
|
||||
TrafficLightParameters
|
||||
TrafficLightTime
|
||||
};
|
||||
|
||||
/// Recorder for the simulation
|
||||
|
@ -114,6 +116,8 @@ public:
|
|||
|
||||
void AddPhysicsControl(const ACarlaWheeledVehicle& Vehicle);
|
||||
|
||||
void AddTrafficLightTime(const ATrafficLightBase& TrafficLight);
|
||||
|
||||
// set episode
|
||||
void SetEpisode(UCarlaEpisode *ThisEpisode)
|
||||
{
|
||||
|
@ -176,6 +180,7 @@ private:
|
|||
CarlaRecorderBoundingBoxes BoundingBoxes;
|
||||
CarlaRecorderPlatformTime PlatformTime;
|
||||
CarlaRecorderPhysicsControls PhysicsControls;
|
||||
CarlaRecorderTrafficLightTimes TrafficLightTimes;
|
||||
|
||||
|
||||
// replayer
|
||||
|
|
|
@ -479,6 +479,31 @@ std::string CarlaRecorderQuery::QueryInfo(std::string Filename, bool bShowAll)
|
|||
SkipPacket();
|
||||
break;
|
||||
|
||||
case static_cast<char>(CarlaRecorderPacketId::TrafficLightTime):
|
||||
if (bShowAll)
|
||||
{
|
||||
ReadValue<uint16_t>(File, Total);
|
||||
if (Total > 0 && !bFramePrinted)
|
||||
{
|
||||
PrintFrame(Info);
|
||||
bFramePrinted = true;
|
||||
}
|
||||
|
||||
Info << " Traffic Light time events: " << Total << std::endl;
|
||||
for (i = 0; i < Total; ++i)
|
||||
{
|
||||
TrafficLightTime.Read(File);
|
||||
Info << " Actor id " << TrafficLightTime.DatabaseId
|
||||
<< ": Green Time " << TrafficLightTime.GreenTime
|
||||
<< " Yellow Time " << TrafficLightTime.YellowTime
|
||||
<< " Red Time " << TrafficLightTime.RedTime
|
||||
<< std::endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
SkipPacket();
|
||||
break;
|
||||
|
||||
// frame end
|
||||
case static_cast<char>(CarlaRecorderPacketId::FrameEnd):
|
||||
// do nothing, it is empty
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
#include <fstream>
|
||||
|
||||
#include "CarlaRecorderTraficLightTime.h"
|
||||
#include "CarlaRecorderPhysicsControl.h"
|
||||
#include "CarlaRecorderPlatformTime.h"
|
||||
#include "CarlaRecorderBoundingBox.h"
|
||||
|
@ -64,6 +65,7 @@ private:
|
|||
CarlaRecorderBoundingBox BoundingBox;
|
||||
CarlaRecorderPlatformTime PlatformTime;
|
||||
CarlaRecorderPhysicsControl PhysicsControl;
|
||||
CarlaRecorderTrafficLightTime TrafficLightTime;
|
||||
|
||||
// read next header packet
|
||||
bool ReadHeader(void);
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
// Copyright (c) 2020 Computer Vision Center (CVC) at the Universitat Autonoma
|
||||
// de Barcelona (UAB).
|
||||
//
|
||||
// This work is licensed under the terms of the MIT license.
|
||||
// For a copy, see <https://opensource.org/licenses/MIT>.
|
||||
|
||||
#include "CarlaRecorderTraficLightTime.h"
|
||||
#include "CarlaRecorder.h"
|
||||
#include "CarlaRecorderHelpers.h"
|
||||
|
||||
|
||||
void CarlaRecorderTrafficLightTime::Write(std::ofstream &OutFile)
|
||||
{
|
||||
WriteValue<uint32_t>(OutFile, this->DatabaseId);
|
||||
WriteValue(OutFile, this->GreenTime);
|
||||
WriteValue(OutFile, this->YellowTime);
|
||||
WriteValue(OutFile, this->RedTime);
|
||||
}
|
||||
|
||||
void CarlaRecorderTrafficLightTime::Read(std::ifstream &InFile)
|
||||
{
|
||||
ReadValue<uint32_t>(InFile, this->DatabaseId);
|
||||
ReadValue(InFile, this->GreenTime);
|
||||
ReadValue(InFile, this->YellowTime);
|
||||
ReadValue(InFile, this->RedTime);
|
||||
}
|
||||
|
||||
// ---------------------------------------------
|
||||
|
||||
void CarlaRecorderTrafficLightTimes::Clear(void)
|
||||
{
|
||||
TrafficLightTimes.clear();
|
||||
}
|
||||
|
||||
void CarlaRecorderTrafficLightTimes::Add(const CarlaRecorderTrafficLightTime &InObj)
|
||||
{
|
||||
TrafficLightTimes.push_back(InObj);
|
||||
}
|
||||
|
||||
void CarlaRecorderTrafficLightTimes::Write(std::ofstream &OutFile)
|
||||
{
|
||||
// write the packet id
|
||||
WriteValue<char>(OutFile, static_cast<char>(CarlaRecorderPacketId::TrafficLightTime));
|
||||
|
||||
uint32_t Total = sizeof(uint16_t) + TrafficLightTimes.size() * sizeof(CarlaRecorderTrafficLightTime);
|
||||
WriteValue<uint32_t>(OutFile, Total);
|
||||
|
||||
Total = TrafficLightTimes.size();
|
||||
WriteValue<uint16_t>(OutFile, Total);
|
||||
|
||||
for (auto& TrafficLightTime : TrafficLightTimes)
|
||||
{
|
||||
TrafficLightTime.Write(OutFile);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
// Copyright (c) 2020 Computer Vision Center (CVC) at the Universitat Autonoma
|
||||
// de Barcelona (UAB).
|
||||
//
|
||||
// This work is licensed under the terms of the MIT license.
|
||||
// For a copy, see <https://opensource.org/licenses/MIT>.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
|
||||
#pragma pack(push, 1)
|
||||
struct CarlaRecorderTrafficLightTime
|
||||
{
|
||||
uint32_t DatabaseId;
|
||||
float GreenTime = 0;
|
||||
float YellowTime = 0;
|
||||
float RedTime = 0;
|
||||
|
||||
void Read(std::ifstream &InFile);
|
||||
|
||||
void Write(std::ofstream &OutFile);
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
class CarlaRecorderTrafficLightTimes
|
||||
{
|
||||
public:
|
||||
|
||||
void Add(const CarlaRecorderTrafficLightTime &InObj);
|
||||
|
||||
void Clear(void);
|
||||
|
||||
void Write(std::ofstream &OutFile);
|
||||
|
||||
private:
|
||||
|
||||
std::vector<CarlaRecorderTrafficLightTime> TrafficLightTimes;
|
||||
};
|
|
@ -108,6 +108,7 @@ void ATrafficLightBase::SetGreenTime(float InGreenTime)
|
|||
TrafficLightComponent->GetController();
|
||||
check(TrafficLightController)
|
||||
TrafficLightController->SetGreenTime(InGreenTime);
|
||||
AddTimeToRecorder();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -133,6 +134,7 @@ void ATrafficLightBase::SetYellowTime(float InYellowTime)
|
|||
TrafficLightComponent->GetController();
|
||||
check(TrafficLightController)
|
||||
TrafficLightController->SetYellowTime(InYellowTime);
|
||||
AddTimeToRecorder();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -158,6 +160,7 @@ void ATrafficLightBase::SetRedTime(float InRedTime)
|
|||
TrafficLightComponent->GetController();
|
||||
check(TrafficLightController)
|
||||
TrafficLightController->SetRedTime(InRedTime);
|
||||
AddTimeToRecorder();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -264,6 +267,15 @@ const UTrafficLightComponent* ATrafficLightBase::GetTrafficLightComponent() cons
|
|||
return TrafficLightComponent;
|
||||
}
|
||||
|
||||
void ATrafficLightBase::AddTimeToRecorder()
|
||||
{
|
||||
auto * Recorder = UCarlaStatics::GetRecorder(GetWorld());
|
||||
if (Recorder && Recorder->IsEnabled())
|
||||
{
|
||||
Recorder->AddTrafficLightTime(*this);
|
||||
}
|
||||
}
|
||||
|
||||
void ATrafficLightBase::LightChangedCompatibility(ETrafficLightState NewLightState)
|
||||
{
|
||||
OnTrafficLightStateChanged(NewLightState);
|
||||
|
|
|
@ -88,6 +88,8 @@ public:
|
|||
// Compatibility old traffic light system with traffic light components
|
||||
void LightChangedCompatibility(ETrafficLightState NewLightState);
|
||||
|
||||
void AddTimeToRecorder();
|
||||
|
||||
protected:
|
||||
|
||||
UFUNCTION(Category = "Traffic Light", BlueprintImplementableEvent)
|
||||
|
|
Loading…
Reference in New Issue