extra power

This commit is contained in:
aj 2020-12-01 16:51:10 +00:00
parent 8584a85871
commit 2d8b3c61cb
4 changed files with 57 additions and 19 deletions

7
maths/func/get_extra_p.m Normal file
View File

@ -0,0 +1,7 @@
function power = get_extra_p(length, offset, seconds, power)
%GET_EXTRA_P Summary of this function goes here
power = [zeros(1, offset) repmat(power, 1, seconds) zeros(1, (length - offset - seconds))];
end

View File

@ -10,13 +10,13 @@ close all;clear all;clc;
CUMULATIVE_ERRORS = false;
ITERATE = ~true;
SAVE = ~true;
SAVE = true;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Parameters
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ITERATIONS = 5;
day_to_seconds = 24*60*60;
hours_to_seconds = 60*60;
MIN_P_IN = 0; % W, max power from fuel cells
MAX_P_IN = 8e6; % W, max power from fuel cells
@ -27,6 +27,12 @@ dp_MAX_P_OUT = 3842e3; % W
dp_MIN_P_OUT = 362e3; % W
dp_SIMULATION_DAYS = 2; % days
cable_drum = get_extra_p(dp_SIMULATION_DAYS*day_to_seconds, 3*hours_to_seconds, 1.5*hours_to_seconds, 946.26e3);
cable_lower = get_extra_p(dp_SIMULATION_DAYS*day_to_seconds, 40*hours_to_seconds, 1.5*hours_to_seconds, 908.41e3);
crane = get_extra_p(dp_SIMULATION_DAYS*day_to_seconds, 12*hours_to_seconds, 15*60, 245.25e3);
rov_launch = get_extra_p(dp_SIMULATION_DAYS*day_to_seconds, 8*hours_to_seconds, 20*60, 454.2e3);
dp_EXTRA_P = [cable_drum ; cable_lower ; crane ; rov_launch];
%%%%% Outbound
out_MAX_P_OUT = 1600e3; % W
out_MIN_P_OUT = 600e3; % W
@ -63,7 +69,7 @@ unused_energy = [unused_energy u_energy];
unavailable_energy = [unavailable_energy una_energy];
% DP
[p_in,b_level,p_out,u_energy,una_energy, ~] = power_sim(dp_MAX_P_OUT, dp_MIN_P_OUT, MAX_P_IN, MIN_P_IN, dp_SIMULATION_DAYS, power_out(end), power_in(end), battery_level(end), CUMULATIVE_ERRORS);
[p_in,b_level,p_out,u_energy,una_energy, ~] = power_sim(dp_MAX_P_OUT, dp_MIN_P_OUT, MAX_P_IN, MIN_P_IN, dp_SIMULATION_DAYS, power_out(end), power_in(end), battery_level(end), CUMULATIVE_ERRORS, dp_EXTRA_P);
power_in = [power_in p_in];
battery_level = [battery_level b_level];
power_out = [power_out p_out];
@ -79,7 +85,7 @@ unused_energy = [unused_energy u_energy];
unavailable_energy = [unavailable_energy una_energy];
% DP
[p_in,b_level,p_out,u_energy,una_energy, ~] = power_sim(dp_MAX_P_OUT, dp_MIN_P_OUT, MAX_P_IN, MIN_P_IN, dp_SIMULATION_DAYS, power_out(end), power_in(end), battery_level(end), CUMULATIVE_ERRORS);
[p_in,b_level,p_out,u_energy,una_energy, ~] = power_sim(dp_MAX_P_OUT, dp_MIN_P_OUT, MAX_P_IN, MIN_P_IN, dp_SIMULATION_DAYS, power_out(end), power_in(end), battery_level(end), CUMULATIVE_ERRORS, dp_EXTRA_P);
power_in = [power_in p_in];
battery_level = [battery_level b_level];
power_out = [power_out p_out];
@ -159,7 +165,7 @@ xlabel('Time (Days)')
hold off;
if SAVE
exportgraphics(gcf, sprintf('%s-%i.png', TITLE, I), 'Resolution', '250')
exportgraphics(gcf, sprintf('mission.png'), 'Resolution', '250', 'ContentType','vector')
end
% FINAL STATS

View File

