1) In order to complete this part, there were a number of fixes I needed to apply to the code.
First, and the simplest fix was to change the "defaultStream" value in the constructor of the Navigation.m class; from "getDefaultStream" to "getGlobalStream"; surely due to a matlab changes.
The second rectification was much more difficult. The section of the code that would allow for the RRT plan to avoid colliding with the obstacles on the map was commented out, and even when un-commented, would not works since there are no variables called "y" declared until that point, and y seems to be the path reaching the new point. So I replaced y with "best.path", and move the segment responsible for putting the new point on the graph down until after it had been checked to verify no collision.
The map1 obstacle course is a very difficult one. In order to increase the chances of reaching the desired destination, I quadrupled the number of points from the initial 500, to 2,000; and yet, the results remain underwhelming:
Which after visualizing would be reduced to:
As can be seen, the RRT is actually functional, but there are no paths planned from [15, 10, 0] to [80, 90, 0]. So when calling the path function we get:
2) So what can be done to make the path more likely? Increasing the number of points! The default number of points of course is 500. I tried a few numbers, and then I decided to crank up the number to a point that I would be guaranteed to have a path to the goal. So I tried 20 times more than the default value! I tried 10,000 points! After nearly an hour of point placing on the map, I ended up with these graphs:
Which of course worked out much better than the previous attempts. As a note, playing with the angle limits did not have a drastic impact on the moving direction of the branches, and due to the randomness of the effect, there is no certain way of depicting the impacts of changing the angle. What is fairly easy to see, is the fact hat we finally have a perfect way from [15, 10, 0] to [80, 90, 0]:
As you can see, we have manged to find a path that successfully circumvents the obstacle. Naturally it is not the perfect path, but it is a very good one nonetheless.
3) For this part I had to reduce the 10,000 node count, since it would take a lot of computation time. I also came up with a new function that would carry out this task, given the path and the rrt:
function t = velocity_time_plot(rrt,path)
time = ones([1,length(path)]);
steering = zeros([1,length(path)]);
velocity = zeros([1,length(path)]);
g = rrt.graph;
steering(1)=0;
velocity(1)=0;
for k= 2:length(path)
time(k) = k;
last_step = g.coord(path(k-1));
new_step = g.coord(path(k));
steering(k) = last_step(3)-new_step(3) ;
velocity(k) = distance(g, k-1, k);
end
figure; plot(time, velocity);
figure; plot(time, steering);
t = true;
end
velocity - time steering - time
4) This part was very simple. As was instructed, I just had to change every occurrence of "rand" to "randn" in resetting the steering. Again, since all these are randomized, there is no guaranteed way seeing perfect and overwhelming improvement, but here, even as a small reference, is a RRT made after the switch to Gaussian distribution:
rrt.plan() rrt.visualize
the 3D path the 2D path
5) To make a local planning that connects the initial pose to the closest vertex, is a strange request. For one thing, it is very possible and optimal that the initial position and the closest vertex actually overlap! And if they don't, then the wisest course of action, is to use the same planning on both directions (one starting from the initial vertex and one from the goal point). So optimally we can manipulate the path function to check the distance between the initial node and the closest vertex. If they are not closer than a certain window, then we start another, smaller RRT from the initial node.
The simplest way of achieving this connection however, would be to use an equivalent to our functions from the previous homework, goToPoint; and so that is exactly what I have done. I imported and appropriated the gotopoint function from the previous homework, and included it in my code. It is however note worthy that if there is an obstacle on the way, this function would not circumvent it, since it is a very simple function. For better results, one would simply have to (as mentioned) use 2 different RRTs, or add more nodes to the already existing RRT.
Please feel free to find every matlab file, and every other picture from this assignment, in the zip file attached to this page.