Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Automatique
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
toc
Etudiants N7
Automatique
Commits
b147aa02
Commit
b147aa02
authored
2 years ago
by
Olivier Cots
Browse files
Options
Downloads
Patches
Plain Diff
Update simu_robot.m
parent
db55bb88
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tp/simu_robot_etu/Ressources/simu_robot.m
+60
-46
60 additions, 46 deletions
tp/simu_robot_etu/Ressources/simu_robot.m
with
60 additions
and
46 deletions
tp/simu_robot_etu/Ressources/simu_robot.m
+
60
−
46
View file @
b147aa02
...
@@ -26,24 +26,31 @@ else
...
@@ -26,24 +26,31 @@ else
options_sim
=
simset
();
options_sim
=
simset
();
end
;
end
;
affichage
(
fich
,
t0
,
xe
,
ue
,
x0
,
tf
,
K
,
options_sim
);
affichage
(
fich
,
t0
,
xe
,
ue
,
x0
,
tf
,
K
,
options_sim
);
simOut
=
sim
(
fich_simulink_etu
,[
t0
tf
],
options_sim
);
simOut
=
sim
(
fich_simulink_etu
,[
t0
tf
],
options_sim
);
%
eps0
=
1e-11
;
% pour la comparaison
% comparaison format long
% fich_mat = ['TP2_Etudiants/Resultats/' fich '.mat'];
% fich_mat = ['TP2_Etudiants/Resultats/' fich '.mat'];
fich_mat
=
[
'Ressources/'
fich
'.mat'
];
fich_mat
=
[
'Ressources/'
fich
'.mat'
];
load
(
fich_mat
,
'X_sol'
,
'U_sol'
);
load
(
fich_mat
,
'X_sol'
,
'U_sol'
);
result
=
comparaison
(
fich
,
simOut
.
X
,
X_sol
,
simOut
.
U
,
U_sol
);
result
=
comparaison
(
fich
,
simOut
.
X
,
X_sol
,
simOut
.
U
,
U_sol
,
eps0
);
% comparaison format short
if
fich
==
'cas1_2'
&
result
==
0
,
if
fich
==
'cas1_2'
&
result
==
0
,
% fich_mat = ['TP2_Etudiants/Resultats/' fich '.mat'];
% fich_mat = ['TP2_Etudiants/Resultats/' fich '.mat'];
fich_mat
=
[
'Ressources/'
fich
'_short.mat'
];
fich_mat
=
[
'Ressources/'
fich
'_short.mat'
];
disp
(
'K format short'
)
disp
(
'K format short'
)
load
(
fich_mat
,
'X_sol'
,
'U_sol'
);
load
(
fich_mat
,
'X_sol'
,
'U_sol'
);
result
=
comparaison
(
fich
,
simOut
.
X
,
X_sol
,
simOut
.
U
,
U_sol
);
result
=
comparaison
(
fich
,
simOut
.
X
,
X_sol
,
simOut
.
U
,
U_sol
,
eps0
);
print
(
fich
,
simOut
.
X
,
X_sol
,
simOut
.
U
,
U_sol
,
eps0
);
else
print
(
fich
,
simOut
.
X
,
X_sol
,
simOut
.
U
,
U_sol
,
eps0
);
end
;
end
;
%
%
% Fonctions
% Fonctions
function
affichage
(
fich
,
t0
,
xe
,
ue
,
x0
,
tf
,
K
,
options_sim
);
function
affichage
(
fich
,
t0
,
xe
,
ue
,
x0
,
tf
,
K
,
options_sim
);
...
@@ -59,52 +66,59 @@ function affichage(fich, t0, xe, ue, x0, tf, K, options_sim);
...
@@ -59,52 +66,59 @@ function affichage(fich, t0, xe, ue, x0, tf, K, options_sim);
disp
([
'pas = '
num2str
(
options_sim
.
FixedStep
)]);
disp
([
'pas = '
num2str
(
options_sim
.
FixedStep
)]);
end
end
function
result
=
comparaison
(
fich
,
X
,
X_sol
,
U
,
U_sol
)
function
result
=
comparaison
(
fich
,
X
,
X_sol
,
U
,
U_sol
,
eps0
)
result
=
0
;
result
=
0
;
if
size
(
X
.
Data
)
==
size
(
X_sol
.
Data
)
&
size
(
U
.
Data
)
==
size
(
U_sol
.
Data
),
eps0
=
1e-11
;
X_erreur
=
max
(
max
(
abs
(
X
.
Data
-
X_sol
.
Data
)));
if
size
(
X
.
Data
)
==
size
(
X_sol
.
Data
)
&
size
(
U
.
Data
)
==
size
(
U_sol
.
Data
),
U_erreur
=
max
(
max
(
abs
(
U
.
Data
-
U_sol
.
Data
)));
disp
(
'dimension ok'
)
if
(
X_erreur
<
eps0
)
&
(
U_erreur
<
eps0
),
X_erreur
=
max
(
max
(
abs
(
X
.
Data
-
X_sol
.
Data
)));
result
=
1
;
U_erreur
=
max
(
max
(
abs
(
U
.
Data
-
U_sol
.
Data
)));
end
disp
([
'||X.Data-X_sol.Data||_inf = '
num2str
(
X_erreur
)])
end
disp
([
'||U.Data-U_sol.Data||_inf = '
num2str
(
U_erreur
)])
if
(
X_erreur
<
eps0
)
&
(
U_erreur
<
eps0
),
disp
(
'Résultats ok'
)
result
=
1
;
else
disp
(
'Résultats faux'
);
end
else
disp
(
'erreur dimensions'
)
end
end
function
print
(
fich
,
X
,
X_sol
,
U
,
U_sol
,
eps0
)
figure
;
if
size
(
X
.
Data
)
==
size
(
X_sol
.
Data
)
&
size
(
U
.
Data
)
==
size
(
U_sol
.
Data
),
graphiques
(
X
,
U
)
disp
(
'dimension ok'
)
figure
(
'Name'
,[
fich
' Sol'
])
X_erreur
=
max
(
max
(
abs
(
X
.
Data
-
X_sol
.
Data
)));
graphiques
(
X_sol
,
U_sol
)
U_erreur
=
max
(
max
(
abs
(
U
.
Data
-
U_sol
.
Data
)));
disp
([
'||X.Data-X_sol.Data||_inf = '
num2str
(
X_erreur
)])
disp
([
'||U.Data-U_sol.Data||_inf = '
num2str
(
U_erreur
)])
if
(
X_erreur
<
eps0
)
&
(
U_erreur
<
eps0
),
disp
(
'Résultats ok'
)
else
disp
(
'Résultats faux'
);
end
else
disp
(
'erreur dimensions'
)
end
function
graphiques
(
x
,
u
)
figure
;
% Réalise les graphiques des simulations issues de simulink
graphiques
(
X
,
U
)
%
figure
(
'Name'
,[
fich
' Sol'
])
% parametres en entrée
graphiques
(
X_sol
,
U_sol
)
% --------------------
% t : temps
% real (N,1)
% x : état
% real (N,n)
% u : contrôle
% real (N,m)
subplot
(
2
,
1
,
1
)
function
graphiques
(
x
,
u
)
plot
(
x
.
Time
,
x
.
Data
)
% Réalise les graphiques des simulations issues de simulink
xlabel
(
't'
)
%
ylabel
(
'états'
);
% parametres en entrée
subplot
(
2
,
1
,
2
)
% --------------------
plot
(
u
.
Time
,
u
.
Data
)
% t : temps
xlabel
(
't'
)
% real (N,1)
ylabel
(
'contrôle'
)
% x : état
% real (N,n)
% u : contrôle
% real (N,m)
end
subplot
(
2
,
1
,
1
)
plot
(
x
.
Time
,
x
.
Data
)
xlabel
(
't'
)
ylabel
(
'états'
);
subplot
(
2
,
1
,
2
)
plot
(
u
.
Time
,
u
.
Data
)
xlabel
(
't'
)
ylabel
(
'contrôle'
)
end
end
end
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment