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 
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 
42 class Motor_Out:public IOInterface {
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  Motor_Out()=default;
50 
51  Motor_Out(float kp, float ki, float kd):Kp(kp), Ki(ki), Kd(kd){}
52 
53  void getData(const Task::Action &a){
54  setReady(0);
55  L=a.getLWheelSpeed();
56  R=a.getRWheelSpeed();
57  setReady(1);
58  }
59 
60  float get_L(){
61  float f=L*L_gain;
62  return f;
63  }
64 
65  float get_R(){
66  float f=R*R_gain;
67  return f;
68  }
69 
77  void adjust_gain( float angle_D, b2Transform observed, float * y_D=NULL);
78 
84  void PID(float e);
85 
97  float outer_loop(float e);
98 
99 
100  void reset(){
101  L_gain=1.0f;
102  R_gain=1.0f;
103  reset_error();
104  }
105 
106  void reset_error(){
107  integral=0;
108  prev_error=0;
109  }
110 
111 };
112 
113 
114 
115 
119 struct GoalChanger{
124  virtual void change_goal(Task * t);
125 };
126 #endif
Definition: configurator.h:17
Definition: control_interface.h:12
Definition: control_interface.h:31
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
Definition: task.h:19
Definition: control_interface.h:119
virtual void change_goal(Task *t)
Definition: task.h:33