9 #include "Kismet/GameplayStatics.h" 22 UTrafficLightComponent::UTrafficLightComponent()
29 const double epsilon = 0.00001;
31 auto References = GetAllReferencesToThisSignal(Map);
33 for (
auto& Reference : References)
35 auto RoadId = Reference.first;
36 const auto* SignalReference = Reference.second;
37 for(
auto &validity : SignalReference->GetValidities())
45 boost::optional<carla::road::element::Waypoint> opt_signal_waypoint = Map.
GetWaypoint(
46 RoadId, lane, SignalReference->GetS());
47 if(opt_signal_waypoint){
48 signal_waypoint = opt_signal_waypoint.get();
50 UE_LOG(LogCarla, Error, TEXT(
"signal_waypoint is not valid") );
56 if (predecessors.size() == 1) {
57 auto predecessor = predecessors.front();
59 signal_waypoint = predecessor;
64 if(Map.
GetLane(signal_waypoint).
GetType() != cr::Lane::LaneType::Driving)
68 float BoxWidth =
static_cast<float>(
70 float BoxLength = 1.5f;
71 float BoxHeight = 1.0f;
75 BoxWidth = std::max(0.01f, BoxWidth);
80 float AdditionalDistance = 1.5f;
83 signal_waypoint.
s = FMath::Clamp(signal_waypoint.
s - (BoxLength + AdditionalDistance),
84 LaneDistance + epsilon, LaneDistance + LaneLength - epsilon);
88 signal_waypoint.
s = FMath::Clamp(signal_waypoint.
s + (BoxLength + AdditionalDistance),
89 LaneDistance + epsilon, LaneDistance + LaneLength - epsilon);
97 GenerateTrafficLightBox(BoxTransform, FVector(100*BoxLength, 100*BoxWidth, 100*BoxHeight));
103 void UTrafficLightComponent::GenerateTrafficLightBox(
const FTransform BoxTransform,
104 const FVector BoxSize)
106 UBoxComponent* BoxComponent = GenerateTriggerBox(BoxTransform, BoxSize);
107 BoxComponent->OnComponentBeginOverlap.AddDynamic(
this, &UTrafficLightComponent::OnBeginOverlapTriggerBox);
108 BoxComponent->OnComponentEndOverlap.AddDynamic(
this, &UTrafficLightComponent::OnEndOverlapTriggerBox);
109 AddEffectTriggerVolume(BoxComponent);
114 LightState = NewState;
115 LightChangeDispatcher.Broadcast();
116 if (GetOwner()->Implements<UTrafficLightInterface>())
118 ITrafficLightInterface::Execute_LightChanged(GetOwner(), LightState);
128 if (Controller !=
nullptr)
130 Controller->SetTrafficLightState(LightState);
140 void UTrafficLightComponent::SetFrozenGroup(
bool InFreeze)
144 GetGroup()->SetFrozenGroup(InFreeze);
150 return TrafficLightController->GetGroup();
155 return TrafficLightController->GetGroup();
160 return TrafficLightController;
165 return TrafficLightController;
171 int32 OtherBodyIndex,
173 const FHitResult &SweepResult)
179 Cast<AWheeledVehicleAIController>(Vehicle->GetController());
180 if (VehicleController)
183 Vehicles.Add(VehicleController);
184 VehicleController->
SetTrafficLight(Cast<ATrafficLightBase>(GetOwner()));
192 int32 OtherBodyIndex)
198 Cast<AWheeledVehicleAIController>(Vehicle->GetController());
199 if (VehicleController)
203 Vehicles.Remove(VehicleController);
210 TrafficLightController = Controller;
TArray< AWheeledVehicleAIController * > Vehicles
boost::optional< element::Waypoint > GetWaypoint(const geom::Location &location, int32_t lane_type=static_cast< int32_t >(Lane::LaneType::Driving)) const
const Lane & GetLane(Waypoint waypoint) const
======================================================================== – Road information --------...
Class which implements the state changing of traffic lights.
double GetDistance() const
void SetTrafficLight(ATrafficLightBase *InTrafficLight)
Set traffic light currently affecting this vehicle.
void SetTrafficLightState(ETrafficLightState InTrafficLightState)
Set traffic light state currently affecting this vehicle.
void LightChangedCompatibility(ETrafficLightState NewLightState)
Wheeled vehicle controller with optional AI.
geom::Transform ComputeTransform(Waypoint waypoint) const
bool IsJunction(RoadId road_id) const
std::vector< Waypoint > GetPredecessors(Waypoint waypoint) const
static std::vector< int > GenerateRange(int a, int b)
FTransform GlobalToLocalTransform(const FTransform &InTransform) const
static ALargeMapManager * GetLargeMapManager(const UObject *WorldContextObject)
Base class for CARLA wheeled vehicles.
Maps a controller from OpenDrive.
double GetLaneWidth(Waypoint waypoint) const