Javiergr cs/recorder doors (#6922)

* 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 <kykim144@gmail.com>
Co-authored-by: bernatx <bernatx@gmail.com>
Co-authored-by: Paul Erik Frivold <paulerikf@gmail.com>
Co-authored-by: Balázs Kis <balazs_kis35@yahoo.com>
Co-authored-by: matejm42 <116560704+matejm42@users.noreply.github.com>
Co-authored-by: Blyron <53337103+Blyron@users.noreply.github.com>
This commit is contained in:
javiergrCS 2023-11-23 09:36:43 +01:00 committed by GitHub
parent 834679d254
commit c461f901cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 265 additions and 1 deletions

View File

@ -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

View File

@ -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<CarlaRecorderDoorVehicle::VehicleDoorType>(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)

View File

@ -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;

View File

@ -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 <https://opensource.org/licenses/MIT>.
#include "CarlaRecorderDoorVehicle.h"
#include "CarlaRecorder.h"
#include "CarlaRecorderHelpers.h"
void CarlaRecorderDoorVehicle::Write(std::ostream &OutFile)
{
// database id
WriteValue<uint32_t>(OutFile, this->DatabaseId);
WriteValue<VehicleDoorType>(OutFile, this->Doors);
WriteValue<bool>(OutFile, this->bIsOpen);
}
void CarlaRecorderDoorVehicle::Read(std::istream &InFile)
{
// database id
ReadValue<uint32_t>(InFile, this->DatabaseId);
ReadValue<VehicleDoorType>(InFile, this->Doors);
ReadValue<bool>(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<char>(OutFile, static_cast<char>(CarlaRecorderPacketId::VehicleDoor));
// write a dummy packet size
uint32_t Total = 2 + Vehicles.size() * sizeof(CarlaRecorderDoorVehicle);
WriteValue<uint32_t>(OutFile, Total);
// write total records
Total = Vehicles.size();
WriteValue<uint16_t>(OutFile, Total);
for (auto& Vehicle : Vehicles)
{
Vehicle.Write(OutFile);
}
}
void CarlaRecorderDoorVehicles::Read(std::istream &InFile)
{
uint16_t Total;
CarlaRecorderDoorVehicle DoorVehicle;
// read Total walkers
ReadValue<uint16_t>(InFile, Total);
for (uint16_t i = 0; i < Total; ++i)
{
DoorVehicle.Read(InFile);
Add(DoorVehicle);
}
}
const std::vector<CarlaRecorderDoorVehicle>& CarlaRecorderDoorVehicles::GetDoorVehicles()
{
return Vehicles;
}

View File

@ -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 <https://opensource.org/licenses/MIT>.
#pragma once
#include <sstream>
#include <vector>
#include <type_traits>
#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<CarlaRecorderDoorVehicle>& GetDoorVehicles();
private:
std::vector<CarlaRecorderDoorVehicle> Vehicles;
};

View File

@ -19,6 +19,8 @@
#include <carla/rpc/VehiclePhysicsControl.h>
#include <compiler/enable-ue4-macros.h>
#include <Carla/Vehicle/CarlaWheeledVehicle.h>
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<char>(CarlaRecorderPacketId::VehicleDoor):
if (bShowAll)
{
ReadValue<uint16_t>(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<EVehicleDoor>(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<char>(CarlaRecorderPacketId::VehicleLight):
if (bShowAll)

View File

@ -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);

View File

@ -378,6 +378,14 @@ void CarlaReplayer::ProcessToTime(double Time, bool IsFirstTime)
SkipPacket();
break;
// vehicle door animation
case static_cast<char>(CarlaRecorderPacketId::VehicleDoor):
if (bFrameFound)
ProcessDoorVehicle();
else
SkipPacket();
break;
// scene lights animation
case static_cast<char>(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<uint16_t>(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;

View File

@ -158,6 +158,8 @@ private:
void ProcessLightVehicle(void);
void ProcessLightScene(void);
void ProcessDoorVehicle(void);
void ProcessWalkerBones(void);
// positions

View File

@ -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<ACarlaWheeledVehicle>(CarlaActor->GetActor());
if (Vehicle) {
if(DoorVehicle.bIsOpen){
Vehicle->OpenDoor(static_cast<EVehicleDoor>(DoorVehicle.Doors));
}else{
Vehicle->CloseDoor(static_cast<EVehicleDoor>(DoorVehicle.Doors));
}
}
}
}
// set the lights for vehicles
void CarlaReplayerHelper::ProcessReplayerLightVehicle(CarlaRecorderLightVehicle LightVehicle)
{

View File

@ -15,6 +15,7 @@
#include "CarlaRecorderAnimVehicleWheels.h"
#include "CarlaRecorderLightVehicle.h"
#include "CarlaRecorderLightScene.h"
#include "CarlaRecorderDoorVehicle.h"
#include "CarlaRecorderWalkerBones.h"
#include <unordered_map>
@ -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);

View File

@ -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"

View File

@ -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()

View File

@ -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--------------------------------