Skip to content

Battery #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 280 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
280 commits
Select commit Hold shift + click to select a range
66b2b3c
chore: set randflag
fedeoli Jun 22, 2022
79e00f7
del: remove former battery model
fedeoli Jun 22, 2022
4815cd8
feat: LTI unstable test control model
fedeoli Jun 22, 2022
bac923e
chore: sim setup
fedeoli Jun 22, 2022
58c9995
feat: plot manipulator and model update
fedeoli Jun 23, 2022
7ecae9c
feat: random around zero init
fedeoli Jun 23, 2022
1fdcd53
feat: test on LTI unstable model
fedeoli Jun 23, 2022
dd0b894
feat: more complex conrol law (drive)
fedeoli Jun 23, 2022
a9b6cee
chore: sim setup
fedeoli Jun 23, 2022
8af6820
feat: use y in control
fedeoli Jul 4, 2022
f0b2e39
chore: update control test model
fedeoli Jul 4, 2022
8c46096
chore: update params sim
fedeoli Jul 4, 2022
5a3817b
feat: test controller - TODO fix obs update
fedeoli Jul 4, 2022
4f22504
Create ECM.slx
tkdesai13 Jul 9, 2022
7fc3f3d
Create Battery_simscape_model.slx
tkdesai13 Jul 9, 2022
8161065
Create 11_05_2015_SP20-2_DST_50SOC.xls
tkdesai13 Jul 9, 2022
686c4e1
Create ECM_parameters.mat
tkdesai13 Jul 9, 2022
a292ef1
Create 11_05_2015_SP20-2_DST_80SOC.xls
tkdesai13 Jul 9, 2022
5ad694a
Create DST_Current_input_SP20-2_DST_50SOC.xlsx
tkdesai13 Jul 9, 2022
4db9b69
Create SP2_25C_DST_50.xlsx
tkdesai13 Jul 9, 2022
cde9e7d
feat: update control law
fedeoli Jul 11, 2022
25518e8
feat: measure diff for estimate and control + reference
fedeoli Jul 11, 2022
2d1ce08
feat: differentiate estimation and control models
fedeoli Jul 11, 2022
3c438fe
feat: add models for reference and target (MRAC)
fedeoli Jul 11, 2022
79cc704
chore: rearrange parameters + add history vars
fedeoli Jul 11, 2022
d9c044a
fix: test obs without changing the calls object (handle)
fedeoli Jul 11, 2022
46d39be
feat: differentiate combined estimation with general sim + delete tes…
fedeoli Jul 11, 2022
6ba4892
chore: plot after test obs
fedeoli Jul 11, 2022
d9f1061
feat: different control laws for ID and control
fedeoli Jul 13, 2022
629da9f
feat: different filters for ID and control
fedeoli Jul 13, 2022
7b85519
chore: edit ref and model measure for control purposes
fedeoli Jul 13, 2022
5b0eb71
chore: edit model control test
fedeoli Jul 13, 2022
83eb47c
feat: ID model + CTRL model
fedeoli Jul 13, 2022
3faeda5
chore: edit init and reference model
fedeoli Jul 13, 2022
549ded1
chore: edit combined sim ID + ctrl
fedeoli Jul 13, 2022
09161c4
chore: edit test ctrl law script and plot
fedeoli Jul 13, 2022
5471072
chore: sim setup
fedeoli Jul 13, 2022
4f84bad
feat: globas search
fedeoli Jul 13, 2022
e47f782
fix: init condition error
fedeoli Jul 13, 2022
b027ed2
feat: estimation model with different structure (no model matching)
fedeoli Jul 15, 2022
f0b46e3
chore: params setup
fedeoli Jul 15, 2022
5553629
chore: params update
fedeoli Jul 15, 2022
163c585
feat: add flags to opt and combined estimation
fedeoli Jul 15, 2022
b647bec
feat: routh criterion and model analysis
fedeoli Jul 15, 2022
90f9557
Battery ECM dynamics added, still optimisation is diverging
tkdesai13 Jul 22, 2022
f80cc16
chore: testing new scheme = est + control
fedeoli Jul 29, 2022
ae87ebe
chore: remove simulink cache files
fedeoli Aug 2, 2022
4f54493
chore: update params
fedeoli Aug 2, 2022
6973ac8
feat: add filter on measure (reference.TF filter)
fedeoli Aug 2, 2022
1655b7f
fix: params dynamics in model, no update as it's a algebraic dependen…
fedeoli Aug 2, 2022
9c2124f
feat: update with control version of obsopt
fedeoli Aug 2, 2022
2def8ce
chore: gitignore
fedeoli Aug 2, 2022
a1ba466
chore: add simulations results (report on overleaf)
fedeoli Aug 2, 2022
4907e39
feat: obsopt multistart, remove control design, terminal cost, max op…
fedeoli Aug 20, 2022
8942c34
feat: control for both id and ref track
fedeoli Aug 20, 2022
bcd667b
chore: params and measurements
fedeoli Aug 20, 2022
5e5af28
feat: weight terms post normalisation
fedeoli Aug 20, 2022
cc1bf1b
chore: model and params in simulation
fedeoli Aug 20, 2022
23e3677
feat: test model
fedeoli Aug 20, 2022
5b2932a
doc: paper
fedeoli Aug 30, 2022
7b21eb9
data: workspace (fedeoli version)
fedeoli Aug 30, 2022
f9b3ff0
chore: rewrite control with switch case
fedeoli Aug 30, 2022
7c8639c
chore: add 2dim filter (option)
fedeoli Aug 30, 2022
75966bd
chore: add second measure (option)
fedeoli Aug 30, 2022
03b11bc
chore: change params init model
fedeoli Aug 30, 2022
19d4d99
feat: opt problem to find first vals for params
fedeoli Aug 30, 2022
b5532fb
feat: script to generate data (fedeoli version)
fedeoli Aug 30, 2022
e7c65eb
feat: CT model
fedeoli Aug 30, 2022
3bf7530
feat: add reference model
fedeoli Aug 30, 2022
cecdd07
feat: ORC sym analysis (several models)
fedeoli Aug 30, 2022
3f0e8ab
feat: add true params values in init procedure
fedeoli Aug 30, 2022
0ef35dc
feat: add update for all the params
fedeoli Aug 30, 2022
df724ba
chore: change params and add first_guess
fedeoli Aug 30, 2022
1bfd2c3
feat: sym analysis ORC (Lie brack and sym grad)
fedeoli Aug 30, 2022
0432499
feat: plot first guesst data
fedeoli Aug 30, 2022
9307b95
feat: add terminal cost with normalisation + Max Iter Time fix
fedeoli Aug 30, 2022
9a1920d
feat: HPPC modular (no more 6500s tops)
fedeoli Aug 31, 2022
102b295
chore: tweak params
fedeoli Aug 31, 2022
9347825
feat: improved barrier fcn + terminal norm as a choice
fedeoli Aug 31, 2022
bb1483c
fixed: correct input law
fedeoli Sep 6, 2022
550da8c
chore: tweak params
fedeoli Sep 6, 2022
3d11040
feat: hanlde Inf cost function
fedeoli Sep 6, 2022
af27d0b
feat: add delta error in initial coefficients
fedeoli Sep 6, 2022
d2970c3
chore: improve plot interp (first guess)
fedeoli Sep 6, 2022
aa2e8f4
test: adaptive control - offline model implementation
fedeoli Sep 7, 2022
6e2a3a5
feat: handle NaN/Inf cost function
fedeoli Sep 7, 2022
6bed3b6
chore: quick
fedeoli Sep 14, 2022
62c9729
fix: adapt to realdata
fedeoli Sep 14, 2022
1208b38
feat: generate measure and simulation with realdata (no synthetic)
fedeoli Sep 14, 2022
80ee71a
chore: add comment on time selection
fedeoli Sep 14, 2022
9f30b24
chore: edit .gitignore
fedeoli Sep 16, 2022
b01a334
data: add last data from tushar
fedeoli Sep 30, 2022
4875338
chore: change params and move optimise flag
fedeoli Sep 30, 2022
126cbc9
chore: move docs
fedeoli Sep 30, 2022
8da590e
feat: SIMULINK model and matlab integration
fedeoli Sep 30, 2022
aedd6e9
feat: MultiMHE
fedeoli Sep 30, 2022
ce7e64e
chore: test simulink wrappers + realdata sim
fedeoli Sep 30, 2022
734c7e8
chore: set params
fedeoli Sep 30, 2022
9073a44
fix: single parameters init
fedeoli Sep 30, 2022
0bd9fbd
chore: Ts and Tend only in simulation_
fedeoli Sep 30, 2022
87fa8a5
feat: add input scaling in params
fedeoli Oct 4, 2022
c093972
feat: add model inconsistemcy for test
fedeoli Oct 4, 2022
29e3bad
fix: first guess - add precision
fedeoli Oct 4, 2022
5d6a210
feat: add better derivative filter (2nd order)
fedeoli Oct 4, 2022
b977850
feat: add constrained simplex
fedeoli Oct 4, 2022
dd15885
fix: separate obs (first guess) from obs_fast
fedeoli Oct 4, 2022
bcaf3a9
chore: plots
fedeoli Oct 4, 2022
702b588
chore: set params
fedeoli Oct 4, 2022
0760f3b
feat: add fminsearch bound
fedeoli Oct 12, 2022
a89966d
chore: update obsopt
fedeoli Oct 12, 2022
9f39eaa
chore: euler integration
fedeoli Oct 12, 2022
f5e35b7
feat: annihilator (Tenni)
fedeoli Oct 12, 2022
7d15309
feat: Zaccarian allocation
fedeoli Oct 12, 2022
9f921f2
chore: gitignore
fedeoli Oct 12, 2022
311e859
data: results
alessandrotenaglia Oct 19, 2022
740d700
chore: add subplot
alessandrotenaglia Oct 19, 2022
5e9b087
feat: thinkpad changes
alessandrotenaglia Oct 25, 2022
ddd321c
feat: lsim integration (only LTI)
fedeoli Oct 25, 2022
f654476
feat: simulation file only for LSIM (some time saved)
fedeoli Oct 25, 2022
40d9d43
fix: add lsim also in propagation after optimization
fedeoli Oct 25, 2022
f1a1d8b
fix: patternsearch setup
fedeoli Oct 28, 2022
6ae4230
fix: fminsearchcon error
fedeoli Oct 29, 2022
50571e4
update: model euler compliant with Lsim
fedeoli Nov 2, 2022
d45e681
feat: nnl cost function (ddz)
fedeoli Nov 2, 2022
531c47e
fix: ScaleMesh flag in patternsearch
fedeoli Nov 2, 2022
ae20c1e
feat: tenny
alessandrotenaglia Nov 4, 2022
cbd4ed9
feat: tenny
alessandrotenaglia Nov 4, 2022
6a95eca
fix: input dimension in J integration
fedeoli Nov 4, 2022
75fa149
fix: input dimensions
fedeoli Nov 4, 2022
874f72a
merge: preparation of obsopt and plot for merging
fedeoli Nov 16, 2022
64569a1
merge: after IFAC merge with control branch
fedeoli Nov 16, 2022
ee2b4ce
mearge: files different from obsopt
fedeoli Nov 16, 2022
d500bf9
merge: files different from obsopt
fedeoli Nov 16, 2022
195b424
merge: obsopt
fedeoli Nov 16, 2022
2f9656d
Merge branch 'battery' into dev
fedeoli Nov 16, 2022
1a92405
merge: check both allocation and battery sim
fedeoli Nov 16, 2022
8d8add2
chore: test battery sim
fedeoli Nov 16, 2022
2d4cc06
chore: remove all mat file
alessandrotenaglia Nov 16, 2022
e1bb42d
Merge branch 'dev' of github.com:IntelligentSystemsLabUTV/obsopt_pkg …
alessandrotenaglia Nov 16, 2022
148f2b7
merge: fix before merge with dev (VDP oscillator)
fedeoli Nov 17, 2022
33731a3
merge: fix conflicts
fedeoli Nov 17, 2022
a344c64
chore: clean up stuff
fedeoli Nov 17, 2022
bf2a4f5
Merge branch 'dev' of github.com:IntelligentSystemsLabUTV/obsopt_pkg …
fedeoli Nov 17, 2022
91ec76f
test: battery test on fminsearchcon
fedeoli Nov 17, 2022
c06288c
chore: params and weights
fedeoli Nov 25, 2022
b3b3ce7
feat: test file on wavelets
fedeoli Nov 28, 2022
6b8816a
feat: test obsopt on wavelets
fedeoli Nov 28, 2022
3dd030b
feat: wavelets on VDP
fedeoli Nov 29, 2022
5b7eb29
chore: params
fedeoli Nov 29, 2022
4dee3ad
feat: rover model first draft
fedeoli Nov 30, 2022
9209611
adding uwb folder
smatto72 Nov 30, 2022
45ecd79
feat: rover params
fedeoli Nov 30, 2022
0c2dc1b
Merge branch 'hyb' of github.com:IntelligentSystemsLabUTV/obsopt_pkg …
fedeoli Nov 30, 2022
4c07666
added USAGE and epsilon
smatto72 Nov 30, 2022
fdc3aa7
Merge branch 'hyb' of github.com:IntelligentSystemsLabUTV/obsopt_pkg …
smatto72 Nov 30, 2022
cf9b146
feat: update rover model
fedeoli Nov 30, 2022
a185f04
Merge branch 'hyb' of github.com:IntelligentSystemsLabUTV/obsopt_pkg …
fedeoli Nov 30, 2022
a33551f
chore: tidy up various folder
fedeoli Nov 30, 2022
6e5dc3d
display parameter
smatto72 Nov 30, 2022
1d78444
Merge branch 'hyb' of github.com:IntelligentSystemsLabUTV/obsopt_pkg …
smatto72 Nov 30, 2022
9886577
no initial condition error
smatto72 Nov 30, 2022
0c109be
feat: quicker sym gradient and noise on dist
fedeoli Dec 2, 2022
d51d528
feat: noise on IMU meas
fedeoli Dec 2, 2022
e1a4aca
fix: noise with bias
smatto72 Dec 2, 2022
2ca41f5
chore: params.noise_mat
fedeoli Dec 2, 2022
5f17a6f
basic observer dynamics
smatto72 Dec 5, 2022
b3a6de6
feat: HGO + code redesign
fedeoli Dec 16, 2022
ac23166
feat: Xmas edit (opt setup)
fedeoli Dec 27, 2022
af87a78
feat: normalise with al trajectories
fedeoli Jan 11, 2023
424a036
feat: best improvements in the J for multistart
fedeoli Jan 11, 2023
2506846
chore: params
fedeoli Jan 11, 2023
f6dd1a0
feat: constant output in UWB meas
fedeoli Jan 17, 2023
5863483
feat: vectorize - still working
fedeoli Jan 20, 2023
1374d63
fix: recover after server breakdown
fedeoli Jan 20, 2023
45d69de
feat: EKF on 6D object
fedeoli Feb 1, 2023
054eade
chore: move doc
fedeoli Feb 1, 2023
4f72446
Merge branch 'hyb' of github.com:IntelligentSystemsLabUTV/obsopt_pkg …
fedeoli Feb 1, 2023
c0ffbb8
feat: working EKF on Armesto - no bias
fedeoli Feb 2, 2023
fb60dd3
feat: EKF on 2D rover
fedeoli Feb 4, 2023
92804fb
feat: EKF + VolterraLotka model
fedeoli Feb 6, 2023
a1a3f0e
fix: check the code after a while - battery project
fedeoli Feb 6, 2023
588d371
test: same measure file for both EKF and Hyb
fedeoli Feb 7, 2023
d66150b
fix: measure function
fedeoli Feb 7, 2023
6858dff
test: periodic sampling + gamma correction jump map
fedeoli Feb 7, 2023
c2b8b6e
test: adaptive sampling
fedeoli Feb 8, 2023
aeefa76
feat: adaptive sampling working
fedeoli Feb 8, 2023
6696b85
chore: no constraint on gamma (nonlinear filter)
fedeoli Feb 9, 2023
c852d93
chore: good params results
fedeoli Feb 9, 2023
6aa835c
chore: adaptive sampling params init in obsopt
fedeoli Feb 9, 2023
496ec53
Merge branch 'hyb' of github.com:IntelligentSystemsLabUTV/obsopt_pkg …
fedeoli Feb 9, 2023
5b98590
feat: 3D version of EKF and hyb
fedeoli Feb 10, 2023
6727270
chore: nonlinconstraints
fedeoli Feb 10, 2023
6954d5f
feat: hills on z
fedeoli Feb 10, 2023
571d9fd
Merge branch 'hyb' of github.com:IntelligentSystemsLabUTV/obsopt_pkg …
fedeoli Feb 10, 2023
0a78bb9
fix: bandpass filter on hyb
fedeoli Feb 13, 2023
c9982ec
Merge branch 'hyb' of github.com:IntelligentSystemsLabUTV/obsopt_pkg …
fedeoli Feb 13, 2023
2b33f9d
fix: PD controller + correct Jdist
fedeoli Feb 13, 2023
058b25e
fix: error derivative
fedeoli Feb 13, 2023
efdbfa2
fix: C params constrained
fedeoli Feb 13, 2023
e9f902c
fix: bandpass filter hyb
fedeoli Feb 13, 2023
59b5a20
fix: WaitAllBuffer 2 test
fedeoli Feb 13, 2023
661bf0f
feat: WaitAllBuffer 2 update (full traj target)
fedeoli Feb 13, 2023
4807be2
test: bandpass testing 3D
fedeoli Feb 14, 2023
77116fd
test: leaning for realdata
fedeoli Feb 14, 2023
60085e0
fix: simulink
fedeoli Feb 22, 2023
6e2e2db
chore: sim battery fixing
fedeoli Feb 25, 2023
cca2b34
chore: diverged branch
fedeoli Feb 25, 2023
3ce3b94
feat: realdata with separate simulink
fedeoli Feb 27, 2023
5303b65
chore: cleanup
fedeoli Feb 27, 2023
62e1aba
update gitignore
fedeoli Sep 8, 2023
6bb0669
Thesis: sim with Nts
fedeoli Sep 14, 2023
f136d4e
test: battery fminunc
fedeoli Sep 15, 2023
c91beb6
Thesis: test on fminsearchcon
fedeoli Sep 17, 2023
5831c06
Thesis: testing
fedeoli Sep 21, 2023
d343d4b
Thesis: chore simulink_realdata
fedeoli Sep 21, 2023
81cb608
Thesis: PE feat on obsotp
fedeoli Sep 25, 2023
80993f3
CALCE dataset trial
tkdesai13 May 7, 2024
74f6444
Initial parameter values and plot modification
tkdesai13 May 18, 2024
6b90e7a
dev: parallel MHE structure for calce
fedeoli May 27, 2024
af56e99
dev: EKF_rover
fedeoli May 27, 2024
ce73053
EKF implemented and parameters updated
tkdesai13 Aug 8, 2024
98a5c92
Data added
tkdesai13 Aug 8, 2024
5a8aaaa
updated params
tkdesai13 Aug 8, 2024
084ddeb
extra plots file
tkdesai13 Aug 8, 2024
9786e19
dev: sensitivity analysis
fedeoli Sep 25, 2024
23b1bbe
chore: test and clean parallel_calce
fedeoli Sep 26, 2024
e982beb
chore: update adaptive sampling
fedeoli Sep 26, 2024
da1cfc8
chore: update adaptive sampling
fedeoli Sep 26, 2024
b8b5dcf
chore: update adaptive sampling
fedeoli Sep 26, 2024
3e644ef
chore: update adaptive sampling
fedeoli Sep 26, 2024
4cb8959
chore: update adaptive sampling
fedeoli Sep 26, 2024
40d0787
dev: update adaptive sampling
fedeoli Oct 4, 2024
c8d7a1f
dev: tests on CALCE params
fedeoli Oct 4, 2024
421628a
chore: fix merge
fedeoli Oct 4, 2024
da0f01d
chore: setup simulations
fedeoli Oct 4, 2024
84ccf2e
dev: tests on CALCE params
fedeoli Oct 4, 2024
a9089f4
BJDST data added
tkdesai13 Oct 6, 2024
4fe9f65
Create BJDST
tkdesai13 Oct 6, 2024
ab9e1a2
Delete data/CALCE/INR_18650/BJDST
tkdesai13 Oct 6, 2024
60ef317
Create 11_11_2015_SP20-2_US06_50SOC.xlsx
tkdesai13 Oct 6, 2024
86f02ee
Add files via upload
tkdesai13 Oct 6, 2024
9b6d3f1
Create 11_09_2015_SP20-2_FUDS_50SOC.xlsx
tkdesai13 Oct 6, 2024
d11b3f8
Add files via upload
tkdesai13 Oct 6, 2024
b89758f
Create 11_09_2015_SP20-2_FUDS_50SOC.xlsx
tkdesai13 Oct 6, 2024
55a00cc
Add files via upload
tkdesai13 Oct 6, 2024
359f232
Delete data/CALCE/INR_18650/BJDST directory
tkdesai13 Oct 6, 2024
ba9c3b9
Create 11_13_2015_SP20-2_BJDST_50SOC.xlsx
tkdesai13 Oct 6, 2024
6e50a0e
Add files via upload
tkdesai13 Oct 6, 2024
4082005
Merge branch 'battery' of https://github.com/IntelligentSystemsLabUTV…
tkdesai13 Oct 6, 2024
2f8d8d4
data loading updated
tkdesai13 Oct 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
29 changes: 21 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
# gitignore file
*
fig/
Latex/
results/
workspace/
config/
x86/
doc/
slprj/
jackal/

