Skip to content

Commit 5e20905

Browse files
authored
Add crosswalks to the test (#9121)
* Add crosswalks to the test * Added checks for crosslwaks * Update check_map.py * Update test_map.py * Update test_map.py * Remove checks in maps without crosswalks * Checksubstrings instead of equal name
1 parent a46b269 commit 5e20905

File tree

4 files changed

+64
-3
lines changed

4 files changed

+64
-3
lines changed

LibCarla/source/carla/opendrive/parser/ObjectParser.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "carla/road/element/RoadInfoCrosswalk.h"
1111
#include "carla/road/Road.h"
1212

13+
1314
#include <pugixml/pugixml.hpp>
1415

1516
namespace carla {
@@ -21,7 +22,6 @@ namespace parser {
2122
carla::road::MapBuilder &map_builder) {
2223

2324
std::vector<road::element::CrosswalkPoint> points;
24-
2525
for (pugi::xml_node node_road : xml.child("OpenDRIVE").children("road")) {
2626

2727
// parse all objects
@@ -33,8 +33,11 @@ namespace parser {
3333
// type Crosswalk
3434
std::string type = node_object.attribute("type").as_string();
3535
std::string name = node_object.attribute("name").as_string();
36-
if (type == "crosswalk") {
37-
36+
std::string name_lower = name;
37+
std::transform(name_lower.begin(), name_lower.end(), name_lower.begin(),
38+
[](unsigned char c){ return std::tolower(c); });
39+
bool bIsCrosswalk = (type == "crosswalk" || (name_lower.find("crosswalk") != std::string::npos));
40+
if (bIsCrosswalk) {
3841
// read all points
3942
pugi::xml_node node_outline = node_object.child("outline");
4043
if (node_outline) {
@@ -119,6 +122,8 @@ namespace parser {
119122
}
120123
}
121124
}
125+
126+
122127
}
123128
} // namespace parser
124129
} // namespace opendrive

LibCarla/source/carla/road/Map.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,7 @@ namespace road {
509509
}
510510
}
511511
}
512+
512513
return result;
513514
}
514515

PythonAPI/test/smoke/test_map.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,12 @@ def _check_map(self, m):
4848
waypoint = random.choice(next_waypoints)
4949
_ = m.transform_to_geolocation(carla.Location())
5050
self.assertTrue(str(m.to_opendrive()))
51+
52+
maps_withoutcrosswalks = ['Town01', 'Town01_Opt', 'Town02', 'Town02_Opt']
53+
if not any(map_name in m.name for map_name in maps_withoutcrosswalks):
54+
# --- Check for crosswalks using get_crosswalks() ---
55+
crosswalks = m.get_crosswalks()
56+
self.assertGreater(
57+
len(crosswalks), 0,
58+
msg=f"Map {m.name} has no crosswalks."
59+
)

PythonAPI/util/check_map.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env python
2+
3+
# Copyright (c) 2020 Computer Vision Center (CVC) at the Universitat Autonoma de
4+
# Barcelona (UAB).
5+
#
6+
# This work is licensed under the terms of the MIT license.
7+
# For a copy, see <https://opensource.org/licenses/MIT>.
8+
9+
"""
10+
11+
Quick check script to get map stuff
12+
"""
13+
14+
import glob
15+
import os
16+
import sys
17+
import numpy as np
18+
from queue import Queue
19+
from queue import Empty
20+
21+
try:
22+
sys.path.append(glob.glob('../carla/dist/carla-*%d.%d-%s.egg' % (
23+
sys.version_info.major,
24+
sys.version_info.minor,
25+
'win-amd64' if os.name == 'nt' else 'linux-x86_64'))[0])
26+
except IndexError:
27+
pass
28+
29+
import carla
30+
31+
32+
def main():
33+
# We start creating the client
34+
client = carla.Client('localhost', 2000)
35+
client.set_timeout(30.0)
36+
world = client.get_world()
37+
crosswalks = world.get_map().get_crosswalks()
38+
print(f"Crosswalks found: {len(crosswalks)}")
39+
for crosswalk in crosswalks:
40+
world.debug.draw_point(crosswalk, size=0.5, color=carla.Color(255, 0, 0), life_time=5000.0)
41+
42+
if __name__ == "__main__":
43+
try:
44+
main()
45+
except KeyboardInterrupt:
46+
print(' - Exited by user.')

0 commit comments

Comments
 (0)