Bratmobile
control_interface.h
1 #ifndef CONTROL_IF_H
2 #define CONTROL_IF_H
3 
4 #include "worldbuilder.h"
5 #include "task.h"
6 
7 class Configurator;
8 
12 // class IOInterface{
13 // protected:
14 // bool ready=false;
15 // public:
16 // IOInterface()=default;
17 
18 // bool isReady(){
19 // return ready;
20 // }
21 
22 // void setReady(bool b){
23 // ready=b;
24 // }
25 
26 // };
27 
31 // class LIDAR_In:public IOInterface{
32 // public:
33 // bool debugOn=0;
34 // int iteration=0;
35 // bool stop=0;
36 // CoordinateContainer data2fp;
37 // };
38 
43  protected:
44  float L=0, R=0, L_gain=1.0f, R_gain=1.0f, Kp=0.45, Ki=0.25, Kd=0.2; //from empirical, Kp should be 1.2
45  float prev_error=0;
46  float integral=0;
47  public:
48 
49  MotorInterface()=default;
50 
51  MotorInterface(float kp, float ki, float kd):Kp(kp), Ki(ki), Kd(kd){}
52 
53  void getData(const Task::Action &a){
54  L=a.getLWheelSpeed();
55  R=a.getRWheelSpeed();
56  }
57 
58  float get_L(){
59  float f=L*L_gain;
60  return f;
61  }
62 
63  float get_R(){
64  float f=R*R_gain;
65  return f;
66  }
67 
75  void adjust_gain( float angle_D, b2Transform observed, float * y_D=NULL);
76 
82  void PID(float e);
83 
95  float outer_loop(float e);
96 
97 
98  void reset(){
99  L_gain=1.0f;
100  R_gain=1.0f;
101  reset_error();
102  }
103 
104  void reset_error(){
105  integral=0;
106  prev_error=0;
107  }
108 
109 };
110 
111 
112 
113 
117 struct GoalChanger{
122  virtual Task change_goal(const Task & t)=0;
123 };
124 #endif
Definition: configurator.h:17
Definition: control_interface.h:42
float outer_loop(float e)
Implements a P controller in the outer loop of the cascade controller.
Definition: control_interface.cpp:26
void PID(float e)
Implements a PID controller.
Definition: control_interface.cpp:18
void adjust_gain(float angle_D, b2Transform observed, float *y_D=NULL)
Adjusts L/R wheel gain, implements a PID controller with option to turn it into cascaded controller.
Definition: control_interface.cpp:3
A closed hybrid control loop. It has an initial disturbance representing the continuous state and a d...
Definition: task.h:47
Definition: control_interface.h:117
virtual Task change_goal(const Task &t)=0
The motor instructions generated by the control strategy used in this tasks.
Definition: task.h:66