Simcenter Prescan How to use Data model API in Prescan

2022-08-23T07:54:17.000-0400
Prescan Teamcenter Share Simcenter Prescan Marketing

Summary

Data model API is a function that allows user to create the content of experiment via a MATLAB


Details

Step1: Create an empty experiment using GUI, build the experiment and save it.



Step2: Open Matlab via Prescan process manager and navigate to your experiment created from GUI



Step 3: In MATLAB create a new script and save it in the experiment folder



Step 4: Inside the script we can start building the model. User can access DMAPI and module using command doc prescan.api



Example script for reference

exp = prescan.api.experiment.Experiment();
 
%% Create a road
road_1 = prescan.api.roads.createRoad(exp);
 
%% Add sections to the road
sectionLength = 250; % [m]
road_1.addStraightSection(sectionLength);
sectionLength = 50;
startCurvature = 0.025;
endCurvature = 0.1;
road_1.addSpiralSection(sectionLength, startCurvature, endCurvature);
%% Once the sections have been added, add lanes to the road
lane1 = road_1.addLeftLane(3.2);
marker = lane1.getLaneMarker('Outer');
marker.setType('Broken');
lane2 = road_1.addLeftLane(3.2);
marker = lane2.getLaneMarker('Outer');
marker.setType('Solid');
lane3 = road_1.addRightLane(3.2);
marker = lane3.getLaneMarker('Outer');
marker.setType('Broken');
lane4 = road_1.addRightLane(3.2);
marker = lane4.getLaneMarker('Outer');
marker.setType('Solid');
 
centerOfLane1 = lane3.poseAtDistance(0.0).position.y;
centerOfLane2 = lane4.poseAtDistance(0.0).position.y;
edgeOfRoadLeft = lane2.poseAtDistance(0.0, 'Outer', 10.0).position.y;
edgeOfRoadRight = lane4.poseAtDistance(0.0, 'Outer', 10.0).position.y;
%% Add objects to the road
vehicleAudi = exp.createObject(exp.objectTypes.Audi_A8_Sedan);
vehicleAudi.name = 'Ego';
 
% Trees
for i = 0:35
    r = -3 + (3+3).*rand(3,1); % Make it random
    xtree = 6 * i + r(1);
    ytree1 = edgeOfRoadLeft + r(2);
    ytree2 = edgeOfRoadRight + r(3);
   
    tree = exp.createObject(exp.objectTypes.Dogwood20y);
    tree.pose.position.x = xtree;
    tree.pose.position.y = ytree1;
   
    tree = exp.createObject(exp.objectTypes.Dogwood20y);
    tree.pose.position.x = xtree;
    tree.pose.position.y = ytree2;
end
 
%% Position the vehicles correctly
vehicleAudi.pose.position.y = centerOfLane2;
 
%% Add a trajectory to the ego vehicle
z = [0, 0];
y = [vehicleAudi.pose.position.y, vehicleAudi.pose.position.y];
x = [vehicleAudi.pose.position.x, 200];
pathAudi = prescan.api.trajectory.createFittedPath(exp, x, y, z);
speedProf = prescan.api.trajectory.createSpeedProfileOfConstantSpeed(exp, 5);
 
trajectoryAudi = prescan.api.trajectory.createTrajectory(vehicleAudi, pathAudi, speedProf);
%% Add a camera to the ego vehicle
cameraAudi = prescan.api.camera.createCameraSensor(vehicleAudi);
 
%% Save the experiment to a file
exp.saveToFile('DMAPI.pb');
 
%% Generate the CS
prescan.api.simulink.generate();
 
%% Run the experiment
prescan.api.simulink.run(exp, 'Regenerate', 'off', 'StopTime', '5')



Step5: Once the required changes are done to the experiment, save the file and run the script.



Step 6: Load the PB file in the Prescan static viewer and see the experiment built using API.


image.png

KB Article ID# KB000054104_EN_US

Contents

SummaryDetails

Associated Components

Documentation Installer License Software