Pedestrians collision deisabled when using AI or in replayer

This commit is contained in:
bernatx 2023-02-17 12:42:13 +01:00 committed by bernat
parent 88f6764e6c
commit 73315d3d62
21 changed files with 161 additions and 19 deletions

View File

@ -6,6 +6,7 @@
* The spectator will be used to load tiles and actor in Large Maps when no other actors with the rolename 'ego_vehicle' or 'hero' are present. Added the `spectator_as_ego` to the `carla.WorldSettings()` to allow users to disable this behavior. * The spectator will be used to load tiles and actor in Large Maps when no other actors with the rolename 'ego_vehicle' or 'hero' are present. Added the `spectator_as_ego` to the `carla.WorldSettings()` to allow users to disable this behavior.
* Fixed the import script, where could use any other TilesInfo.txt if the destination folder has many * Fixed the import script, where could use any other TilesInfo.txt if the destination folder has many
* Restored gamma value to 2.2 instead of 2.4 * Restored gamma value to 2.2 instead of 2.4
* Pedestrians with AI or in replayer are now faster around 10x. They have collisions disabled until they hit a vehicle.
* Added API function to avoid replaying the spectator * Added API function to avoid replaying the spectator
* `Client.set_replayer_ignore_spectator(bool)` * `Client.set_replayer_ignore_spectator(bool)`
* `start_replaying.py` using flag `--move-spectator` * `start_replaying.py` using flag `--move-spectator`

View File

@ -84,6 +84,10 @@ namespace client {
GetEpisode().Lock()->SetActorSimulatePhysics(*this, enabled); GetEpisode().Lock()->SetActorSimulatePhysics(*this, enabled);
} }
void Actor::SetCollisions(const bool enabled) {
GetEpisode().Lock()->SetActorCollisions(*this, enabled);
}
void Actor::SetEnableGravity(const bool enabled) { void Actor::SetEnableGravity(const bool enabled) {
GetEpisode().Lock()->SetActorEnableGravity(*this, enabled); GetEpisode().Lock()->SetActorEnableGravity(*this, enabled);
} }

View File

@ -99,6 +99,9 @@ namespace client {
/// Enable or disable physics simulation on this actor. /// Enable or disable physics simulation on this actor.
void SetSimulatePhysics(bool enabled = true); void SetSimulatePhysics(bool enabled = true);
/// Enable or disable collisions on this actor.
void SetCollisions(bool enabled = true);
/// Enable or disable gravity on this actor. /// Enable or disable gravity on this actor.
void SetEnableGravity(bool enabled = true); void SetEnableGravity(bool enabled = true);

View File

@ -23,6 +23,9 @@ namespace client {
auto nav = GetEpisode().Lock()->GetNavigation(); auto nav = GetEpisode().Lock()->GetNavigation();
if (nav != nullptr) { if (nav != nullptr) {
nav->AddWalker(walker->GetId(), walker->GetLocation()); nav->AddWalker(walker->GetId(), walker->GetLocation());
// disable physics and collision of walker actor
GetEpisode().Lock()->SetActorSimulatePhysics(*walker, false);
GetEpisode().Lock()->SetActorCollisions(*walker, false);
} }
} }
} }

View File

@ -412,6 +412,10 @@ namespace detail {
_pimpl->CallAndWait<void>("set_actor_simulate_physics", actor, enabled); _pimpl->CallAndWait<void>("set_actor_simulate_physics", actor, enabled);
} }
void Client::SetActorCollisions(rpc::ActorId actor, const bool enabled) {
_pimpl->CallAndWait<void>("set_actor_collisions", actor, enabled);
}
void Client::SetActorEnableGravity(rpc::ActorId actor, const bool enabled) { void Client::SetActorEnableGravity(rpc::ActorId actor, const bool enabled) {
_pimpl->AsyncCall("set_actor_enable_gravity", actor, enabled); _pimpl->AsyncCall("set_actor_enable_gravity", actor, enabled);
} }

View File

