Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* Fixed bug causing the Traffic Manager to not be deterministic when using hybrid mode
* Added `NormalsSensor`, a new sensor with normals information
* Added support for N wheeled vehicles
* Added weather events to recordings for replaying and querying

## CARLA 0.9.13

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "Carla/Walker/WalkerControl.h"
#include "Carla/Walker/WalkerController.h"
#include "Components/BoxComponent.h"
#include "Carla/Weather/Weather.h"

#include <compiler/disable-ue4-macros.h>
#include "carla/rpc/VehicleLightState.h"
Expand Down Expand Up @@ -318,6 +319,13 @@ void ACarlaRecorder::AddTrafficLightTime(const ATrafficLightBase& TrafficLight)
}
}

void ACarlaRecorder::AddWeather(const FWeatherParameters& WeatherParams)
{
CarlaRecorderWeather Weather;
Weather.Params = WeatherParams;
Weathers.Add(Weather);
}

std::string ACarlaRecorder::Start(std::string Name, FString MapName, bool AdditionalData)
{
// stop replayer if any in course
Expand Down Expand Up @@ -359,6 +367,9 @@ std::string ACarlaRecorder::Start(std::string Name, FString MapName, bool Additi
// add all existing actors
AddExistingActors();

// add current weather for start of recording
AddStartingWeather();

return std::string(Filename);
}

Expand Down Expand Up @@ -391,6 +402,7 @@ void ACarlaRecorder::Clear(void)
TriggerVolumes.Clear();
PhysicsControls.Clear();
TrafficLightTimes.Clear();
Weathers.Clear();
}

void ACarlaRecorder::Write(double DeltaSeconds)
Expand Down Expand Up @@ -428,6 +440,9 @@ void ACarlaRecorder::Write(double DeltaSeconds)
TrafficLightTimes.Write(File);
}

// weather state
Weathers.Write(File);

// end
Frames.WriteEnd(File);

Expand Down Expand Up @@ -608,6 +623,15 @@ void ACarlaRecorder::AddExistingActors(void)

}

void ACarlaRecorder::AddStartingWeather(void)
{
AWeather *Weather = AWeather::FindWeatherInstance(Episode->GetWorld());
if (Weather)
{
AddWeather(Weather->GetCurrentWeather());
}
}

void ACarlaRecorder::CreateRecorderEventAdd(
uint32_t DatabaseId,
uint8_t Type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "CarlaRecorderPosition.h"
#include "CarlaRecorderQuery.h"
#include "CarlaRecorderState.h"
#include "CarlaRecorderWeather.h"
#include "CarlaReplayer.h"

#include "CarlaRecorder.generated.h"
Expand Down Expand Up @@ -59,7 +60,8 @@ enum class CarlaRecorderPacketId : uint8_t
PlatformTime,
PhysicsControl,
TrafficLightTime,
TriggerVolume
TriggerVolume,
Weather
};

/// Recorder for the simulation
Expand Down Expand Up @@ -122,6 +124,8 @@ class CARLA_API ACarlaRecorder : public AActor

void AddTrafficLightTime(const ATrafficLightBase& TrafficLight);

void AddWeather(const FWeatherParameters& WeatherParams);

