blmc_drivers
motor.hpp
Go to the documentation of this file.
1 
8 #pragma once
9 
10 #include <memory>
11 #include <string>
12 
13 #include "real_time_tools/timer.hpp"
14 
15 #include "real_time_tools/threadsafe/threadsafe_object.hpp"
16 #include "real_time_tools/threadsafe/threadsafe_timeseries.hpp"
19 
20 namespace blmc_drivers
21 {
22 
29 {
30 public:
31 
35  typedef real_time_tools::ThreadsafeTimeseries<double> ScalarTimeseries;
41  template<typename Type> using Ptr = std::shared_ptr<Type>;
42 
47  enum MeasurementIndex {current, position, velocity, encoder_index,
48  measurement_count};
49 
53  virtual ~MotorInterface() {}
54 
58  virtual void send_if_input_changed() = 0;
59 
72  const int& index = 0) const = 0;
73 
81 
88 
99  virtual void set_current_target(const double& current_target) = 0;
100 
108  virtual void set_command(const MotorBoardCommand& command) = 0;
109 };
110 
114 class Motor: public MotorInterface
115 {
116 public:
123  Motor(Ptr<MotorBoardInterface> board, bool motor_id);
124 
129  virtual ~Motor() { }
130 
135  virtual void send_if_input_changed()
136  {
137  board_->send_if_input_changed();
138  }
139 
151  virtual Ptr<const ScalarTimeseries> get_measurement(const int& index = 0)
152  const;
153 
161 
168 
179  virtual void set_current_target(const double& current_target);
180 
186  virtual void set_command(const MotorBoardCommand& command)
187  {
188  board_->set_command(command);
189  }
190 
192  virtual void print() const;
193 
194 protected:
199 
203  bool motor_id_;
204 };
205 
215 class SafeMotor: public Motor
216 {
217 public:
226  SafeMotor(Ptr<MotorBoardInterface> board, bool motor_id,
227  const double& max_current_target = 2.0,
228  const size_t& history_length = 1000,
229  const double& max_velocity = std::numeric_limits<
230  double>::quiet_NaN());
231 
242  {
243  return current_target_;
244  }
245 
255  virtual void set_current_target(const double& current_target);
256 
262  void set_max_current(double max_current_target)
263  {
264  max_current_target_ = max_current_target;
265  }
266 
272  void set_max_velocity(double max_velocity)
273  {
274  max_velocity_ = max_velocity;
275  }
276 
277 private:
282 
287 
292 };
293 
294 } // namespace blmc_drivers
virtual void set_command(const MotorBoardCommand &command)=0
Set the command.
std::shared_ptr< Type > Ptr
This a useful alias for the shared Pointer creation.
Definition: motor.hpp:41
This namespace is the standard namespace of the package.
Definition: const_torque_control.cpp:12
This class implements the MotorInterface.
Definition: motor.hpp:114
virtual ~Motor()
Destroy the Motor object.
Definition: motor.hpp:129
This MotorBoardCommand class is a data structurs that defines a command.
Definition: motor_board.hpp:30
virtual Ptr< const ScalarTimeseries > get_current_target() const
Getters.
Definition: motor.hpp:241
virtual Ptr< const ScalarTimeseries > get_current_target() const =0
Get the current target object.
virtual Ptr< const ScalarTimeseries > get_sent_current_target() const =0
Get the history of the sent current targets.
Ptr< ScalarTimeseries > current_target_
History of the target current sent.
Definition: motor.hpp:291
double max_velocity_
max_velocity_ limits the motor velocity.
Definition: motor.hpp:286
This class declares an interface to the motor.
Definition: motor.hpp:28
this class exists purely for logical reasons, it does not in itself implement anything.
Definition: device_interface.hpp:36
virtual void set_command(const MotorBoardCommand &command)
Set the command.
Definition: motor.hpp:186
virtual void send_if_input_changed()=0
Actually send the commands and controls.
Ptr< MotorBoardInterface > board_
The MotorBoard to be used for the communication.
Definition: motor.hpp:198
double max_current_target_
max_current_target_ is the limit of the current.
Definition: motor.hpp:281
virtual Ptr< const ScalarTimeseries > get_measurement(const int &index=0) const =0
Getters.
bool motor_id_
The id of the motor on the MotorBoard.
Definition: motor.hpp:203
real_time_tools::ThreadsafeTimeseries< double > ScalarTimeseries
This is a useful alias.
Definition: motor.hpp:35
virtual void send_if_input_changed()
Actually send the command and controls via the network, See MotorInterface for more information...
Definition: motor.hpp:135
void set_max_current(double max_current_target)
Set the max_current_target_ object.
Definition: motor.hpp:262
void set_max_velocity(double max_velocity)
Set the max_velocity_ constant.
Definition: motor.hpp:272
This class is a safe implementation of the Motor class.
Definition: motor.hpp:215
virtual void set_current_target(const double &current_target)=0
Setters.
MeasurementIndex
Here is a list of the different measurement available on the blmc card.
Definition: motor.hpp:47
virtual ~MotorInterface()
Destroy the MotorInterface object.
Definition: motor.hpp:53