Using MatLab show the implementation of Bug-1: Robot goes towards the goal until
ID: 2085674 • Letter: U
Question
Using MatLab show the implementation of Bug-1: Robot goes towards the goal until it hits an obstacle. When an obstacle is encountered, the robot encircles the obstacle and then goes to the point on the boundary of the obstacle which is nearest to the goal. The algorithm is terminated when the goal is reached.
obstacle1.txt:
1
4
-8.052000 -6.720000
4.576000 7.933333
1.408000 8.353333
-11.000000 -5.040000
3 1 2
3 0 1
obstacle2.txt:
3
12
-8.140000 7.980000
-11.000000 6.953333
-12.320000 5.273333
-12.188000 3.406667
-11.088000 1.773333
-9.020000 1.120000
-7.304000 1.400000
-5.588000 2.286667
-4.224000 3.546667
-3.520000 5.413333
-4.312000 7.933333
-6.380000 8.586666
18
-9.108000 -9.613333
-8.888000 -10.593333
-7.612000 -10.686666
-5.500000 -9.566666
-3.124000 -7.420000
-0.088000 -4.106666
1.804000 -0.606667
3.256000 3.500000
4.268000 7.233333
5.148000 8.026666
5.148000 8.820000
4.488000 9.006666
2.728000 8.120000
1.188000 4.666666
0.484000 0.606667
-1.408000 -2.753333
-4.312000 -5.880000
-7.612000 -8.960000
6
7.832000 -0.980000
5.236000 -8.540000
9.988000 -10.500000
11.572000 -9.426666
7.524000 -7.793333
9.636000 -1.306667
Explanation / Answer
options = struct;
options.name = 'Obstacle avoidance';
constr = {cbox, cbnd, ode, obstacles};
solution = ezsolve(objective, constr, x0, options);
% Optimum x, y, and speed, to use as starting guess in the next iteration
xopt = subs(x, solution);
yopt = subs(y, solution);
vxopt = subs(vx, solution);
vyopt = subs(vy, solution);
thetaopt = subs(theta, solution);
speed = subs(V,solution);