blmc_drivers
pd_control.hpp
Go to the documentation of this file.
1 
8 
9 namespace blmc_drivers{
10 
14 typedef std::shared_ptr<blmc_drivers::SafeMotor> SafeMotor_ptr;
18 typedef std::shared_ptr<blmc_drivers::AnalogSensor> Slider_ptr;
22 typedef std::pair<SafeMotor_ptr, Slider_ptr> PairMotorSlider;
23 
28 {
29 public:
35  PDController(std::vector<PairMotorSlider> motor_slider_pairs):
36  motor_slider_pairs_(motor_slider_pairs)
37  {
38  stop_loop=false;
39  }
40 
45  {
46  stop_loop=true;
47  rt_thread_.join();
48  }
49 
53  void start_loop()
54  {
55  rt_thread_.create_realtime_thread(&PDController::loop, this);
56  }
57 
58 private:
59 
64  std::vector<PairMotorSlider> motor_slider_pairs_;
68  real_time_tools::RealTimeThread rt_thread_;
69 
74  static THREAD_FUNCTION_RETURN_TYPE loop(void* instance_pointer)
75  {
76  ((PDController*)(instance_pointer))->loop();
77  return THREAD_FUNCTION_RETURN_VALUE;
78  }
79 
87  void loop();
88 
92  bool stop_loop;
93 
94 }; // end class PDController definition
95 
96 }// namespace blmc_drivers
void start_loop()
This method is a helper to start the thread loop.
Definition: pd_control.hpp:53
~PDController()
Destroy the PDController object.
Definition: pd_control.hpp:44
static THREAD_FUNCTION_RETURN_TYPE loop(void *instance_pointer)
this function is just a wrapper around the actual loop function, such that it can be spawned as a pos...
Definition: pd_control.hpp:74
real_time_tools::RealTimeThread rt_thread_
This is the real time thread object.
Definition: pd_control.hpp:68
PDController(std::vector< PairMotorSlider > motor_slider_pairs)
Construct a new PDController object.
Definition: pd_control.hpp:35
This namespace is the standard namespace of the package.
Definition: const_torque_control.cpp:12
This is a basic PD controller to be used in the demos of this package.
Definition: pd_control.hpp:27
std::pair< SafeMotor_ptr, Slider_ptr > PairMotorSlider
This is a simple shortcut.
Definition: pd_control.hpp:22
std::vector< PairMotorSlider > motor_slider_pairs_
This is a pair of motor and sliders so that we associate one with the other.
Definition: pd_control.hpp:64
bool stop_loop
managing the stopping of the loop
Definition: pd_control.hpp:92
std::shared_ptr< blmc_drivers::AnalogSensor > Slider_ptr
This is a simple shortcut.
Definition: pd_control.hpp:18
void loop()
this is a simple control loop which runs at a kilohertz.
Definition: pd_control.cpp:12
std::shared_ptr< blmc_drivers::SafeMotor > SafeMotor_ptr
This is a simple shortcut.
Definition: const_torque_control.hpp:15