Drake
road_rulebook.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <vector>
4 
10 
11 namespace drake {
12 namespace maliput {
13 namespace api {
14 namespace rules {
15 
16 /// Abstract interface for querying "rules of the road". This interface
17 /// provides access to static information about a road network (i.e.,
18 /// information determined prior to the beginning of a simulation). Some
19 /// rule types may refer to additional dynamic information which will be
20 /// provided by other interfaces. (For example, see RightOfWayRule.)
21 ///
22 /// Concrete implementations of this interface shall be provided by
23 /// implementing the pure virtual methods declared in private scope.
24 class RoadRulebook {
25  public:
27 
28  virtual ~RoadRulebook() = default;
29 
30  /// Results of a FindRules() query. Results are organized by type; an
31  /// empty vector indicates no applicable rules of that type are known.
32  struct QueryResults {
33  std::vector<RightOfWayRule> right_of_way;
34  std::vector<SpeedLimitRule> speed_limit;
35  };
36 
37  /// Returns a QueryResults structure which contains any rules which are
38  /// applicable to the provided `ranges`.
39  ///
40  /// `tolerance` is the acceptable linear-tolerance in longitudinal
41  /// s-coordinate in each range and must be non-negative. A non-zero
42  /// `tolerance` makes the query more permissive. However, a non-zero
43  /// `tolerance` does not permit matching across BranchPoints (past the
44  /// s-bounds of a Lane).
45  ///
46  /// @throws std::runtime_error if `tolerance` is negative.
48  const std::vector<LaneSRange>& ranges, double tolerance) const {
49  DRAKE_THROW_UNLESS(tolerance >= 0.);
50  return DoFindRules(ranges, tolerance);
51  }
52 
53  /// Returns the RightOfWayRule with the specified `id`.
54  ///
55  /// Throws std::out_of_range if `id` is unknown.
57  return DoGetRule(id);
58  }
59 
60  /// Returns the SpeedLimitRule with the specified `id`.
61  ///
62  /// Throws std::out_of_range if `id` is unknown.
64  return DoGetRule(id);
65  }
66 
67  protected:
68  RoadRulebook() = default;
69 
70  private:
71  // @name NVI implementations of the public methods.
72  // These must satisfy the constraints/invariants of the
73  // corresponding public methods.
74  //@{
75  virtual QueryResults DoFindRules(
76  const std::vector<LaneSRange>& ranges, double tolerance) const = 0;
77  virtual RightOfWayRule DoGetRule(const RightOfWayRule::Id& id) const = 0;
78  virtual SpeedLimitRule DoGetRule(const SpeedLimitRule::Id& id) const = 0;
79  //@}
80 };
81 
82 } // namespace rules
83 } // namespace api
84 } // namespace maliput
85 } // namespace drake
QueryResults FindRules(const std::vector< LaneSRange > &ranges, double tolerance) const
Returns a QueryResults structure which contains any rules which are applicable to the provided ranges...
Definition: road_rulebook.h:47
Rule describing right-of-way, a.k.a.
Definition: right_of_way_rule.h:40
Abstract interface for querying "rules of the road".
Definition: road_rulebook.h:24
Provides a convenient wrapper to throw an exception when a condition is unmet.
Definition: bullet_model.cc:22
RightOfWayRule GetRule(const RightOfWayRule::Id &id) const
Returns the RightOfWayRule with the specified id.
Definition: road_rulebook.h:56
Rule describing speed limits.
Definition: speed_limit_rule.h:22
#define DRAKE_THROW_UNLESS(condition)
Evaluates condition and iff the value is false will throw an exception with a message showing at leas...
Definition: drake_throw.h:23
SpeedLimitRule GetRule(const SpeedLimitRule::Id &id) const
Returns the SpeedLimitRule with the specified id.
Definition: road_rulebook.h:63
std::vector< RightOfWayRule > right_of_way
Definition: road_rulebook.h:33
Results of a FindRules() query.
Definition: road_rulebook.h:32
#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
std::vector< SpeedLimitRule > speed_limit
Definition: road_rulebook.h:34
const double tolerance
Definition: dynamic_bicycle_car_test.cc:42
Provides careful macros to selectively enable or disable the special member functions for copy-constr...