I am building a robot simulation by solving the differential equations at different input speed values, the function uses [0 0 0]=[x y theta] as initial conditions then updates the initial conditions every iteration. when i use a for loop to input the number of iterations i want the equation to be solved it works fine!, however when i use a while loop to keep the function solving as i input the speed (through a edit text in gui) i get an error message "KPATH returns a vector of length 0, but the length of initial conditions vector is 3." . How can function return a zero length vector ? or the while loop cannot be used in this case ?
%
**code 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 sld1global 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 for j = 1:length(s(:,1)) q = plot(s(j,1),s(j,2),'ro','MarkerSize',5,'linewidth',1.5); axis([-2.5 2.5 -2.5 2.5]);grid on; pause(0.01) delete(q) endendfunction 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]
Best Answer