在附图中我有两个静态物体,起点和目标点,机器人从起点到目标。
然而,当我为另一个移动物体添加此代码时,模拟结果显示连续闪光而没有机器人移动: 添加移动对象的代码是;
hold on
origin_x = [9.5 9.5 11.5 11.5 ]; %// initial coordinates of vertices
origin_y = [12.6 14.6 14.6 12.6];
destination_x = origin_x + 3; %// final coordinates of vertices
destination_y = origin_y + 2;
n_steps = 100; %// number of "frames"
t_pause = .03; %// seconds between frames
h = fill(origin_x, origin_y, 'b'); %// create object at initial position
for t = linspace(0,1,n_steps)
x = (1-t)*origin_x + t*destination_x; %// update x
y = (1-t)*origin_y + t*destination_y; %// update y
set(h, 'Vertices', [x(:) y(:)]) %// change object's position
pause(t_pause) %// a pause is needed to make movement slower
drawnow %// probably not needed after pause. Just in case
end