Skip to content

Commit

Permalink
Add pretty debug setup and output
Browse files Browse the repository at this point in the history
  • Loading branch information
dzalkind committed Jul 2, 2020
1 parent 5d1f2f5 commit d6722bb
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 18 deletions.
7 changes: 4 additions & 3 deletions src/ControllerBlocks.f90
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,19 @@ SUBROUTINE StateMachine(CntrPar, LocalVar)
END IF
END SUBROUTINE StateMachine
!-------------------------------------------------------------------------------------------------------------------------------
SUBROUTINE WindSpeedEstimator(LocalVar, CntrPar, objInst, PerfData)
SUBROUTINE WindSpeedEstimator(LocalVar, CntrPar, objInst, PerfData, DebugVar)
! Wind Speed Estimator estimates wind speed at hub height. Currently implements two types of estimators
! WE_Mode = 0, Filter hub height wind speed as passed from servodyn using first order low pass filter with 1Hz cornering frequency
! WE_Mode = 1, Use Inversion and Inveriance filter as defined by Ortege et. al.
USE ROSCO_Types, ONLY : LocalVariables, ControlParameters, ObjectInstances, PerformanceData
USE ROSCO_Types, ONLY : LocalVariables, ControlParameters, ObjectInstances, PerformanceData, DebugVariables
IMPLICIT NONE

! Inputs
TYPE(ControlParameters), INTENT(IN) :: CntrPar
TYPE(LocalVariables), INTENT(INOUT) :: LocalVar
TYPE(ObjectInstances), INTENT(INOUT) :: objInst
TYPE(PerformanceData), INTENT(INOUT) :: PerfData
TYPE(DebugVariables), INTENT(INOUT) :: DebugVar
! Allocate Variables
REAL(4) :: F_WECornerFreq ! Corner frequency (-3dB point) for first order low pass filter for measured hub height wind speed [Hz]

Expand Down Expand Up @@ -216,7 +217,7 @@ SUBROUTINE WindSpeedEstimator(LocalVar, CntrPar, objInst, PerfData)
LocalVar%WE_Vw = v_m + v_t

! Debug Outputs
LocalVar%WE_Cp = Cp_op
DebugVar%WE_Cp = Cp_op
ENDIF

ELSE
Expand Down
2 changes: 2 additions & 0 deletions src/Controllers.f90
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,10 @@ SUBROUTINE PitchControl(avrSWAP, CntrPar, LocalVar, objInst)
PitComT_Last = LocalVar%PC_PitComT

