Hi, Bonnie,
Thank you very much for your answers.
I found FAST V8.10 can “ add an additional FAST_SFunc input from Simulink, just change the third S-Function parameter in the S-Function block in Simulink and then modify FAST_Library.f90 to handle the new input value” , I think this could help me to add an flap control signal input from simulink.But I met another problem.I modify some FAST source code list as below:
(1) FAST_Library.f90
subroutine FAST_SetExternalInputs(NumInputs_c, InputAry, m_FAST)
……
! add some variable
REAL(ReKi) , DIMENSION(1:3) :: FlapCom_STU ! Flap commands from Simulink/Labview [rad/s]
REAL :: COM1_STU,COM2_STU,COM3_STU ! Deliver the flap commands parameter to AeroSubs.f90 file.
COMMON COM1_STU,COM2_STU,COM3_STU
……
IF ( NumInputs_c > NumFixedInputs ) THEN ! NumFixedInputs is the fixed number of inputs
IF ( NumInputs_c == NumFixedInputs + 3 ) &
m_FAST%ExternInput%FlapCom_STU = InputAry(9:11) ! use the input port InputAry(9:11) to pass the flap commands
!m_FAST%ExternInput%LidarFocus = InputAry(9:11)
END IF
COM1_STU = FlapCom_STU(1)
COM2_STU = FlapCom_STU(2)
COM3_STU = FlapCom_STU(3)
end subroutine FAST_SetExternalInputs
(2)AeroSubs.f90
SUBROUTINE AD_GetInput(InitInp, P, x, xd, z, O, y, ErrStat, ErrMess )
……
! add some variable
CHARACTER (1024) :: FlapNm(100)
INTEGER :: L
INTEGER :: FlapCom
REAL :: COM11_STU,COM12_STU,COM13_STU
COMMON COM11_STU,COM12_STU,COM13_STU
……
!read the flap airfoil file name(s)
CALL ReadAryLines( UnIn, InitInp%ADFileName, FlapNm, 10, AryName=‘FlapNm’, AryDescr=‘Flap file names’, ErrStat=ErrStat, ErrMsg=ErrMess )
IF (ErrStat >= AbortErrLev) THEN
CLOSE(UnIn)
RETURN
END IF
! flap airfoil data file name(s) pass to FlapNm(L)
DO L=1,10
IF ( PathIsRelative( FlapNm(L) ) ) FlapNm(L) = TRIM(FilePath)//TRIM( FlapNm(L) )
END DO
FlapCom = INT( COM11_STU ) !Use the COM11_STU as an flap command single
! use the new flap airfoil data file to replace the old airfoil data file according to the flap command single
SELECT CASE (FlapCom)
CASE(1)
P%AirFoil%FoilNm(10)=FlapNm(1)
CASE(2)
P%AirFoil%FoilNm(10)=FlapNm(2)
CASE(3)
P%AirFoil%FoilNm(10)=FlapNm(3)
CASE(4)
P%AirFoil%FoilNm(10)=FlapNm(4)
CASE(5)
P%AirFoil%FoilNm(10)=FlapNm(5)
CASE(6)
P%AirFoil%FoilNm(10)=FlapNm(6)
CASE(7)
P%AirFoil%FoilNm(10)=FlapNm(7)
CASE(8)
P%AirFoil%FoilNm(10)=FlapNm(8)
CASE(9)
P%AirFoil%FoilNm(10)=FlapNm(9)
CASE(10)
P%AirFoil%FoilNm(10)=FlapNm(10)
CASE DEFAULT
WRITE(,)“ERROR”
STOP
END SELECT
……
Then run the …\Simulink\VisualStudio\FAST_Library.vfproj, It could create the FAST_Library_debug_Win32.dll. And then use the new FAST_Library_debug_Win32.dll replace the old FAST_Library _Win32.dll, and run the Run_OpenLoop.m file, An error occur , the prompt message are as below:
This segmentation violation occurred while executing the
S-function 'FAST_SFunc' in block 'O'.
A common cause of this segmentation violation is an incorrect
input port direct feedthrough setting. Each input port of the
S-function that is read (accessed) in mdlOutputs and/or
mdlGetTimeOfNextVarHit must specify that it needs its input
signal in these routines by setting direct feedthrough for
these input ports.
1) To debug your C-MEX S-function, you can enable diagnostics
by compiling the S-function source with the -g flag, e.g.,
mex -g sfunction_name.c
2) You can ask Simulink to try assuming your S-function has
direct feedthrough using:
set_param('modelname','TryForcingSFcnDF','on')
If Simulink can find a valid sorting mode that does not
result in algebraic loops involving your S-function, your
model will execute (assuming that the cause of this
segmentation violation is an incorrect direct feedthrough
setting on an input port).
See matlabroot/simulink/src/sfuntmpl_directfeed.txt
-------------------------------------------------------------
Error using Run_OpenLoop (line 30)
Error while obtaining sizes from MEX S-function ‘FAST_SFunc’ in ‘OpenLoop/FAST Nonlinear Wind
Turbine/S-Function’.
Caused by:
Error using Run_OpenLoop (line 30)
FatalException
There are something wrong happen in the interface of the FAST_SFunc and Matlab\Simulink, I don’t know how to solve it. Can anybody help me?
Best regards,
keshan