0

I am building a robot simulation which solves 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 for, it works fine! However, when I use a while loop to keep the function solving as I input the speed (through an edit text in my 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 is the while loop the issue 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 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]
2
  • Are you sure check is a boolean scalar?
    – qbzenker
    Commented Apr 18, 2017 at 16:13
  • yeah its a check box either a true or false Commented Apr 18, 2017 at 17:52

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.