clear all; close all; ts=0.001; for k=1:1:2001 xd(k)=cos((k-1)pits); yd(k)=sin((k-1)pits); thd(k)=tspi(k-1)+pi/2; end for k=1:1:2001 u1(k)=0;u2(k)=0; e1(k)=0;e2(k)=0; e3(k)=0; end y0=[1;0;pi/2]; M=20; for i=0:1:M i pause(0.001); for k=1:1:2001 if k==1 q=y0; end xp(k)=q(1); yp(k)=q(2); th(k)=q(3); qd=[xd(k);yd(k);thd(k)]; ce1(k)=qd(1)-q(1); ce2(k)=qd(2)-q(2); ce3(k)=qd(3)-q(3); u=[u1(k);u2(k)]; B=ts*[cos(q(3)) 0 sin(q(3)) 0 0 1]; L1=10*[cos(q(3)) sin(q(3)) 0; 0 0 1]; L2=L1; cond=norm(eye(2)-L1B); U=u+L1+L2*[ce1(k);ce2(k);ce3(k)]; u1(k)=U(1); u2(k)=U(2); u=[u1(k);u2(k)]; q=q+Bu; e1(k)=cos(ktspi)-q(1); e2(k)=sin(ktspi)-q(2); e3(k)=tskpi+pi/2-q(3); end figure(1); hold on; plot(xd,yd,'r',xp,yp,'b'); xlabel('xd xp');ylabel('yd,yp'); j=i+1; times(j)=j-1; e1i(j)=max(abs(ce1)); e2i(j)=max(abs(ce2)); e3i(j)=max(abs(ce3)); end figure(2); plot(xd,yd,'r',xp,yp,'b'); xlabel('xd xp');ylabel('yd,yp'); figure(3); plot(times,e1i,'-r',times,e2i,'o-b',times,e3i,'o-k'); title('Change of maximum absolute value of e1,e2 and angle with times i'); xlabel('times');ylabel('e1,e2 and angle');
时间: 2023-12-10 16:04:35 浏览: 112
操作列表-java开发基础(基础语法+面向对象基础+集合基础+常用api)
这段代码存在一些语法错误,可能是因为复制时出现了一些问题。我对代码进行了一些修改,如下所示。你可以试着运行一下,看看是否可以正常工作。
```
clear all;
close all;
ts = 0.001;
pits = pi/180;
tspi = (1:2001) * ts;
for k = 1:1:2001
xd(k) = cos((k-1) * pits);
yd(k) = sin((k-1) * pits);
thd(k) = tspi(k-1) + pi/2;
end
for k = 1:1:2001
u1(k) = 0;
u2(k) = 0;
e1(k) = 0;
e2(k) = 0;
e3(k) = 0;
end
y0 = [1; 0; pi/2];
M = 20;
for i = 0:1:M
pause(0.001);
for k = 1:1:2001
if k == 1
q = y0;
end
xp(k) = q(1);
yp(k) = q(2);
th(k) = q(3);
qd = [xd(k); yd(k); thd(k)];
ce1(k) = qd(1) - q(1);
ce2(k) = qd(2) - q(2);
ce3(k) = qd(3) - q(3);
u = [u1(k); u2(k)];
B = ts * [cos(q(3)), 0; sin(q(3)), 0; sin(q(3)), 0; 0, 0; 0, 0; 1, 0];
L1 = 10 * [cos(q(3)), sin(q(3)), 0; 0, 0, 1];
L2 = L1;
cond = norm(eye(2) - L1 * B);
U = u + L1 * [e1(k); e2(k); e3(k)] + L2 * [ce1(k); ce2(k); ce3(k)];
u1(k) = U(1);
u2(k) = U(2);
u = [u1(k); u2(k)];
q = q + B * u;
e1(k) = cos(k * tspi) - q(1);
e2(k) = sin(k * tspi) - q(2);
e3(k) = ts * k * pi + pi/2 - q(3);
end
figure(1);
hold on;
plot(xd, yd, 'r', xp, yp, 'b');
xlabel('xd xp');
ylabel('yd,yp');
j = i + 1;
times(j) = j - 1;
e1i(j) = max(abs(ce1));
e2i(j) = max(abs(ce2));
e3i(j) = max(abs(ce3));
end
figure(2);
plot(xd, yd, 'r', xp, yp, 'b');
xlabel('xd xp');
ylabel('yd,yp');
figure(3);
plot(times, e1i, '-r', times, e2i, 'o-b', times, e3i, 'o-k');
title('Change of maximum absolute value of e1,e2 and angle with times i');
xlabel('times');
ylabel('e1,e2 and angle');
```
这里还存在一些问题,例如,第30行的 `ktspi` 变量没有定义,需要根据具体的需求进行修改。同时,该代码中存在一些算法上的问题,需要进行进一步的检查和修改才能保证正确性。
阅读全文