How can I export an actor trajectory from a RoadRunner simulation by using the API?

I want to export the trajectory of the Sedan actor from a RoadRunner scenario by using the RoadRunner API. I used the following workflow:
rrApp = roadrunner(projectFolder);
rrApi = roadrunnerAPI(rrApp);
openScene(rrApp, sceneFile);
openScenario(rrApp, scenarioFile);
rrSim = createSimulation(rrApp);
set(rrSim, "MaxSimulationTime", 10);
set(rrSim, "SimulationCommand", "Start");
pause(15)
exportActorTrajectoryToCSV(rrApp, 'FolderPath', outputFolderPath, 'FolderName', outputFolderName);
The simulation runs, but the export fails with this error:
Unable to export CSV file. Set the value of 'enable_runtime_log' field of the 'SimulateScenario' method to 'true' to enable simulation logging.
I also tried enabling logging through simulateScenario(rrApp,'EnableLogging',true), but that changed the workflow and  appeared to interfere with the "MaxSimulationTime" in the "set" command.

 采纳的回答

"exportActorTrajectoryToCSV" requires simulation logging to be enabled before the simulation is started. If logging is not enabled, the export command cannot access runtime trajectory data, however, the enablement with "simulateScenario" is invalid.
For this workflow, there are three practical approaches:
1. Built-in CSV export after simulation logging
Use createSimulation, turn logging on explicitly, run the simulation, wait until it finishes, and then call exportActorTrajectoryToCSV. This is the most direct method when the goal is to export trajectory data to CSV by using the built-in export function.
rrApp = roadrunner(projectfolder);
openScenario(rrApp, "TrajectoryCutIn");
rrSim = createSimulation(rrApp);
set(rrSim, "Logging", "On");
set(rrSim, "SimulationCommand", "Start");
while strcmp(get(rrSim,"SimulationStatus"),"Running")
pause(1);
end
exportActorTrajectoryToCSV(rrApp);
2. Custom timed trajectory export from SimulationLog
If more control is needed, run the simulation with logging enabled, retrieve SimulationLog, extract pose and time data, and write the CSV manually. This method is useful when both path and timestamp information are needed in a
custom format.
rrApp = roadrunner(projectfolder);
openScenario(rrApp, "TrajectoryCutIn");
rrSim = createSimulation(rrApp);
set(rrSim, "Logging", "On");
set(rrSim, "SimulationCommand", "Start");
while strcmp(get(rrSim,"SimulationStatus"),"Running")
pause(1);
end
rrLog = get(rrSim, "SimulationLog");
t = [poseTimeSeries.Time].';
P = reshape([poseTimeSeries.Pose], 4, 4, []);
xyz = squeeze(P(1:3, 4, :)).';
T = table(t, xyz(:,1), xyz(:,2), xyz(:,3), ...
'VariableNames', {'Time','X','Y','Z'});
writetable(T, 'actor1_pose.csv');
3. Static route points through roadrunnerAPI
If only the actor path is needed and simulation time is not required, use roadrunnerAPI to read the actor route directly from the scenario. This method does not require running a simulation.
rrApp = roadrunner(projectfolder);
openScenario(rrApp, "TrajectoryCutIn");
rrApi = roadrunnerAPI(rrApp);
actor1 = rrApi.Scenario.Actors(1);
xyz = actor1.InitialPoint.Route.PositionSamples;
T = array2table(xyz, 'VariableNames', {'X','Y','Z'});
writetable(T, 'points.csv')

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by