Drake
right_of_way_rule.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "drake/automotive/maliput/api/rules/regions.h"
4 #include "drake/automotive/maliput/api/type_specific_identifier.h"
5 #include "drake/common/drake_copyable.h"
6 
7 namespace drake {
8 namespace maliput {
9 namespace api {
10 namespace rules {
11 
12 
13 /// Rule describing right-of-way, a.k.a. priority.
14 ///
15 /// Right-of-way rules cover things like stop signs, yield signs, and
16 /// traffic lights: in other words, control over how competing traffic
17 /// flows take turns traversing regions of the road network.
18 ///
19 /// Each rule instance comprises:
20 /// * a controlled_zone (a LaneSRoute) which specifies a contiguous
21 /// longitudinal lane-wise section of the road network to which the
22 /// instance applies;
23 /// * a type (a Type) which indicates the right-of-way semantics for a vehicle
24 /// traversing the controlled_zone.
25 /// The type may be "dynamic", in which the semantic state is delegated to
26 /// an RightOfWayStateProvider agent, linked by this rule's Id.
27 ///
28 /// A RightOfWayRule instance determines whether or not a vehicle is
29 /// allowed to enter the controlled_zone. Having entered, vehicles
30 /// should not stop within a controlled_zone, and thus should not
31 /// enter the controlled_zone if traffic conditions may cause them
32 /// to stop within the zone.
34  public:
36 
37  /// Basic static semantics of the rule instance.
38  // TODO(maddog@tri.global) Describe turn-taking rules for StopThenGo
39  // (e.g., 4-way stop intersection), which is
40  // related to...
41  // TODO(maddog@tri.global) Add explicit yield-to-whom semantics.
42  enum class Type {
43  kProceed = 0, ///< No restriction on vehicle's right-of-way, but it
44  /// must still avoid stopping within the controlled-zone.
45  kYield, ///< Vehicles must yield to competing traffic.
46  kStopThenGo, ///< Vehicles must come to a complete stop before entering
47  /// the controlled-zone, but may then proceed if safe.
48  kDynamic ///< Delegate semantics to a RightOfWayStateProvider,
49  /// with state linked by the Id of this rule.
50  };
51 
52  /// Rule semantics which may be expressed via a dynamic agent.
53  // TODO(maddog@tri.global) Better define fallback semantics of "dark-mode".
54  // TODO(maddog@tri.global) Better distinguish Go, Caution, Yield
55  enum class DynamicState {
56  kUncontrolled = 0, ///< Signaling apparatus is non-functional (e.g.,
57  /// "dark mode").
58  kGo, ///< Vehicle has right-of-way.
59  kPrepareToStop, ///< Vehicle has right-of-way, but rule state will
60  /// soon transition to kStop.
61  kStop, ///< Vehicle does not have right-of-way (and thus
62  /// must not enter the controlled-zone).
63  kPrepareToGo, ///< Vehicle does not have right-of-way, but rule
64  /// state will soon transition to kGo.
65  kProceedWithCaution, ///< Vehicle has right-of-way.
66  kYield, ///< Vehicles must yield to competing traffic.
67  kStopThenGo ///< Vehicle must come to complete stop before
68  /// entering controlled-zone, but may then
69  /// proceed if safe;
70  };
71 
73 
74  /// Constructs a RightOfWayRule.
75  ///
76  /// @param id the unique ID of this rule (in the RoadRulebook)
77  /// @param controlled_zone LaneSRoute to which this rule applies
78  /// @param type the static semantics of this rule
79  RightOfWayRule(const Id& id,
81  : id_(id), controlled_zone_(controlled_zone), type_(type) {}
82 
83  /// Returns the persistent identifier.
84  Id id() const { return id_; }
85 
86  /// Returns the rule's controlled zone.
87  const LaneSRoute& controlled_zone() const { return controlled_zone_; }
88 
89  /// Returns the static rule semantic.
90  Type type() const { return type_; }
91 
92  private:
93  Id id_;
94  LaneSRoute controlled_zone_;
95  Type type_{};
96  // TODO(maddog) Add bool field for "stopping is excluded in zone"?
97 };
98 
99 
100 /// Abstract interface for the provider of the dynamic semantic state of
101 /// a RightOfWayRule.
103  public:
105 
106  virtual ~RightOfWayStateProvider() = default;
107 
108  /// Returns the current state of the RightOfWayRule identified by `id`.
109  ///
110  /// Throws an exception if `id` is unrecognized, which should be the
111  /// case if no such rule exists or if the rule has only static semantics.
112  // TODO(maddog@tri.global) Better to throw exception or return an optional?
114  return DoGetState(id);
115  }
116 
117  protected:
118  RightOfWayStateProvider() = default;
119 
120  private:
121  virtual RightOfWayRule::DynamicState DoGetState(
122  const RightOfWayRule::Id& id) const = 0;
123 };
124 
125 
126 } // namespace rules
127 } // namespace api
128 } // namespace maliput
129 } // namespace drake
Rule describing right-of-way, a.k.a.
Definition: right_of_way_rule.h:33
Definition: automotive_demo.cc:90
Vehicles must yield to competing traffic.
No restriction on vehicle&#39;s right-of-way, but it must still avoid stopping within the controlled-zone...
const LaneSRoute & controlled_zone() const
Returns the rule&#39;s controlled zone.
Definition: right_of_way_rule.h:87
Type
Basic static semantics of the rule instance.
Definition: right_of_way_rule.h:42
Id id() const
Returns the persistent identifier.
Definition: right_of_way_rule.h:84
RightOfWayRule(const Id &id, const LaneSRoute &controlled_zone, Type type)
Constructs a RightOfWayRule.
Definition: right_of_way_rule.h:79
#define DRAKE_DEFAULT_COPY_AND_MOVE_AND_ASSIGN(Classname)
DRAKE_DEFAULT_COPY_AND_MOVE_AND_ASSIGN defaults the special member functions for copy-construction, copy-assignment, move-construction, and move-assignment.
Definition: drake_copyable.h:57
A longitudinal route, possibly spanning multiple (end-to-end) lanes.
Definition: regions.h:72
Abstract interface for the provider of the dynamic semantic state of a RightOfWayRule.
Definition: right_of_way_rule.h:102
RightOfWayRule::DynamicState GetState(const RightOfWayRule::Id &id) const
Returns the current state of the RightOfWayRule identified by id.
Definition: right_of_way_rule.h:113
Delegate semantics to a RightOfWayStateProvider, with state linked by the Id of this rule...
Type type() const
Returns the static rule semantic.
Definition: right_of_way_rule.h:90
DynamicState
Rule semantics which may be expressed via a dynamic agent.
Definition: right_of_way_rule.h:55
#define DRAKE_NO_COPY_NO_MOVE_NO_ASSIGN(Classname)
DRAKE_NO_COPY_NO_MOVE_NO_ASSIGN deletes the special member functions for copy-construction, copy-assignment, move-construction, and move-assignment.
Definition: drake_copyable.h:33
Vehicles must come to a complete stop before entering the controlled-zone, but may then proceed if sa...