Prevent adding trigger boxes inside the intersections

This commit is contained in:
Joel Moriana 2022-05-02 16:11:58 +02:00 committed by Axel1092
parent 49223437b2
commit cf0600293e
8 changed files with 126 additions and 39 deletions

View File

@ -100,6 +100,20 @@ UBoxComponent* USignComponent::GenerateTriggerBox(const FTransform &BoxTransform
return BoxComponent;
}
UBoxComponent* USignComponent::GenerateTriggerBox(const FTransform &BoxTransform,
const FVector &BoxSize)
{
AActor *ParentActor = GetOwner();
UBoxComponent *BoxComponent = NewObject<UBoxComponent>(ParentActor);
BoxComponent->RegisterComponent();
BoxComponent->AttachToComponent(
ParentActor->GetRootComponent(),
FAttachmentTransformRules::KeepRelativeTransform);
BoxComponent->SetWorldTransform(BoxTransform);
BoxComponent->SetBoxExtent(BoxSize, true);
return BoxComponent;
}
void USignComponent::AddEffectTriggerVolume(UBoxComponent* TriggerVolume)
{
EffectTriggerVolumes.Add(TriggerVolume);

View File

@ -67,6 +67,9 @@ protected:
UBoxComponent* GenerateTriggerBox(const FTransform &BoxTransform,
float BoxSize);
UBoxComponent* GenerateTriggerBox(const FTransform &BoxTransform,
const FVector &BoxSize);
private:
UPROPERTY(Category = "Traffic Sign", EditAnywhere)

View File

@ -8,6 +8,8 @@
#include "TrafficLightState.h"
#include <queue>
#include "Carla/Game/CarlaStatics.h"
#include "Carla/MapGen/LargeMapManager.h"
#include <compiler/disable-ue4-macros.h>
#include <carla/road/element/RoadInfoSpeed.h>
#include <compiler/enable-ue4-macros.h>
@ -38,27 +40,43 @@ void UStopSignComponent::InitializeSign(const carla::road::Map &Map)
if(Map.GetLane(signal_waypoint).GetType() != cr::Lane::LaneType::Driving)
continue;
// Get 90% of the half size of the width of the lane
float BoxSize = static_cast<float>(
0.9*Map.GetLaneWidth(signal_waypoint)*0.5);
auto box_waypoint = signal_waypoint;
// Prevent adding the bounding box inside the intersection
if (Map.IsJunction(RoadId)) {
auto previous_waypoints = Map.GetPrevious(signal_waypoint, 2.0);
if (previous_waypoints.size() == 1) {
box_waypoint = previous_waypoints.front();
}
}
// Get 50% of the half size of the width of the lane
float BoxWidth = static_cast<float>(
0.5f*Map.GetLaneWidth(box_waypoint)*0.5);
float BoxLength = 1.5f;
float BoxHeight = 1.0f;
// Prevent a situation where the road width is 0,
// this could happen in a lane that is just appearing
BoxSize = std::max(0.01f, BoxSize);
BoxWidth = std::max(0.01f, BoxWidth);
// Get min and max
double LaneLength = Map.GetLane(signal_waypoint).GetLength();
double LaneDistance = Map.GetLane(signal_waypoint).GetDistance();
double LaneLength = Map.GetLane(box_waypoint).GetLength();
double LaneDistance = Map.GetLane(box_waypoint).GetDistance();
if(lane < 0)
{
signal_waypoint.s = FMath::Clamp(signal_waypoint.s - BoxSize,
box_waypoint.s = FMath::Clamp(box_waypoint.s - BoxWidth,
LaneDistance + epsilon, LaneDistance + LaneLength - epsilon);
}
else
{
signal_waypoint.s = FMath::Clamp(signal_waypoint.s + BoxSize,
box_waypoint.s = FMath::Clamp(box_waypoint.s + BoxWidth,
LaneDistance + epsilon, LaneDistance + LaneLength - epsilon);
}
float UnrealBoxSize = 100*BoxSize;
GenerateStopBox(Map.ComputeTransform(signal_waypoint), UnrealBoxSize);
FTransform BoxTransform = Map.ComputeTransform(box_waypoint);
ALargeMapManager* LargeMapManager = UCarlaStatics::GetLargeMapManager(GetWorld());
if (LargeMapManager)
{
BoxTransform = LargeMapManager->GlobalToLocalTransform(BoxTransform);
}
GenerateStopBox(BoxTransform, FVector(100*BoxLength, 100*BoxWidth, 100*BoxHeight));
auto Predecessors = Map.GetPredecessors(signal_waypoint);
for(auto &Prev : Predecessors)
@ -110,7 +128,14 @@ void UStopSignComponent::InitializeSign(const carla::road::Map &Map)
// This could happen in a lane that is just appearing
BoxSize = std::max(0.01f, BoxSize);
float UEBoxSize = 100*BoxSize;
GenerateCheckBox(Map.ComputeTransform(NextWaypoint), UEBoxSize);
FTransform BoxTransform = Map.ComputeTransform(NextWaypoint);
ALargeMapManager* LargeMapManager = UCarlaStatics::GetLargeMapManager(GetWorld());
if (LargeMapManager)
{
BoxTransform = LargeMapManager->GlobalToLocalTransform(BoxTransform);
}
GenerateCheckBox(BoxTransform, UEBoxSize);
while (true)
{
auto Next = Map.GetNext(NextWaypoint, 2*BoxSize);
@ -123,8 +148,12 @@ void UStopSignComponent::InitializeSign(const carla::road::Map &Map)
{
break;
}
GenerateCheckBox(Map.ComputeTransform(NextWaypoint), UEBoxSize);
BoxTransform = Map.ComputeTransform(NextWaypoint);
if (LargeMapManager)
{
BoxTransform = LargeMapManager->GlobalToLocalTransform(BoxTransform);
}
GenerateCheckBox(BoxTransform, UEBoxSize);
}
// Cover the road before the junction
// Hard coded anticipation time (boxes placed prior to the junction)
@ -166,7 +195,7 @@ void UStopSignComponent::InitializeSign(const carla::road::Map &Map)
}
void UStopSignComponent::GenerateStopBox(const FTransform BoxTransform,
float BoxSize)
const FVector BoxSize)
{
UBoxComponent* BoxComponent = GenerateTriggerBox(BoxTransform, BoxSize);
BoxComponent->OnComponentBeginOverlap.AddDynamic(this, &UStopSignComponent::OnOverlapBeginStopEffectBox);

View File

@ -23,7 +23,7 @@ public:
private:
void GenerateStopBox(const FTransform BoxTransform,
float BoxSize);
const FVector BoxSize);
void GenerateCheckBox(const FTransform BoxTransform,
float BoxSize);

View File

@ -39,43 +39,53 @@ void UTrafficLightComponent::InitializeSign(const carla::road::Map &Map)
auto signal_waypoint = Map.GetWaypoint(
RoadId, lane, SignalReference->GetS()).get();
// Prevent adding the bounding box inside the intersection
if (Map.IsJunction(RoadId)) {
auto previous_waypoints = Map.GetPrevious(signal_waypoint, 2.0);
if (previous_waypoints.size() == 1) {
signal_waypoint = previous_waypoints.front();
}
}
if(Map.GetLane(signal_waypoint).GetType() != cr::Lane::LaneType::Driving)
continue;
// Get 90% of the half size of the width of the lane
float BoxSize = static_cast<float>(
0.9f*Map.GetLaneWidth(signal_waypoint)*0.5);
// Get 50% of the half size of the width of the lane
float BoxWidth = static_cast<float>(
0.5f*Map.GetLaneWidth(signal_waypoint)*0.5);
float BoxLength = 1.5f;
float BoxHeight = 1.0f;
// Prevent a situation where the road width is 0,
// this could happen in a lane that is just appearing
BoxSize = std::max(0.01f, BoxSize);
BoxWidth = std::max(0.01f, BoxWidth);
// Get min and max
double LaneLength = Map.GetLane(signal_waypoint).GetLength();
double LaneDistance = Map.GetLane(signal_waypoint).GetDistance();
if(lane < 0)
{
signal_waypoint.s = FMath::Clamp(signal_waypoint.s - BoxSize,
signal_waypoint.s = FMath::Clamp(signal_waypoint.s - BoxWidth,
LaneDistance + epsilon, LaneDistance + LaneLength - epsilon);
}
else
{
signal_waypoint.s = FMath::Clamp(signal_waypoint.s + BoxSize,
signal_waypoint.s = FMath::Clamp(signal_waypoint.s + BoxWidth,
LaneDistance + epsilon, LaneDistance + LaneLength - epsilon);
}
float UnrealBoxSize = 100*BoxSize;
FTransform BoxTransform = Map.ComputeTransform(signal_waypoint);
ALargeMapManager* LargeMapManager = UCarlaStatics::GetLargeMapManager(GetWorld());
if (LargeMapManager)
{
BoxTransform = LargeMapManager->GlobalToLocalTransform(BoxTransform);
}
GenerateTrafficLightBox(BoxTransform, UnrealBoxSize);
GenerateTrafficLightBox(BoxTransform, FVector(100*BoxLength, 100*BoxWidth, 100*BoxHeight));
}
}
}
}
void UTrafficLightComponent::GenerateTrafficLightBox(const FTransform BoxTransform,
float BoxSize)
const FVector BoxSize)
{
UBoxComponent* BoxComponent = GenerateTriggerBox(BoxTransform, BoxSize);
BoxComponent->OnComponentBeginOverlap.AddDynamic(this, &UTrafficLightComponent::OnOverlapTriggerBox);

View File

@ -68,7 +68,7 @@ private:
void GenerateTrafficLightBox(
const FTransform BoxTransform,
float BoxSize);
const FVector BoxSize);
UPROPERTY(Category = "Traffic Light", EditAnywhere)
ETrafficLightState LightState;