# exceptions (dir)
!data/
!doc/
!Lib/
# files
*.asv
*.save
.gitignore
*.autosave
*.original
*.slxc
*.zip
*.prj
*.tmp

#exceptions (files)
!COPYING
!README.md
# exceptions
!results/simulations/battery/report
877 changes: 877 additions & 0 deletions BaseZoom.m

Large diffs are not rendered by default.

Binary file added Lib/.DS_Store
Binary file not shown.
105 changes: 85 additions & 20 deletions Lib/control/control.m
Original file line number Diff line number Diff line change
@@ -1,26 +1,91 @@
%% CONTROL
% file: control.m
% author: Federico Oliva
% date: 10/01/2022
% description: this function implements the control law
% INPUT:
% t: time instant
% drive: error variable
% params: structure with all the necessary parameters
% OUTPUT:
% u: control variable
function u = control(t,drive,params)

% check if the input is enabled
function u = control(t,drive,params,obs)

% init input
u = zeros(params.dim_input,length(t));

if params.input_enable

% traj
traj = obs.init.traj;

% PWM 3 levels

% 2nd order system
% u(1,:) = -2*params.rhox(1)*params.wnx(obs.init.traj)*drive(2) -params.wnx(obs.init.traj)^2*drive(1);
% u(2,:) = -2*params.rhoy(1)*params.wny(obs.init.traj)*drive(6) -params.wny(obs.init.traj)^2*drive(5);

