Commit 0f44fc17 authored by Alan Wai Hou Lio's avatar Alan Wai Hou Lio

Tested on 5/4.

parent 7e42029a
License Generator Version: 1.0a2
License Created by: MIKF
License Created: 2018-08-21 12:54:31
-------------------------------------------------------------------------------
INPUT
-------------------------------------------------------------------------------
{'H2': True,
'HS2': False,
'add_domain': False,
'add_ipv4s': False,
'add_macs': True,
'comment': 'Extended DTU licenses',
'edic': {'import_mac': 'C:\\Sandbox\\LicenseGenerator\\macs',
'load_database': 'C:/Sandbox/LicenseGenerator/LicenseGenerator/Database',
'load_databaseH2': 'C:/Sandbox/LicenseGenerator/HAWC2LicenseSource',
'load_databaseHS2': 'C:/Sandbox/LicenseGenerator/HAWCStab2LicenseSource',
'log_path': 'C:/Sandbox/LicenseGenerator/LicenseGenerator/CompileFolder\\LicenseGenerator.log',
'set_MS_build_path': '"C:\\Program Files '
'(x86)\\MSBuild\\14.0\\Bin\\MSBuild.exe"',
'set_fp_path_32': 'C:\\lazarus32\\fpc\\3.0.4\\bin\\i386-win32\\fpc.exe',
'set_fp_path_64': 'C:/lazarus/fpc/3.0.0/bin/x86_64-win64/fpc.exe',
'set_working_folder': 'C:/Sandbox/LicenseGenerator/LicenseGenerator/CompileFolder'},
'license_type': 1,
'overwrite_expiry': '01-01-2020'}
-------------------------------------------------------------------------------
License Manager Version:
-------------------------------------------------------------------------------
licence_manager.dll was latest releasted in version: (9, 267)
current licence_manager.dll version: (9, 268)
function [sig,Freq,Time,Flag,Binary] = ReadHawc2(FileName)
% Reads HAWC2 binary and ascii results file
% ------------------------------------------------------------------------
% [sig,Freq,Time,Flag,Binary] = ReadHAWC2(FileName);
% filename should be without extension
% e.g. FileName = '..\res\test'
% output:
% sig: all data in file
% Freq: sampling frequency
% Time: total simulation time in file
% Flag: 0 if file do not exist, 1 if reading scucceed,
% 2 if some data but not for full time span
% Binary: 1 if fils is in binary format, 0 if ascii
% ------------------------------------------------------------------------
% Made by Bjarne Skovmose Kallese
% 24/9-2008
% modified 18/12-2008: file error handelig added
% modified 26/2-2009: error msg for empty date file
% ------------------------------------------------------------------------
%% reading scale factors from *.sel file
fid = fopen([FileName,'.sel'], 'r');
if fid == -1
Flag = 0;
disp(' ')
disp('==============================================================')
disp(['file "',FileName,'" could not be found'])
disp('--------------------------------------------------------------')
sig = [];Freq = 0;Time=0;Binary=[];
return
end
fgets(fid); fgets(fid); fgets(fid); % skip 3 lines
fgets(fid); fgets(fid); fgets(fid); % skip 3 lines
fgets(fid); fgets(fid); % skip 2 lines
tline = fscanf(fid,'%f'); % read line number 9
N = tline(1);
Nch = tline(2);
Time = tline(3);
FileType = fscanf(fid,'%s');
fclose(fid);
Freq = N/Time;
%% Binary data
if FileType(1:6) == 'BINARY'
Binary = 1;
fid = fopen([FileName,'.dat'], 'r');
sig = fread(fid,[N,Nch],'int16');
if isempty(sig)
Flag = 0;
disp(' ')
disp('==============================================================')
disp(['no data in file "',FileName,'.dat"'])
disp('--------------------------------------------------------------')
sig = [];Freq = 0;Time=0;Binary=[];
return
end
ScaleFactor = dlmread([FileName,'.sel'],'',[9+Nch+5 0 9+2*Nch+4 0]);
sig = sig*diag(ScaleFactor);
fclose(fid);
Flag = 1;
%% ascii data
elseif FileType(1:5) == 'ASCII'
Binary = 0;
sig = dlmread([FileName,'.dat']);
if isempty(sig)
Flag = 0;
disp(' ')
disp('==============================================================')
disp(['no data in file "',FileName,'.dat"'])
disp('--------------------------------------------------------------')
sig = [];Freq = 0;Time=0;Binary=[];
return
end
if length(sig(:,1)) < N
Time = length(sig(:,1))/Freq;
Flag = 2;
disp(' ')
disp('==============================================================')
disp(['not full data in file "',FileName,'.dat"'])
disp('--------------------------------------------------------------')
return
end
Flag = 1;
%% error
else
disp('unknown file type')
Flag = 0;
end
\ No newline at end of file
This diff is collapsed.
% PIControllerInit
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Controller parameters
Controller.PiParams.Kk = 1.135E+00;%
Controller.PiParams.Ki = 0.2;%
Controller.PiParams.Kp = 0.5;%
Controller.PiParams.CornerFreq = 0.25*2*pi*1;%
% Wind turbine operating parameters
Controller.PiParams.Pnom = 10.0e+006;
Controller.PiParams.KII = 1.0*0.100131E+08;%
Controller.PiParams.Ng = 1;
Controller.PiParams.GenRot_nom = 1.0053;%
Controller.PiParams.Qgmax = 1.9960e+05*1.2;%
Controller.PiParams.Qgmin = 0;
Controller.PiParams.dQgmax = 15e3;
Controller.PiParams.dQgmin = -15e3;
Controller.PiParams.th_max = 90;
Controller.PiParams.th_min = -2;%
Controller.PiParams.dthmax = 8;
Controller.PiParams.dthmin = -8;
% Main simulation loop
% Matlab controller loop
while time <= Tend
% keyboard;
% THE VARIABLE �mssg� WILL CONTAIN THE OUTPUT VALUES FROM HAWC2
StringFromHawc=[];
while (isempty(StringFromHawc))
StringFromHawc = read(TCPOBJ);
......@@ -13,7 +11,7 @@ while time <= Tend
ArrayFromHawc = str2num(StringFromHawc);
% Remove first entry from array
ArrayFromHawc = ArrayFromHawc(2:end);
%%%%%%%%%%%%%%%%%%%%% Measurement %%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%% Get Measurement from HAWC2 %%%%%%%%%%%%%%
time = ArrayFromHawc(1); % 1: time [s]
omega = ArrayFromHawc(2); % 2: rotor speed [rad/s]
theta_bar = ArrayFromHawc(3); % 3: Pitch angle reference of blade 1 from DTU Basic Controller [rad]
......@@ -35,16 +33,13 @@ while time <= Tend
theta3 = 0;
%%%%%%%%%%%%%%%%%%% Signals to HAWC2 output %%%%%%%%%%%%%%%%%
%%%%% DON'T CHANGE %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ArrayToHawc = zeros(40,1);
ArrayToHawc = zeros(40,1);
ArrayToHawc(1) = theta_bar+theta1;% 2: Pitch angle reference of blade 1 [rad]
ArrayToHawc(2) = theta_bar+theta2;% 3: Pitch angle reference of blade 2 [rad]
ArrayToHawc(3) = theta_bar+theta3;% 4: Pitch angle reference of blade 3 [rad]
ArrayToHawc(4) = Qe_bar;% 1: Generator torque reference [Nm]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% THE VARIABLE BACK TO HAWC2 SHOULD BE PLACED IN THE SAME ORDER AS IN THE HTC FILE
% IMPORTANT THE STRING SHOULD END WITH AN ASTERIX THE �*�
StringToHawc = [sprintf('%0.12f;',ArrayToHawc) '*'];
write(TCPOBJ,int8(StringToHawc));
end
......
% =========================================================================
% Programmed by: %
% Wai Hou Lio %
% wali@dtu.dk %
% Department of Wind Energy %
% Technical University of Denmark %
% %
% History: Ver2.0 @ %
% %
% License: << Open Source Research Collaboration >> %
% %
% This version is not Linux compatible! %
% =========================================================================
%% Main file for the Matlab and HAWC2 interface
clc; fclose all; clear all;
clc; fclose all; clear all; warning off; profile on;beep off;
%%
% -------------------------------------------------------------------------
% Initialization
% -------------------------------------------------------------------------
global saved_vars Sys_PPF SimParams Controller;
if ~exist('PI_Controller','file')
addpath([pwd, '\lib']);
end
if ~exist('DTUConrtollerHAWC2','file')
addpath([pwd, '\DTUController']);
end
DTU_PIControllerInit;
% -------------------------------------------------------------------------
% Initialization of controller dependent variables
% -------------------------------------------------------------------------
time = 0;
%%
% kill all processes!
%% Initisation
% kill all processes
system('c:\Windows\System32\taskkill.exe /f /im hawc2mb.exe');
system('c:\Windows\System32\taskkill.exe /f /im cmd.exe');
% -------------------------------------------------------------------------
% SIMULATION OPTIONS SETUP
% -------------------------------------------------------------------------
% % Simulation time options
Tstart = 0; % From what time results should be saved
Tend = 600; % Simulation length
Ts = 0.01; % Sample time
SimParams.Ts = Ts;
% Simulation set-up
time = 0;
Tend = 600; % Simulation length
%%
TCPportnumber = 1239;
%% ************************************************************************
% * Start HAWC2 and run simulation
% ************************************************************************
% tic-toc measures computation time of simulation
tic
% Open HAWC2
cd(['../DTU_10_MW_Reference_Wind_Turbine_v_9-1' ]);
if isunix
system('wine hawc2MB.exe ./htc/DTU_10MW_RWT.htc')
else
!hawc2MB.exe ./htc/DTU_10MW_RWT.htc &
end
cd(['../hawc2_htc' ]);% Go to hawc2 and htc fodler
% call HAWC2
!hawc2MB.exe ./htc/DTU_10MW_RWT.htc &
cd('../matlab');
TcpIpConnected = 0;
for i = 1:100
if TcpIpConnected
......@@ -83,7 +27,6 @@ for i = 1:100
end
pause(.1);
try
% JTCPOBJ = jtcp('REQUEST','localhost',TCPportnumber);
TCPOBJ = tcpclient('127.0.0.1',TCPportnumber,'ConnectTimeout',30);
TcpIpConnected = 1;
catch TryTcpIpConnect
......@@ -92,7 +35,7 @@ for i = 1:100
end
end
HAWC2matlabScript
HAWC2matlabScript
toc
......
function Controller_Output = PI_Controller(measurements)
% U - (1) Pitch angle, (2) generator torque
% X - (1) Filtered generator speed, (2) integral error state
global WT1 SimParams Controller;
persistent CtrlStates CtrlInputs;
if isempty(CtrlStates), CtrlStates=[0;0]; end;
if isempty(CtrlInputs), CtrlInputs=[0;0]; end;
GenRot = WT1.Measrmnt.GenSpeed;%
Ts = SimParams.Ts;
Ei = CtrlStates(1);
GenRot_filter = CtrlStates(2);
% Lowpass filter for generator speed
Alpha = exp( ( -Ts )*Controller.PiParams.CornerFreq );
GenRot_filter = ( 1.0 - Alpha )*GenRot + Alpha*GenRot_filter;
% Speed error
Ep = GenRot_filter - Controller.PiParams.GenRot_nom;
% Integrated speed error
Ei = Ei + Ep*Ts;
Kgs = 1/(1+(pi/180*(CtrlInputs(1)-Controller.PiParams.th_min))/Controller.PiParams.Kk)*180/pi;
% Limit of generator speed where optimal tracking ends
GenRot_high = Controller.PiParams.GenRot_nom*.95;
% Generator torque control
Qh = Controller.PiParams.KII * GenRot_high^2/Controller.PiParams.Ng^3;
Qnom = Controller.PiParams.Pnom/Controller.PiParams.GenRot_nom;
U(2,1) = Controller.PiParams.KII * GenRot_filter^2/Controller.PiParams.Ng^3;
%
if CtrlInputs(1) <= Controller.PiParams.th_min+0.1 % Below rated wind speed
if GenRot_filter <= GenRot_high
U(2,1) = Controller.PiParams.KII * GenRot_filter^2/Controller.PiParams.Ng^3;
else
U(2,1) = Qh + (Qnom-Qh)*(GenRot_filter-GenRot_high)/(Controller.PiParams.GenRot_nom-GenRot_high);
end
else % Above rated wind speed
U(2,1) = Controller.PiParams.Pnom/GenRot_filter;%4.1337e+004;%
end
% PI controller for pitch angle
U(1,1) = Kgs*(Controller.PiParams.Kp*Ep + Controller.PiParams.Ki*Ei);
% Saturation limits of control signals
Umax = [Controller.PiParams.th_max Controller.PiParams.Qgmax]';
Umin = [Controller.PiParams.th_min Controller.PiParams.Qgmin]';
dUmax = [Controller.PiParams.dthmax Controller.PiParams.dQgmax]';
dUmin = [Controller.PiParams.dthmin Controller.PiParams.dQgmin]';
% Saturate control signal
U = min(max(U,Umin),Umax);
% Saturate control signal rate
dU = min(max((U-CtrlInputs)/Ts,dUmin),dUmax);
% Calc. saturated control signal
U = CtrlInputs+dU*Ts;
% Integrator anti-windup
% This line is important for it prevents the negative error to accumulate in the integrator!
Ei = (U(1) - Kgs*Controller.PiParams.Kp*Ep)/(Kgs*Controller.PiParams.Ki);
X(1,1) = Ei;
X(2,1) = GenRot_filter;
CtrlStates = X;
CtrlInputs = U;
Controller_Output = [U(1); U(2)];
return;
This diff is collapsed.
......@@ -4,35 +4,27 @@ Matlab-HAWC2 Interface
The Matlab-HAWC2 interfance enables you to build your controller in Matlab and calls HAWC2 in the Matlab environment. The folder also contains a working example of the [DTU10MW Reference Wind Turbine
Model](http://www.hawc2.dk/Download/HAWC2-Model/DTU-10-MW-Reference-Wind-Turbine).
 
Installation
============
This repository is written for Windows.
[HAWC2 ](http://www.hawc2.dk/) should be installed and the executable HAWC2mb.exe should be in the directory of "DTU_10_MW_Reference_Wind_Turbine_v9-1". The HAWC2mb.exe file and DTU10MW should be checked and updated from time to time.
[HAWC2](http://www.hawc2.dk/) should be installed. The executable `HAWC2mb.exe`, licence files and other files from HAWC2 should be in the folder of "hawc2_htc".
To install this package, just simply download it and unzip it or you can use clone the repository and pip install as follows:
```
git clone https://github.com/alanliowh/Matlab-Hawc2-interface.git
cd Matlab-Hawc2-interface
pip install .
```
The turbine model (htc, data, control folders) should be placed in hawc2_htc folder as well. A working exmaple of DTU 10MW model is provided.
Example
=======
To begin, go into the "matlab" directory.
To begin, go into the "matlab" folder.
Run "Main.m"
If you want to change the controller, go to "HAWC2matlabScript.m", where you can place your own controller instead of the default PID controller.
If you want to design your own controller, go to "HAWC2matlabScript.m", where you can place your own controller. By default, the Matlab script will call the [DTU Wind Energy Controller (DTUWEC)](https://gitlab.windenergy.dtu.dk/OpenLAC/BasicDTUController).
Contact
=====
Feel free to contact me if you encounter any problem regarding this interface at wali@dtu.dk.
Feel free to contact me if you encounter any problems regarding this interface at wali@dtu.dk.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment