Drake
rotary_encoders.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <memory>
4 #include <vector>
5 
9 
10 namespace drake {
11 namespace systems {
12 namespace sensors {
13 
14 /// Simple model to capture the quantization and calibration offset effects
15 /// of a rotary encoder. Consider combining this with a ZeroOrderHold system
16 /// to capture the sampled-data effects.
17 ///
18 /// The inputs to this system are assumed to be in radians, and the outputs of
19 /// the system are also in radians.
20 ///
21 /// @ingroup sensor_systems
22 template <typename T>
23 class RotaryEncoders final : public VectorSystem<T> {
24  public:
26 
27  /// Quantization-only constructor. Specifies one ticks_per_revolution count
28  /// for every element of the input port.
29  explicit RotaryEncoders(const std::vector<int>& ticks_per_revolution);
30 
31  /// Selector-only constructor. Provides arguments to select particular
32  /// indices from the input signal to use in the output. Since
33  /// ticks_per_revolution is not being set, the outputs will NOT be quantized.
34  /// @param input_port_size Dimension of the expected input signal
35  /// @param input_vector_indices List of indices
36  RotaryEncoders(int input_port_size,
37  const std::vector<int>& input_vector_indices);
38 
39  /// Quantization and Selector constructor.
40  RotaryEncoders(int input_port_size,
41  const std::vector<int>& input_vector_indices,
42  const std::vector<int>& ticks_per_revolution);
43 
44  /// Scalar-converting copy constructor. See @ref system_scalar_conversion.
45  template <typename U>
46  explicit RotaryEncoders(const RotaryEncoders<U>&);
47 
48  /// Set the calibration offset parameters.
50  Context<T>* context,
51  const Eigen::Ref<VectorX<T>>& calibration_offsets) const;
52 
53  /// Retreive the calibration offset parameters.
54  Eigen::VectorBlock<const VectorX<T>> get_calibration_offsets(
55  const Context<T>& context) const;
56 
57  private:
58  // Allow different specializations to access each other's private data.
59  template <typename> friend class RotaryEncoders;
60 
61  // Outputs the transformed signal.
62  void DoCalcVectorOutput(
63  const Context<T>& context,
64  const Eigen::VectorBlock<const VectorX<T>>& input,
65  const Eigen::VectorBlock<const VectorX<T>>& state,
66  Eigen::VectorBlock<VectorX<T>>* output) const override;
67 
68  const int num_encoders_{0}; // Dimension of the output port.
69  const std::vector<int> indices_; // Selects from the input port.
70  const std::vector<int> ticks_per_revolution_; // For quantization.
71 };
72 
73 } // namespace sensors
74 } // namespace systems
75 } // namespace drake
This file contains abbreviated definitions for certain specializations of Eigen::Matrix that are comm...
A base class that specializes LeafSystem for use with only zero or one vector input ports...
Definition: vector_system.h:29
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
friend class RotaryEncoders
Definition: rotary_encoders.h:59
void set_calibration_offsets(Context< T > *context, const Eigen::Ref< VectorX< T >> &calibration_offsets) const
Set the calibration offset parameters.
Definition: rotary_encoders.cc:102
Simple model to capture the quantization and calibration offset effects of a rotary encoder...
Definition: rotary_encoders.h:23
#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
Eigen::VectorBlock< const VectorX< T > > get_calibration_offsets(const Context< T > &context) const
Retreive the calibration offset parameters.
Definition: rotary_encoders.cc:113
Provides careful macros to selectively enable or disable the special member functions for copy-constr...