Drake
simple_car.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <memory>
4 
5 #include "drake/automotive/gen/driving_command.h"
6 #include "drake/automotive/gen/simple_car_params.h"
7 #include "drake/automotive/gen/simple_car_state.h"
12 
13 namespace drake {
14 namespace automotive {
15 
16 /// SimpleCar models an idealized response to driving commands, neglecting all
17 /// physics. Note that SimpleCar can move forward, stop, turn left, and turn
18 /// right but *cannot* travel in reverse.
19 ///
20 /// parameters:
21 /// * uses systems::Parameters wrapping a SimpleCarParams
22 ///
23 /// state vector (planar for now):
24 /// * position: x, y, heading;
25 /// heading is 0 rad when pointed +x, pi/2 rad when pointed +y;
26 // heading is defined around the +z axis, so positive-turn-left
27 /// * velocity
28 ///
29 /// input vector:
30 /// * steering angle (virtual center wheel angle);
31 /// a positive angle means a positive change in heading (left turn);
32 /// the value must lie within (-pi, +pi).
33 /// * throttle (0-1)
34 /// * brake (0-1)
35 ///
36 /// output port 0: same as state vector.
37 /// output port 1: A PoseVector containing X_WC, where C is the car frame.
38 /// output port 2: A FrameVelocity containing Xdot_WC, where C is the car frame.
39 ///
40 /// @tparam T must support certain arithmetic operations;
41 /// for details, see drake::symbolic::Expression.
42 ///
43 /// Instantiated templates for the following ScalarTypes are provided:
44 /// - double
45 /// - drake::AutoDiffXd
46 /// - drake::symbolic::Expression
47 ///
48 /// They are already available to link against in the containing library.
49 ///
50 /// @ingroup automotive_plants
51 template <typename T>
52 class SimpleCar final : public systems::LeafSystem<T> {
53  public:
55 
56  SimpleCar();
57 
58  /// Scalar-converting copy constructor. See @ref system_scalar_conversion.
59  template <typename U>
60  explicit SimpleCar(const SimpleCar<U>&);
61 
62  // System<T> overrides
64  const systems::Context<T>& context,
65  systems::ContinuousState<T>* derivatives) const override;
66 
67  const systems::OutputPort<T>& state_output() const;
68  const systems::OutputPort<T>& pose_output() const;
70 
71  private:
72  void CalcStateOutput(const systems::Context<T>&, SimpleCarState<T>*) const;
73  void CalcPose(const systems::Context<T>&,
75  void CalcVelocity(const systems::Context<T>&,
77 
78  void ImplCalcTimeDerivatives(const SimpleCarParams<T>& params,
79  const SimpleCarState<T>& state,
80  const DrivingCommand<T>& input,
81  SimpleCarState<T>* rates) const;
82 
83  void CalcSteeringAngleConstraint(const systems::Context<T>&,
84  VectorX<T>*) const;
85  void CalcAccelerationConstraint(const systems::Context<T>&,
86  VectorX<T>*) const;
87  void CalcVelocityConstraint(const systems::Context<T>&, VectorX<T>*) const;
88 };
89 
90 } // namespace automotive
91 } // namespace drake
void DoCalcTimeDerivatives(const systems::Context< T > &context, systems::ContinuousState< T > *derivatives) const override
Definition: simple_car.cc:145
Definition: automotive_demo.cc:88
Context is an abstract base class template that represents all the inputs to a System: time...
Definition: query_handle.h:10
Eigen::Matrix< Scalar, Eigen::Dynamic, 1 > VectorX
A column vector of any size, templated on scalar type.
Definition: eigen_types.h:46
SimpleCar()
Definition: simple_car.cc:61
An OutputPort belongs to a System and represents the properties of one of that System&#39;s output ports...
Definition: output_port.h:67
A superclass template that extends System with some convenience utilities that are not applicable to ...
Definition: leaf_system.h:82
SimpleCar models an idealized response to driving commands, neglecting all physics.
Definition: simple_car.h:52
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
const systems::OutputPort< T > & state_output() const
Definition: simple_car.cc:84
const systems::OutputPort< T > & velocity_output() const
Definition: simple_car.cc:94
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
const systems::OutputPort< T > & pose_output() const
Definition: simple_car.cc:89
#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
Provides careful macros to selectively enable or disable the special member functions for copy-constr...