function [xPath, yPath] = extractCoordinates()
% createDrivingScenario Returns the drivingScenario defined in the Designer
function scenario = road()
% createDrivingScenario Returns the drivingScenario defined in the Designer
% Generated by MATLAB(R) 9.9 (R2020b) and Automated Driving Toolbox 3.2 (R2020b).
% Generated on: 03-Sep-2023 12:35:41
% Construct a drivingScenario object.
scenario = drivingScenario('GeographicReference', [36.7324 3.05285 0], ...
'VerticalAxis', 'Y');
% Add all road segments
roadCenters = [216.001 -55.9053 -0.00389893;
283.244 -60.5975 -0.00657046;
292.855 -61.6625 -0.00701424;
331.229 -65.9335 -0.00893222;
378.642 -75.0646 -0.0116688];
laneSpecification = lanespec(1);
road(scenario, roadCenters, 'Lanes', laneSpecification, 'Name', 'Première Rocade Sud');
roadCenters = [93.9858 -50.1258 0.815777;
216.001 -55.9053 -0.00389893];
laneSpecification = lanespec(1);
road(scenario, roadCenters, 'Lanes', laneSpecification, 'Name', 'Première Rocade Sud');
roadCenters = [735.311 -295.977 -0.0492237;
720.428 -274.993 -0.0465851;
704.446 -253.299 -0.0439008;
687.008 -232.693 -0.0412134;
659.413 -204.497 -0.0373349;
623.092 -172.673 -0.0327437];
laneSpecification = lanespec(1);
road(scenario, roadCenters, 'Lanes', laneSpecification, 'Name', 'Première Rocade Sud');
roadCenters = [623.092 -172.673 -0.0327437;
558.454 -130.741 -0.019014;
491.628 -92.415 0.00740094;
450.958 -75.7824 0.0443691;
382.857 -55.9771 0.0962656;
337.865 -47.8336 0.159615;
306.744 -44.2282 0.235454;
261.556 -40.8672 0.325228;
211.267 -39.2484 0.42834;
126.982 -35.932 0.54533;
-32.6833 -26.6556 0.674792;
-115.548 -19.4638 0.815591];
laneSpecification = lanespec(1);
road(scenario, roadCenters, 'Lanes', laneSpecification, 'Name', 'Première Rocade Sud');
roadCenters = [581.243 -166.639 -0.0286364;
604.915 -185.392 -0.0313541;
627.104 -202.103 -0.0340038;
652.153 -222.209 -0.0371836;
680.113 -250.416 -0.0411487;
710.621 -286.568 -0.0459974;
729.141 -315.131 -0.0494366;
760.74 -365.754 -0.0558334;
850.545 -510.443 -0.0771328;
910.753 -604.386 -0.0936717];
laneSpecification = lanespec(1);
road(scenario, roadCenters, 'Lanes', laneSpecification, 'Name', 'Première Rocade Sud');
roadCenters = [-1193.087 159.3178 -0.113451;
-1118.459 162.648 -0.1000283;
-1068.251 163.7957 -0.09146141;
-1026.619 163.0249 -0.0846128;
-989.1135 160.2906 -0.0786238;
-951.9746 152.9844 -0.07279926;
-916.7653 143.6588 -0.06742988];
laneSpecification = lanespec(1);
road(scenario, roadCenters, 'Lanes', laneSpecification, 'Name', 'Première Rocade Sud');
roadCenters = [-916.765 143.659 -0.0674299;
-872.008 130.848 0.143282;
-785.771 98.8905 0.767553];
laneSpecification = lanespec(1);
road(scenario, roadCenters, 'Lanes', laneSpecification, 'Name', 'Première Rocade Sud');
roadCenters = [-1204.705 175.122 -0.116048;
-1291.312 169.9522 -0.1328336;
-1364.511 166.6233 -0.1479671;
-1445.007 165.8042 -0.1656534];
laneSpecification = lanespec(1);
road(scenario, roadCenters, 'Lanes', laneSpecification, 'Name', 'Première Rocade Sud');
roadCenters = [-1573.03 165.7491 -0.1959051;
-1606.597 166.4211 -0.2042794;
-1634.626 168.7014 -0.2114527;
-1672.247 172.404 -0.2212931;
-1731.893 182.3147 -0.2374677;
-1764.476 189.0019 -0.2465829;
-1817.057 200.3987 -0.2616771;
-1838.984 206.5513 -0.2681508;
-1885.453 223.7954 -0.2822858];
laneSpecification = lanespec(1);
road(scenario, roadCenters, 'Lanes', laneSpecification, 'Name', 'Première Rocade Sud');
roadCenters = [-1885.453 223.7954 -0.2822858;
-1927.314 239.3076 -0.2953477;
-1949.115 249.1558 -0.302343;
-1977.56 262.7565 -0.3116361;
-1994.993 271.7605 -0.3174371];
laneSpecification = lanespec(1);
road(scenario, roadCenters, 'Lanes', laneSpecification, 'Name', 'Première Rocade Sud');
roadCenters = [-1994.993 271.7605 -0.3174371;
-2018.821 284.1173 -0.3254657;
-2030.44 290.9116 -0.3294567;
-2073.521 317.6108 -0.3445779;
-2129.506 357.2418 -0.3651051;
-2229.361 439.4204 -0.4043333];
laneSpecification = lanespec(1);
road(scenario, roadCenters, 'Lanes', laneSpecification, 'Name', 'Première Rocade Sud');
roadCenters = [-1445.007 165.8042 -0.1656534;
-1514.838 163.9075 -0.1817878;
-1557.132 164.2702 -0.1919701;
-1573.03 165.7491 -0.1959051];
laneSpecification = lanespec(1);
road(scenario, roadCenters, 'Lanes', laneSpecification, 'Name', 'Première Rocade Sud');
roadCenters = [-254.284 -23.811 1.83239;
-249.345 -24.3549 1.99138;
-118.603 -36.9198 1.65481;
93.9858 -50.1258 0.815777];
laneSpecification = lanespec(1);
road(scenario, roadCenters, 'Lanes', laneSpecification, 'Name', 'Première Rocade Sud');
roadCenters = [-115.548 -19.4638 0.815591;
-247.871 -7.00988 1.88373;
-255.865 -5.9776 1.83237];
laneSpecification = lanespec(1);
road(scenario, roadCenters, 'Lanes', laneSpecification, 'Name', 'Première Rocade Sud');
roadCenters = [-292.782 -1.21569 1.83079;
-306.698 0.582554 1.97192;
-445.639 22.2727 1.98071;
-493.828 27.5244 1.86939;
-543.062 34.7073 1.63283;
-590.169 45.5857 1.27129;
-615.483 52.5011 0.786789];
laneSpecification = lanespec(1);
road(scenario, roadCenters, 'Lanes', laneSpecification, 'Name', 'Première Rocade Sud');
roadCenters = [-767.1283 113.4373 -0.04708969;
-800.9799 126.3466 -0.05148945;
-865.1908 148.736 -0.06035068;
-920.1749 166.1644 -0.06846861;
-968.3267 175.7467 -0.07584634;
-1024 181.4128 -0.08469029;
-1041.578 181.3927 -0.08753271];
laneSpecification = lanespec(1);
road(scenario, roadCenters, 'Lanes', laneSpecification, 'Name', 'Première Rocade Sud');
roadCenters = [-683.026 77.9079 -0.0370057;
-767.128 113.437 -0.0470897];
laneSpecification = lanespec(1);
road(scenario, roadCenters, 'Lanes', laneSpecification, 'Name', 'Première Rocade Sud');
roadCenters = [-785.771 98.8905 0.767553;
-688.226 61.0515 1.20012;
-640.878 44.8681 1.53435;
-598.093 31.9144 1.77608;
-561.847 23.0453 1.92524;
-496.66 10.8342 1.98484;
-308.7 -17.8499 1.95918;
-299.133 -18.8934 1.83047];
laneSpecification = lanespec(1);
road(scenario, roadCenters, 'Lanes', laneSpecification, 'Name', 'Première Rocade Sud');
% Initialize arrays to store X and Y coordinates
xPath = 0;
yPath = 0;
% Loop through the road segments in the scenario
for i = 1:numel(scenario.RoadNetwork)
roadSegment = scenario.RoadNetwork(i);
for j = 1:numel(roadSegment.Waypoints)
waypoints = roadSegment.Waypoints{j};
% Extract X and Y coordinates and append to arrays
xPath = [xPath; waypoints(:, 1)];
yPath = [yPath; waypoints(:, 2)];
Call the function to extract coordinates
[xPath, yPath] = extractCoordinates();
% Plot the path
plot(xPath,yPath,'b')
axis equal
xlabel('X')
ylabel('Y')
title('Road Path in Local Coordinates')
end
end
end
end
i have exported a function script from a drivingsenariodesigner toolbox and i have added a code to extract the x,y path from the data and waypoints provided.
is my code right?
how can i get the x,y plot?
how can i use this function in Simulink?
if there is any other way to extract a road to MATLAB code, I would appreciate you telling me, thank you.
knowing that my aim is to extract x,y path from a road to integrate it in my kinematic bicycle model in Simulink.