Skip to content

Commit

Permalink
Started creation of a PI controller function for generator torque con…
Browse files Browse the repository at this point in the history
…trol in region 2.5 (unfinished!)
  • Loading branch information
Sebastiaan Mulders committed Aug 29, 2017
1 parent 16a7566 commit 72db4bd
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Source/Filters.f90
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ REAL FUNCTION LPFilter( InputSignal, DT, CornerFreq, iStatus, inst)

! Save signals for next time step

InputSignalLast (inst) = InputSignal
OutputSignalLast (inst) = LPFilter
InputSignalLast(inst) = InputSignal
OutputSignalLast(inst) = LPFilter

END FUNCTION LPFilter
!-------------------------------------------------------------------------------------------------------------------------------
Expand Down
31 changes: 30 additions & 1 deletion Source/FunctionToolbox.f90
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ MODULE FunctionToolbox
!-------------------------------------------------------------------------------------------------------------------------------
! Saturates inputValue. Makes sure it is not smaller than minValue and not larger than maxValue
REAL FUNCTION saturate(inputValue,minValue,maxValue)
!...............................................................................................................................
!

IMPLICIT NONE

Expand All @@ -19,4 +19,33 @@ REAL FUNCTION saturate(inputValue,minValue,maxValue)

END FUNCTION saturate
!-------------------------------------------------------------------------------------------------------------------------------
! PI controller, with output saturation
REAL FUNCTION PI(error,kp,ki,minValue,maxValue,DT,I0,inst)
!

IMPLICIT NONE

! Inputs
REAL(4), INTENT(IN) :: error
REAL(4), INTENT(IN) :: kp
REAL(4), INTENT(IN) :: ki
REAL(4), INTENT(IN) :: minValue
REAL(4), INTENT(IN) :: maxValue
REAL(4), INTENT(IN) :: DT
REAL(4), INTENT(IN) :: inst
REAL(4), INTENT(IN) :: I0

! Local
REAL(4) :: PTerm ! Proportional term
REAL(4), DIMENSION(99), SAVE :: ITermLast ! Integral term signal the last time this controller was called. Supports 99 separate instances.


PTerm = kp*error
ITerm(inst) = ITerm(inst) + DT*ki*error
ITerm(inst) = saturate(ITerm(inst),maxValue,minValue)
PI = PTerm + ITerm(inst)
PI = saturate(PI,maxValue,minValue)

END FUNCTION saturate
!-------------------------------------------------------------------------------------------------------------------------------
END MODULE FunctionToolbox

0 comments on commit 72db4bd

Please sign in to comment.