! Combine and saturate all individual pitch commands:
! Filter to emulate pitch actuator
DO K = 1,LocalVar%NumBl ! Loop through all blades, add IPC contribution and limit pitch rate
LocalVar%PitCom(K) = LocalVar%PC_PitComT + LocalVar%IPC_PitComF(K) + LocalVar%FA_PitCom(K)
! LocalVar%PitCom(K) = SecLPFilter(LocalVar%PitCom(K), LocalVar%DT, , Damp, iStatus, reset, inst)
LocalVar%PitCom(K) = saturate(LocalVar%PitCom(K), LocalVar%PC_MinPit, CntrPar%PC_MaxPit) ! Saturate the overall command using the pitch angle limits
LocalVar%PitCom(K) = ratelimit(LocalVar%PitCom(K), LocalVar%BlPitch(K), CntrPar%PC_MinRat, CntrPar%PC_MaxRat, LocalVar%DT) ! Saturate the overall command of blade K using the pitch rate limit
END DO
Expand Down
5 changes: 3 additions & 2 deletions src/DISCON.F90
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ SUBROUTINE DISCON(avrSWAP, aviFAIL, accINFILE, avcOUTNAME, avcMSG) BIND (C, NAME
TYPE(LocalVariables), SAVE :: LocalVar
TYPE(ObjectInstances), SAVE :: objInst
TYPE(PerformanceData), SAVE :: PerfData
TYPE(DebugVariables), SAVE :: DebugVar

!------------------------------------------------------------------------------------------------------------------------------
! Main control calculations
Expand All @@ -66,7 +67,7 @@ SUBROUTINE DISCON(avrSWAP, aviFAIL, accINFILE, avcOUTNAME, avcMSG) BIND (C, NAME
CALL ComputeVariablesSetpoints(CntrPar, LocalVar, objInst)

CALL StateMachine(CntrPar, LocalVar)
CALL WindSpeedEstimator(LocalVar, CntrPar, objInst, PerfData)
CALL WindSpeedEstimator(LocalVar, CntrPar, objInst, PerfData, DebugVar)

CALL SetpointSmoother(LocalVar, CntrPar, objInst)

Expand All @@ -75,7 +76,7 @@ SUBROUTINE DISCON(avrSWAP, aviFAIL, accINFILE, avcOUTNAME, avcMSG) BIND (C, NAME
CALL YawRateControl(avrSWAP, CntrPar, LocalVar, objInst)
CALL FlapControl(avrSWAP, CntrPar, LocalVar, objInst)

CALL Debug(LocalVar, CntrPar, avrSWAP, RootName, SIZE(avcOUTNAME))
CALL Debug(LocalVar, CntrPar, DebugVar, avrSWAP, RootName, SIZE(avcOUTNAME))
END IF

avcMSG = TRANSFER(TRIM(ErrMsg)//C_NULL_CHAR, avcMSG, SIZE(avcMSG))
Expand Down
1 change: 1 addition & 0 deletions src/Filters.f90
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ SUBROUTINE PreFilterMeasuredSignals(CntrPar, LocalVar, objInst)
! Filtering the tower fore-aft acceleration signal
IF (CntrPar%Fl_Mode == 1) THEN
LocalVar%NacIMU_FA_AccF = SecLPFilter(LocalVar%NacIMU_FA_Acc, LocalVar%DT, CntrPar%F_FlCornerFreq, CntrPar%F_FlDamping, LocalVar%iStatus, .FALSE., objInst%instSecLPF) ! Fixed Damping
LocalVar%NacIMU_FA_AccF = HPFilter(LocalVar%NacIMU_FA_AccF, LocalVar%DT, CntrPar%F_FlCornerFreq/3, LocalVar%iStatus, .FALSE., objInst%instHPF)
! LocalVar%NacIMU_FA_AccF = NotchFilterSlopes(LocalVar%NacIMU_FA_Acc, LocalVar%DT, CntrPar%F_FlCornerFreq, CntrPar%F_FlDamping, LocalVar%iStatus, .FALSE., objInst%instNotchSlopes) ! Fixed Damping
IF (CntrPar%F_NotchType >= 2) THEN
LocalVar%NACIMU_FA_AccF = NotchFilter(LocalVar%NacIMU_FA_AccF, LocalVar%DT, CntrPar%F_NotchCornerFreq, CntrPar%F_NotchBetaNumDen(1), CntrPar%F_NotchBetaNumDen(2), LocalVar%iStatus, .FALSE., objInst%instNotch) ! Fixed Damping
Expand Down
56 changes: 44 additions & 12 deletions src/Functions.f90
Original file line number Diff line number Diff line change
Expand Up @@ -440,33 +440,65 @@ REAL FUNCTION AeroDynTorque(LocalVar, CntrPar, PerfData)

END FUNCTION AeroDynTorque
!-------------------------------------------------------------------------------------------------------------------------------
SUBROUTINE Debug(LocalVar, CntrPar, avrSWAP, RootName, size_avcOUTNAME)
SUBROUTINE Debug(LocalVar, CntrPar, DebugVar, avrSWAP, RootName, size_avcOUTNAME)
! Debug routine, defines what gets printed to DEBUG.dbg if LoggingLevel = 1

USE, INTRINSIC :: ISO_C_Binding
USE ROSCO_Types, ONLY : LocalVariables, ControlParameters
USE ROSCO_Types, ONLY : LocalVariables, ControlParameters, DebugVariables

IMPLICIT NONE

TYPE(ControlParameters), INTENT(IN) :: CntrPar
TYPE(LocalVariables), INTENT(IN) :: LocalVar
TYPE(DebugVariables), INTENT(IN) :: DebugVar

INTEGER(4), INTENT(IN) :: size_avcOUTNAME
INTEGER(4) :: I ! Generic index.
INTEGER(4) :: I , nDebugOuts ! Generic index.
CHARACTER(1), PARAMETER :: Tab = CHAR(9) ! The tab character.
CHARACTER(25), PARAMETER :: FmtDat = "(F8.3,99('"//Tab//"',ES10.3E2,:)) " ! The format of the debugging data
CHARACTER(29), PARAMETER :: FmtDat = "(F10.3,TR5,99(ES10.3E2,TR5:))" ! The format of the debugging data
INTEGER(4), PARAMETER :: UnDb = 85 ! I/O unit for the debugging information
INTEGER(4), PARAMETER :: UnDb2 = 86 ! I/O unit for the debugging information, avrSWAP
REAL(C_FLOAT), INTENT(INOUT) :: avrSWAP(*) ! The swap array, used to pass data to, and receive data from, the DLL controller.
CHARACTER(size_avcOUTNAME-1), INTENT(IN) :: RootName ! a Fortran version of the input C string (not considered an array here) [subtract 1 for the C null-character]

CHARACTER(10) :: DebugOutStr1, DebugOutStr2, DebugOutStr3, DebugOutStr4, DebugOutStr5, &
DebugOutStr6, DebugOutStr7, DebugOutStr8, DebugOutStr9, DebugOutStr10, &
DebugOutStr11, DebugOutStr12, DebugOutStr13, DebugOutStr14, DebugOutStr15, &
DebugOutUni1, DebugOutUni2, DebugOutUni3, DebugOutUni4, DebugOutUni5, &
DebugOutUni6, DebugOutUni7, DebugOutUni8, DebugOutUni9, DebugOutUni10, &
DebugOutUni11, DebugOutUni12, DebugOutUni13, DebugOutUni14, DebugOutUni15
CHARACTER(10), ALLOCATABLE :: DebugOutStrings(:), DebugOutUnits(:)
REAL(4), ALLOCATABLE :: DebugOutData(:)

! Set up Debug Strings and Data
! Note that Debug strings have 10 character limit
nDebugOuts = 8
ALLOCATE(DebugOutData(nDebugOuts))
! Header Unit Variable
DebugOutStr1 = 'IMU_FA_AccF'; DebugOutUni1 = '(m/s)'; DebugOutData(1) = LocalVar%NacIMU_FA_AccF
DebugOutStr2 = 'WE_Vw'; DebugOutUni2 = '(rad)'; DebugOutData(2) = LocalVar%WE_Vw
DebugOutStr3 = 'IMU_FA_Acc'; DebugOutUni3 = '(rad/s^2)'; DebugOutData(3) = LocalVar%NacIMU_FA_Acc
DebugOutStr4 = 'FA_Acc'; DebugOutUni4 = '(m/s^2)'; DebugOutData(4) = LocalVar%FA_Acc
DebugOutStr5 = 'Fl_Pitcom'; DebugOutUni5 = '(rad)'; DebugOutData(5) = LocalVar%Fl_Pitcom
DebugOutStr6 = 'WE_Cp'; DebugOutUni6 = '(-)'; DebugOutData(6) = DebugVar%WE_Cp
DebugOutStr7 = 'PC_MinPit'; DebugOutUni7 = '(rad)'; DebugOutData(7) = LocalVar%PC_MinPit
DebugOutStr8 = 'SS_dOmF'; DebugOutUni8 = '(rad/s)'; DebugOutData(8) = LocalVar%SS_DelOmegaF

Allocate(DebugOutStrings(nDebugOuts))
Allocate(DebugOutUnits(nDebugOuts))
DebugOutStrings = [CHARACTER(10) :: DebugOutStr1, DebugOutStr2, DebugOutStr3, DebugOutStr4, &
DebugOutStr5, DebugOutStr6, DebugOutStr7, DebugOutStr8]
DebugOutUnits = [CHARACTER(10) :: DebugOutUni1, DebugOutUni2, DebugOutUni3, DebugOutUni4, &
DebugOutUni5, DebugOutUni6, DebugOutUni7, DebugOutUni8]

! Initialize debug file
IF (LocalVar%iStatus == 0) THEN ! .TRUE. if we're on the first call to the DLL
! If we're debugging, open the debug file and write the header:
! Note that the headers will be Truncated to 10 characters!!
IF (CntrPar%LoggingLevel > 0) THEN
OPEN(unit=UnDb, FILE='DEBUG.dbg')
WRITE (UnDb,'(A)') ' Time ' //Tab//' NacIMU_FA_AccF ' //Tab//' WE_Vw ' //Tab//' NacIMU_FA_Acc ' //Tab//' FA_Acc ' //Tab//' Fl_Pitcom ' //Tab//' WE_Cp ' //Tab//' PC_MinPit ' //Tab// ' SS_DelOmegaF '
WRITE (UnDb,'(A)') ' (sec) ' //Tab//'(m/s) ' //Tab//'(rad) ' //Tab//'(rad/s^2) ' //Tab//'(m/s^2) '//Tab//'(rad) ' //Tab//'(-) ' //Tab//'(rad)' //Tab // '(rad/s)'
WRITE (UnDb,'(99(a10,TR5:))') 'Time', DebugOutStrings
WRITE (UnDb,'(99(a10,TR5:))') '(sec)', DebugOutUnits
END IF

IF (CntrPar%LoggingLevel > 1) THEN
Expand All @@ -482,15 +514,15 @@ SUBROUTINE Debug(LocalVar, CntrPar, avrSWAP, RootName, size_avcOUTNAME)
100 FORMAT('Generator speed: ', f6.1, ' RPM, Pitch angle: ', f5.1, ' deg, Power: ', f7.1, ' kW, Est. wind Speed: ', f5.1, ' m/s')
END IF

! Output debugging information if requested:
IF (CntrPar%LoggingLevel > 0) THEN
WRITE (UnDb,FmtDat) LocalVar%Time, LocalVar%NacIMU_FA_AccF, LocalVar%WE_Vw, LocalVar%NacIMU_FA_Acc, LocalVar%FA_Acc, LocalVar%Fl_PitCom, LocalVar%WE_Cp, LocalVar%PC_MinPit, LocalVar%SS_DelOmegaF
END IF

IF (CntrPar%LoggingLevel > 1) THEN
WRITE (UnDb2,FmtDat) LocalVar%Time, avrSWAP(1:85)
WRITE (UnDb2,FmtDat) LocalVar%Time, DebugOutData
END IF
END IF

! Want debug on first timestep
IF (CntrPar%LoggingLevel > 0) THEN
WRITE (UnDb,FmtDat) LocalVar%Time, LocalVar%NacIMU_FA_AccF, LocalVar%WE_Vw, LocalVar%NacIMU_FA_Acc, LocalVar%FA_Acc, LocalVar%Fl_PitCom, DebugVar%WE_Cp, LocalVar%PC_MinPit, LocalVar%SS_DelOmegaF
END IF

IF (MODULO(LocalVar%Time, 10.0) == 0.0) THEN
!LocalVar%TestType = LocalVar%TestType + 10
Expand Down
5 changes: 4 additions & 1 deletion src/ROSCO_Types.f90
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ MODULE ROSCO_Types
REAL(4) :: WE_Vw ! Estimated wind speed [m/s]
REAL(4) :: WE_VwI ! Integrated wind speed quantity for estimation [m/s]
REAL(4) :: WE_VwIdot ! Differentiated integrated wind speed quantity for estimation [m/s]
REAL(4) :: WE_Cp ! Cp that WSE uses to determine aerodynamic torque, for debug purposes [-]
REAL(4) :: Y_AccErr ! Accumulated yaw error [rad].
REAL(4) :: Y_ErrLPFFast ! Filtered yaw error by fast low pass filter [rad].
REAL(4) :: Y_ErrLPFSlow ! Filtered yaw error by slow low pass filter [rad].
Expand Down Expand Up @@ -214,4 +213,8 @@ MODULE ROSCO_Types
REAL(4), DIMENSION(:,:), ALLOCATABLE :: Cq_mat
END TYPE PerformanceData

TYPE, PUBLIC :: DebugVariables
REAL(4) :: WE_Cp ! Cp that WSE uses to determine aerodynamic torque, for debug purposes [-]
END TYPE DebugVariables

END MODULE ROSCO_Types
17 changes: 17 additions & 0 deletions src/ReadSetParameters.f90
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,24 @@ SUBROUTINE SetParameters(avrSWAP, aviFAIL, accINFILE, ErrMsg, size_avcMSG, CntrP
' Jan-Willem van Wingerden '//NEW_LINE('A')// &
'Visit our GitHub-page to contribute to this project: '//NEW_LINE('A')// &
'https://github.com/NREL/ROSCO '//NEW_LINE('A')// &
' '//NEW_LINE('A')// &
'------------------------------------------------------------------------------'

print *, 'Version 1.0.1: pretty debug'

! ErrMsg = ' '//NEW_LINE('A')// &
! '------------------------------------------------------------------------------'//NEW_LINE('A')// &
! 'Running a controller implemented through NREL''s ROSCO Toolbox '//NEW_LINE('A')// &
! 'A wind turbine controller framework for public use in the scientific field '//NEW_LINE('A')// &
! 'Developed in collaboration: National Renewable Energy Laboratory '//NEW_LINE('A')// &
! ' Delft University of Technology, The Netherlands '//NEW_LINE('A')// &
! ' '//NEW_LINE('A')// &
! 'Visit our GitHub-page to contribute to this project: '//NEW_LINE('A')// &
! 'https://github.com/NREL/ROSCO '//NEW_LINE('A')// &
! ' '//NEW_LINE('A')// &
! 'Version: 1.0.0 '//NEW_LINE('A')// &
! '------------------------------------------------------------------------------'

CALL ReadControlParameterFileSub(CntrPar, accINFILE, NINT(avrSWAP(50)))

IF (CntrPar%WE_Mode > 0) THEN
Expand Down

0 comments on commit d6722bb

Please sign in to comment.