@ -9,12 +9,14 @@ close all;clear all;clc;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
CUMULATIVE_ERRORS = false;
ITERATE = ~true;
SAVE = ~true;
ITERATE = true;
SAVE = true;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Parameters
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
day_to_seconds = 24*60*60;
hours_to_seconds = 60*60;
ITERATIONS = 5;
@ -28,6 +30,12 @@ MIN_P_OUT = 362e3; % W
TITLE = 'Dyn. Pos. Sea State 7';
SIMULATION_DAYS = 2; % days
cable_drum = get_extra_p(SIMULATION_DAYS*day_to_seconds, 3*hours_to_seconds, 1.5*hours_to_seconds, 946.26e3);
cable_lower = get_extra_p(SIMULATION_DAYS*day_to_seconds, 40*hours_to_seconds, 1.5*hours_to_seconds, 908.41e3);
crane = get_extra_p(SIMULATION_DAYS*day_to_seconds, 12*hours_to_seconds, 15*60, 245.25e3);
rov_launch = get_extra_p(SIMULATION_DAYS*day_to_seconds, 8*hours_to_seconds, 20*60, 454.2e3);
EXTRA_P = [cable_drum ; cable_lower ; crane ; rov_launch];
%%%%% Outbound
% MAX_P_OUT = 1600e3; % W
% MIN_P_OUT = 600e3; % W
@ -46,14 +54,16 @@ SIMULATION_DAYS = 2; % days
% TITLE = 'Homebound';
% SIMULATION_DAYS = 3; % days
BATT_INIT_LEVEL = 0.5;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Simulate
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
p_av = (MAX_P_OUT + MIN_P_OUT) / 2;
if exist('EXTRA_P')
[power_in,battery_level,power_out,unused_energy,unavailable_energy, batt_capacity] = power_sim(MAX_P_OUT, MIN_P_OUT, MAX_P_IN, MIN_P_IN, SIMULATION_DAYS, p_av, p_av, -1, CUMULATIVE_ERRORS, EXTRA_P);
else
[power_in,battery_level,power_out,unused_energy,unavailable_energy, batt_capacity] = power_sim(MAX_P_OUT, MIN_P_OUT, MAX_P_IN, MIN_P_IN, SIMULATION_DAYS, p_av, p_av, -1, CUMULATIVE_ERRORS);
end
sim_seconds = length(power_in);
@ -141,7 +151,7 @@ end
hold off;
if SAVE
exportgraphics(gcf, sprintf('%s-%i.png', TITLE, I), 'Resolution', '250')
exportgraphics(gcf, sprintf('%s.png', TITLE), 'Resolution', '250', 'ContentType','vector')
end
% FINAL STATS

View File

@ -1,5 +1,5 @@
function [power_in,battery_level,power_out,unused_energy,unavailable_energy, batt_capacity] = ...
power_sim(MAX_P_OUT, MIN_P_OUT, MAX_P_IN, MIN_P_IN, SIMULATION_DAYS, init_p_out, init_p_in, init_battery, CUMULATIVE_ERRORS)
power_sim(MAX_P_OUT, MIN_P_OUT, MAX_P_IN, MIN_P_IN, SIMULATION_DAYS, init_p_out, init_p_in, init_battery, CUMULATIVE_ERRORS, extra_p_out)
%POWER_SIM Summary of this function goes here
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@ -36,7 +36,7 @@ sim_seconds = SIMULATION_DAYS * 24 * 60 * 60;
batt_capacity = batt_capacity * 3600; % J
BATT_FULL_LEVEL = 0.8; % battery level at which the power input decreases
BATT_WARN_LEVEL = 0.4; % battery level at which the power input increases
BATT_WARN_LEVEL = 0.5; % battery level at which the power input increases
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Simulate
@ -63,10 +63,19 @@ else
end
power_out(1) = init_p_out;
EXTRA_POWER = false;
if exist('extra_p_out')
EXTRA_POWER = true;
end
% loop through day
for SECOND=1:sim_seconds
battery_net = current_p_in - current_p_out; % net power this second
if EXTRA_POWER
battery_net = battery_net - sum(extra_p_out(:, SECOND));
end
% get last energy value at the battery
% set cumulative values
if SECOND == 1
@ -118,19 +127,25 @@ for SECOND=1:sim_seconds
battery_level(SECOND) = max(min(curr_battery, batt_capacity), 0);
power_out(SECOND) = current_p_out;
if EXTRA_POWER
power_out(SECOND) = power_out(SECOND) + sum(extra_p_out(:, SECOND));
end
% CHANGE LOAD
power_out_delta = (rand - 0.5) * 2 * P_OUT_INTERVAL;
current_p_out = min(max(current_p_out + power_out_delta, MIN_P_OUT), MAX_P_OUT);
batt_percent = (battery_level(SECOND)/batt_capacity);
% BATTERY LOW, INCREASE POWER IN
% if battery_net < 0 && (battery_level(SECOND)/batt_capacity) < BATT_WARN_LEVEL
if (battery_level(SECOND)/batt_capacity) < BATT_WARN_LEVEL
percent_diff = (BATT_WARN_LEVEL - (battery_level(SECOND)/batt_capacity)) / BATT_WARN_LEVEL;
% if battery_net < 0 && batt_percent < BATT_WARN_LEVEL
if batt_percent < BATT_WARN_LEVEL
percent_diff = (BATT_WARN_LEVEL - batt_percent) / BATT_WARN_LEVEL;
current_p_in = min(current_p_in + percent_diff * P_IN_INTERVAL, MAX_P_IN);
% BATTERY HIGH, DECREASE POWER IN
elseif (battery_level(SECOND)/batt_capacity) > BATT_FULL_LEVEL
percent_diff = 1 - (abs(BATT_FULL_LEVEL - (battery_level(SECOND)/batt_capacity)) / (1 - BATT_FULL_LEVEL));
elseif batt_percent > BATT_FULL_LEVEL && batt_percent < 1
percent_diff = 1 - (abs(BATT_FULL_LEVEL - batt_percent) / (1 - BATT_FULL_LEVEL));
current_p_in = max(current_p_in - percent_diff * P_IN_INTERVAL, MIN_P_IN);
% NEITHER, RELAX TO EFFICIENT STATE