|
@@ -13,8 +13,8 @@
|
|
|
#include "sim_support.h"
|
|
|
|
|
|
#define START_TIME 0.0
|
|
|
-#define STOP_TIME 9.0
|
|
|
-#define STEP_SIZE 0.001
|
|
|
+#define STOP_TIME 4.5
|
|
|
+#define STEP_SIZE 0.00001
|
|
|
|
|
|
FMU fmu_env, fmu_control_sa, fmu_power_sa, fmu_loop_sa;
|
|
|
|
|
@@ -28,6 +28,11 @@ int main(void) {
|
|
|
FILE *fp_fmu_loop_sa;
|
|
|
fp_fmu_loop_sa = fopen("result_loop_sa.csv", "w");
|
|
|
|
|
|
+ fprintf(fp_fmu_env,"t,dup,dup_stop,ddown,ddown_stop,pup,pup_stop,pdown,pdown_stop,obj\n");
|
|
|
+ fprintf(fp_fmu_control_sa,"t,u,d\n");
|
|
|
+ fprintf(fp_fmu_power_sa,"t,i,omega,theta\n");
|
|
|
+ fprintf(fp_fmu_loop_sa,"t,tau,height\n");
|
|
|
+
|
|
|
puts("Loading Dlls\n");
|
|
|
|
|
|
loadDll("libFMI_Environment.dll", &fmu_env, "PW_ENV_");
|
|
@@ -45,7 +50,7 @@ int main(void) {
|
|
|
char *fmuResourceLocation_env = "libFMI_Environment.dll";
|
|
|
char *fmuResourceLocation_control_sa = "libFMI_controller_sa.dll";
|
|
|
char *fmuResourceLocation_power_sa = "libFMI_power_sa.dll";
|
|
|
- char *fmuResourceLocation_window_sa = "libFMI_loop_sa.dll";
|
|
|
+ char *fmuResourceLocation_loop_sa = "libFMI_loop_sa.dll";
|
|
|
|
|
|
fmi2CallbackFunctions callbacks_env= {fmuLogger, calloc, free, NULL, &fmu_env};
|
|
|
fmi2CallbackFunctions callbacks_control_sa = {fmuLogger, calloc, free, NULL, &fmu_control_sa};
|
|
@@ -55,9 +60,9 @@ int main(void) {
|
|
|
c_env = fmu_env.instantiate("env", fmi2CoSimulation, "1", fmuResourceLocation_env, &callbacks_env, fmi2False, fmi2False);
|
|
|
c_control_sa = fmu_control_sa.instantiate("control_sa", fmi2CoSimulation, "1", fmuResourceLocation_control_sa, &callbacks_control_sa, fmi2False, fmi2False);
|
|
|
c_power_sa = fmu_power_sa.instantiate("power_sa", fmi2CoSimulation, "1", fmuResourceLocation_power_sa, &callbacks_power_sa, fmi2False, fmi2False);
|
|
|
- c_loop_sa = fmu_loop_sa.instantiate("loop_sa",fmi2CoSimulation, "1", fmuResourceLocation_window_sa, &callbacks_loop_sa, fmi2False, fmi2False );
|
|
|
+ c_loop_sa = fmu_loop_sa.instantiate("loop_sa",fmi2CoSimulation, "1", fmuResourceLocation_loop_sa, &callbacks_loop_sa, fmi2False, fmi2False );
|
|
|
|
|
|
- fmi2Boolean toleranceDefined = fmi2False; // Disables zero crossings
|
|
|
+ fmi2Boolean toleranceDefined = fmi2False; // Disables accurate zero crossing
|
|
|
fmi2Real tolerance = 0; // used in setting up the experiment
|
|
|
|
|
|
puts("FMU components instantiated, setting up experiments\n");
|
|
@@ -143,24 +148,24 @@ int main(void) {
|
|
|
fmi2ValueReference vr_out_env[9]={0,1,2,3,4,5,6,7,8};
|
|
|
fmi2Boolean b_out_env[9];
|
|
|
fmi2ValueReference vr_in_control_sa_from_env[8]={0,1,2,3,4,5,6,7};
|
|
|
- fmi2ValueReference vr_in_control_sa_from_window[1] = {0};
|
|
|
+ fmi2ValueReference vr_in_control_sa_from_power[1] = {0};
|
|
|
fmi2ValueReference vr_out_control_sa[2]={9,10};
|
|
|
- fmi2ValueReference vr_in_power_sa_u_d[2] = {3,5};
|
|
|
+ fmi2ValueReference vr_in_power_sa_u_d[2] = {5,3};
|
|
|
fmi2ValueReference vr_in_power_sa_tau[1] = {4};
|
|
|
- fmi2ValueReference vr_out_loop_sa[1] = {0};
|
|
|
+ fmi2ValueReference vr_out_loop_sa[2] = {0,3}; // tau, height
|
|
|
+ fmi2ValueReference vr_out_power_sa[3] = {0,1,2};
|
|
|
fmi2Real r_in_power_from_control[2] = {0,0};
|
|
|
fmi2Real r_in_power_from_loop[1]={0};
|
|
|
- fmi2ValueReference vr_out_power_sa[3] = {0,1,2};
|
|
|
fmi2Real r_out_power[3];
|
|
|
- fmi2Real r_out_loop_sa[1];
|
|
|
+ fmi2Real r_out_loop_sa[2];
|
|
|
|
|
|
fmi2Boolean b_out_control_sa[2];
|
|
|
double currentTime = START_TIME;
|
|
|
- const fmi2StatusKind lst = fmi2LastSuccessfulTime;
|
|
|
+ //const fmi2StatusKind lst = fmi2LastSuccessfulTime;
|
|
|
|
|
|
while(currentTime <= STOP_TIME){
|
|
|
printf("\n----master new loop, ct:%f, h:%f\n",currentTime,STEP_SIZE);
|
|
|
- double next_step_size = STEP_SIZE;
|
|
|
+ //double next_step_size = STEP_SIZE;
|
|
|
|
|
|
// do step
|
|
|
auxFlag = fmu_power_sa.setReal(c_power_sa,vr_in_power_sa_u_d,2, &r_in_power_from_control[0]);
|
|
@@ -216,7 +221,7 @@ int main(void) {
|
|
|
fflush(stdout);
|
|
|
return 1;
|
|
|
}
|
|
|
- auxFlag = fmu_control_sa.setReal(c_control_sa,vr_in_control_sa_from_window,1, &r_out_power[0]);
|
|
|
+ auxFlag = fmu_control_sa.setReal(c_control_sa,vr_in_control_sa_from_power,1, &r_out_power[0]);
|
|
|
if(auxFlag != fmi2OK){
|
|
|
printf("Failed fmu_control_sa.setReal\n");
|
|
|
fflush(stdout);
|
|
@@ -270,15 +275,16 @@ int main(void) {
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
|
- if (fmu_loop_sa.getReal(c_loop_sa, vr_out_loop_sa, 1, &r_out_loop_sa[0]) != fmi2OK){
|
|
|
+ if (fmu_loop_sa.getReal(c_loop_sa, vr_out_loop_sa, 2, &r_out_loop_sa[0]) != fmi2OK){
|
|
|
printf("Failed getReal\n");
|
|
|
fflush(stdout);
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
|
- fprintf(fp_fmu_loop_sa,"%f,%f\n",
|
|
|
+ fprintf(fp_fmu_loop_sa,"%f,%f,%f\n",
|
|
|
currentTime,
|
|
|
- r_out_loop_sa[0]
|
|
|
+ r_out_loop_sa[0],
|
|
|
+ r_out_loop_sa[1]
|
|
|
);
|
|
|
|
|
|
r_in_power_from_loop[0] = r_out_loop_sa[0];
|