// set episode
void SetEpisode(UCarlaEpisode *ThisEpisode)
{
Expand Down Expand Up @@ -188,6 +192,7 @@ class CARLA_API ACarlaRecorder : public AActor
CarlaRecorderPlatformTime PlatformTime;
CarlaRecorderPhysicsControls PhysicsControls;
CarlaRecorderTrafficLightTimes TrafficLightTimes;
CarlaRecorderWeathers Weathers;


// replayer
Expand All @@ -197,6 +202,7 @@ class CARLA_API ACarlaRecorder : public AActor
CarlaRecorderQuery Query;

void AddExistingActors(void);
void AddStartingWeather(void);
void AddActorPosition(FCarlaActor *CarlaActor);
void AddWalkerAnimation(FCarlaActor *CarlaActor);
void AddVehicleAnimation(FCarlaActor *CarlaActor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,27 @@ std::string CarlaRecorderQuery::QueryInfo(std::string Filename, bool bShowAll)
SkipPacket();
break;

case static_cast<char>(CarlaRecorderPacketId::Weather):
if (bShowAll)
{
ReadValue<uint16_t>(File, Total);
if (Total > 0 && !bFramePrinted)
{
PrintFrame(Info);
bFramePrinted = true;
}

Info << " Weather events: " << Total << std::endl;
for (i = 0; i < Total; ++i)
{
Weather.Read(File);
Info << " " << Weather.Print() << std::endl;
}
}
else
SkipPacket();
break;

// frame end
case static_cast<char>(CarlaRecorderPacketId::FrameEnd):
// do nothing, it is empty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "CarlaRecorderInfo.h"
#include "CarlaRecorderPosition.h"
#include "CarlaRecorderState.h"
#include "CarlaRecorderWeather.h"

class CarlaRecorderQuery
{
Expand Down Expand Up @@ -66,6 +67,7 @@ class CarlaRecorderQuery
CarlaRecorderPlatformTime PlatformTime;
CarlaRecorderPhysicsControl PhysicsControl;
CarlaRecorderTrafficLightTime TrafficLightTime;
CarlaRecorderWeather Weather;

// read next header packet
bool ReadHeader(void);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// 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 "CarlaRecorderWeather.h"
#include "CarlaRecorder.h"
#include "CarlaRecorderHelpers.h"


void CarlaRecorderWeather::Write(std::ofstream &OutFile) const
{
WriteValue<float>(OutFile, this->Params.Cloudiness);
WriteValue<float>(OutFile, this->Params.Precipitation);
WriteValue<float>(OutFile, this->Params.PrecipitationDeposits);
WriteValue<float>(OutFile, this->Params.WindIntensity);
WriteValue<float>(OutFile, this->Params.SunAzimuthAngle);
WriteValue<float>(OutFile, this->Params.SunAltitudeAngle);
WriteValue<float>(OutFile, this->Params.FogDensity);
WriteValue<float>(OutFile, this->Params.FogDistance);
WriteValue<float>(OutFile, this->Params.FogFalloff);
WriteValue<float>(OutFile, this->Params.Wetness);
WriteValue<float>(OutFile, this->Params.ScatteringIntensity);
WriteValue<float>(OutFile, this->Params.MieScatteringScale);
WriteValue<float>(OutFile, this->Params.RayleighScatteringScale);
}

void CarlaRecorderWeather::Read(std::ifstream &InFile)
{
ReadValue<float>(InFile, this->Params.Cloudiness);
ReadValue<float>(InFile, this->Params.Precipitation);
ReadValue<float>(InFile, this->Params.PrecipitationDeposits);
ReadValue<float>(InFile, this->Params.WindIntensity);
ReadValue<float>(InFile, this->Params.SunAzimuthAngle);
ReadValue<float>(InFile, this->Params.SunAltitudeAngle);
ReadValue<float>(InFile, this->Params.FogDensity);
ReadValue<float>(InFile, this->Params.FogDistance);
ReadValue<float>(InFile, this->Params.FogFalloff);
ReadValue<float>(InFile, this->Params.Wetness);
ReadValue<float>(InFile, this->Params.ScatteringIntensity);
ReadValue<float>(InFile, this->Params.MieScatteringScale);
ReadValue<float>(InFile, this->Params.RayleighScatteringScale);
}

std::string CarlaRecorderWeather::Print() const
{
std::ostringstream oss;
oss << TCHAR_TO_UTF8(*Params.ToString());
return oss.str();
}

// ---------------------------------------------

void CarlaRecorderWeathers::Clear(void)
{
Weathers.clear();
}

void CarlaRecorderWeathers::Add(const CarlaRecorderWeather &Weather)
{
Weathers.push_back(Weather);
}

void CarlaRecorderWeathers::Write(std::ofstream &OutFile) const
{
if (Weathers.size() == 0)
{
return;
}
// write the packet id
WriteValue<char>(OutFile, static_cast<char>(CarlaRecorderPacketId::Weather));

std::streampos PosStart = OutFile.tellp();

// write a dummy packet size
uint32_t Total = 2 + Weathers.size() * sizeof(CarlaRecorderWeather);
WriteValue<uint32_t>(OutFile, Total);

// write total records
Total = Weathers.size();
WriteValue<uint16_t>(OutFile, Total);

for (auto& Weather : Weathers)
{
Weather.Write(OutFile);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// 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>
#include "Carla/Weather/WeatherParameters.h"

#pragma pack(push, 1)
struct CarlaRecorderWeather
{

FWeatherParameters Params;

void Read(std::ifstream &InFile);

void Write(std::ofstream &OutFile) const;

std::string Print() const;
};
#pragma pack(pop)

struct CarlaRecorderWeathers
{
public:

void Add(const CarlaRecorderWeather &InObj);

void Clear(void);

void Write(std::ofstream &OutFile) const;

private:

std::vector<CarlaRecorderWeather> Weathers;
};
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,11 @@ void CarlaReplayer::ProcessToTime(double Time, bool IsFirstTime)
SkipPacket();
break;

// weather state
case static_cast<char>(CarlaRecorderPacketId::Weather):
ProcessWeather();
break;

// frame end
case static_cast<char>(CarlaRecorderPacketId::FrameEnd):
if (bFrameFound)
Expand Down Expand Up @@ -574,6 +579,20 @@ void CarlaReplayer::ProcessLightScene(void)
}
}

void CarlaReplayer::ProcessWeather(void)
{
uint16_t Total;
CarlaRecorderWeather Weather;

// read Total light events
ReadValue<uint16_t>(File, Total);
for (uint16_t i = 0; i < Total; ++i)
{
Weather.Read(File);
Helper.ProcessReplayerWeather(Weather);
}
}

void CarlaReplayer::ProcessPositions(bool IsFirstTime)
{
uint16_t i, Total;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ class CarlaReplayer
void ProcessLightVehicle(void);
void ProcessLightScene(void);

void ProcessWeather(void);

// positions
void UpdatePositions(double Per, double DeltaTime);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "Carla/Game/CarlaStatics.h"
#include "Carla/MapGen/LargeMapManager.h"
#include "Components/BoxComponent.h"
#include "Carla/Weather/Weather.h"

#include <compiler/disable-ue4-macros.h>
#include <carla/rpc/VehicleLightState.h>
Expand Down Expand Up @@ -413,6 +414,16 @@ void CarlaReplayerHelper::ProcessReplayerLightScene(CarlaRecorderLightScene Ligh
}
}

void CarlaReplayerHelper::ProcessReplayerWeather(const CarlaRecorderWeather &RecordedWeather)
{
check(Episode != nullptr);
AWeather *Weather = AWeather::FindWeatherInstance(Episode->GetWorld());
if (Weather)
{
Weather->ApplyWeather(RecordedWeather.Params);
}
}

// set the animation for walkers
void CarlaReplayerHelper::ProcessReplayerAnimWalker(CarlaRecorderAnimWalker Walker)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "CarlaRecorderAnimVehicle.h"
#include "CarlaRecorderLightVehicle.h"
#include "CarlaRecorderLightScene.h"
#include "CarlaRecorderWeather.h"

#include <unordered_map>

Expand Down Expand Up @@ -64,6 +65,9 @@ class CarlaReplayerHelper
// set scene lights
void ProcessReplayerLightScene(CarlaRecorderLightScene LightScene);

// set weather
void ProcessReplayerWeather(const CarlaRecorderWeather &RecordedWeather);

// replay finish
bool ProcessReplayerFinish(bool bApplyAutopilot, bool bIgnoreHero, std::unordered_map<uint32_t, bool> &IsHero);

Expand Down
Loading