adding --ignore-spectator to the replayer

This commit is contained in:
bernatx 2023-01-31 09:06:33 +01:00 committed by bernat
parent ed53705b5b
commit 7f5bb15731
14 changed files with 72 additions and 4 deletions

View File

@ -3,6 +3,9 @@
* Fixed bug causing the TM's unstuck logic to incorrectly remove the vehicles in some situations.
* Fixed the extra data in Directx textures, so we need to copy row by row on Windows to remove extra bytes on images
* Restored gamma value to 2.2 instead of 2.4
* Added API function to avoid replaying the spectator
* `Client.set_replayer_ignore_spectator(bool)`
* `start_replaying.py` using flag `--move-spectator`
## CARLA 0.9.14

View File

@ -137,6 +137,10 @@ namespace client {
_simulator->SetReplayerIgnoreHero(ignore_hero);
}
void SetReplayerIgnoreSpectator(bool ignore_spectator) {
_simulator->SetReplayerIgnoreSpectator(ignore_spectator);
}
void ApplyBatch(
std::vector<rpc::Command> commands,
bool do_tick_cue = false) const {

View File

@ -574,6 +574,10 @@ namespace detail {
_pimpl->AsyncCall("set_replayer_ignore_hero", ignore_hero);
}
void Client::SetReplayerIgnoreSpectator(bool ignore_spectator) {
_pimpl->AsyncCall("set_replayer_ignore_spectator", ignore_spectator);
}
void Client::SubscribeToStream(
const streaming::Token &token,
std::function<void(Buffer)> callback) {

View File

@ -362,6 +362,8 @@ namespace detail {
void SetReplayerIgnoreHero(bool ignore_hero);
void SetReplayerIgnoreSpectator(bool ignore_spectator);
void StopReplayer(bool keep_actors);
void SubscribeToStream(

View File

@ -576,6 +576,10 @@ namespace detail {
_client.SetReplayerIgnoreHero(ignore_hero);
}
void SetReplayerIgnoreSpectator(bool ignore_spectator) {
_client.SetReplayerIgnoreSpectator(ignore_spectator);
}
void StopReplayer(bool keep_actors) {
_client.StopReplayer(keep_actors);
}

View File

@ -210,6 +210,7 @@ void export_client() {
.def("stop_replayer", &cc::Client::StopReplayer, (arg("keep_actors")))
.def("set_replayer_time_factor", &cc::Client::SetReplayerTimeFactor, (arg("time_factor")))
.def("set_replayer_ignore_hero", &cc::Client::SetReplayerIgnoreHero, (arg("ignore_hero")))
.def("set_replayer_ignore_spectator", &cc::Client::SetReplayerIgnoreSpectator, (arg("ignore_spectator")))
.def("apply_batch", &ApplyBatchCommands, (arg("commands"), arg("do_tick")=false))
.def("apply_batch_sync", &ApplyBatchCommandsSync, (arg("commands"), arg("do_tick")=false))
.def("get_trafficmanager", CONST_CALL_WITHOUT_GIL_1(cc::Client, GetInstanceTM, uint16_t), (arg("port")=ctm::TM_DEFAULT_PORT))

View File

@ -71,6 +71,10 @@ def main():
'-i', '--ignore-hero',
action='store_true',
help='ignore hero vehicles')
argparser.add_argument(
'--move-spectator',
action='store_true',
help='move spectator camera')
argparser.add_argument(
'--spawn-sensors',
action='store_true',
@ -88,6 +92,9 @@ def main():
# set to ignore the hero vehicles or not
client.set_replayer_ignore_hero(args.ignore_hero)
# set to ignore the spectator camera or not
client.set_replayer_ignore_spectator(not args.move_spectator)
# replay the session
print(client.replay_file(args.recorder_filename, args.start, args.duration, args.camera, args.spawn_sensors))

View File

@ -73,6 +73,11 @@ void ACarlaRecorder::SetReplayerIgnoreHero(bool IgnoreHero)
Replayer.SetIgnoreHero(IgnoreHero);
}
void ACarlaRecorder::SetReplayerIgnoreSpectator(bool IgnoreSpectator)
{
Replayer.SetIgnoreSpectator(IgnoreSpectator);
}
void ACarlaRecorder::StopReplayer(bool KeepActors)
{
Replayer.Stop(KeepActors);

View File

@ -166,6 +166,7 @@ public:
uint32_t FollowId, bool ReplaySensors);
void SetReplayerTimeFactor(double TimeFactor);
void SetReplayerIgnoreHero(bool IgnoreHero);
void SetReplayerIgnoreSpectator(bool IgnoreSpectator);
void StopReplayer(bool KeepActors = false);
void Ticking(float DeltaSeconds);

View File

@ -175,6 +175,12 @@ std::string CarlaReplayer::ReplayFile(std::string Filename, double TimeStart, do
Info << "Replaying from " << TimeStart << " s - " << TimeToStop << " s (" << TotalTime << " s) at " <<
std::setprecision(1) << std::fixed << TimeFactor << "x" << std::endl;
if (IgnoreHero)
Info << "Ignoring Hero vehicle" << std::endl;
if (IgnoreSpectator)
Info << "Ignoring Spectator camera" << std::endl;
// set the follow Id
FollowId = ThisFollowId;
@ -446,6 +452,7 @@ void CarlaReplayer::ProcessEventsAdd(void)
EventAdd.Description,
EventAdd.DatabaseId,
IgnoreHero,
IgnoreSpectator,
bReplaySensors);
switch (Result.first)
@ -466,10 +473,16 @@ void CarlaReplayer::ProcessEventsAdd(void)
// mapping id (say desired Id is mapped to what)
MappedId[EventAdd.DatabaseId] = Result.second;
break;
// actor ignored (either Hero or Spectator)
case 3:
UE_LOG(LogCarla, Log, TEXT("ignoring actor from replayer (Hero or Spectator)"));
break;
}
// check to mark if actor is a hero vehicle or not
if (Result.first > 0)
if (Result.first > 0 && Result.first < 3)
{
// init
IsHeroMap[Result.second] = false;
@ -727,8 +740,9 @@ void CarlaReplayer::UpdatePositions(double Per, double DeltaTime)
// go through each actor and update
for (auto &Pos : CurrPos)
{
// check if ignore this actor
if (!(IgnoreHero && IsHeroMap[Pos.DatabaseId]))
// check if ignore this actor (hero) or the spectator (id == 1)
if (!(IgnoreHero && IsHeroMap[Pos.DatabaseId]) &&
!(IgnoreSpectator && Pos.DatabaseId == 1))
{
// check if exist a previous position
auto Result = TempMap.find(Pos.DatabaseId);

View File

@ -86,6 +86,12 @@ public:
IgnoreHero = InIgnoreHero;
}
// set ignore spectator
void SetIgnoreSpectator(bool InIgnoreSpectator)
{
IgnoreSpectator = InIgnoreSpectator;
}
// check if after a map is loaded, we need to replay
void CheckPlayAfterMapLoaded(void);
@ -119,6 +125,7 @@ private:
double TimeFactor { 1.0 };
// ignore hero vehicles
bool IgnoreHero { false };
bool IgnoreSpectator { true };
std::unordered_map<uint32_t, bool> IsHeroMap;
// utils

View File

@ -179,6 +179,7 @@ std::pair<int, uint32_t> CarlaReplayerHelper::ProcessReplayerEventAdd(
CarlaRecorderActorDescription Description,
uint32_t DesiredId,
bool bIgnoreHero,
bool bIgnoreSpectator,
bool ReplaySensors)
{
check(Episode != nullptr);
@ -200,6 +201,13 @@ std::pair<int, uint32_t> CarlaReplayerHelper::ProcessReplayerEventAdd(
IsHero = true;
}
// check to ignore Hero or Spectator
if ((bIgnoreHero && IsHero) ||
(bIgnoreSpectator && ActorDesc.Id.StartsWith("spectator")))
{
return std::make_pair(3, 0);
}
auto result = TryToCreateReplayerActor(
Location,
Rotation,

View File

@ -38,6 +38,7 @@ public:
CarlaRecorderActorDescription Description,
uint32_t DesiredId,
bool bIgnoreHero,
bool bIgnoreSpectator,
bool ReplaySensors);
// replay event for removing actor

View File

@ -2232,6 +2232,13 @@ void FCarlaServer::FPimpl::BindActions()
return R<void>::Success();
};
BIND_SYNC(set_replayer_ignore_spectator) << [this](bool ignore_spectator) -> R<void>
{
REQUIRE_CARLA_EPISODE();
Episode->GetRecorder()->SetReplayerIgnoreSpectator(ignore_spectator);
return R<void>::Success();
};
BIND_SYNC(stop_replayer) << [this](bool keep_actors) -> R<void>
{
REQUIRE_CARLA_EPISODE();