05_traffic_rules/main.cpp
Go to the documentation of this file.
3 #include <lanelet2_core/primitives/Lanelet.h>
7 
9 
10 // we want assert statements to work in release mode
11 #undef NDEBUG
12 
14 
15 int main() {
16  // this tutorial shows how to use traffic rule objects to interpret map data
18  return 0;
19 }
20 
22  using namespace lanelet;
23  using namespace lanelet::units::literals;
24 
25  // first lets construct a sequence of lanelets. left is left of right, next follows right.
29  LineString3d nextLeftLs{utils::getId(),
30  {middleLs.back(), Point3d(utils::getId(), middleLs.back().x() + 1., middleLs.back().y())}};
31  LineString3d nextRightLs{utils::getId(),
32  {rightLs.back(), Point3d(utils::getId(), rightLs.back().x() + 1, rightLs.back().y())}};
33  Lanelet left{utils::getId(), leftLs, middleLs};
34  Lanelet right{utils::getId(), middleLs, rightLs};
35  Lanelet next{utils::getId(), nextLeftLs, nextRightLs};
36 
37  // to get information where we can drive, we need a traffic rule object o do the interpretation for us.
38  // we use the traffic rules factory to get an traffic rules object that interprets the lanelets from the perspective
39  // of a german vehicle.
40  traffic_rules::TrafficRulesPtr trafficRules =
42  traffic_rules::TrafficRulesPtr pedestrianRules =
44 
45  // now we can ask the traffic rules specific things about the lanelet. For now, we have not added any tags, so we
46  // get a default interpretation of the lanelet:
47  assert(trafficRules->canPass(right)); // lanelets are by default "road" lanelets
48  assert(!pedestrianRules->canPass(right)); // and not passable for pedestrians.
49  // by default, lanelets are one-directional, so inverted lanelets are also not passable
50  assert(!trafficRules->canPass(right.invert()));
51 
52  // also: no tags, no lane changes
53  assert(!trafficRules->canPass(right, left));
54 
55  // we can also query the speed limit. Without tags we get the speed limit for urban roads
57  assert(limit.speedLimit == 50_kmh);
58  assert(limit.isMandatory); // mandatory means we must not exceed the speed limit
59 
60  // now lets start to add some tags to get more meaningful results:
61  middleLs.attributes()[AttributeName::Type] = AttributeValueString::LineThin;
66  left.attributes() = right.attributes();
67  next.attributes() = right.attributes();
68  left.attributes()[AttributeName::OneWay] = false;
69 
70  // now we can see that lane changes are possible
71  assert(trafficRules->canChangeLane(right, left));
72  assert(trafficRules->canChangeLane(left, right));
73 
74  // and left is no drivable in inverted direction:
75  assert(trafficRules->canPass(left.invert()));
76  // but not do lane change to right (because right is not drivable in inverted direction)
77  assert(!trafficRules->canChangeLane(left, right.invert()));
78  assert(!trafficRules->canChangeLane(left.invert(), right.invert()));
79 
80  // also the reported speed limit is different (because lanelets are now nonurban)
81  limit = trafficRules->speedLimit(right);
82  assert(limit.speedLimit == 100_kmh); // on german nonurban roads
83 
84  // if we now add a speed limit regulatory element, the speed limit changes
86  SpeedLimit::Ptr speedLimit =
87  SpeedLimit::make(utils::getId(), {}, {{sign}, "de274-60"}); // id of a speed limit 60 sign in germany
88  right.addRegulatoryElement(speedLimit);
89  assert(trafficRules->speedLimit(right).speedLimit == 60_kmh);
90 
91  // if the type of the lanelet is changed from road to walkway, it is no longer drivable for vehicles:
93  assert(!trafficRules->canPass(right));
94 
95  // but instead, it is passable for pedestrians
96  assert(pedestrianRules->canPass(right));
97 }
lanelet::traffic_rules::SpeedLimitInformation::speedLimit
Velocity speedLimit
lanelet::SpeedLimit::make
static Ptr make(Id id, AttributeMap attributes, const std::string &signType, const LineStrings3d &refLines={}, const LineStrings3d &cancelLines={})
LaneletMap.h
lanelet
TrafficRulesFactory.h
next
Optional< ConstLaneletOrArea > next
lanelet::Participants::Pedestrian
static constexpr const char Pedestrian[]
lanelet::AttributeName::OneWay
@ OneWay
lanelet::utils::getId
Id getId()
lanelet::AttributeValueString::LineThin
static constexpr const char LineThin[]
right
BasicPolygon3d right
BasicRegulatoryElements.h
Units.h
part1UsingTrafficRules
void part1UsingTrafficRules()
Definition: 05_traffic_rules/main.cpp:21
lanelet::Lanelet
lanelet::AttributeName::Type
@ Type
lanelet::AttributeValueString::Crosswalk
static constexpr const char Crosswalk[]
lanelet::Locations::Germany
static constexpr char Germany[]
lanelet::examples::getLineStringAtY
LineString3d getLineStringAtY(double y)
Definition: ExampleHelpers.h:12
ExampleHelpers.h
lanelet::AttributeName::Location
@ Location
lanelet::Point3d
main
int main()
Definition: 05_traffic_rules/main.cpp:15
left
BasicPolygon3d left
lanelet::traffic_rules::SpeedLimitInformation
lanelet::Participants::Vehicle
static constexpr const char Vehicle[]
TrafficRules.h
lanelet::AttributeValueString::Road
static constexpr const char Road[]
lanelet::AttributeValueString::Nonurban
static constexpr const char Nonurban[]
lanelet::traffic_rules::TrafficRulesFactory::create
static TrafficRulesUPtr create(const std::string &location, const std::string &participant, TrafficRules::Configuration configuration=TrafficRules::Configuration())
lanelet::SpeedLimit::Ptr
std::shared_ptr< SpeedLimit > Ptr
lanelet::units::literals
lanelet::AttributeValueString::Dashed
static constexpr const char Dashed[]
lanelet::AttributeValueString::Lanelet
static constexpr const char Lanelet[]
lanelet::examples::getLineStringAtX
LineString3d getLineStringAtX(double x)
Definition: ExampleHelpers.h:7
lanelet::LineString3d
lanelet::AttributeName::Subtype
@ Subtype
lanelet::traffic_rules::SpeedLimitInformation::isMandatory
bool isMandatory
lanelet::traffic_rules::TrafficRulesPtr
std::shared_ptr< TrafficRules > TrafficRulesPtr


lanelet2_examples
Author(s): Fabian Poggenhans
autogenerated on Thu Mar 6 2025 03:26:15