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
0 个评论
采纳的回答
Divyajyoti Nayak
2025-5-5
编辑:Divyajyoti Nayak
2025-5-5
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
The 'Line' object called 'WaylineActor1' is the generated trajectory.
%Extracting coordinates from the 'Line' object
a.Children(1)
xData = a.Children(1).XData
yData = a.Children(1).YData
Hope this helps!
0 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!