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 }
static constexpr char Germany[]
static constexpr const char Road[]
static constexpr const char Nonurban[]
static constexpr const char Vehicle[]
Optional< ConstLaneletOrArea > next
static constexpr const char Lanelet[]
static constexpr const char LineThin[]
BasicPolygon3d right
BasicPolygon3d left
static TrafficRulesUPtr create(const std::string &location, const std::string &participant, TrafficRules::Configuration configuration=TrafficRules::Configuration())
static constexpr const char Pedestrian[]
void part1UsingTrafficRules()
int main()
static Ptr make(Id id, const AttributeMap &attributes, const TrafficSignsWithType &trafficSigns, const TrafficSignsWithType &cancellingTrafficSigns={}, const LineStrings3d &refLines={}, const LineStrings3d &cancelLines={})
LineString3d getLineStringAtY(double y)
static constexpr const char Crosswalk[]
LineString3d getLineStringAtX(double x)
Definition: ExampleHelpers.h:7
static constexpr const char Dashed[]
std::shared_ptr< TrafficRules > TrafficRulesPtr
std::shared_ptr< SpeedLimit > Ptr


lanelet2_examples
Author(s): Fabian Poggenhans
autogenerated on Tue Jun 6 2023 02:24:00