Limited Collision events to one

This commit is contained in:
Guillermo 2023-04-26 13:21:49 +02:00 committed by bernat
parent 9fefb127a6
commit 3f2acd3465
3 changed files with 36 additions and 14 deletions

View File

@ -3,7 +3,7 @@
* 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
* Added empty actor
* 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
* 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
* Restored gamma value to 2.2 instead of 2.4
* Added API function to avoid replaying the spectator
@ -13,6 +13,7 @@
* Added maps, vehicles, pedestrians and props catalogues to the documentation
* Add keyword arguments for `carla.TrafficManager` Python API functions
* Fixed bug causing the `FPixelReader::SavePixelsToDisk(PixelData, FilePath)` function to crash due to pixel array not set correctly.
* Collisions detected by the CollisionSensor no longer generate more than one event per frame.
## CARLA 0.9.14

View File

@ -10,6 +10,7 @@
#include "Carla/Actor/ActorBlueprintFunctionLibrary.h"
#include "Carla/Actor/ActorRegistry.h"
#include "Carla/Game/CarlaEpisode.h"
#include "Carla/Game/CarlaEngine.h"
#include "Carla/Game/CarlaGameInstance.h"
#include "Carla/Game/CarlaGameModeBase.h"
@ -44,18 +45,34 @@ void ACollisionSensor::OnCollisionEvent(
FVector NormalImpulse,
const FHitResult &Hit)
{
if ((Actor != nullptr) && (OtherActor != nullptr))
{
const auto &Episode = GetEpisode();
constexpr float TO_METERS = 1e-2;
NormalImpulse *= TO_METERS;
GetDataStream(*this).Send(
*this,
Episode.SerializeActor(Actor),
Episode.SerializeActor(OtherActor),
carla::geom::Vector3D{NormalImpulse.X, NormalImpulse.Y, NormalImpulse.Z});
// record the collision event
if (Episode.GetRecorder()->IsEnabled())
Episode.GetRecorder()->AddCollision(Actor, OtherActor);
if ((Actor == nullptr) || (OtherActor == nullptr)){
return;
}
uint64_t CurrentFrame = FCarlaEngine::GetFrameCounter();
auto CollisionRegistry_ = CollisionRegistry;
for (auto & Collision: CollisionRegistry_){
if (std::get<0>(Collision) < CurrentFrame){
auto Index = std::find(CollisionRegistry.begin(), CollisionRegistry.end(), Collision);
CollisionRegistry.erase(Index);
}
else if ((std::get<0>(Collision) == CurrentFrame) && (std::get<1>(Collision) == Actor) && (std::get<2>(Collision) == OtherActor)){
return;
}
}
const auto &Episode = GetEpisode();
constexpr float TO_METERS = 1e-2;
NormalImpulse *= TO_METERS;
GetDataStream(*this).Send(
*this,
Episode.SerializeActor(Actor),
Episode.SerializeActor(OtherActor),
carla::geom::Vector3D{NormalImpulse.X, NormalImpulse.Y, NormalImpulse.Z});
// record the collision event
if (Episode.GetRecorder()->IsEnabled()){
Episode.GetRecorder()->AddCollision(Actor, OtherActor);
}
CollisionRegistry.push_back(std::make_tuple(CurrentFrame, Actor, OtherActor));
}

View File

@ -36,4 +36,8 @@ private:
AActor *OtherActor,
FVector NormalImpulse,
const FHitResult &Hit);
/// Registry that saves all collisions. Used to avoid sending the same collision more than once per frame,
/// as the collision sensor uses the PhysX substepping tick. Helps with sensor usage and stream overload.
std::vector<std::tuple<uint64_t, AActor*, AActor*>> CollisionRegistry;
};