blmc_drivers
sine_position_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;
15 
20 {
21 public:
27  SinePositionControl(std::vector<SafeMotor_ptr> motor_list):
28  motor_list_(motor_list)
29  {
30  encoders_.clear();
31  velocities_.clear();
32  currents_.clear();
33  control_buffer_.clear();
34 
35  for(size_t i=0 ; i<motor_list.size() ; ++i)
36  {
37  encoders_.push_back(std::deque<double>());
38  currents_.push_back(std::deque<double>());
39  velocities_.push_back(std::deque<double>());
40  control_buffer_.push_back(std::deque<double>());
41  encoders_.back().clear();
42  velocities_.back().clear();
43  currents_.back().clear();
44  control_buffer_.back().clear();
45  }
46  stop_loop_=false;
47  kp_ = 0.0;
48  kd_ = 0.0;
49  }
50 
55  {
56  stop_loop_=true;
57  rt_thread_.join();
58  }
59 
63  void start_loop()
64  {
65  rt_thread_.create_realtime_thread(&SinePositionControl::loop, this);
66  }
67 
71  void stop_loop();
72 
73  void set_gains(double kp, double kd)
74  {
75  kp_ = kp;
76  kd_ = kd;
77  }
78 
79 private:
80 
84  std::vector<SafeMotor_ptr> motor_list_;
88  real_time_tools::RealTimeThread rt_thread_;
89 
94  static THREAD_FUNCTION_RETURN_TYPE loop(void* instance_pointer)
95  {
96  ((SinePositionControl*)(instance_pointer))->loop();
97  return THREAD_FUNCTION_RETURN_VALUE;
98  }
99 
107  void loop();
108 
113 
118 
122  std::vector<std::deque<double> > encoders_;
123 
127  std::vector<std::deque<double> > velocities_;
128 
132  std::vector<std::deque<double> > currents_;
133 
137  std::vector<std::deque<double> > control_buffer_;
138 
142  double kp_;
143 
147  double kd_;
148 
149 }; // end class SinePositionControl definition
150 
151 }// namespace blmc_drivers
This is a basic PD controller to be used in the demos of this package.
Definition: sine_position_control.hpp:19
std::vector< std::deque< double > > control_buffer_
control_buffer_
Definition: sine_position_control.hpp:137
std::vector< std::deque< double > > encoders_
Encoder data.
Definition: sine_position_control.hpp:122
This namespace is the standard namespace of the package.
Definition: const_torque_control.cpp:12
double kp_
Controller proportional gain.
Definition: sine_position_control.hpp:142
real_time_tools::RealTimeThread rt_thread_
This is the real time thread object.
Definition: sine_position_control.hpp:88
double kd_
Controller derivative gain.
Definition: sine_position_control.hpp:147
void start_loop()
This method is a helper to start the thread loop.
Definition: sine_position_control.hpp:63
~SinePositionControl()
Destroy the SinePositionControl object.
Definition: sine_position_control.hpp:54
SinePositionControl(std::vector< SafeMotor_ptr > motor_list)
Construct a new SinePositionControl object.
Definition: sine_position_control.hpp:27
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: sine_position_control.hpp:94
unsigned memory_buffer_size_
memory_buffer_size_ is the max size of the memory buffer.
Definition: sine_position_control.hpp:117
std::vector< std::deque< double > > currents_
current data
Definition: sine_position_control.hpp:132
std::vector< std::deque< double > > velocities_
Velocity data.
Definition: sine_position_control.hpp:127
std::vector< SafeMotor_ptr > motor_list_
This is list of motors.
Definition: sine_position_control.hpp:84
void loop()
this is a simple control loop which runs at a kilohertz.
Definition: sine_position_control.cpp:13
void stop_loop()
Stop the control and dump the data.
Definition: sine_position_control.cpp:94
bool stop_loop_
managing the stopping of the loop
Definition: sine_position_control.hpp:112
std::shared_ptr< blmc_drivers::SafeMotor > SafeMotor_ptr
This is a simple shortcut.
Definition: const_torque_control.hpp:15