RSeries astromech firmware
TargetSteering.h
Go to the documentation of this file.
1 #ifndef TargetSteering_h
2 #define TargetSteering_h
3 
4 #include "PID.h"
5 
7 {
8 public:
9  TargetSteering(int desiredDistance, int desiredAngle = 0) :
10  fDesiredDistance(desiredDistance),
11  fDesiredAngle(desiredAngle),
12  fDSet(desiredDistance),
13  fDistance(fDIn, fDOut, fDSet, 1.0, 0.1, 0.1),
14  fASet(desiredAngle),
15  fAngle(fAIn, fAOut, fASet, 0.5, 0.05, 0.02),
16  fDIn(desiredDistance),
17  fDOut(0),
18  fAIn(desiredAngle),
19  fAOut(0),
20  fThrottle(0),
21  fTurning(0)
22  {
23  fDistance.setAutomatic(true);
24  fDistance.setSampleTime(10);
26 
27  fAngle.setAutomatic(true);
28  fAngle.setSampleTime(10);
30  }
31 
32  float getThrottle()
33  {
34  return -fThrottle / fDistance.getOutputMax();
35  }
36 
37  float getTurning()
38  {
39  return -fTurning / fAngle.getOutputMax()*2;
40  }
41 
42  void lost()
43  {
44  fThrottle *= 0.95;
45  fTurning *= 0.8;
46  }
47 
48  void stop()
49  {
50  setCurrentDistance(fDesiredDistance);
51  setCurrentAngle(fDesiredAngle);
52  }
53 
54  void setCurrentDistance(int distance)
55  {
56  fDSet = distance;
57  fDistance.process();
58  fThrottle = fDOut;
59  }
60 
61  void setSampleTime(unsigned sampleTime)
62  {
63  fDistance.setSampleTime(sampleTime);
64  fAngle.setSampleTime(sampleTime);
65  }
66 
67  void setCurrentAngle(int angle)
68  {
69  fASet = angle;
70  fAngle.process();
71  fTurning = fAOut;// * (1.0 + fabs(fThrottle) * 0.05);
72  }
73 
74  void setAngleOutputLimits(float limit)
75  {
76  setAngleOutputLimits(-limit, limit);
77  }
78 
79  void setAngleOutputLimits(float outputMin, float outputMax)
80  {
81  fAngle.setOutputLimits(outputMin, outputMax);
82  }
83 
84  void setDistanceTunings(float Kp, float Ki, float Kd)
85  {
86  fDistance.setTunings(Kp, Ki, Kd);
87  }
88 
89  void setDistanceOutputLimits(float limit)
90  {
91  setDistanceOutputLimits(-limit, limit);
92  }
93 
94  void setDistanceOutputLimits(float outputMin, float outputMax)
95  {
96  fDistance.setOutputLimits(outputMin, outputMax);
97  }
98 
99 private:
100  int fDesiredDistance;
101  int fDesiredAngle;
102  float fDSet;
103  PID<float> fDistance;
104  float fASet;
105  PID<float> fAngle;
106  float fDIn;
107  float fDOut;
108  float fAIn;
109  float fAOut;
110  float fThrottle;
111  float fTurning;
112 };
113 
114 #endif
TargetSteering::stop
void stop()
Definition: TargetSteering.h:48
TargetSteering::setDistanceOutputLimits
void setDistanceOutputLimits(float limit)
Definition: TargetSteering.h:89
TargetSteering::TargetSteering
TargetSteering(int desiredDistance, int desiredAngle=0)
Definition: TargetSteering.h:9
PID::process
bool process()
Definition: PID.h:53
PID.h
PID::setOutputLimits
void setOutputLimits(T outputMin, T outputMax)
Definition: PID.h:106
TargetSteering
Definition: TargetSteering.h:6
TargetSteering::setDistanceTunings
void setDistanceTunings(float Kp, float Ki, float Kd)
Definition: TargetSteering.h:84
PID::setAutomatic
void setAutomatic(bool automatic)
Definition: PID.h:89
PID::setTunings
void setTunings(T Kp, T Ki, T Kd, bool pOnError)
Definition: PID.h:125
PID< float >
PID::setSampleTime
void setSampleTime(unsigned sampleTime)
Definition: PID.h:165
TargetSteering::setSampleTime
void setSampleTime(unsigned sampleTime)
Definition: TargetSteering.h:61
TargetSteering::lost
void lost()
Definition: TargetSteering.h:42
TargetSteering::getTurning
float getTurning()
Definition: TargetSteering.h:37
PID::getOutputMax
T getOutputMax() const
Definition: PID.h:101
TargetSteering::setAngleOutputLimits
void setAngleOutputLimits(float outputMin, float outputMax)
Definition: TargetSteering.h:79
TargetSteering::setAngleOutputLimits
void setAngleOutputLimits(float limit)
Definition: TargetSteering.h:74
TargetSteering::setDistanceOutputLimits
void setDistanceOutputLimits(float outputMin, float outputMax)
Definition: TargetSteering.h:94
TargetSteering::setCurrentDistance
void setCurrentDistance(int distance)
Definition: TargetSteering.h:54
TargetSteering::getThrottle
float getThrottle()
Definition: TargetSteering.h:32
TargetSteering::setCurrentAngle
void setCurrentAngle(int angle)
Definition: TargetSteering.h:67