We can save in any folder now, or by default at 'Saved' folder.

This commit is contained in:
bernatx 2019-03-11 14:34:34 +01:00
parent 702474f764
commit bac4060eb1
9 changed files with 68 additions and 35 deletions

View File

@ -415,7 +415,9 @@ converted to OpenDrive format, and saved to disk as such.
CARLA includes now a recording and replaying API, that allows to record a simulation in a file and later replay that simulation. The file is written on server side only, and it includes which **actors are created or destroyed** in the simulation, the **state of the traffic lights** and the **position/orientation** of all vehicles and walkers.
All data is written in a binary file on the server, on folder **CarlaUE4/Saved**. As estimation, a simulation with about 150 actors (50 traffic lights, 100 vehicles) for 1h of recording takes around 200 Mb in size.
All data is written in a binary file on the server. We can use filenames with or without a path. If we specify a filename without any of '\\', '/' or ':' characters, then it is considered to be only a filename and will be saved on folder **CarlaUE4/Saved**. If we use any of the previous characters then the filename will be considered as an absolute filename with path (for example: '/home/carla/recording01.log' or 'c:\\records\\recording01.log').
As estimation, a simulation with about 150 actors (50 traffic lights, 100 vehicles) for 1h of recording takes around 200 Mb in size.
To start recording we only need to supply a file name:

View File

@ -221,11 +221,10 @@ void UCarlaEpisode::EndPlay(void)
std::string UCarlaEpisode::StartRecorder(std::string Name)
{
std::string result;
FString Name2(Name.c_str());
if (Recorder)
{
result = Recorder->Start(FPaths::ConvertRelativePathToFull(FPaths::ProjectSavedDir()), Name2, MapName);
result = Recorder->Start(Name, MapName);
}
else
{

View File

@ -6,6 +6,7 @@
// #include "Carla.h"
#include "CarlaRecorder.h"
#include "CarlaReplayerHelper.h"
#include "Carla/Actor/ActorDescription.h"
#include <ctime>
@ -24,25 +25,25 @@ ACarlaRecorder::ACarlaRecorder(const FObjectInitializer &ObjectInitializer)
Disable();
}
std::string ACarlaRecorder::ShowFileInfo(std::string Path, std::string Name)
std::string ACarlaRecorder::ShowFileInfo(std::string Name)
{
return Query.QueryInfo(Path + Name);
return Query.QueryInfo(Name);
}
std::string ACarlaRecorder::ShowFileCollisions(std::string Path, std::string Name, char Type1, char Type2)
std::string ACarlaRecorder::ShowFileCollisions(std::string Name, char Type1, char Type2)
{
return Query.QueryCollisions(Path + Name, Type1, Type2);
return Query.QueryCollisions(Name, Type1, Type2);
}
std::string ACarlaRecorder::ShowFileActorsBlocked(std::string Path, std::string Name, double MinTime, double MinDistance)
std::string ACarlaRecorder::ShowFileActorsBlocked(std::string Name, double MinTime, double MinDistance)
{
return Query.QueryBlocked(Path + Name, MinTime, MinDistance);
return Query.QueryBlocked(Name, MinTime, MinDistance);
}
std::string ACarlaRecorder::ReplayFile(std::string Path, std::string Name, double TimeStart, double Duration, uint32_t FollowId)
std::string ACarlaRecorder::ReplayFile(std::string Name, double TimeStart, double Duration, uint32_t FollowId)
{
Stop();
return Replayer.ReplayFile(Path + Name, TimeStart, Duration, FollowId);
return Replayer.ReplayFile(Name, TimeStart, Duration, FollowId);
}
inline void ACarlaRecorder::SetReplayerSpeed(double TimeFactor)
@ -125,7 +126,7 @@ void ACarlaRecorder::Disable(void)
Enabled = false;
}
std::string ACarlaRecorder::Start(FString Path, FString Name, FString MapName)
std::string ACarlaRecorder::Start(std::string Name, FString MapName)
{
// stop replayer if any in course
if (Replayer.IsEnabled())
@ -134,13 +135,16 @@ std::string ACarlaRecorder::Start(FString Path, FString Name, FString MapName)
// stop recording
Stop();
// reset collisions Id
NextCollisionId = 0;
FString Filename = Path + Name;
// get the final path + filename
std::string Filename = GetRecorderFilename(Name);
// binary file
// file.open(filename.str(), std::ios::binary | std::ios::trunc |
// std::ios::out);
File.open(TCHAR_TO_UTF8(*Filename), std::ios::binary);
File.open(Filename, std::ios::binary);
if (!File.is_open())
{
return "";
@ -162,7 +166,7 @@ std::string ACarlaRecorder::Start(FString Path, FString Name, FString MapName)
// add all existing actors
AddExistingActors();
return std::string(TCHAR_TO_UTF8(*Filename));
return std::string(Filename);
}
void ACarlaRecorder::Stop(void)

View File

@ -58,7 +58,7 @@ public:
void Disable(void);
// start / stop
std::string Start(FString Path, FString Name, FString MapName);
std::string Start(std::string Name, FString MapName);
void Stop(void);
@ -98,11 +98,11 @@ public:
return &Replayer;
}
// forwarded to replayer
std::string ShowFileInfo(std::string Path, std::string Name);
std::string ShowFileCollisions(std::string Path, std::string Name, char Type1, char Type2);
std::string ShowFileActorsBlocked(std::string Path, std::string Name, double MinTime = 30, double MinDistance = 10);
std::string ReplayFile(std::string Path, std::string Name, double TimeStart, double Duration, uint32_t FollowId);
// queries
std::string ShowFileInfo(std::string Name);
std::string ShowFileCollisions(std::string Name, char Type1, char Type2);
std::string ShowFileActorsBlocked(std::string Name, double MinTime = 30, double MinDistance = 10);
std::string ReplayFile(std::string Name, double TimeStart, double Duration, uint32_t FollowId);
void SetReplayerSpeed(double TimeFactor);
void Tick(float DeltaSeconds) final;

