From c461f901cf5e76357b7ef1da0da0c20b5fb584d9 Mon Sep 17 00:00:00 2001 From: javiergrCS <139075626+javiergrCS@users.noreply.github.com> Date: Thu, 23 Nov 2023 09:36:43 +0100 Subject: [PATCH] Javiergr cs/recorder doors (#6922) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix a typo in setting the max brake From self._max_steer to self._max_brake * Fix example commands in Multi-GPU docs Only one dash before `-nullrhi` argument * Correct incoherent structuring of tutorial for adding sensor to CARLA. * Add contribution to CHANGELOG.md * Add notes into breakout boxes in sensor create tutorial. * Update build_linux.md Change pseudopath to linux format * Update build_linux.md The same change 1 line above * Fixing Recast pulling by branch instead of hash id * Added functionality to the recorder to add door state info * Final update * Correction CarlaRecorder.h * Include correction CarlaRecorderQuery.cpp * Last correction * Changelog update * Last corrections --------- Co-authored-by: kykim0 Co-authored-by: bernatx Co-authored-by: Paul Erik Frivold Co-authored-by: Balázs Kis Co-authored-by: matejm42 <116560704+matejm42@users.noreply.github.com> Co-authored-by: Blyron <53337103+Blyron@users.noreply.github.com> --- CHANGELOG.md | 4 + .../Source/Carla/Recorder/CarlaRecorder.cpp | 19 +++++ .../Source/Carla/Recorder/CarlaRecorder.h | 8 ++ .../Recorder/CarlaRecorderDoorVehicle.cpp | 75 +++++++++++++++++++ .../Carla/Recorder/CarlaRecorderDoorVehicle.h | 45 +++++++++++ .../Carla/Recorder/CarlaRecorderQuery.cpp | 45 +++++++++++ .../Carla/Recorder/CarlaRecorderQuery.h | 2 + .../Source/Carla/Recorder/CarlaReplayer.cpp | 27 +++++++ .../Source/Carla/Recorder/CarlaReplayer.h | 2 + .../Carla/Recorder/CarlaReplayerHelper.cpp | 18 +++++ .../Carla/Recorder/CarlaReplayerHelper.h | 4 + .../Carla/Settings/CarlaSettingsDelegate.cpp | 2 +- .../Carla/Vehicle/CarlaWheeledVehicle.cpp | 12 +++ .../Carla/Vehicle/CarlaWheeledVehicle.h | 3 + 14 files changed, 265 insertions(+), 1 deletion(-) create mode 100644 Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaRecorderDoorVehicle.cpp create mode 100644 Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaRecorderDoorVehicle.h diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e25a3c61..56073502d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## Latest + + * Added vehicle doors to the recorder + ## CARLA 0.9.15 * Added Digital Twins feature version 0.1. Now you can create your own map based on OpenStreetMaps diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaRecorder.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaRecorder.cpp index 50cadabd8..596e8473f 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaRecorder.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaRecorder.cpp @@ -304,6 +304,15 @@ void ACarlaRecorder::AddVehicleLight(FCarlaActor *CarlaActor) AddLightVehicle(LightVehicle); } +void ACarlaRecorder::AddVehicleDoor(const ACarlaWheeledVehicle &Vehicle, const EVehicleDoor SDoors, bool bIsOpen) +{ + CarlaRecorderDoorVehicle DoorVehicle; + DoorVehicle.DatabaseId = Episode->GetActorRegistry().FindCarlaActor(&Vehicle)->GetActorId(); + DoorVehicle.Doors = static_cast(SDoors); + DoorVehicle.bIsOpen = bIsOpen; + AddDoorVehicle(DoorVehicle); +} + void ACarlaRecorder::AddActorKinematics(FCarlaActor *CarlaActor) { check(CarlaActor != nullptr); @@ -478,6 +487,7 @@ void ACarlaRecorder::Clear(void) PhysicsControls.Clear(); TrafficLightTimes.Clear(); WalkersBones.Clear(); + DoorVehicles.Clear(); Wheels.Clear(); Bikers.Clear(); } @@ -496,6 +506,7 @@ void ACarlaRecorder::Write(double DeltaSeconds) EventsDel.Write(File); EventsParent.Write(File); Collisions.Write(File); + DoorVehicles.Write(File); // positions and states Positions.Write(File); @@ -652,6 +663,14 @@ void ACarlaRecorder::AddLightVehicle(const CarlaRecorderLightVehicle &LightVehic } } +void ACarlaRecorder::AddDoorVehicle(const CarlaRecorderDoorVehicle &DoorVehicle) +{ + if (Enabled) + { + DoorVehicles.Add(DoorVehicle); + } +} + void ACarlaRecorder::AddEventLightSceneChanged(const UCarlaLight* Light) { if (Enabled) diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaRecorder.h b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaRecorder.h index f6662d254..12f527728 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaRecorder.h +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaRecorder.h @@ -33,7 +33,9 @@ #include "CarlaRecorderState.h" #include "CarlaRecorderVisualTime.h" #include "CarlaRecorderWalkerBones.h" +#include "CarlaRecorderDoorVehicle.h" #include "CarlaReplayer.h" +#include "Carla/Vehicle/CarlaWheeledVehicle.h" #include "CarlaRecorder.generated.h" @@ -67,6 +69,7 @@ enum class CarlaRecorderPacketId : uint8_t FrameCounter, WalkerBones, VisualTime, + VehicleDoor, AnimVehicleWheels, AnimBiker }; @@ -137,6 +140,10 @@ public: void AddActorBones(FCarlaActor *CarlaActor); + void AddVehicleDoor(const ACarlaWheeledVehicle& Vehicle, const EVehicleDoor SDoors, bool bIsOpen); + + void AddDoorVehicle(const CarlaRecorderDoorVehicle &DoorVehicle); + // set episode void SetEpisode(UCarlaEpisode *ThisEpisode) { @@ -208,6 +215,7 @@ private: CarlaRecorderTrafficLightTimes TrafficLightTimes; CarlaRecorderWalkersBones WalkersBones; CarlaRecorderVisualTime VisualTime; + CarlaRecorderDoorVehicles DoorVehicles; // replayer CarlaReplayer Replayer; diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaRecorderDoorVehicle.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaRecorderDoorVehicle.cpp new file mode 100644 index 000000000..ab6da8860 --- /dev/null +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaRecorderDoorVehicle.cpp @@ -0,0 +1,75 @@ +// Copyright (c) 2023 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 . + +#include "CarlaRecorderDoorVehicle.h" +#include "CarlaRecorder.h" +#include "CarlaRecorderHelpers.h" + + +void CarlaRecorderDoorVehicle::Write(std::ostream &OutFile) +{ + // database id + WriteValue(OutFile, this->DatabaseId); + WriteValue(OutFile, this->Doors); + WriteValue(OutFile, this->bIsOpen); +} +void CarlaRecorderDoorVehicle::Read(std::istream &InFile) +{ + // database id + ReadValue(InFile, this->DatabaseId); + ReadValue(InFile, this->Doors); + ReadValue(InFile, this->bIsOpen); +} + +// --------------------------------------------- + +void CarlaRecorderDoorVehicles::Clear(void) +{ + Vehicles.clear(); +} + +void CarlaRecorderDoorVehicles::Add(const CarlaRecorderDoorVehicle &Vehicle) +{ + Vehicles.push_back(Vehicle); +} + +void CarlaRecorderDoorVehicles::Write(std::ostream &OutFile) +{ + // write the packet id + WriteValue(OutFile, static_cast(CarlaRecorderPacketId::VehicleDoor)); + + // write a dummy packet size + uint32_t Total = 2 + Vehicles.size() * sizeof(CarlaRecorderDoorVehicle); + WriteValue(OutFile, Total); + + // write total records + Total = Vehicles.size(); + WriteValue(OutFile, Total); + + for (auto& Vehicle : Vehicles) + { + Vehicle.Write(OutFile); + } +} + +void CarlaRecorderDoorVehicles::Read(std::istream &InFile) +{ + uint16_t Total; + CarlaRecorderDoorVehicle DoorVehicle; + + // read Total walkers + ReadValue(InFile, Total); + for (uint16_t i = 0; i < Total; ++i) + { + DoorVehicle.Read(InFile); + Add(DoorVehicle); + } +} + +const std::vector& CarlaRecorderDoorVehicles::GetDoorVehicles() +{ + return Vehicles; +} diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaRecorderDoorVehicle.h b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaRecorderDoorVehicle.h new file mode 100644 index 000000000..0ba395f47 --- /dev/null +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaRecorderDoorVehicle.h @@ -0,0 +1,45 @@ +// Copyright (c) 2023 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 . + +#pragma once + +#include +#include +#include + +#pragma pack(push, 1) +struct CarlaRecorderDoorVehicle +{ + // Use same type as carla::vehicle::CarlaWheeledVehicle::EVehicleDoor + using VehicleDoorType = uint8_t; + + uint32_t DatabaseId; + VehicleDoorType Doors; + bool bIsOpen; + + void Read(std::istream &InFile); + + void Write(std::ostream &OutFile); +}; +#pragma pack(pop) + +struct CarlaRecorderDoorVehicles +{ +public: + + void Add(const CarlaRecorderDoorVehicle &InObj); + + void Clear(void); + + void Write(std::ostream &OutFile); + + void Read(std::istream &InFile); + + const std::vector& GetDoorVehicles(); + +private: + std::vector Vehicles; +}; diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaRecorderQuery.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaRecorderQuery.cpp index 47cda18c5..75f2202c8 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaRecorderQuery.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaRecorderQuery.cpp @@ -19,6 +19,8 @@ #include #include +#include + inline bool CarlaRecorderQuery::ReadHeader(void) { if (File.eof()) @@ -271,6 +273,49 @@ std::string CarlaRecorderQuery::QueryInfo(std::string Filename, bool bShowAll) SkipPacket(); break; + // vehicle door animations + case static_cast(CarlaRecorderPacketId::VehicleDoor): + if (bShowAll) + { + ReadValue(File, Total); + if (Total > 0 && !bFramePrinted) + { + PrintFrame(Info); + bFramePrinted = true; + } + Info << " Vehicle door animations: " << Total << std::endl; + for (i = 0; i < Total; ++i) + { + DoorVehicle.Read(File); + + CarlaRecorderDoorVehicle::VehicleDoorType doorVehicle; + doorVehicle = DoorVehicle.Doors; + EVehicleDoor eDoorVehicle = static_cast(doorVehicle); + std::string opened_doors_list; + + Info << " Id: " << DoorVehicle.DatabaseId << std::endl; + Info << " Doors opened: "; + if (eDoorVehicle == EVehicleDoor::FL) + Info << " Front Left " << std::endl; + if (eDoorVehicle == EVehicleDoor::FR) + Info << " Front Right " << std::endl; + if (eDoorVehicle == EVehicleDoor::RL) + Info << " Rear Left " << std::endl; + if (eDoorVehicle == EVehicleDoor::RR) + Info << " Rear Right " << std::endl; + if (eDoorVehicle == EVehicleDoor::Hood) + Info << " Hood " << std::endl; + if (eDoorVehicle == EVehicleDoor::Trunk) + Info << " Trunk " << std::endl; + if (eDoorVehicle == EVehicleDoor::All) + Info << " All " << std::endl; + } + } + else + SkipPacket(); + break; + + // vehicle light animations case static_cast(CarlaRecorderPacketId::VehicleLight): if (bShowAll) diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaRecorderQuery.h b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaRecorderQuery.h index 070fb117c..f3e4c53cb 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaRecorderQuery.h +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaRecorderQuery.h @@ -26,6 +26,7 @@ #include "CarlaRecorderPosition.h" #include "CarlaRecorderState.h" #include "CarlaRecorderWalkerBones.h" +#include "CarlaRecorderDoorVehicle.h" class CarlaRecorderQuery { @@ -69,6 +70,7 @@ private: CarlaRecorderPhysicsControl PhysicsControl; CarlaRecorderTrafficLightTime TrafficLightTime; CarlaRecorderWalkerBones WalkerBones; + CarlaRecorderDoorVehicle DoorVehicle; // read next header packet bool ReadHeader(void); diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaReplayer.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaReplayer.cpp index 918d3aa51..64e208b55 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaReplayer.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaReplayer.cpp @@ -378,6 +378,14 @@ void CarlaReplayer::ProcessToTime(double Time, bool IsFirstTime) SkipPacket(); break; + // vehicle door animation + case static_cast(CarlaRecorderPacketId::VehicleDoor): + if (bFrameFound) + ProcessDoorVehicle(); + else + SkipPacket(); + break; + // scene lights animation case static_cast(CarlaRecorderPacketId::SceneLight): if (bFrameFound) @@ -649,6 +657,25 @@ void CarlaReplayer::ProcessLightVehicle(void) } } +void CarlaReplayer::ProcessDoorVehicle(void) +{ + uint16_t Total; + CarlaRecorderDoorVehicle DoorVehicle; + + // read Total walkers + ReadValue(File, Total); + for (uint16_t i = 0; i < Total; ++i) + { + DoorVehicle.Read(File); + DoorVehicle.DatabaseId = MappedId[DoorVehicle.DatabaseId]; + // check if ignore this actor + if (!(IgnoreHero && IsHeroMap[DoorVehicle.DatabaseId])) + { + Helper.ProcessReplayerDoorVehicle(DoorVehicle); + } + } +} + void CarlaReplayer::ProcessLightScene(void) { uint16_t Total; diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaReplayer.h b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaReplayer.h index f1e73f05e..3e2f2408b 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaReplayer.h +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaReplayer.h @@ -158,6 +158,8 @@ private: void ProcessLightVehicle(void); void ProcessLightScene(void); + void ProcessDoorVehicle(void); + void ProcessWalkerBones(void); // positions diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaReplayerHelper.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaReplayerHelper.cpp index 3ca4c4b4f..9bfa120f6 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaReplayerHelper.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaReplayerHelper.cpp @@ -416,6 +416,24 @@ void CarlaReplayerHelper::ProcessReplayerAnimVehicle(CarlaRecorderAnimVehicle Ve } } +// set the openings and closings of vehicle doors +void CarlaReplayerHelper::ProcessReplayerDoorVehicle(CarlaRecorderDoorVehicle DoorVehicle) +{ + check(Episode != nullptr); + FCarlaActor * CarlaActor = Episode->FindCarlaActor(DoorVehicle.DatabaseId); + if (CarlaActor) + { + ACarlaWheeledVehicle * Vehicle = Cast(CarlaActor->GetActor()); + if (Vehicle) { + if(DoorVehicle.bIsOpen){ + Vehicle->OpenDoor(static_cast(DoorVehicle.Doors)); + }else{ + Vehicle->CloseDoor(static_cast(DoorVehicle.Doors)); + } + } + } +} + // set the lights for vehicles void CarlaReplayerHelper::ProcessReplayerLightVehicle(CarlaRecorderLightVehicle LightVehicle) { diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaReplayerHelper.h b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaReplayerHelper.h index f6751117d..d4379dddd 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaReplayerHelper.h +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaReplayerHelper.h @@ -15,6 +15,7 @@ #include "CarlaRecorderAnimVehicleWheels.h" #include "CarlaRecorderLightVehicle.h" #include "CarlaRecorderLightScene.h" +#include "CarlaRecorderDoorVehicle.h" #include "CarlaRecorderWalkerBones.h" #include @@ -65,6 +66,9 @@ public: // set the animation for walkers void ProcessReplayerAnimWalker(CarlaRecorderAnimWalker Walker); + // set the openings and closing of vehicle doors + void ProcessReplayerDoorVehicle(CarlaRecorderDoorVehicle DoorVehicle); + // set the animation for bikers void ProcessReplayerAnimBiker(CarlaRecorderAnimBiker Biker); diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Settings/CarlaSettingsDelegate.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Settings/CarlaSettingsDelegate.cpp index 33f018ae2..673ef6ebe 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Settings/CarlaSettingsDelegate.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Settings/CarlaSettingsDelegate.cpp @@ -4,7 +4,7 @@ #include "Carla/Game/CarlaGameInstance.h" #include "Carla/Settings/CarlaSettings.h" -#include "Carla/Game/CarlaGameInstance.h" + #include "Async.h" #include "Components/StaticMeshComponent.h" #include "Engine/DirectionalLight.h" diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CarlaWheeledVehicle.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CarlaWheeledVehicle.cpp index 1580e7180..8ba705acd 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CarlaWheeledVehicle.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CarlaWheeledVehicle.cpp @@ -1019,6 +1019,8 @@ void ACarlaWheeledVehicle::OpenDoorPhys(const EVehicleDoor DoorIdx) { (*CollisionDisable)->InitComponentConstraint(); } + + RecordDoorChange(DoorIdx, true); } void ACarlaWheeledVehicle::CloseDoorPhys(const EVehicleDoor DoorIdx) @@ -1032,6 +1034,16 @@ void ACarlaWheeledVehicle::CloseDoorPhys(const EVehicleDoor DoorIdx) DoorComponent->SetWorldTransform(DoorInitialTransform); DoorComponent->AttachToComponent( GetMesh(), FAttachmentTransformRules(EAttachmentRule::KeepWorld, true)); + RecordDoorChange(DoorIdx, false); +} + +void ACarlaWheeledVehicle::RecordDoorChange(const EVehicleDoor DoorIdx, bool bIsOpen) +{ + auto * Recorder = UCarlaStatics::GetRecorder(GetWorld()); + if (Recorder && Recorder->IsEnabled()) + { + Recorder->AddVehicleDoor(*this, DoorIdx, bIsOpen); + } } void ACarlaWheeledVehicle::ApplyRolloverBehavior() diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CarlaWheeledVehicle.h b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CarlaWheeledVehicle.h index 704d4c72f..0f5b4fea8 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CarlaWheeledVehicle.h +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CarlaWheeledVehicle.h @@ -406,6 +406,9 @@ public: UFUNCTION(Category = "CARLA Wheeled Vehicle", BlueprintCallable) void CloseDoorPhys(const EVehicleDoor DoorIdx); + UFUNCTION(Category = "CARLA Wheeled Vehicle", BlueprintCallable) + void RecordDoorChange(const EVehicleDoor DoorIdx, const bool bIsOpen); + virtual FVector GetVelocity() const override; //-----CARSIM--------------------------------