@ -236,6 +236,10 @@ namespace detail {
rpc::ActorId actor, rpc::ActorId actor,
bool enabled); bool enabled);
void SetActorCollisions(
rpc::ActorId actor,
bool enabled);
void SetActorEnableGravity( void SetActorEnableGravity(
rpc::ActorId actor, rpc::ActorId actor,
bool enabled); bool enabled);

View File

@ -431,6 +431,10 @@ namespace detail {
_client.SetActorSimulatePhysics(actor.GetId(), enabled); _client.SetActorSimulatePhysics(actor.GetId(), enabled);
} }
void SetActorCollisions(Actor &actor, bool enabled) {
_client.SetActorCollisions(actor.GetId(), enabled);
}
void SetActorEnableGravity(Actor &actor, bool enabled) { void SetActorEnableGravity(Actor &actor, bool enabled) {
_client.SetActorEnableGravity(actor.GetId(), enabled); _client.SetActorEnableGravity(actor.GetId(), enabled);
} }

View File

@ -57,8 +57,24 @@ namespace detail {
commands.emplace_back(Cmd::ApplyWalkerState{ handle.walker, trans, speed }); commands.emplace_back(Cmd::ApplyWalkerState{ handle.walker, trans, speed });
} }
} }
_client.ApplyBatchSync(std::move(commands), false); _client.ApplyBatchSync(std::move(commands), false);
// check if any agent has been killed
bool alive;
for (auto handle : *walkers) {
// get the agent state
if (_nav.IsWalkerAlive(handle.walker, alive)) {
if (!alive) {
_client.SetActorCollisions(handle.walker, true);
// remove from the crowd
_nav.RemoveAgent(handle.walker);
// destroy the controller
_client.DestroyActor(handle.controller);
// unregister from list
UnregisterWalker(handle.walker, handle.controller);
}
}
}
} }
void WalkerNavigation::CheckIfWalkerExist(std::vector<WalkerHandle> walkers, const EpisodeState &state) { void WalkerNavigation::CheckIfWalkerExist(std::vector<WalkerHandle> walkers, const EpisodeState &state) {

View File

@ -862,7 +862,8 @@ namespace nav {
std::lock_guard<std::mutex> lock(_mutex); std::lock_guard<std::mutex> lock(_mutex);
ag = _crowd->getAgent(i); ag = _crowd->getAgent(i);
} }
if (!ag->active || ag->paused) {
if (!ag->active || ag->paused || ag->dead) {
continue; continue;
} }
@ -1203,5 +1204,39 @@ namespace nav {
return true; return true;
} }
bool Navigation::IsWalkerAlive(ActorId id, bool &alive) {
// check if all is ready
if (!_ready) {
return false;
}
DEBUG_ASSERT(_crowd != nullptr);
// get the internal index
auto it = _mapped_walkers_id.find(id);
if (it == _mapped_walkers_id.end()) {
return false;
}
// get the index found
int index = it->second;
if (index == -1) {
return false;
}
// get the walker
const dtCrowdAgent *agent;
{
// critical section, force single thread running this
std::lock_guard<std::mutex> lock(_mutex);
agent = _crowd->getAgent(index);
}
// mark
alive = !agent->dead;
return true;
}
} // namespace nav } // namespace nav
} // namespace carla } // namespace carla

View File

