Drake
maliput_railcar.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <memory>
4 #include <vector>
5 
15 
16 namespace drake {
17 namespace automotive {
18 
62 template <typename T>
64  public:
74  static constexpr double kLaneEndEpsilon{1e-12};
75 
89  static constexpr double kTimeEpsilon{1e-12};
90 
95  explicit MaliputRailcar(const LaneDirection& initial_lane_direction);
96 
97  // System<T> overrides.
99  const systems::Context<T>& context,
100  systems::ContinuousState<T>* derivatives) const override;
101 
102  void SetDefaultState(const systems::Context<T>& context,
103  systems::State<T>* state) const override;
104 
106  static void SetDefaultState(MaliputRailcarState<T>* railcar_state);
107 
110  systems::Context<T>* context) const;
111 
115  const systems::OutputPort<T>& state_output() const;
117  const systems::OutputPort<T>& pose_output() const;
120 
121  static constexpr T kDefaultInitialS = T(0);
122  static constexpr T kDefaultInitialSpeed = T(1);
123 
124  protected:
125  // LeafSystem<T> overrides.
126  std::unique_ptr<systems::AbstractValues> AllocateAbstractState()
127  const override;
128  optional<bool> DoHasDirectFeedthrough(int, int) const override;
129  void DoCalcNextUpdateTime(const systems::Context<T>& context,
131  T* time) const override;
133  const systems::Context<T>& context,
135  systems::State<T>* state) const override;
136 
137  private:
138  void CalcStateOutput(
139  const systems::Context<T>& context,
140  MaliputRailcarState<T>* output) const;
141 
142  void CalcLaneOutput(
143  const systems::Context<T>& context,
144  LaneDirection* output) const;
145 
146  void CalcPose(
147  const systems::Context<T>& context,
149 
150  void CalcVelocity(
151  const systems::Context<T>& context,
153 
154  void ImplCalcTimeDerivatives(
155  const MaliputRailcarParams<T>& params,
156  const MaliputRailcarState<T>& state,
157  const LaneDirection& lane_direction,
158  const systems::BasicVector<T>& input,
159  MaliputRailcarState<T>* rates) const;
160 
161  void ImplCalcTimeDerivativesDouble(
162  const MaliputRailcarParams<double>& params,
163  const MaliputRailcarState<double>& state,
164  MaliputRailcarState<double>* rates) const;
165 
166  // Calculates the vehicle's `r` coordinate based on whether it's traveling
167  // with or against `s` in the current lane relative to the initial lane.
168  T CalcR(const MaliputRailcarParams<T>& params,
169  const LaneDirection& lane_direction) const;
170 
171  // Finds our parameters in a context.
172  const MaliputRailcarParams<T>& get_parameters(
173  const systems::Context<T>& context) const;
174 
175  const LaneDirection initial_lane_direction_{};
176  int command_input_port_index_{};
177  int state_output_port_index_{};
178  int lane_state_output_port_index_{};
179  int pose_output_port_index_{};
180  int velocity_output_port_index_{};
181 };
182 
183 } // namespace automotive
184 } // namespace drake
static constexpr T kDefaultInitialSpeed
Definition: maliput_railcar.h:122
void DoCalcTimeDerivatives(const systems::Context< T > &context, systems::ContinuousState< T > *derivatives) const override
Definition: maliput_railcar.cc:231
optional< bool > DoHasDirectFeedthrough(int, int) const override
Returns true if there is direct-feedthrough from the given input_port to the given output_port...
Definition: maliput_railcar.cc:301
static constexpr double kTimeEpsilon
Defines a time interval that is used to ensure a desired update time is always greater than (i...
Definition: maliput_railcar.h:89
std::unique_ptr< systems::AbstractValues > AllocateAbstractState() const override
Reserves the abstract state as required by CreateDefaultContext.
Definition: maliput_railcar.cc:292
const systems::OutputPort< T > & state_output() const
Definition: maliput_railcar.cc:108
MaliputRailcarParams< T > * get_mutable_parameters(systems::Context< T > *context) const
Returns a mutable pointer to the parameters in the given context.
Definition: maliput_railcar.cc:128
static constexpr double kLaneEndEpsilon
Defines a distance that is "close enough" to the end of a lane for the vehicle to transition to an on...
Definition: maliput_railcar.h:74
Definition: automotive_demo.cc:88
void DoCalcNextUpdateTime(const systems::Context< T > &context, systems::CompositeEventCollection< T > *, T *time) const override
Definition: maliput_railcar.cc:336
Context is an abstract base class template that represents all the inputs to a System: time...
Definition: query_handle.h:10
MaliputRailcar models a vehicle that follows a maliput::api::Lane as if it were on rails and neglecti...
Definition: maliput_railcar.h:63
This class represents an unrestricted update event.
Definition: event.h:326
std::vector< double > vector
Definition: translator_test.cc:20
InputPortDescriptor is a notation for specifying the kind of input a System accepts, on a given port.
Definition: input_port_descriptor.h:19
stx::optional< T > optional
Definition: drake_optional.h:15
An OutputPort belongs to a System and represents the properties of one of that System&#39;s output ports...
Definition: output_port.h:67
static constexpr T kDefaultInitialS
Definition: maliput_railcar.h:121
const systems::OutputPort< T > & pose_output() const
Definition: maliput_railcar.cc:118
State is a container for all the data comprising the complete state of a particular System at a parti...
Definition: state.h:27
const systems::OutputPort< T > & velocity_output() const
Definition: maliput_railcar.cc:123
Specializes BasicVector with specific getters and setters.
Definition: maliput_railcar_state.h:37
const systems::OutputPort< T > & lane_state_output() const
Definition: maliput_railcar.cc:113
A superclass template that extends System with some convenience utilities that are not applicable to ...
Definition: leaf_system.h:43
LaneDirection holds the lane that a MaliputRailcar is traversing and the direction in which it is mov...
Definition: lane_direction.h:13
A 7-vector representing the transform of frame A in the world frame, X_WA, in the form {p_WA...
Definition: pose_vector.h:19
BasicVector is a semantics-free wrapper around an Eigen vector that satisfies VectorBase.
Definition: basic_vector.h:25
This class bundles an instance of each EventCollection<EventType> into one object that stores the het...
Definition: event.h:22
const double time
Definition: robot_plan_interpolator_test.cc:63
MaliputRailcar(const MaliputRailcar &)=delete
void DoCalcUnrestrictedUpdate(const systems::Context< T > &context, const std::vector< const systems::UnrestrictedUpdateEvent< T > * > &, systems::State< T > *state) const override
Definition: maliput_railcar.cc:378
void SetDefaultState(const systems::Context< T > &context, systems::State< T > *state) const override
Isometry3< double > pose
Definition: pose_smoother.cc:28
A 6-vector representing the derivatives of the position transform of frame A in the world frame...
Definition: frame_velocity.h:22
ContinuousState is a container for all the continuous state variables xc.
Definition: continuous_state.h:44
Specializes BasicVector with specific getters and setters.
Definition: maliput_railcar_params.h:39
const systems::InputPortDescriptor< T > & command_input() const
Getter methods for input and output ports.
Definition: maliput_railcar.cc:103
#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:35
Provides careful macros to selectively enable or disable the special member functions for copy-constr...