blmc_drivers
leg.hpp
Go to the documentation of this file.
1 
8 #pragma once
9 
10 #include <memory>
11 #include <string>
12 #include <map>
13 
14 #include <real_time_tools/threadsafe/threadsafe_timeseries.hpp>
15 
18 
19 namespace blmc_drivers
20 {
21 
27 {
28 public:
32  typedef real_time_tools::ThreadsafeTimeseries<double> ScalarTimeseries;
33 
40  template<typename Type> using Ptr = std::shared_ptr<Type>;
41 
46  enum MotorMeasurementIndexing {current, position, velocity, encoder_index,
47  motor_measurement_count};
48 
52  enum MotorIndexing {hip, knee, motor_count};
53 
57  virtual ~LegInterface() {}
58 
73  get_motor_measurement(const int& motor_index,
74  const int& measurement_index) const = 0;
75 
76 
86  get_current_target(const int& motor_index) const = 0;
87 
97  get_sent_current_target(const int& motor_index) const = 0;
98 
111  virtual void set_current_target(const double& current_target,
112  const int& motor_index) = 0;
113 
121  virtual void send_if_input_changed() = 0;
122 };
123 
128 class Leg: public LegInterface
129 {
130 public:
137  Leg(std::shared_ptr<MotorInterface> hip_motor,
138  std::shared_ptr<MotorInterface> knee_motor)
139  {
140  motors_[hip] = hip_motor;
141  motors_[knee] = knee_motor;
142  }
143 
147  virtual ~Leg() {}
148 
161  get_motor_measurement(const int& motor_index,
162  const int& measurement_index) const
163  {
164  return motors_[motor_index]->get_measurement(measurement_index);
165  }
166 
167  // input logs --------------------------------------------------------------
169  get_current_target(const int& motor_index) const
170  {
171  return motors_[motor_index]->get_current_target();
172  }
174  get_sent_current_target(const int& motor_index) const
175  {
176  return motors_[motor_index]->get_sent_current_target();
177  }
178 
180  virtual void set_current_target(const double& current_target,
181  const int& motor_index)
182  {
183  motors_[motor_index]->set_current_target(current_target);
184  }
185 
187  virtual void send_if_input_changed()
188  {
189  for(size_t i = 0; i < motors_.size(); i++)
190  motors_[i]->send_if_input_changed();
191  }
192 
194  private:
199  std::array<std::shared_ptr<MotorInterface>, 2> motors_;
200 
201 };
202 
203 }
virtual Ptr< const ScalarTimeseries > get_current_target(const int &motor_index) const
Get the actual target current.
Definition: leg.hpp:169
virtual Ptr< const ScalarTimeseries > get_sent_current_target(const int &motor_index) const =0
Get the last sent target current.
virtual void set_current_target(const double &current_target, const int &motor_index)
setters ================================================================
Definition: leg.hpp:180
This namespace is the standard namespace of the package.
Definition: const_torque_control.cpp:12
virtual ~Leg()
Destroy the Leg object.
Definition: leg.hpp:147
std::shared_ptr< Type > Ptr
This is a shortcut for creating shared pointer in a simpler writting expression.
Definition: leg.hpp:40
std::array< std::shared_ptr< MotorInterface >, 2 > motors_
========================================================================
Definition: leg.hpp:199
virtual void send_if_input_changed()
sender =================================================================
Definition: leg.hpp:187
This class defines an interface to control a leg.
Definition: leg.hpp:26
virtual Ptr< const ScalarTimeseries > get_motor_measurement(const int &motor_index, const int &measurement_index) const =0
Getters.
Leg(std::shared_ptr< MotorInterface > hip_motor, std::shared_ptr< MotorInterface > knee_motor)
Construct a new Leg object.
Definition: leg.hpp:137
virtual Ptr< const ScalarTimeseries > get_current_target(const int &motor_index) const =0
Get the actual target current.
virtual void set_current_target(const double &current_target, const int &motor_index)=0
Setters.
this class exists purely for logical reasons, it does not in itself implement anything.
Definition: device_interface.hpp:36
MotorIndexing
This enum list the motors in the leg.
Definition: leg.hpp:52
real_time_tools::ThreadsafeTimeseries< double > ScalarTimeseries
ScalarTimeseries is a simple shortcut for more intelligible code.
Definition: leg.hpp:32
virtual ~LegInterface()
Destroy the LegInterface object.
Definition: leg.hpp:57
virtual Ptr< const ScalarTimeseries > get_sent_current_target(const int &motor_index) const
Get the last sent target current.
Definition: leg.hpp:174
virtual void send_if_input_changed()=0
Sender.
MotorMeasurementIndexing
MotorMeasurementIndexing this enum allow to access the different kind of sensor measurements in an un...
Definition: leg.hpp:46
virtual Ptr< const ScalarTimeseries > get_motor_measurement(const int &motor_index, const int &measurement_index) const
Getters.
Definition: leg.hpp:161
The leg class is the implementation of the LegInterface.
Definition: leg.hpp:128