Skip to content

Commit

Permalink
Bugfixes: double use of a filter object (yaw-by-IPC)
Browse files Browse the repository at this point in the history
  • Loading branch information
Unknown committed Oct 16, 2017
1 parent 8553e77 commit 7b61b0a
Show file tree
Hide file tree
Showing 8 changed files with 180 additions and 5 deletions.
Binary file modified DISCON/DISCON_gwin32.dll
Binary file not shown.
13 changes: 13 additions & 0 deletions Scripts/CompileDISCONHere.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
:: Compiling DISCON

:: Main DISCON source-file directory:
set "DISCONSourceDir=..\"

:: Remove old .dll file
DEL %DISCONSourceDir%\DISCON\DISCON_gwin32.dll

:: Compile new .dll file
cd %DISCONSourceDir%\Source
mingw32-make.exe

pause
2 changes: 1 addition & 1 deletion Source/DISCON.f90
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ SUBROUTINE DISCON (avrSWAP, aviFAIL, accINFILE, avcOUTNAME, avcMSG) BIND (C, NAM
INTEGER(4), PARAMETER :: UnUser = 88 ! I/O unit for user defined parameter file
INTEGER(4), PARAMETER :: UnPitchGains = 89 ! I/O unit for user defined pitch gains parameter file

LOGICAL(1), PARAMETER :: DbgOut = .TRUE. ! Flag to indicate whether to output debugging information
LOGICAL(1), PARAMETER :: DbgOut = .FALSE. ! Flag to indicate whether to output debugging information

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
Expand Down
42 changes: 41 additions & 1 deletion Source/FunctionToolbox.f90
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ REAL FUNCTION interp1d(xData, yData, xq)

END FUNCTION interp1d
!-------------------------------------------------------------------------------------------------------------------------------
! PI controller, with output saturation
! DF controller, with output saturation
REAL FUNCTION DFController(error, Kd, Tf, DT, inst)
!
IMPLICIT NONE
Expand Down Expand Up @@ -140,4 +140,44 @@ REAL FUNCTION DFController(error, Kd, Tf, DT, inst)
DFControllerLast(inst) = DFController
END FUNCTION DFController
!-------------------------------------------------------------------------------------------------------------------------------
! PRBS identification signal generator function
!REAL FUNCTION PRBSgen(mean, amplitude, cycleTime, seed, initValue, reset, inst)
!!
! IMPLICIT NONE
!
! ! Inputs
! REAL(4), INTENT(IN) :: mean
! REAL(4), INTENT(IN) :: amplitude
! INTEGER(4), INTENT(IN) :: cycleTime
! INTEGER(4), INTENT(IN) :: seed
! LOGICAL, INTENT(IN) :: reset
! REAL(4), INTENT(IN) :: initValue
!
! ! Local
! INTEGER(4) :: i ! Counter for making arrays
! REAL(4) :: randomNumber
! INTEGER(4), DIMENSION(99), SAVE :: FirstCall = (/ (1, i=1,99) /)
!
! IF ((FirstCall(inst) == 1) .OR. reset) THEN
! RANDOM_NUMBER(1)
! RAND(seed)
!
! FirstCall(inst) = 0
! PRBSgen = initValue
! ELSE
! randomNumber = RAND()
!
! IF randomNumber > 0.5 THEN
! randomNumber = 1
! ELSE
! randomNumber = 0
! END IF
!
! randomNumber = randomNumber - 0.5
! randomNumber = randomNumber*amplitude*2 + mean
! PRBSgen = randomNumber
! END IF
!
!END FUNCTION PRBSgen
!-------------------------------------------------------------------------------------------------------------------------------
END MODULE FunctionToolbox
8 changes: 5 additions & 3 deletions Source/IPC.f90
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ SUBROUTINE IPC(rootMOOP, aziAngle, phi, Y_MErr, DT, KInter, Y_IPC_KP, Y_IPC_KI,

! Calculate commanded IPC pitch angles

CALL CalculatePitCom(rootMOOPF, aziAngle, Y_MErr, DT, KInter, Y_IPC_KP, Y_IPC_KI, omegaHP, zetaHP, phi, iStatus, IPC_ControlMode, Y_ControlMode, PitComIPC)
CALL CalculatePitCom(rootMOOPF, aziAngle, Y_MErr, DT, KInter, Y_IPC_KP, Y_IPC_KI, omegaHP, omegaLP, zetaHP, zetaLP, phi, iStatus, IPC_ControlMode, Y_ControlMode, PitComIPC)

! Filter PitComIPC with second order low pass filter

Expand All @@ -82,7 +82,7 @@ SUBROUTINE IPC(rootMOOP, aziAngle, phi, Y_MErr, DT, KInter, Y_IPC_KP, Y_IPC_KI,
! Calculates the commanded pitch angles.
! NOTE: if it is required for this subroutine to be used multiple times (for 1p and 2p IPC for example), the saved variables
! IntAxisTilt and IntAxisYaw need to be modified so that they support multiple instances (see LPFilter in the Filters module).
SUBROUTINE CalculatePitCom(rootMOOP, aziAngle, Y_MErr, DT, KInter, Y_IPC_KP, Y_IPC_KI, omegaHP, zetaHP, phi, iStatus, IPC_ControlMode, Y_ControlMode, PitComIPC)
SUBROUTINE CalculatePitCom(rootMOOP, aziAngle, Y_MErr, DT, KInter, Y_IPC_KP, Y_IPC_KI, omegaHP, omegaLP, zetaHP, zetaLP, phi, iStatus, IPC_ControlMode, Y_ControlMode, PitComIPC)
!...............................................................................................................................

IMPLICIT NONE
Expand All @@ -94,8 +94,10 @@ SUBROUTINE CalculatePitCom(rootMOOP, aziAngle, Y_MErr, DT, KInter, Y_IPC_KP, Y_I
REAL(4), INTENT(IN) :: DT ! The time step
REAL(4), INTENT(IN) :: KInter ! Integrator gain
REAL(4), INTENT(IN) :: omegaHP ! High-pass filter cut-in frequency
REAL(4), INTENT(IN) :: omegaLP ! Low-pass filter cut-off frequency
REAL(4), INTENT(IN) :: phi ! Phase offset added to the azimuth angle
REAL(4), INTENT(IN) :: zetaHP ! High-pass filter damping value
REAL(4), INTENT(IN) :: zetaLP ! Low-pass filter damping value
INTEGER(4), INTENT(IN) :: iStatus ! A status flag set by the simulation as follows: 0 if this is the first call, 1 for all subsequent time steps, -1 if this is the final call at the end of the simulation.
INTEGER(4), INTENT(IN) :: Y_ControlMode ! Yaw control mode
REAL(4), INTENT(IN) :: Y_MErr ! Yaw alignment error, measured [rad]
Expand Down Expand Up @@ -148,7 +150,7 @@ SUBROUTINE CalculatePitCom(rootMOOP, aziAngle, Y_MErr, DT, KInter, Y_IPC_KP, Y_I

IF (Y_ControlMode == 2) THEN
axisYawF = HPFilter(axisYaw, DT, omegaHP, iStatus, 1)
Y_MErrF = SecLPFilter(Y_MErr, DT, omegaLP, zetaLP, iStatus, 1)
Y_MErrF = SecLPFilter(Y_MErr, DT, omegaLP, zetaLP, iStatus, 2)
Y_MErrF_IPC = PIController(Y_MErrF, Y_IPC_KP, Y_IPC_KI, -100.0, 100.0, DT, 0.0, .FALSE., 3)
ELSE
axisYawF = axisYaw
Expand Down
Binary file added Source/Obj_win32/filters.mod
Binary file not shown.
Binary file added Source/Obj_win32/functiontoolbox.mod
Binary file not shown.
120 changes: 120 additions & 0 deletions Source/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
#================================================================================#
# This makefile created by B. Jonkman on 2-Apr-2013, #
# adapted from Crunch (M. Buhl on 25-Jan-2013). #
# (c) 2013 National Renewable Energy Laboratory #
# #
# This makefile has been tested on Windows 7 with gfortran. #
# This makefile works with mingw32-make.exe. #
# #
# It was designed to be used with discon.f90 for the Bladed DLL Interface #
#================================================================================#

# 32-bit or 64-bit?
BITS = 32
#BITS = 64


# Location of source files for the DLL.
# You may need to change these for your DLL.

DLL_DIR = .

SOURCE_FILE = FunctionToolbox.f90 Filters.f90 IPC.f90 DISCON.f90


# Name of compiler to use and flags to use.
FC = gfortran
FFLAGS = -O2 -m$(BITS) -fbacktrace -ffree-line-length-none -x f95-cpp-input -C
LDFLAGS = -shared -O2 -m$(BITS) -fbacktrace

# other useful gfortran options:
# -fdefault-real-8 -fcheck=bounds -std=f2003 -O0 -v
# -Wl,--out-implib,DISCON.lib


# Destination and RootName for executable

OUTPUT_NAME = DISCON
DEST_DIR = ../DISCON

#==========================================================#
# You should not need to change anything beyond this point #
#==========================================================#

# System-specific settings.

ifeq ($(OS),Windows_NT)
# Windows
DEL_CMD = del
EXE_EXT = _gwin$(BITS).dll
INTER_DIR = Obj_win$(BITS)
MD_CMD = @mkdir
OBJ_EXT = .obj
PATH_SEP = \\
SYS_FILE = SysGnuWin
else

FFLAGS := $(FFLAGS) -DIMPLICIT_DLLEXPORT

# Linux
DEL_CMD = rm -f
EXE_EXT = _glin$(BITS).so
INTER_DIR = Obj_lin$(BITS)
MD_CMD = @mkdir -p
OBJ_EXT = .o
PATH_SEP = /
SYS_FILE = SysGnuLinux

UNAME := $(shell uname -s)

ifneq ($(UNAME), Darwin)
FFLAGS := $(FFLAGS) -fPIC
LDFLAGS := $(LDFLAGS) -fPIC
endif
endif


# Source files (by module)

DLL_SOURCES = \
$(SOURCE_FILE)

vpath %.f90 $(DLL_DIR)
vpath %.mod $(INTER_DIR)
vpath %.obj $(INTER_DIR)

ALL_OBJS = $(DLL_SOURCES:.f90=.obj)

# Rule to do everything.

all: default
default: $(INTER_DIR) $(DEST_DIR)/$(OUTPUT_NAME)$(EXE_EXT)

# General rules for compliling the files.

%.obj: %.f90
$(FC) $(FFLAGS) -c $< -o $(INTER_DIR)/$@ -J $(INTER_DIR) -B $(INTER_DIR)


# Dependency rules.
#$(SYS_FILE).obj: $(PREC).obj


# Make sure the destination directory for the intermediate files exist.

$(INTER_DIR):
$(MD_CMD) $(INTER_DIR)


# For linking DLL.

$(DEST_DIR)/$(OUTPUT_NAME)$(EXE_EXT): $(ALL_OBJS) | $(INTER_DIR)
$(FC) $(LDFLAGS) -I $(INTER_DIR) -o $(DEST_DIR)/$(OUTPUT_NAME)$(EXE_EXT) \
$(foreach src, $(ALL_OBJS), $(addprefix $(INTER_DIR)/,$(src)))

# Cleanup afterwards.

clean:
$(DEL_CMD) $(INTER_DIR)$(PATH_SEP)*.mod $(INTER_DIR)$(PATH_SEP)*.obj

#gfortran -shared -O2 -m32 -fbacktrace -ffree-line-length-none -x f95-cpp-input -C ../CertTest/5MW_Baseline/ServoData/Source/DISCON.f90

0 comments on commit 7b61b0a

Please sign in to comment.