BVB Source Codes

CRYENGINE Show AIPIDController.h Source code

Return Download CRYENGINE: download AIPIDController.h Source code - Download CRYENGINE Source code - Type:.h
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. #ifndef AIPIDCONTROLLER_H
  4. #define AIPIDCONTROLLER_H
  5.  
  6. #if _MSC_VER > 1000
  7.         #pragma once
  8. #endif // _MSC_VER > 1000
  9.  
  10. //====================================================================
  11. // CAIPIDController
  12. //====================================================================
  13. struct CAIPIDController
  14. {
  15.         /// CP, CI and CD are the three coefficients. integralTimescale is the time over which
  16.         /// to accululate the integral term (approximate).
  17.         /// proportionalPower indicates the power that the error term should be raised to
  18.         CAIPIDController(float CP = 0.0f, float CI = 0.0f, float CD = 0.0f, float integralTimescale = 1.0f, unsigned proportionalPower = 1);
  19.  
  20.         /// Update the intenal state and calculate an output
  21.         float Update(float error, float dt);
  22.  
  23.         /// The proportional, integral and derivative coefficients
  24.         float CP, CI, CD;
  25.  
  26.         /// The time over which to accululate the integral
  27.         float integralTimescale;
  28.  
  29.         /// output is proportional to error raised to this power
  30.         unsigned proportionalPower;
  31.  
  32.         void     Serialize(TSerialize ser);
  33.  
  34. private:
  35.         float runningIntegral;
  36.         float lastError;
  37. };
  38.  
  39. //====================================================================
  40. // Update
  41. //====================================================================
  42. inline float CAIPIDController::Update(float error, float dt)
  43. {
  44.         float frac = min(dt / integralTimescale, 1.0f);
  45.         runningIntegral = frac * error + (1.0f - frac) * runningIntegral; // not quite dt independant...
  46.         float output = CP * powf(error, (float) proportionalPower);
  47.         output += CI * runningIntegral;
  48.         if (dt > 0.0f)
  49.                 output += CD * (error - lastError) / dt;
  50.         lastError = error;
  51.         return output;
  52. }
  53.  
  54. //====================================================================
  55. // CAIPIDController
  56. //====================================================================
  57. inline CAIPIDController::CAIPIDController(float CP, float CI, float CD,
  58.                                           float integralTimescale, unsigned proportionalPower) :
  59.         CP(CP), CI(CI), CD(CD), integralTimescale(integralTimescale), proportionalPower(proportionalPower),
  60.         runningIntegral(0.0f), lastError(0.0f)
  61. {
  62. }
  63.  
  64. #endif
  65.  
downloadAIPIDController.h Source code - Download CRYENGINE Source code
Related Source Codes/Software:
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top