View File

@ -8,6 +8,8 @@
#include "TrafficLightState.h"
#include <queue>
#include "Carla/Game/CarlaStatics.h"
#include "Carla/MapGen/LargeMapManager.h"
#include "Carla/Vehicle/CarlaWheeledVehicle.h"
#include <compiler/disable-ue4-macros.h>
#include <carla/road/element/RoadInfoSpeed.h>
@ -40,27 +42,43 @@ void UYieldSignComponent::InitializeSign(const carla::road::Map &Map)
if(Map.GetLane(signal_waypoint).GetType() != cr::Lane::LaneType::Driving)
continue;
// Get 90% of the half size of the width of the lane
float BoxSize = static_cast<float>(
0.9*Map.GetLaneWidth(signal_waypoint)/2.0);
auto box_waypoint = signal_waypoint;
// Prevent adding the bounding box inside the intersection
if (Map.IsJunction(RoadId)) {
auto previous_waypoints = Map.GetPrevious(signal_waypoint, 2.0);
if (previous_waypoints.size() == 1) {
box_waypoint = previous_waypoints.front();
}
}
// Get 50% of the half size of the width of the lane
float BoxWidth = static_cast<float>(
0.5f*Map.GetLaneWidth(box_waypoint)*0.5);
float BoxLength = 1.5f;
float BoxHeight = 1.0f;
// Prevent a situation where the road width is 0,
// this could happen in a lane that is just appearing
BoxSize = std::max(0.01f, BoxSize);
BoxWidth = std::max(0.01f, BoxWidth);
// Get min and max
double LaneLength = Map.GetLane(signal_waypoint).GetLength();
double LaneDistance = Map.GetLane(signal_waypoint).GetDistance();
double LaneLength = Map.GetLane(box_waypoint).GetLength();
double LaneDistance = Map.GetLane(box_waypoint).GetDistance();
if(lane < 0)
{
signal_waypoint.s = FMath::Clamp(signal_waypoint.s - BoxSize,
box_waypoint.s = FMath::Clamp(box_waypoint.s - BoxWidth,
LaneDistance + epsilon, LaneDistance + LaneLength - epsilon);
}
else
{
signal_waypoint.s = FMath::Clamp(signal_waypoint.s + BoxSize,
box_waypoint.s = FMath::Clamp(box_waypoint.s + BoxWidth,
LaneDistance + epsilon, LaneDistance + LaneLength - epsilon);
}
float UnrealBoxSize = 100*BoxSize;
GenerateYieldBox(Map.ComputeTransform(signal_waypoint), UnrealBoxSize);
FTransform BoxTransform = Map.ComputeTransform(box_waypoint);
ALargeMapManager* LargeMapManager = UCarlaStatics::GetLargeMapManager(GetWorld());
if (LargeMapManager)
{
BoxTransform = LargeMapManager->GlobalToLocalTransform(BoxTransform);
}
GenerateYieldBox(BoxTransform, FVector(100*BoxLength, 100*BoxWidth, 100*BoxHeight));
auto Predecessors = Map.GetPredecessors(signal_waypoint);
for(auto &Prev : Predecessors)
@ -113,7 +131,15 @@ void UYieldSignComponent::InitializeSign(const carla::road::Map &Map)
// this could happen in a lane that is just appearing
BoxSize = std::max(0.01f, BoxSize);
float UEBoxSize = 100*BoxSize;
GenerateCheckBox(Map.ComputeTransform(NextWaypoint), UEBoxSize);
FTransform BoxTransform = Map.ComputeTransform(NextWaypoint);
ALargeMapManager* LargeMapManager = UCarlaStatics::GetLargeMapManager(GetWorld());
if (LargeMapManager)
{
BoxTransform = LargeMapManager->GlobalToLocalTransform(BoxTransform);
}
GenerateCheckBox(BoxTransform, UEBoxSize);
while (true)
{
auto Next = Map.GetNext(NextWaypoint, 2*BoxSize);
@ -126,8 +152,13 @@ void UYieldSignComponent::InitializeSign(const carla::road::Map &Map)
{
break;
}
BoxTransform = Map.ComputeTransform(NextWaypoint);
if (LargeMapManager)
{
BoxTransform = LargeMapManager->GlobalToLocalTransform(BoxTransform);
}
GenerateCheckBox(BoxTransform, UEBoxSize);
GenerateCheckBox(Map.ComputeTransform(NextWaypoint), UEBoxSize);
}
// Cover the road before the junction
// Hard coded anticipation time (boxes placed prior to the junction)
@ -169,7 +200,7 @@ void UYieldSignComponent::InitializeSign(const carla::road::Map &Map)
}
void UYieldSignComponent::GenerateYieldBox(const FTransform BoxTransform,
float BoxSize)
const FVector BoxSize)
{
UBoxComponent* BoxComponent = GenerateTriggerBox(BoxTransform, BoxSize);
BoxComponent->OnComponentBeginOverlap.AddDynamic(this, &UYieldSignComponent::OnOverlapBeginYieldEffectBox);

View File

@ -23,7 +23,7 @@ public:
private:
void GenerateYieldBox(const FTransform BoxTransform,
float BoxSize);
const FVector BoxSize);
void GenerateCheckBox(const FTransform BoxTransform,
float BoxSize);