-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Open
Description
Setup
- CARLA version: ue4-dev
- Platform: Ubuntu 22.04
- Python version: 3.10.12
- GPU: 2x RTX 4090s
- GPU Drivers: 580.95.05
Describe the bug
The bus (Fusorosa) gets physically blocked by some stop signs (the ones in the rural area) in large maps because they are too close to the road.
Steps to Reproduce
import carla
try:
client = carla.Client('localhost', 2000)
client.set_timeout(40.0)
for map in ['Town12']:
client.load_world(map)
world = client.get_world()
settings = world.get_settings()
settings.fixed_delta_seconds = 0.05
settings.synchronous_mode = True
world.apply_settings(settings)
sp = world.get_spectator()
traffic_manager = client.get_trafficmanager(8000)
traffic_manager.set_synchronous_mode(True)
bp = world.get_blueprint_library().filter('fusorosa')[0]
vehicle = None
while vehicle is None:
vehicle = world.try_spawn_actor(bp, carla.Transform(carla.Location(x=1580.4, y=1816.6, z=357.4), carla.Rotation(yaw=269.55)))
vehicle.set_autopilot(True, 8000)
vehicle.set_simulate_physics(True)
# vehicle.show_debug_telemetry(True)
traffic_manager.update_vehicle_lights(vehicle, True)
world.tick()
t = 4000
for j in range(t):
world.tick()
transform = vehicle.get_transform()
# Calculate the spectator's desired position.
view_x = transform.location.x - 16.0 * transform.get_forward_vector().x
view_y = transform.location.y - 16.0 * transform.get_forward_vector().y
view_z = transform.location.z + 8.0
# Calculate the spectator's desired orientation.
view_roll = transform.rotation.roll
view_pitch = transform.rotation.pitch - 16.0
view_yaw = transform.rotation.yaw
# Get the spectator and place it in the calculated position.
sp.set_transform(
carla.Transform(
carla.Location(x=view_x, y=view_y, z=view_z),
carla.Rotation(roll=view_roll, pitch=view_pitch, yaw=view_yaw)
)
)
vehicle.destroy()
world.tick()
except KeyboardInterrupt:
print('Cancelled by user. Shutting down.')
vehicle.destroy()
finally:
settings = world.get_settings()
settings.synchronous_mode = False
world.apply_settings(settings)Screenshots
Solution
Not the prettiest but using the code below in LargeMapManager.cpp seems to work by adding a horizontal offset to the stop signs that are too close to the road centerline (distance less than 210 cm), and from what I've seen the bounding boxes remain correct after applying the offset while the trigger volume is excepted from it.
void ALargeMapManager::AdjustAllSignsToHeightGround()
{
UWorld* World = GetWorld();
if (!World)
{
return;
}
UCarlaEpisode* CarlaEpisode = UCarlaStatics::GetCurrentEpisode(World);
ACarlaGameModeBase *GameMode = UCarlaStatics::GetGameMode(CarlaEpisode->GetWorld());
const boost::optional<carla::road::Map>& CarlaMap = GameMode->GetMap();
TArray<AActor*> ActorsToIgnore;
TArray<AActor*> ActorsToAdjustHeight;
UGameplayStatics::GetAllActorsOfClass(World, ATrafficSignBase::StaticClass(), ActorsToAdjustHeight);
ActorsToIgnore.Append(ActorsToAdjustHeight);
const float MinDistanceToWaypoint = 210.0f;
for (AActor* Actor : ActorsToAdjustHeight)
{
ATrafficSignBase* TrafficSign = Cast<ATrafficSignBase>(Actor);
if (!IsValid(TrafficSign))
continue;
if (TrafficSign->bPositioned)
continue;
FVector OriginalLocation = Actor->GetActorLocation();
FVector AdjustedLocation = OriginalLocation;
TrafficSign->bPositioned = AdjustSignHeightToGround(AdjustedLocation, Actor->GetName(), ActorsToIgnore);
if (TrafficSign->bPositioned)
{
if (Actor->GetName().Contains("BP_Stop_v02"))
{
if (!CarlaMap.has_value())
{
LM_LOG(Warning, "No Carla map available to offset stop sign %s position", *Actor->GetName());
continue;
}
FVector GlobalLocation = LocalToGlobalLocation(AdjustedLocation);
carla::geom::Location CarlaLocation = GlobalLocation;
auto Waypoint = CarlaMap->GetClosestWaypointOnRoad(CarlaLocation);
if (Waypoint.has_value())
{
carla::geom::Transform WaypointTransform = CarlaMap->ComputeTransform(Waypoint.value());
carla::geom::Location WaypointLocation = WaypointTransform.location;
// Calculate 2D distance
float dx = (CarlaLocation.x - WaypointLocation.x);
float dy = (CarlaLocation.y - WaypointLocation.y);
float Distance = FMath::Sqrt(dx*dx + dy*dy) * 100.0f;
if (Distance <= MinDistanceToWaypoint)
{
FVector ForwardVector = Actor->GetActorForwardVector();
AdjustedLocation += ForwardVector * (MinDistanceToWaypoint - Distance + 0.02f);
AdjustSignHeightToGround(AdjustedLocation, Actor->GetName(), ActorsToIgnore);
LM_LOG(Log, "Offsetting stop sign %s (distance: %.2f cm) by %.2f cm",
*Actor->GetName(), Distance, MinDistanceToWaypoint - Distance + 0.02f);
}
}
}
FVector Offset = AdjustedLocation - OriginalLocation;
Actor->GetRootComponent()->SetMobility(EComponentMobility::Movable);
Actor->SetActorLocation(AdjustedLocation);
TArray<UBoxComponent*> BoxComponents;
Actor->GetComponents<UBoxComponent>(BoxComponents);
for (UBoxComponent* BoxComp : BoxComponents)
{
if (!BoxComp) continue;
FVector BoxLocation = BoxComp->GetRelativeLocation();
if (BoxComp->GetName().Contains("Stop Box"))
{
BoxLocation.Z -= Offset.Z;
} else {
BoxLocation -= Offset;
}
BoxComp->SetRelativeLocation(BoxLocation);
}
LM_LOG(Log, "Adjusted sign %s height by %f cm", *Actor->GetName(), Offset.Z);
Actor->UpdateComponentTransforms();
Actor->GetRootComponent()->SetMobility(EComponentMobility::Static);
}
}
}Metadata
Metadata
Assignees
Labels
No labels