% sum of sines (position)
% target(1,:) = exp(-params.rhox.*t).*(params.Ax(1)*sin(params.wnx(1).*t + params.phi(1)) + params.Ax(2)*sin(params.wnx(2).*t + params.phi(1)));
% target(2,:) = exp(-params.rhoy.*t).*(params.Ay(1)*sin(params.wny(1).*t + params.phi(2)) + params.Ay(2)*sin(params.wny(2).*t + params.phi(2)));
% u(1,:) = params.Ku(1)*(target(1,:)-drive(1,:));
% u(2,:) = params.Ku(2)*(target(2,:)-drive(6,:));

% !REMARK!
% simply uncomment or add the law you need, according to params

%%%% control law - battery %%%%
u = [sin(t); zeros(size(t))];
% patrolling on x-y
T = t(1);
vx = 0;
vy = 0;
if mod(T,params.freq_u) < 0.25*params.freq_u
vx = params.amp_ux;
elseif mod(T,params.freq_u) < 0.5*params.freq_u
vy = params.amp_uy;
elseif mod(T,params.freq_u) < 0.75*params.freq_u
vx = -params.amp_ux;
else
vy = -params.amp_uy;
end
u(1,:) = params.Ku(1)*(vx-drive(params.pos_v(1)));
u(2,:) = params.Ku(2)*(vy-drive(params.pos_v(2)));

