How to return the trajectory generated from the waypoints using `smoothtrajectory`

3 次查看(过去 30 天)
I have a drivingscenario defined as provided in the example and I spawn two vehicles in an intersection. I have given waypoints for them to drive and called the smoothtrajectory function to create the trajectory from the waypoints using speed, yaw and jerk limits. However, it does not return the generated trajectory. I cant find the trajectory in the scenario.Actors as well. So I am not sure how to return the trajectory generated. Can somebody please point to the generated trajectory? Thanks

采纳的回答

Divyajyoti Nayak
Divyajyoti Nayak 2025-5-5
编辑:Divyajyoti Nayak 2025-5-5
Hi @Arpan,
I'm assuming that you want the co-ordinates of the trajectory generated by the 'smoothtrajectory' function. Although I couldn't find a direct way to get the data from the 'drivingscenario' object or the 'vehicle' object, I was able to extract the data from the figure created by plotting the scenario. Here's some sample code to show this:
%Example scenario
scenario = drivingScenario('SampleTime',0.05);
roadcenters = [0 0; 24.2 27.7; 50 30];
lspec = lanespec(2);
road(scenario,roadcenters,'Lanes',lspec);
v = vehicle(scenario,'ClassID',1);
waypoints = [2.6 1.0; 23.6 24.9; 45.5 28.6];
speed = [9 8 9];
smoothTrajectory(v,waypoints,speed)
%Plotting the scenario
plot(scenario,'Waypoints','on','RoadCenters','on');
a = gca; %getting current axis
a.Children %Getting all the graphics plotted on the axes
ans =
7x1 graphics array: Line (WaylineActor1) Line (WaypointActor1) Patch (ActorPatch1) Line (RoadCenters) Line (RoadBoundary1) Patch (LaneMarkingPatch) Patch (RoadTilesPatch)
The 'Line' object called 'WaylineActor1' is the generated trajectory.
%Extracting coordinates from the 'Line' object
a.Children(1)
ans =
Line (WaylineActor1) with properties: Color: [0 0.4470 0.7410] LineStyle: '-' LineWidth: 0.5000 Marker: 'none' MarkerSize: 6 MarkerFaceColor: 'none' XData: [2.6000 2.6157 2.6266 2.6423 2.6531 2.6688 2.6797 2.6954 2.7062 2.7219 2.7328 2.7485 2.7594 2.7750 2.7859 2.8016 2.8125 2.8282 2.8390 ... ] (1x2049 double) YData: [1 1.0274 1.0464 1.0738 1.0927 1.1201 1.1391 1.1665 1.1855 1.2129 1.2319 1.2593 1.2782 1.3056 1.3246 1.3520 1.3710 1.3984 1.4173 1.4447 ... ] (1x2049 double) ZData: [0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 0.0020 ... ] (1x2049 double) Use GET to show all properties
xData = a.Children(1).XData
xData = 1×2049
2.6000 2.6157 2.6266 2.6423 2.6531 2.6688 2.6797 2.6954 2.7062 2.7219 2.7328 2.7485 2.7594 2.7750 2.7859 2.8016 2.8125 2.8282 2.8390 2.8547 2.8656 2.8813 2.8922 2.9079 2.9187 2.9344 2.9453 2.9610 2.9719 2.9876
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
yData = a.Children(1).YData
yData = 1×2049
1.0000 1.0274 1.0464 1.0738 1.0927 1.1201 1.1391 1.1665 1.1855 1.2129 1.2319 1.2593 1.2782 1.3056 1.3246 1.3520 1.3710 1.3984 1.4173 1.4447 1.4637 1.4911 1.5101 1.5375 1.5564 1.5838 1.6028 1.6302 1.6492 1.6766
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
Hope this helps!

更多回答(0 个)

产品


版本

R2024a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by