2024-08-05 18:18:22 +02:00
|
|
|
function [ref, dref] = set_trajectory(i, sim_data)
|
2024-07-12 19:13:29 +02:00
|
|
|
syms s
|
|
|
|
|
|
|
|
switch i
|
|
|
|
case 0
|
2024-08-05 18:18:22 +02:00
|
|
|
% a straigth line trajectory at v=0.2m/s
|
|
|
|
xref = 0.2*s;
|
2024-07-12 19:13:29 +02:00
|
|
|
yref = 0;
|
|
|
|
case 1
|
2024-08-05 18:18:22 +02:00
|
|
|
% a straigth line trajectory at v=0.8m/s
|
|
|
|
xref = 0.8*s;
|
2024-07-12 19:13:29 +02:00
|
|
|
yref = 0;
|
|
|
|
case 2
|
2024-07-13 12:15:26 +02:00
|
|
|
% straight line, with initial error
|
|
|
|
xref = 5 + 0.5*s;
|
|
|
|
yref = 0;
|
|
|
|
case 3
|
|
|
|
% straight line, initial error, faster
|
2024-08-05 18:18:22 +02:00
|
|
|
xref = 5 + 0.8*s;
|
2024-07-13 12:15:26 +02:00
|
|
|
yref = 0;
|
|
|
|
case 4
|
2024-08-05 18:18:22 +02:00
|
|
|
% circle
|
|
|
|
xref = cos(0.25*s);
|
|
|
|
yref = sin(0.25*s);
|
2024-07-13 12:15:26 +02:00
|
|
|
case 5
|
2024-08-05 18:18:22 +02:00
|
|
|
% bigger circle, same velocity
|
|
|
|
xref = 2.5*cos(s);
|
|
|
|
yref = 2.5*sin(s);
|
2024-07-13 12:15:26 +02:00
|
|
|
case 6
|
2024-08-05 18:18:22 +02:00
|
|
|
% sin
|
|
|
|
xref = sim_data.speed*s;
|
|
|
|
yref = 0.25*sin(2*pi*sim_data.frequency*s);
|
2024-07-27 14:51:23 +02:00
|
|
|
%xref = 0.6*s;
|
|
|
|
%yref = cos(0.6*s);
|
2024-07-23 18:07:50 +02:00
|
|
|
case 7
|
2024-08-05 18:18:22 +02:00
|
|
|
% slightly bigger, slower circle
|
|
|
|
xref = 2.55*cos(0.05*s);
|
|
|
|
yref = 2.55*sin(0.05*s);
|
2024-07-27 14:51:23 +02:00
|
|
|
case 8
|
2024-08-05 18:18:22 +02:00
|
|
|
% straightline, on y=1
|
2024-07-27 14:51:23 +02:00
|
|
|
xref = 0.5*s;
|
|
|
|
yref = 1;
|
|
|
|
case 9
|
2024-08-05 18:18:22 +02:00
|
|
|
% strange sine
|
2024-07-27 14:51:23 +02:00
|
|
|
xref = 0.9*s;
|
|
|
|
yref = 0.5*cos(0.65*s);
|
|
|
|
case 10
|
2024-08-05 18:18:22 +02:00
|
|
|
% figure8
|
|
|
|
xref = cos(sim_data.xrep*sim_data.speed*s);
|
|
|
|
yref = sin(sim_data.yrep*sim_data.speed*s);
|
2024-07-28 12:58:36 +02:00
|
|
|
case 11
|
2024-07-29 15:22:49 +02:00
|
|
|
% cardioid
|
2024-08-05 18:18:22 +02:00
|
|
|
a = sim_data.a;
|
|
|
|
b = sim_data.b;
|
|
|
|
spd = sim_data.speed;
|
|
|
|
xref = 2*a*(1-cos(spd*s))*sin(spd*s);
|
2024-07-29 15:22:49 +02:00
|
|
|
%xref = 4*a*(0.2-cos(0.5*s))*sin(0.5*s);
|
2024-08-05 18:18:22 +02:00
|
|
|
yref = 2*b*(1-cos(spd*s))*cos(spd*s);
|
2024-07-29 15:22:49 +02:00
|
|
|
case 12
|
|
|
|
% square! in parametic form! https://math.stackexchange.com/questions/978486/parametric-form-of-square
|
2024-08-05 18:18:22 +02:00
|
|
|
speed = sim_data.speed;
|
|
|
|
%speed = 0.18;
|
|
|
|
%side = 1.5;
|
|
|
|
side = sim_data.side;
|
2024-07-29 15:22:49 +02:00
|
|
|
s_ = speed * s;
|
|
|
|
%xref = side * cos(s) / max(abs(cos(speed*s)), abs(sin(speed*s))) ;
|
|
|
|
%yref = side * sin(s) / max(abs(cos(speed*s)), abs(sin(speed+s))) ;
|
|
|
|
p = (sqrt(2) * (abs(sin(s_ + pi/4)) + abs(cos(s_ + pi/4))));
|
|
|
|
xref = side * cos(s_) / p;
|
|
|
|
yref = side * sin(s_) / p;
|
2024-08-05 18:18:22 +02:00
|
|
|
case 13
|
|
|
|
xref = -2*cos(sim_data.speed*s)+2;
|
|
|
|
yref = sim_data.speed*0.5*s^2;
|
|
|
|
case 14
|
|
|
|
maxx=sim_data.maxx;
|
|
|
|
xspeed=sim_data.xspeed;
|
|
|
|
stoptime = maxx/xspeed;
|
|
|
|
yspeed=sim_data.ydisplacement/stoptime;
|
|
|
|
tms = mod(s, stoptime);
|
|
|
|
|
|
|
|
xref = piecewise(s < stoptime, xspeed*tms, s >= stoptime, maxx-xspeed*tms);
|
|
|
|
yref=yspeed*s;
|
|
|
|
dxref = piecewise(s < stoptime, xspeed, s >= stoptime, -xspeed);
|
|
|
|
dyref=yspeed;
|
|
|
|
|
|
|
|
ref = [xref; yref];
|
|
|
|
dref = [dxref; dyref];
|
|
|
|
return
|
|
|
|
case 15
|
|
|
|
%st_ = sim_data.stoptime-s;
|
|
|
|
%ss = sim_data.speed*s;
|
|
|
|
%xref=ss*max(st_,0)/(st_+0.00001) + (sim_data.stoptime-ss)*max(-st_,0)/(-st_+0.00001)
|
|
|
|
%yref=0;
|
|
|
|
%vxref=s*max(st_,0)/(st_+0.00001) -s*max(-st_,0)/(-st_+0.00001)
|
|
|
|
%vyref=0;
|
|
|
|
%ref = [xref; yref];
|
|
|
|
%dref = [vxref; vyref];
|
|
|
|
%return
|
|
|
|
maxx=simdata.maxx;
|
|
|
|
xspeed=sim_data.xspeed;
|
|
|
|
yspeed=sim_data.yspeed;
|
|
|
|
stoptime = maxx/xspeed;
|
|
|
|
tms = mod(s, stoptime);
|
|
|
|
|
|
|
|
xref = piecewise(s < stoptime, xspeed*tms, s >= stoptime, maxx-xspeed*tms);
|
|
|
|
yref=yspeed*s;
|
|
|
|
dxref = piecewise(s < stoptime, xspeed, s >= stoptime, -xspeed);
|
|
|
|
dyref=yspeed;
|
|
|
|
|
|
|
|
ref = [xref; yref];
|
|
|
|
dref = [dxref; dyref];
|
|
|
|
return
|
|
|
|
case 16
|
|
|
|
%square 2
|
|
|
|
speed = sim_data.speed;
|
|
|
|
side = sim_data.side;
|
|
|
|
sidet = side / speed;
|
|
|
|
ms = mod(s, sidet);
|
|
|
|
tms = mod(s, 4*sidet);
|
|
|
|
xref = piecewise((0 <= s) & (tms < sidet), side , (tms >= sidet) & (tms < sidet*2), side-speed*ms, (tms >= sidet*2) & (tms < sidet*3), 0, (tms >= sidet*3) & (tms <= sidet*4), speed*ms);
|
|
|
|
yref = piecewise((0 <= s) & (tms < sidet), speed*ms, (tms >= sidet) & (tms < sidet*2), side, (tms >= sidet*2) & (tms < sidet*3), side-speed*ms, (tms >= sidet*3) & (tms <= sidet*4), 0);
|
|
|
|
dxref = piecewise((0 <= s) & (tms < sidet), 0 , (tms >= sidet) & (tms < sidet*2), -speed, (tms >= sidet*2) & (tms < sidet*3), 0, (tms >= sidet*3) & (tms <= sidet*4), speed);
|
|
|
|
dyref = piecewise((0 <= s) & (tms < sidet), speed, (tms >= sidet) & (tms < sidet*2), 0, (tms >= sidet*2) & (tms < sidet*3), -speed, (tms >= sidet*3) & (tms <= sidet*4), 0);
|
|
|
|
ref = [xref; yref];
|
|
|
|
dref = [dxref; dyref];
|
|
|
|
return
|
|
|
|
|
2024-07-12 19:13:29 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
ref = [xref; yref];
|
|
|
|
dref = diff(ref, s);
|
2024-08-05 18:18:22 +02:00
|
|
|
end
|