@ -108,6 +108,8 @@ namespace nav {
bool HasVehicleNear(ActorId id, float distance, carla::geom::Location direction); bool HasVehicleNear(ActorId id, float distance, carla::geom::Location direction);
/// make agent look at some location /// make agent look at some location
bool SetWalkerLookAt(ActorId id, carla::geom::Location location); bool SetWalkerLookAt(ActorId id, carla::geom::Location location);
/// return if the agent has been killed by a vehicle
bool Navigation::IsWalkerAlive(ActorId id, bool &alive);
dtCrowd *GetCrowd() { return _crowd; }; dtCrowd *GetCrowd() { return _crowd; };

View File

@ -124,6 +124,7 @@ void export_actor() {
.def("add_angular_impulse", &cc::Actor::AddAngularImpulse, (arg("angular_impulse"))) .def("add_angular_impulse", &cc::Actor::AddAngularImpulse, (arg("angular_impulse")))
.def("add_torque", &cc::Actor::AddTorque, (arg("torque"))) .def("add_torque", &cc::Actor::AddTorque, (arg("torque")))
.def("set_simulate_physics", &cc::Actor::SetSimulatePhysics, (arg("enabled") = true)) .def("set_simulate_physics", &cc::Actor::SetSimulatePhysics, (arg("enabled") = true))
.def("set_collisions", &cc::Actor::SetCollisions, (arg("enabled") = true))
.def("set_enable_gravity", &cc::Actor::SetEnableGravity, (arg("enabled") = true)) .def("set_enable_gravity", &cc::Actor::SetEnableGravity, (arg("enabled") = true))
.def("destroy", CALL_WITHOUT_GIL(cc::Actor, Destroy)) .def("destroy", CALL_WITHOUT_GIL(cc::Actor, Destroy))
.def(self_ns::str(self_ns::self)) .def(self_ns::str(self_ns::self))

View File

@ -17,6 +17,7 @@
#include "Carla/Vehicle/MovementComponents/ChronoMovementComponent.h" #include "Carla/Vehicle/MovementComponents/ChronoMovementComponent.h"
#include "Carla/Traffic/TrafficLightBase.h" #include "Carla/Traffic/TrafficLightBase.h"
#include "Carla/Game/CarlaStatics.h" #include "Carla/Game/CarlaStatics.h"
#include "Components/CapsuleComponent.h"
#include <compiler/disable-ue4-macros.h> #include <compiler/disable-ue4-macros.h>
#include <carla/rpc/AckermannControllerSettings.h> #include <carla/rpc/AckermannControllerSettings.h>
@ -578,6 +579,18 @@ ECarlaServerResponse FCarlaActor::SetActorSimulatePhysics(bool bEnabled)
return ECarlaServerResponse::Success; return ECarlaServerResponse::Success;
} }
ECarlaServerResponse FCarlaActor::SetActorCollisions(bool bEnabled)
{
if (IsDormant())
{
}
else
{
GetActor()->SetActorEnableCollision(bEnabled);
}
return ECarlaServerResponse::Success;
}
ECarlaServerResponse FCarlaActor::SetActorEnableGravity(bool bEnabled) ECarlaServerResponse FCarlaActor::SetActorEnableGravity(bool bEnabled)
{ {
if (IsDormant()) if (IsDormant())
@ -1201,12 +1214,15 @@ ECarlaServerResponse FWalkerActor::SetWalkerState(
{ {
FVector NewLocation = Transform.GetLocation(); FVector NewLocation = Transform.GetLocation();
FVector CurrentLocation = GetActorGlobalLocation(); FVector CurrentLocation = GetActorGlobalLocation();
NewLocation.Z += 90.0f; // move point up because in Unreal walker is centered in the middle height
// if difference between Z position is small, then we keep current, otherwise we set the new one // adjust position up by half of capsule height
// (to avoid Z fighting position and falling pedestrians) // (because in Unreal walker is centered at the capsule middle,
if (NewLocation.Z - CurrentLocation.Z < 100.0f) // while Recast uses the bottom point)
NewLocation.Z = CurrentLocation.Z; UCapsuleComponent* Capsule = Cast<UCapsuleComponent>(GetActor()->GetRootComponent());
if (Capsule)
{
NewLocation.Z += Capsule->GetScaledCapsuleHalfHeight();
}
FTransform NewTransform = Transform; FTransform NewTransform = Transform;
NewTransform.SetLocation(NewLocation); NewTransform.SetLocation(NewLocation);

View File

@ -225,6 +225,8 @@ public:
virtual ECarlaServerResponse SetActorSimulatePhysics(bool bEnabled); virtual ECarlaServerResponse SetActorSimulatePhysics(bool bEnabled);
virtual ECarlaServerResponse SetActorCollisions(bool bEnabled);
virtual ECarlaServerResponse SetActorEnableGravity(bool bEnabled); virtual ECarlaServerResponse SetActorEnableGravity(bool bEnabled);
// Vehicle functions // Vehicle functions

View File

@ -350,6 +350,8 @@ private:
bool SetActorSimulatePhysics(FCarlaActor &CarlaActor, bool bEnabled); bool SetActorSimulatePhysics(FCarlaActor &CarlaActor, bool bEnabled);
bool SetActorCollisions(FCarlaActor &CarlaActor, bool bEnabled);
void TickTimers(float DeltaSeconds) void TickTimers(float DeltaSeconds)
{ {
ElapsedGameTime += DeltaSeconds; ElapsedGameTime += DeltaSeconds;

View File

@ -30,6 +30,7 @@ void CarlaReplayer::Stop(bool bKeepActors)
Helper.ProcessReplayerFinish(bKeepActors, IgnoreHero, IsHeroMap); Helper.ProcessReplayerFinish(bKeepActors, IgnoreHero, IsHeroMap);
} }
if (File.is_open())
File.close(); File.close();
} }

View File

@ -218,20 +218,26 @@ std::pair<int, uint32_t> CarlaReplayerHelper::ProcessReplayerEventAdd(
if (result.first != 0) if (result.first != 0)
{ {
// disable physics and autopilot on vehicles // disable physics and autopilot on vehicles
if (result.second->GetActorType() == FCarlaActor::ActorType::Vehicle) if (result.second->GetActorType() == FCarlaActor::ActorType::Vehicle ||
result.second->GetActorType() == FCarlaActor::ActorType::Walker)
{ {
// ignore hero ? // ignore hero ?
if (!(bIgnoreHero && IsHero)) if (!(bIgnoreHero && IsHero))
{ {
// disable physics // disable physics
SetActorSimulatePhysics(result.second, false); SetActorSimulatePhysics(result.second, false);
// disable autopilot // disable collisions
result.second->GetActor()->SetActorEnableCollision(false);
// disable autopilot for vehicles
if (result.second->GetActorType() == FCarlaActor::ActorType::Vehicle)
SetActorAutopilot(result.second, false, false); SetActorAutopilot(result.second, false, false);
} }
else else
{ {
// reenable physics just in case // enable physics just in case
SetActorSimulatePhysics(result.second, true); SetActorSimulatePhysics(result.second, true);
// enable collisions
result.second->GetActor()->SetActorEnableCollision(true);
} }
} }
return std::make_pair(result.first, result.second->GetActorId()); return std::make_pair(result.first, result.second->GetActorId());

View File

@ -55,7 +55,7 @@ void FPixelReader::WritePixelsToBuffer(
RHICmdList.GetRenderQueryResult(Query, OldAbsTime, true); RHICmdList.GetRenderQueryResult(Query, OldAbsTime, true);
} }
AsyncTask(ENamedThreads::AnyNormalThreadNormalTask, [=, Readback=std::move(BackBufferReadback)]() mutable { AsyncTask(ENamedThreads::ActualRenderingThread, [=, Readback=std::move(BackBufferReadback)]() mutable {
{ {
TRACE_CPUPROFILER_EVENT_SCOPE_STR("Wait GPU transfer"); TRACE_CPUPROFILER_EVENT_SCOPE_STR("Wait GPU transfer");
while (!Readback->IsReady()) while (!Readback->IsReady())

View File

@ -1384,6 +1384,31 @@ void FCarlaServer::FPimpl::BindActions()
return R<void>::Success(); return R<void>::Success();
}; };
BIND_SYNC(set_actor_collisions) << [this](
cr::ActorId ActorId,
bool bEnabled) -> R<void>
{
REQUIRE_CARLA_EPISODE();
FCarlaActor* CarlaActor = Episode->FindCarlaActor(ActorId);
if (!CarlaActor)
{
return RespondError(
"set_actor_collisions",
ECarlaServerResponse::ActorNotFound,
" Actor Id: " + FString::FromInt(ActorId));
}
ECarlaServerResponse Response =
CarlaActor->SetActorCollisions(bEnabled);
if (Response != ECarlaServerResponse::Success)
{
return RespondError(
"set_actor_collisions",
Response,
" Actor Id: " + FString::FromInt(ActorId));
}
return R<void>::Success();
};
BIND_SYNC(set_actor_enable_gravity) << [this]( BIND_SYNC(set_actor_enable_gravity) << [this](
cr::ActorId ActorId, cr::ActorId ActorId,
bool bEnabled) -> R<void> bool bEnabled) -> R<void>

View File

@ -826,10 +826,23 @@ void ACarlaWheeledVehicle::ShowDebugTelemetry(bool Enabled)
} }
void ACarlaWheeledVehicle::SetVehicleLightState(const FVehicleLightState &LightState) void ACarlaWheeledVehicle::SetVehicleLightState(const FVehicleLightState &LightState)
{
if (LightState.Position != InputControl.LightState.Position ||
LightState.LowBeam != InputControl.LightState.LowBeam ||
LightState.HighBeam != InputControl.LightState.HighBeam ||
LightState.Brake != InputControl.LightState.Brake ||
LightState.RightBlinker != InputControl.LightState.RightBlinker ||
LightState.LeftBlinker != InputControl.LightState.LeftBlinker ||
LightState.Reverse != InputControl.LightState.Reverse ||
LightState.Fog != InputControl.LightState.Fog ||
LightState.Interior != InputControl.LightState.Interior ||
LightState.Special1 != InputControl.LightState.Special1 ||
LightState.Special2 != InputControl.LightState.Special2)
{ {
InputControl.LightState = LightState; InputControl.LightState = LightState;
RefreshLightState(LightState); RefreshLightState(LightState);
} }
}
void ACarlaWheeledVehicle::SetFailureState(const carla::rpc::VehicleFailureState &InFailureState) void ACarlaWheeledVehicle::SetFailureState(const carla::rpc::VehicleFailureState &InFailureState)
{ {

View File

@ -274,8 +274,8 @@ unset GTEST_BASENAME
# -- Get Recast&Detour and compile it with libc++ ------------------------------ # -- Get Recast&Detour and compile it with libc++ ------------------------------
# ============================================================================== # ==============================================================================
RECAST_HASH=0b13b0 RECAST_HASH=22dfcb
RECAST_COMMIT=0b13b0d288ac96fdc5347ee38299511c6e9400db RECAST_COMMIT=22dfcb46204df1a07f696ae3d9efc76f718ea531
RECAST_BASENAME=recast-${RECAST_HASH}-${CXX_TAG} RECAST_BASENAME=recast-${RECAST_HASH}-${CXX_TAG}
RECAST_INCLUDE=${PWD}/${RECAST_BASENAME}-install/include RECAST_INCLUDE=${PWD}/${RECAST_BASENAME}-install/include

View File

@ -35,8 +35,8 @@ rem If not set set the build dir to the current dir
if "%BUILD_DIR%" == "" set BUILD_DIR=%~dp0 if "%BUILD_DIR%" == "" set BUILD_DIR=%~dp0
if not "%BUILD_DIR:~-1%"=="\" set BUILD_DIR=%BUILD_DIR%\ if not "%BUILD_DIR:~-1%"=="\" set BUILD_DIR=%BUILD_DIR%\
set RECAST_HASH=0b13b0 set RECAST_HASH=22dfcb
set RECAST_COMMIT=0b13b0d288ac96fdc5347ee38299511c6e9400db set RECAST_COMMIT=22dfcb46204df1a07f696ae3d9efc76f718ea531
set RECAST_SRC=recast-%RECAST_HASH%-src set RECAST_SRC=recast-%RECAST_HASH%-src
set RECAST_SRC_DIR=%BUILD_DIR%%RECAST_SRC%\ set RECAST_SRC_DIR=%BUILD_DIR%%RECAST_SRC%\
set RECAST_INSTALL=recast-%RECAST_HASH%-install set RECAST_INSTALL=recast-%RECAST_HASH%-install