else
u = zeros(params.dim_input,1);
% compute the time index
for i=1:length(t)
tdiff = obs.setup.time-t(i);
pos(i) = find(abs(tdiff) == min(abs(tdiff)),1,'first');
pos(i) = max(1,pos(i));
end
ind = pos(1);

% hills on z
p_now = drive(params.pos_p(1:2));
p_est = zeros(1,2);
p_grid = [params.X_gauss(1,:); params.Y_gauss(:,1)'];
for i=1:2
pdiff = p_grid(i,:)-p_now(i);
p_est(i) = find(abs(pdiff) == min(abs(pdiff)),1,'first');
end
z_des = params.G_gauss(p_est(2),p_est(1));
z_now = drive(params.pos_p(3));
zdot_now = drive(params.pos_v(3));

obs.init.params.z_des_story(:,ind) = z_des;
obs.init.params.z_now_story(:,ind) = z_now;

% error
e = (z_des-z_now);
obs.init.params.err(traj).val(:,ind) = e;

% derivative
[edot, obs.init.params.err_der_buffer, obs.init.params.err_der_counter(traj).val] = PseudoDer(params.Ts,...
obs.init.params.err(traj).val(:,max(1,ind-1)),params.wlen_err,...
params.buflen_err,params.dim_err,0,0,obs,obs.init.params.err_der_buffer,obs.init.params.err_der_counter(traj).val);
obs.init.params.err_der(traj).val(:,ind) = edot;

% integral
obs.init.params.err_int(traj).val(:,ind) = obs.init.params.err_int(traj).val(:,max(1,ind-1)) + e*params.Ts;
eint = obs.init.params.err_int(traj).val(:,ind);

% control
u(3,:) = -params.Kz(1)*-e -params.Kz(2)*zdot_now + params.Kff*[e edot eint]';

% ony for testing
u(4,:) = z_des;

% Volterra Lotka
% u(1,:) = params.K1*(drive(1)-params.target(1));
% u(2,:) = params.K2*(drive(1)-params.target(1));
% % sat
% u(1,:) = min(max(-params.umax,u(1,:)),params.umax);
% u(2,:) = min(max(-params.umax,u(2,:)),params.umax);
end

end
28 changes: 28 additions & 0 deletions Lib/control/control_TCV.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
%% CONTROL
% file: control.m
% author: Federico Oliva
% date: 10/01/2022
% description: this function implements the control law
% INPUT:
% t: time instant
% drive: error variable
% params: structure with all the necessary parameters
% OUTPUT:
% u: control variable
function u = control_TCV(t,drive,params,obs)

% check if the input is enabled
if params.input_enable

% !REMARK!
% simply uncomment or add the law you need, according to params

% for i=1:params.m
% tmpstr = ['u(', num2str(i) ',:) = ', num2str(i), '*sin(', num2str(i), '*t);'];
% eval(tmpstr);
% end
u(:,1) = ones(1,length(t));
else
u = zeros(params.dim_input,1);
end
end
33 changes: 33 additions & 0 deletions Lib/control/control_battery.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
%% CONTROL
% file: control.m
% author: Federico Oliva
% date: 10/01/2022
% description: this function implements the control law
% INPUT:
% t: time instant
% drive: error variable
% params: structure with all the necessary parameters
% OUTPUT:
% u: control variable
function u = control_battery(t,drive,params,obs)

% init input
u = zeros(1,length(t));
% params.dim_input

% compute the time index
for i=1:length(t)
tdiff = obs.setup.time-t(i);
pos(i) = find(abs(tdiff) == min(abs(tdiff)),1,'first');
pos(i) = max(1,pos(i));
end

% check if the input is enabled
if params.input_enable

% from input data
u = params.u_sim(:,pos);


end
end
78 changes: 78 additions & 0 deletions Lib/control/drive.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
%% control drive function (observer or control design)
function drive_out = drive(varargin)

obj = varargin{1};

% init drive
drive_out = [];

% x - varargin
x_star = varargin{2}(1:obj.init.params.dim_state,:);
x = varargin{3}(1:obj.init.params.dim_state,:);


% just x
% drive_out = [drive_out; x(obj.setup.plot_vars)];
drive_out = [drive_out; x];

% get y
if 1
y_meas = varargin{4}(:,:,end);
pos = varargin{5};

y = obj.setup.measure(x,obj.init.params,pos,obj.init.input_story(obj.init.traj).val(:,max(1,pos-1)));

%%% compute filters %%%
y_filt = [];
y_filt_meas = [];
if 1 && obj.setup.Nfilt > 0

% how long iterate
tspan_pos = [max(1,pos-1), pos];

% update buffer - only first (RK4)
obj.init.Y_buffer_control(obj.init.traj).val(1,:,pos) = y;

try
ok = 1;
[Y_filt, x_filter] = obj.measure_filter(obj.init.Y_buffer_control(obj.init.traj).val,tspan_pos,obj.init.X_filter_buffer_control(obj.init.traj));
catch
ok=0;
end

if ok
for filt=1:obj.setup.Nfilt
for dim=1:obj.setup.dim_out
% Lsim
y_filt(filt,dim) = Y_filt{filt,dim}.val(end);
obj.init.X_filter_buffer_control(obj.init.traj).val{filt,dim}(:,unique(tspan_pos)) = x_filter{filt,dim}.val;

end

% update buffer - only first (RK4)
obj.init.Y_buffer_control(obj.init.traj).val(1+filt,:,pos) = y_filt(filt,:);
end

y_filt = reshape(y_filt,size(y));
y_pad = zeros(size(y).*[2,1]);
y_pad(1:2:end) = y;
y_pad(2:2:end) = y_filt;
y = y_pad;

else
% y_meas = reshape(y_meas,size(y_meas,1)*size(y_meas,2));
y = y_meas;
end
end

y_meas = reshape(y_meas,size(y));
tmp = y_meas-y;
tmp = reshape(tmp,length(y),1);

drive_out = [drive_out; tmp];
end

% save drive story
obj.init.drive_out(obj.init.traj).val(:,pos) = drive_out;

end
18 changes: 18 additions & 0 deletions Lib/control/generate_HCCP.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
%%
function [HCCP, tspan, tspan_pos] = generate_HCCP(Ts,Cnh)

% time span
tspan = 0:Ts:60;
tspan_pos = 1:length(tspan);

% intervals
tstops = [tspan_pos(1) find(tspan==20) find(tspan==50) tspan_pos(end)];
tamplitudes = [1*Cnh 0 -0.5*Cnh];

% generate wave
HCCP = zeros(size(tspan));
for i=1:length(tamplitudes)
HCCP(tstops(i):tstops(i+1)) = tamplitudes(i);
end

end
18 changes: 8 additions & 10 deletions Lib/integration/odeDD.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
function out = odeDD(varargin)

% init params
nargin = length(varargin);

% handle function to the dynamics
ode = varargin{1};
Expand All @@ -21,35 +22,32 @@
% y0: initial condition
x0 = varargin{3};

% U: input
U = varargin{4};

% TF: transfer function
TF = varargin{5};
% integrations options
if nargin > 3
opts = varargin{4};
end

% number of state's components
N = length(x0);

% numer of time steps
M = length(tspan);
M = length(tspan);

% initial time instant
t0 = tspan(1);

% Matrices allocation
X = zeros(N,M);
X(:,1) = x0;
Y(:,1) = 0*U(:,1);

% integration
for i = 1:M-1

% DD step
[Y(:,i+1),X(:,i+1)] = feval(ode,tspan(i),X(:,i),U,TF.A, TF.B, TF.C, TF.D);
X(:,i+1) = feval(ode,tspan(i),X(:,i));

end

% store
out.x = X;
out.y = Y(:,2:end);
out.y = X;
end
Loading