我正在建立一个机器人模拟,它解决了不同输入速度值下的微分方程,该函数使用[0 0 0]=[x y theta]
作为初始条件,然后每次迭代更新初始条件。
当我使用for循环输入迭代次数时,我希望求解方程式,它运行正常!但是,当我使用while循环来保持函数求解时,我输入速度(通过GUI中的编辑文本),我收到一条错误消息
KPATH返回长度为0的向量,但初始条件向量的长度为3。
函数如何返回零长度向量?或者在这种情况下,while循环是问题吗?
码
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global sld1
global sld2
check = get(handles.checkbox1,'Value');
initials = zeros(1,3); %start at origin
p = par();
tspan = [0 1];
while check == true
p.WL = sld1 ;p.WR = sld2;
sol= ode23(@Kpath, tspan, initials,[],p);
[t,s] = ode23(@Kpath, tspan, initials,[],p);
initials = deval(sol,2);
xlabel('x-position [m]');ylabel('y-position [m]');
title('robot path');
grid on
plot(s(:,1),s(:,2),'b','linewidth',1.5);
hold on
end
function p = par()
p.L = 0.12; %length [m]
p.r = 0.1; %radius of wheel [m]
function dt = Kpath(t,c,p)
x = c(1);y = c(2);th = c(3);
dx = (((p.r*p.WL)+(p.r*p.WR))/2) * cos(th);
dy = (((p.r*p.WL)+(p.r*p.WR))/2) * sin(th);
dth= ((p.r*p.WL)-(p.r*p.WR))/p.L;
dt = [dx;dy;dth]