Compute displacement direction when moving signals

This commit is contained in:
Joel Moriana 2022-08-16 12:05:06 +02:00 committed by glopezdiest
parent e33c3400dd
commit 46089af72f
1 changed files with 18 additions and 2 deletions

View File

@ -1054,18 +1054,34 @@ void MapBuilder::CreateController(
(map.ComputeTransform(closest_waypoint_to_signal.get()).location -
signal_position).Length();
double lane_width = map.GetLaneWidth(closest_waypoint_to_signal.get());
int displacement_direction = 1;
int iter = 0;
int MaxIter = 10;
// Displaces signal until it finds a suitable spot
while(distance_to_road < (lane_width * 0.7) && iter < MaxIter) {
while(distance_to_road < (lane_width * 0.7) && iter < MaxIter && displacement_direction != 0) {
if(iter == 0) {
log_debug("Traffic sign",
signal->GetSignalId(),
"overlaps a driving lane. Moving out of the road...");
}
auto right_waypoint = map.GetRight(closest_waypoint_to_signal.get());
auto right_lane_type = (right_waypoint) ? map.GetLaneType(right_waypoint.get()) : carla::road::Lane::LaneType::None;
auto left_waypoint = map.GetLeft(closest_waypoint_to_signal.get());
auto left_lane_type = (left_waypoint) ? map.GetLaneType(left_waypoint.get()) : carla::road::Lane::LaneType::None;
if (right_lane_type != carla::road::Lane::LaneType::Driving) {
displacement_direction = 1;
} else if (left_lane_type != carla::road::Lane::LaneType::Driving) {
displacement_direction = -1;
} else {
displacement_direction = 0;
}
geom::Vector3D displacement = 1.f*(signal->GetTransform().GetRightVector()) *
static_cast<float>(abs(lane_width))*0.2f;
signal_position += displacement;
signal_position += (displacement * displacement_direction);
closest_waypoint_to_signal =
map.GetClosestWaypointOnRoad(signal_position,
static_cast<int32_t>(carla::road::Lane::LaneType::Shoulder) | static_cast<int32_t>(carla::road::Lane::LaneType::Driving));