update credits
[librepilot.git] / flight / libraries / pid / pidcontroldown.h
blob8ea18561030dead8a908faf70b057142e21748fc
1 /**
2 ******************************************************************************
3 * @addtogroup OpenPilotModules OpenPilot Modules
4 * @{
5 * @addtogroup PathFollower PID Control implementation
6 * @brief PID Controller for down direction
7 * @{
9 * @file PIDControlDown.h
10 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2015.
11 * @brief Executes control loop for down direction
13 * @see The GNU Public License (GPL) Version 3
15 *****************************************************************************/
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 3 of the License, or
20 * (at your option) any later version.
22 * This program is distributed in the hope that it will be useful, but
23 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
24 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25 * for more details.
27 * You should have received a copy of the GNU General Public License along
28 * with this program; if not, write to the Free Software Foundation, Inc.,
29 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 #ifndef PIDCONTROLDOWN_H
32 #define PIDCONTROLDOWN_H
33 extern "C" {
34 #include <pid.h>
35 #include <stabilizationdesired.h>
37 #include "pidcontroldowncallback.h"
39 class PIDControlDown {
40 public:
41 PIDControlDown();
42 ~PIDControlDown();
43 void Initialize(PIDControlDownCallback *callback);
44 void SetThrustLimits(float min_thrust, float max_thrust);
45 void Deactivate();
46 void Activate();
47 bool IsActive()
49 return mActive;
51 void UpdateParameters(float kp, float ki, float kd, float beta, float dT, float velocityMax);
52 void UpdateNeutralThrust(float neutral);
53 void UpdateVelocitySetpoint(float setpoint);
54 void RateLimit(float *spDesired, float *spCurrent, float rateLimit);
55 void UpdateVelocityState(float pv);
56 float GetVelocityDesired(void);
57 float GetDownCommand(void);
58 void UpdatePositionalParameters(float kp);
59 void UpdatePositionState(float pvDown);
60 void UpdatePositionSetpoint(float setpointDown);
61 void ControlPosition();
62 void ControlPositionWithPath(struct path_status *progress);
63 void UpdateBrakeVelocity(float startingVelocity, float dT, float brakeRate, float currentVelocity, float *updatedVelocity);
64 void UpdateVelocityStateWithBrake(float pvDown, float path_time, float brakeRate);
65 void DisableNeutralThrustCalc()
67 mAllowNeutralThrustCalc = false;
69 void EnableNeutralThrustCalc()
71 mAllowNeutralThrustCalc = true;
74 private:
75 void setup_neutralThrustCalc();
76 void run_neutralThrustCalc();
78 struct pid2 PID;
79 float deltaTime;
80 float mVelocitySetpointTarget;
81 float mVelocitySetpointCurrent;
82 float mVelocityState;
83 float mDownCommand;
84 PIDControlDownCallback *mCallback;
85 float mNeutral;
86 float mVelocityMax;
87 struct pid PIDpos;
88 float mPositionSetpointTarget;
89 float mPositionState;
90 float mMinThrust;
91 float mMaxThrust;
93 struct NeutralThrustEstimation {
94 uint32_t count;
95 float sum;
96 float average;
97 float correction;
98 float min;
99 float max;
100 bool start_sampling;
101 bool have_correction;
103 struct NeutralThrustEstimation neutralThrustEst;
104 bool mActive;
105 bool mAllowNeutralThrustCalc;
108 #endif // PIDCONTROLDOWN_H