View File

@ -12,6 +12,23 @@
// create a temporal buffer to convert from and to FString and bytes
static std::vector<uint8_t> CarlaRecorderHelperBuffer;
// get the final path + filename
std::string GetRecorderFilename(std::string Filename)
{
std::string Filename2;
// check if a relative path was specified
if (Filename.find("\\") != std::string::npos || Filename.find("/") != std::string::npos || Filename.find(":") != std::string::npos)
Filename2 = Filename;
else
{
FString Path = FPaths::ConvertRelativePathToFull(FPaths::ProjectSavedDir());
Filename2 = TCHAR_TO_UTF8(*Path) + Filename;
}
return Filename2;
}
// ------
// write
// ------

View File

@ -8,6 +8,9 @@
#include <fstream>
// get the final path + filename
std::string GetRecorderFilename(std::string Filename);
// ---------
// recorder
// ---------

View File

@ -54,11 +54,14 @@ std::string CarlaRecorderQuery::QueryInfo(std::string Filename, bool bShowAll)
{
std::stringstream Info;
// get the final path + filename
std::string Filename2 = GetRecorderFilename(Filename);
// try to open
File.open(Filename, std::ios::binary);
File.open(Filename2, std::ios::binary);
if (!File.is_open())
{
Info << "File " << Filename << " not found on server\n";
Info << "File " << Filename2 << " not found on server\n";
return Info.str();
}
@ -220,11 +223,14 @@ std::string CarlaRecorderQuery::QueryCollisions(std::string Filename, char Categ
{
std::stringstream Info;
// get the final path + filename
std::string Filename2 = GetRecorderFilename(Filename);
// try to open
File.open(Filename, std::ios::binary);
File.open(Filename2, std::ios::binary);
if (!File.is_open())
{
Info << "File " << Filename << " not found on server\n";
Info << "File " << Filename2 << " not found on server\n";
return Info.str();
}
@ -393,11 +399,14 @@ std::string CarlaRecorderQuery::QueryBlocked(std::string Filename, double MinTim
{
std::stringstream Info;
// get the final path + filename
std::string Filename2 = GetRecorderFilename(Filename);
// try to open
File.open(Filename, std::ios::binary);
File.open(Filename2, std::ios::binary);
if (!File.is_open())
{
Info << "File " << Filename << " not found on server\n";
Info << "File " << Filename2 << " not found on server\n";
return Info.str();
}

View File

@ -111,13 +111,16 @@ std::string CarlaReplayer::ReplayFile(std::string Filename, double TimeStart, do
Stop();
}
Info << "Replaying File: " << Filename << std::endl;
// get the final path + filename
std::string Filename2 = GetRecorderFilename(Filename);
Info << "Replaying File: " << Filename2 << std::endl;
// try to open
File.open(Filename, std::ios::binary);
File.open(Filename2, std::ios::binary);
if (!File.is_open())
{
Info << "File " << Filename << " not found on server\n";
Info << "File " << Filename2 << " not found on server\n";
Stop();
return Info.str();
}
@ -139,7 +142,7 @@ std::string CarlaReplayer::ReplayFile(std::string Filename, double TimeStart, do
// prepare autoplay after map is loaded
Autoplay.Enabled = true;
Autoplay.Filename = Filename;
Autoplay.Filename = Filename2;
Autoplay.Mapfile = RecInfo.Mapfile;
Autoplay.TimeStart = TimeStart;
Autoplay.Duration = Duration;

View File

@ -726,7 +726,6 @@ void FTheNewCarlaServer::FPimpl::BindActions()
{
REQUIRE_CARLA_EPISODE();
return R<std::string>(Episode->GetRecorder()->ShowFileInfo(
carla::rpc::FromFString(FPaths::ConvertRelativePathToFull(FPaths::ProjectSavedDir())),
name));
};
@ -734,7 +733,6 @@ void FTheNewCarlaServer::FPimpl::BindActions()
{
REQUIRE_CARLA_EPISODE();
return R<std::string>(Episode->GetRecorder()->ShowFileCollisions(
carla::rpc::FromFString(FPaths::ConvertRelativePathToFull(FPaths::ProjectSavedDir())),
name,
type1,
type2));
@ -744,7 +742,6 @@ void FTheNewCarlaServer::FPimpl::BindActions()
{
REQUIRE_CARLA_EPISODE();
return R<std::string>(Episode->GetRecorder()->ShowFileActorsBlocked(
carla::rpc::FromFString(FPaths::ConvertRelativePathToFull(FPaths::ProjectSavedDir())),
name,
min_time,
min_distance));
@ -754,7 +751,6 @@ void FTheNewCarlaServer::FPimpl::BindActions()
{
REQUIRE_CARLA_EPISODE();
return R<std::string>(Episode->GetRecorder()->ReplayFile(
carla::rpc::FromFString(FPaths::ConvertRelativePathToFull(FPaths::ProjectSavedDir())),
name,
start,
duration,