22 const double epsilon = 0.00001;
24 auto References = GetAllReferencesToThisSignal(Map);
26 for (
auto& Reference : References)
28 auto RoadId = Reference.first;
29 const auto* SignalReference = Reference.second;
30 TSet<carla::road::RoadId> SignalPredecessors;
32 for(
auto &validity : SignalReference->GetValidities())
34 for(
auto lane :
carla::geom::Math::GenerateRange(validity._from_lane, validity._to_lane))
39 auto signal_waypoint_optional = Map.
GetWaypoint(RoadId, lane, SignalReference->GetS());
40 if (!signal_waypoint_optional) {
41 carla::log_warning(
"YieldSignComponent::InitializeSignsignal() waypoint seems to be invalid, ignoring. RoadId:", RoadId,
" LaneId:", lane,
" s:", SignalReference->GetS());
44 auto signal_waypoint = signal_waypoint_optional.value();
45 if(Map.
GetLane(signal_waypoint).
GetType() != cr::Lane::LaneType::Driving) {
49 auto box_waypoint = signal_waypoint;
53 if (predecessors.size() == 1) {
54 auto predecessor = predecessors.front();
56 box_waypoint = predecessor;
62 float BoxWidth =
static_cast<float>(
64 float BoxLength = 1.5f;
65 float BoxHeight = 1.0f;
68 BoxWidth = std::max(0.01f, BoxWidth);
73 float AdditionalDistance = 1.5f;
76 box_waypoint.s = FMath::Clamp(box_waypoint.s - (BoxLength + AdditionalDistance),
77 LaneDistance + epsilon, LaneDistance + LaneLength - epsilon);
81 box_waypoint.s = FMath::Clamp(box_waypoint.s + (BoxLength + AdditionalDistance),
82 LaneDistance + epsilon, LaneDistance + LaneLength - epsilon);
90 GenerateYieldBox(BoxTransform, FVector(100*BoxLength, 100*BoxWidth, 100*BoxHeight));
93 for(
auto &Prev : Predecessors)
95 if(!SignalPredecessors.Contains(Prev.road_id))
97 SignalPredecessors.Add(Prev.road_id);
108 if(
Junction->RoadHasConflicts(RoadId))
110 const auto &ConflictingRoads =
Junction->GetConflictsOfRoad(RoadId);
111 for(
const auto &Conflict : ConflictingRoads)
114 for(
auto& Waypoint : Waypoints)
117 bool bHasSamePredecessor =
false;
119 for(
auto &Prev : Predecessors)
121 if(SignalPredecessors.Contains(Prev.road_id))
123 bHasSamePredecessor =
true;
126 if(bHasSamePredecessor)
131 if(Map.
GetLane(Waypoint).
GetType() != cr::Lane::LaneType::Driving)
135 auto CurrentWaypoint = Waypoint;
136 auto NextWaypoint = CurrentWaypoint;
137 float BoxSize =
static_cast<float>(
141 BoxSize = std::max(0.01f, BoxSize);
142 float UEBoxSize = 100*BoxSize;
150 GenerateCheckBox(BoxTransform, UEBoxSize);
154 auto Next = Map.
GetNext(NextWaypoint, 2*BoxSize);
155 if (Next.size() != 1)
159 NextWaypoint = Next.front();
160 if(NextWaypoint.road_id != Waypoint.road_id)
169 GenerateCheckBox(BoxTransform, UEBoxSize);
174 double AnticipationTime = 0.1;
175 auto Previous = Map.
GetPrevious(Waypoint, 2*BoxSize);
176 std::queue<std::pair<float, carla::road::element::Waypoint>>
178 for (
auto & Prev : Previous)
180 WaypointQueue.push({AnticipationTime, Prev});
182 while (!WaypointQueue.empty())
184 auto CurrentElement = WaypointQueue.front();
194 float RemainingTime = CurrentElement.first - BoxSize/Speed;
195 if(RemainingTime > 0)
197 Previous = Map.
GetPrevious(CurrentElement.second, 2*BoxSize);
198 for (
auto & Prev : Previous)
200 WaypointQueue.push({RemainingTime, Prev});
211void UYieldSignComponent::GenerateYieldBox(
const FTransform BoxTransform,
212 const FVector BoxSize)
214 UBoxComponent* BoxComponent = GenerateTriggerBox(BoxTransform, BoxSize);
215 BoxComponent->OnComponentBeginOverlap.AddDynamic(
this, &UYieldSignComponent::OnOverlapBeginYieldEffectBox);
216 BoxComponent->OnComponentEndOverlap.AddDynamic(
this, &UYieldSignComponent::OnOverlapEndYieldEffectBox);
217 AddEffectTriggerVolume(BoxComponent);
220void UYieldSignComponent::GenerateCheckBox(
const FTransform BoxTransform,
223 UBoxComponent* BoxComponent = GenerateTriggerBox(BoxTransform, BoxSize);
224 BoxComponent->OnComponentBeginOverlap.AddDynamic(
this, &UYieldSignComponent::OnOverlapBeginYieldCheckBox);
225 BoxComponent->OnComponentEndOverlap.AddDynamic(
this, &UYieldSignComponent::OnOverlapEndYieldCheckBox);
228void UYieldSignComponent::GiveWayIfPossible()
230 if (VehiclesToCheck.Num() == 0)
232 for (
auto Vehicle : VehiclesInYield)
235 Cast<AWheeledVehicleAIController>(
Vehicle->GetController());
241 if(VehiclesInYield.Num())
243 for (
auto Vehicle : VehiclesInYield)
246 Cast<AWheeledVehicleAIController>(
Vehicle->GetController());
250 DelayedGiveWay(0.5f);
255void UYieldSignComponent::DelayedGiveWay(
float Delay)
257 FTimerHandle TimerHandler;
258 GetWorld()->GetTimerManager().
259 SetTimer(TimerHandler,
this, &UYieldSignComponent::GiveWayIfPossible, Delay);
265 int32 OtherBodyIndex,
267 const FHitResult &SweepResult)
273 Cast<AWheeledVehicleAIController>(
Vehicle->GetController());
274 if (VehicleController)
277 RemoveSameVehicleInBothLists();
286 int32 OtherBodyIndex)
291 VehiclesInYield.Remove(
Vehicle);
298 int32 OtherBodyIndex,
300 const FHitResult &SweepResult)
305 if(!VehiclesInYield.Contains(
Vehicle))
307 if (!VehiclesToCheck.Contains(
Vehicle))
309 VehiclesToCheck.Add(
Vehicle, 0);
320 int32 OtherBodyIndex)
325 if(VehiclesToCheck.Contains(
Vehicle))
328 if(VehiclesToCheck[
Vehicle] <= 0)
330 VehiclesToCheck.Remove(
Vehicle);
337void UYieldSignComponent::RemoveSameVehicleInBothLists()
339 for(
auto*
Vehicle : VehiclesInYield)
341 if(VehiclesToCheck.Contains(
Vehicle))
343 VehiclesToCheck.Remove(
Vehicle);
Base class for CARLA wheeled vehicles.
FTransform GlobalToLocalTransform(const FTransform &InTransform) const
Wheeled vehicle controller with optional AI.
void SetTrafficLightState(ETrafficLightState InTrafficLightState)
Set traffic light state currently affecting this vehicle.
static ALargeMapManager * GetLargeMapManager(const UObject *WorldContextObject)
double GetDistance() const
JuncId GetJunctionId(RoadId road_id) const
std::vector< Waypoint > GetPrevious(Waypoint waypoint, double distance) const
Return the list of waypoints at distance in the reversed direction that a vehicle at waypoint could d...
bool IsJunction(RoadId road_id) const
double GetLaneWidth(Waypoint waypoint) const
boost::optional< element::Waypoint > GetWaypoint(const geom::Location &location, int32_t lane_type=static_cast< int32_t >(Lane::LaneType::Driving)) const
std::vector< Waypoint > GetNext(Waypoint waypoint, double distance) const
Return the list of waypoints at distance such that a vehicle at waypoint could drive to.
Junction * GetJunction(JuncId id)
std::vector< Waypoint > GenerateWaypointsInRoad(RoadId road_id, Lane::LaneType lane_type=Lane::LaneType::Driving) const
Generate waypoints at the entry of each lane of the specified road
geom::Transform ComputeTransform(Waypoint waypoint) const
std::vector< Waypoint > GetPredecessors(Waypoint waypoint) const
const Lane & GetLane(Waypoint waypoint) const
========================================================================
const T * GetInfo(const double s) const
carla::SharedPtr< carla::client::Junction > Junction
This file contains definitions of common data structures used in traffic manager.
static void log_warning(Args &&... args)