function [nbNodes, obstacle, points] = buildPRM() %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %function [nbNodes, obstacle, points] = buildPRM() % % Task: Implement a code that creates a map of random points in the q1 q2 joint space % and checks the presence of an obstacle between each of them in the x y cartesian space % That algorithm is called Probabilistic RoadMaps (PRM) % % Inputs: q1 random variable % q2 random variable % % Outputs: % -nbNodes: number of nodes of the graph excluding the starting and goal points % -obstacle: a matrix containing the distance between connected nodes % (NaN refers to not connected nodes) % The matrix has a size of (nbNodes+2)x(nbNodes+2) %-points: a matrix saving the q1 q2 and x y coordinates of each point, % the 1st column describing the 1st (start) point % % % % % Thomas OLIVE (thomas.olive@ecam.fr) % 18/12/2021 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% clc close all addpath("C:/Users/Admin/Documents/ProjectMotionPlanning/motion_planning"); [S, G, randVmin, randVmax, L1, L2, threshold] = setParams(); threshold = 0.000001; [nbSol, qi] = solveIK2LinkPlanarRobot(2, 1, 2, 0); Sq1 = qi(1,1) Sq2 = qi(1,2) [nbSol, qi] = solveIK2LinkPlanarRobot(2, 1, -2, 0); Gq1 = qi(1,1) Gq2 = qi(1,2) points = [Sq1 Sq2 S(1) S(2)]'; obstacle = []; GapValue = 10; X_space = [S(1) G(1)]; Y_space = [S(2) G(2)]; n=columns(points); % represents the number of validated points WhileCond = 12; % number of desired points in the tree while n= L1 - threshold || y <= -L1 + threshold || (x>=-L2 - threshold && x<=L2 - threshold && y>=-L2 - threshold && y<=L2 + threshold)) n=columns(points); if n==WhileCond-1 % if it is the last iteration (concerns the goal point) figure 1 hold on text(Gq1, Gq2, 'G', 'FontSize', 20); %text function is used to plot points with their description figure 2 hold on text(G(1), G(2), 'G', 'FontSize', 20); q1 = Gq1; % the values are not random but known q2 = Gq2; x = G(1); y = G(2); points = [points [q1;q2;x;y]]; %Store q1 q2 x y values obstacle(n+1,n+1) = NaN; elseif n==1 % if it is the first iteration (concerns the start point) figure 1 hold on text(Sq1, Sq2, 'S', 'FontSize', 20); text(q1, q2, int2str(n), 'FontSize', 20); figure 2 hold on text(S(1), S(2), 'S', 'FontSize', 20); obstacle(n,n) = NaN; % enlarges the obstacle matrix so we can write later the valid links computed around the new point obstacle(n+1,n+1) = NaN; points = [points [q1;q2;x;y]]; elseif n