Skip to content

Add crosswalks to the test #9121

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions LibCarla/source/carla/opendrive/parser/ObjectParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "carla/road/element/RoadInfoCrosswalk.h"
#include "carla/road/Road.h"


#include <pugixml/pugixml.hpp>

namespace carla {
Expand All @@ -21,7 +22,6 @@ namespace parser {
carla::road::MapBuilder &map_builder) {

std::vector<road::element::CrosswalkPoint> points;

for (pugi::xml_node node_road : xml.child("OpenDRIVE").children("road")) {

// parse all objects
Expand All @@ -33,8 +33,11 @@ namespace parser {
// type Crosswalk
std::string type = node_object.attribute("type").as_string();
std::string name = node_object.attribute("name").as_string();
if (type == "crosswalk") {

std::string name_lower = name;
std::transform(name_lower.begin(), name_lower.end(), name_lower.begin(),
[](unsigned char c){ return std::tolower(c); });
bool bIsCrosswalk = (type == "crosswalk" || (name_lower.find("crosswalk") != std::string::npos));
if (bIsCrosswalk) {
// read all points
pugi::xml_node node_outline = node_object.child("outline");
if (node_outline) {
Expand Down Expand Up @@ -119,6 +122,8 @@ namespace parser {
}
}
}


}
} // namespace parser
} // namespace opendrive
Expand Down
1 change: 1 addition & 0 deletions LibCarla/source/carla/road/Map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,7 @@ namespace road {
}
}
}

return result;
}

Expand Down
9 changes: 9 additions & 0 deletions PythonAPI/test/smoke/test_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,12 @@ def _check_map(self, m):
waypoint = random.choice(next_waypoints)
_ = m.transform_to_geolocation(carla.Location())
self.assertTrue(str(m.to_opendrive()))

maps_withoutcrosswalks = ['Town01', 'Town01_Opt', 'Town02', 'Town02_Opt']
if not any(map_name in m.name for map_name in maps_withoutcrosswalks):
# --- Check for crosswalks using get_crosswalks() ---
crosswalks = m.get_crosswalks()
self.assertGreater(
len(crosswalks), 0,
msg=f"Map {m.name} has no crosswalks."
)
46 changes: 46 additions & 0 deletions PythonAPI/util/check_map.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env python

# Copyright (c) 2020 Computer Vision Center (CVC) at the Universitat Autonoma de
# Barcelona (UAB).
#
# This work is licensed under the terms of the MIT license.
# For a copy, see <https://opensource.org/licenses/MIT>.

"""

Quick check script to get map stuff
"""

import glob
import os
import sys
import numpy as np
from queue import Queue
from queue import Empty

try:
sys.path.append(glob.glob('../carla/dist/carla-*%d.%d-%s.egg' % (
sys.version_info.major,
sys.version_info.minor,
'win-amd64' if os.name == 'nt' else 'linux-x86_64'))[0])
except IndexError:
pass

import carla


def main():
# We start creating the client
client = carla.Client('localhost', 2000)
client.set_timeout(30.0)
world = client.get_world()
crosswalks = world.get_map().get_crosswalks()
print(f"Crosswalks found: {len(crosswalks)}")
for crosswalk in crosswalks:
world.debug.draw_point(crosswalk, size=0.5, color=carla.Color(255, 0, 0), life_time=5000.0)

if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
print(' - Exited by user.')