Plot one trajectory of a "mobile robot" following another

2 views (last 30 days)
I am trying to plot a trajectory for a mobile robot in matlab. So far I can make the "robot" navigate from one point to another, however, I was hoping I could get it to travel to one position and then to a second position within the same simulation. I realize I might need to duplicate some code, but is there something special I have to do to break up the time steps? The following is what I have so far but it is not working...
%%Simulation
% Time setup
T = 100; % Simulation time
dt = 1;
N = T/dt + 1;
for ii1 = 2:N/2
%%Cartesian state trajectory 1 here
xdot1(ii1) = cos(th1(ii1-1))*v1(ii1-1);
ydot1(ii1) = sin(th1(ii1-1))*v1(ii1-1);
thdot1(ii1) = w1(ii1-1);
...
for ii2 = 50:N
%%Cartesian state trajectory 2 here
xdot2(ii2) = cos(th2(ii2-1))*v2(ii2-1);
ydot2(ii2) = sin(th2(ii2-1))*v2(ii2-1);
thdot2(ii2) = w2(ii2-1);
...
plot(x2,y2,'b--')
hold on
plot(x2(ii2),y2(ii2),'r*')
hold off
xlim([-10,10]/2+3)
ylim([-10,10]/2)
xlabel(num2str(ii2*dt))
pause(dt*0.1)
end
plot(x1,y1,'b--')
hold on
plot(x1(ii1),y1(ii1),'r*')
hold off
xlim([-10,10]/2+3)
ylim([-10,10]/2)
xlabel(num2str(ii1*dt))
pause(dt*0.1)
end

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!