% Einsende_B_MES_dat.m
% Simulation Servoachse (x-und y-Achse)
clear all
% Modellparameter

m1=10;   % kg Masse y-Achse
m2=100; % Masse x+y-Achse
k=1e6;  % N/m Gesamtsteifigkeit
J1=0.0001;  % kgm2 Rotationsträgheit motorseitig
MR=0.1; % Nm Motorlagerreibmoment
FR=10;  % N Reibkraft der Schlittenführung
T=1e-5; % s Zeitkonstante
Mmax=5; % Max Motormoment
r=0.05; % m Radius Treibrollenritzel
deltaphi=6.28e-3;   % rad Auflösung Motormesssystem
g=9.81; % m/s² Erdbeschleunigung
i=5;

% Reglereinstellungen

Kpx=100;    % Lageregelverstärkung x-Achse
Kpy=100;    % Lageregelverstärkung y-Achse
Kpvx=150;   % Drehzahlregelverstärkung x-Achse
Kpvy=100;   % Drehzahlregelverstärkung y-Achse
Fv=0;   % Proportionalitätsfaktor Geschwindigkeitsvorsteuerung

% Führungsgrößen

vB=0.1; % m/s Vorschubgeschwindigkeit
Tsoll=[0 0.05/vB 0.1/vB 0.15/vB];   % s Zeitvektor für Repeating Sequenz
Xsoll=[0 0.01 0.01 0.02];   % m Sollposition x-Achse
Ysoll=[0 0 0.01 0.01];  % m Sollposition y-Achse
Vsoll=[0 vB vB vB]; % s Sollgeschwindigkeit

% Simulationszeit

Tsim=max(Tsoll);

% Simulationsparameter

simulation_opt=simset('MaxRows',10000,'Solver','ode5','FixedStep',1e-5);

% Simulationsaufruf

[x,y,t]=sim('Einsende_B_MES_mod',Tsim,simulation_opt);

% Darstellung

figure(1);
hold off;
plot(x2s,y2s,'r');
hold on;
plot(Xsoll,Ysoll,'k--');
grid;
title('Bahndarstellung');
xlabel('x in m');
ylabel('y in m');
figure(2);
hold off;
plot(Tsoll,Xsoll,'k--');
hold on;
plot(ts,x2s,'b');
grid;
title('Zeitverlauf der x-Achse');
xlabel('t in s');
ylabel('x in m');
figure(3);
hold off;
plot(Tsoll,Ysoll,'k--');
hold on;
plot(ts,y2s,'b');
grid;
title('Zeitverlauf der y-Achse');
xlabel('t in s');
ylabel('y in m');
