generateCode
Syntax
Description
generateCode(
generates code from the tracker specified in tracker,fileName)tracker and its
corresponding object functions. It creates a MEX tracker with the name specified in
fileName, and stores the generated MEX tracker in a folder also named
fileName. This function also generates code for the getProperty and
setProperty function,
which you can use to get or set any tunable property of the generated MEX tracker.
generateCode(
specifies code generation properties using one or more name-value arguments. Unspecified
properties have default values.tracker,fileName,Name=Value)
returns the arguments used by the code generation function codegenArg = generateCode(___)codegen. Use
codegenArg to regenerate code from the entry-point functions.
Note
You must have a MATLAB® Coder™ license to use this object function.
Examples
Create trackerGNN Object and Lock It
Construct a trackerGNN object with the default 2-D constant-velocity Kalman filter initialization function initcvkf.
tracker = trackerGNN(FilterInitializationFcn=@initcvkf, ... TrackLogic='Score', ... StateParameters=struct('Frame','Rectangular','Position',[0 0 0],'Velocity',[0 0 0]));
To use the generateCode function, lock the tracker first by calling it using real detection information. To check the locked status, use the isLocked function.
isLocked(tracker)
ans = logical
0
detections = {objectDetection(0,[5;0],"SensorIndex",1, ...
"ObjectClassID",5,"ObjectAttributes",{struct("ID",1)}); ...
objectDetection(0,[0;10],"SensorIndex",1, ...
"ObjectClassID",2,"ObjectAttributes",{struct("ID",2)})};
time = 0;
tracks = tracker(detections,time);
isLocked(tracker)ans = logical
1
Generate and run MEX functions
Create MEX functions for the tracker under a directory named myGNNTracker.
codegenArgs = generateCode(tracker,"myGNNTracker");Generating code. Code generation successful.
Initialize myGNNTracker with a detection report using the generated step MEX function. The detection report contains two detections with nonzero ObjectClassID, which immediately create confirmed tracks. The MEX tracker resets after generating code and does not retain any detection information that was used to lock it.
[confTracks0,~,~,~] = myGNNTracker('step',detections,0);Update myGNNTracker with a new detection report. Display the updated tracker state.
detections1 = {objectDetection(1,[25;0],"SensorIndex",1, ...
"ObjectClassID",5,"ObjectAttributes",{struct("ID",1)}); ...
objectDetection(1,[0;20],"SensorIndex",1, ...
"ObjectClassID",2,"ObjectAttributes",{struct("ID",2)})};
[confTracks1,~,~,~] = myGNNTracker("step",detections1,1);
disp(confTracks1(1).State) 24.8044
19.6577
0
0
disp(confTracks1(2).State)
0
0
19.9022
9.8289
Predict and display the states of the tracks at a later time using the generated predictTracksToTime MEX function.
predictedTracks5 = myGNNTracker('predictTracksToTime','all',5); disp(predictedTracks5(1).State)
103.4352
19.6577
0
0
disp(predictedTracks5(2).State)
0
0
59.2176
9.8289
Reset MEX Tracker and Start New Simulation With Different StateParameters
Reset MEX tracker using the generated reset MEX function.
myGNNTracker('reset');Inspect the current parameters of the track state reference frame.
myGNNTracker('getProperty','StateParameters')
ans = struct with fields:
Frame: 'Rectangular'
Position: [0 0 0]
Velocity: [0 0 0]
Change the parameters of the track state reference frame to a rectangular reference frame whose origin position is at [0 1 0] meters and whose origin velocity is [-1 0 0] meters per second with respect to the scenario frame.
StatePara = struct('Frame','Rectangular','Position',[0 1 0],'Velocity',[-1 0 0]); myGNNTracker('setProperty','StateParameters',StatePara);
Restart the simulation using the same detection reports as before.
[newConfTracks0,~,~,~] = myGNNTracker('step',detections,0); [newConfTracks1,~,~,~] = myGNNTracker('step',detections1,1);
Display the updated tracker StateParameters.
disp(newConfTracks1(1).StateParameters)
Frame: 'Rectangular'
Position: [0 1 0]
Velocity: [-1 0 0]
disp(newConfTracks1(2).StateParameters)
Frame: 'Rectangular'
Position: [0 1 0]
Velocity: [-1 0 0]
Input Arguments
Tracker object, specified as a trackerGNN,
trackerTOMHT,
trackerJPDA, or trackerPHD
object. You must lock the tracker object to use generateCode. To
lock the tracker object, call it or use the step function with detection information. To check the locked status of
the tracker object, use the isLocked function.
To generate code, any tracker property that requires a function handle as input,
such as FilterInitializationFcn, must reference a private function
defined in a separate file. It cannot be a local or anonymous function. For
trackerGNN, trackerJPDA and
trackerTOMHT, you must specify the
FilterInitializationFcn property as trackingKF,
trackingEKF, trackingCKF,
trackingUKF, trackingABF, or
trackingMSCEKF.
Tip
You can use real or placeholder detection data to lock the tracker. Once you generate the code, the generated MEX tracker resets and does not retain any detection information that was used to lock it.
Name of the generated MEX tracker and name of the folder containing the generated MEX tracker, specified as a string scalar or character vector.
Example: generateCode(tracker,"myTracker")
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN, where Name is
the argument name and Value is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Example: generateCode(tracker,"myTracker",Methods="All",CoderConfig=coder.config("mex"))
Path to output folder to store generated code, specified as a string scalar or
character vector. If you do not specify this argument,
generateCode uses the current working folder, as returned by
pwd.
Configuration object, specified as a code generation configuration object. For
more information, see coder.config (MATLAB Coder).
Example: generateCode(tracker,"myJPDATracker",CoderConfig=coder.config("dll"))
Names of tracker object functions, specified as an array of strings or as a cell
array of character vectors. By default, generateCode function
generates code for all the tracker object functions that support code generation. To
generate code for only a specific set of tracker object functions, specify the
function names as strings or character vectors. For a full list of supported code
generation-capable tracker object functions, see the tables below.
trackerGNN Object Functions | Support and Limitations |
|---|---|
step | Full support. |
reset | Full support. |
getProperty | Full support. |
setProperty | Full support. |
initializeTrack | generateCode does not support the syntax with
function input argument filter. |
confirmTrack | trackID must be uint32, single, or
double. |
deleteTrack | trackID must be uint32, single, or
double. |
getTrackFilterProperties | trackID must be uint32, single, or double.
generateCode supports only one filter property in
a call. |
setTrackFilterProperties | trackID must be uint32, single, or double.
generateCode supports only one filter property in
a call. |
predictTracksToTime | Input argument time must belong to the same
class as detection.Measurement. |
trackerJPDA
Object Functions | Support and Limitations |
|---|---|
step | Full support. |
reset | Full support. |
getProperty | Full support. |
setProperty | Full support. |
initializeTrack | generateCode does not support the syntax with
function input argument filter. |
confirmTrack | trackID must be uint32, single, or
double. |
deleteTrack | trackID must be uint32, single, or
double. |
getTrackFilterProperties | trackID must be uint32, single, or double.
generateCode supports only one filter property in
a call. |
setTrackFilterProperties | trackID must be uint32, single, or double.
generateCode supports only one filter property in
a call. |
predictTracksToTime | Input argument time must belongs to the same
class as detection.Measurement. |
trackerPHD Object Functions | Support and Limitations |
|---|---|
step | Full support. |
reset | Full support. |
getProperty | Full support. |
setProperty | Full support. |
initializeTrack |
|
deleteTrack | trackID must be uint32, single, or
double. |
predictTracksToTime | Input argument time must belongs to the same
class as detection.Measurement. |
trackerTOMHT Object Functions | Support and Limitations |
|---|---|
step | Full support. |
reset | Full support. |
getProperty | Full support. |
setProperty | Full support. |
initializeTrack | generateCode does not support the syntax with
function input argument filter. |
deleteTrack | trackID must be uint32, single, or
double. |
getTrackFilterProperties | trackID must be uint32, single, or
double. |
setTrackFilterProperties | trackID must be uint32, single, or double.
generateCode supports only one filter property in
a call. |
predictTracksToTime | Input argument time must be in the same class as
detection.Measurement. |
getBranches | Full support. |
confirmBranch | branchID must be uint32, single, or
double. |
initializeBranch | generateCode does not support the syntax with
function input argument filter.
trackID and branchID must be
uint32, single, or double. |
deleteBranch | branchID must be uint32, single, or
double. |
Output Arguments
Compile-time arguments used by codegen (MATLAB Coder) to generate codes, returned as a 1-by-N cell
array. Use codegenArg to regenerate code from the entry-point
functions saved in the output folder. To integrate additional functions into the
generated code, add your entry-point functions and their respective compile-time inputs
to codegenArg.
Limitations
You must have a MATLAB Coder license to use this object function.
generateCodebehavior is guaranteed only fortrackerGNN,trackerJPDA,trackerTOMHT, andtrackerPHD. If your tracker is inherited,generateCodecan fail or generate code only for tracker functions of supported classes that can generate code.
More About
fileName('getProperty',TrackerProperty) returns the value of the
property specified in the TrackerProperty argument.
TrackerProperty can be any tunable tracker property,
'NumTracks', or 'NumConfirmedTracks'. This function
works only for generated code.
For example, myJPDATracker('getProperty', 'DeathRate') returns the
value of the DeathRate property for a generated MEX JPDA tracker named
myJPDATracker with TrackLogic set to
"integrated".
fileName('setProperty',TrackerProperty,PropertyValue) sets the value
of the property specified in the TrackerProperty argument as
PropertyValue. TrackerProperty must be a tunable
tracker property. This function works only for generated code.
For example, myGNNTracker('setProperty', 'AssignmentThreshold', [20
Inf]) sets the AssignmentThreshold property of the generated
MEX tracker named myGNNTracker to [20 Inf].
AssignmentThresholdConfirmationThreshold(tunable only whenTrackLogic="Score")DeletionThreshold(tunable only whenTrackLogic="Score")DetectionProbabilityFalseAlarmRateVolumeBetaInitialClassProbabilities(the values are tunable only whenClassFusionMethod="Bayes"; number of elements is nontunable)ClassFusionWeight(tunable only whenClassFusionMethod="Bayes")StateParameters
AssignmentThresholdConfirmationThreshold(tunable only whenTrackLogic="Integrated")DeletionThreshold(tunable only whenTrackLogic="Integrated")DetectionProbabilityInitializationThresholdClutterDensityNewTargetDensityDeathRateInitialClassProbabilities(the values are tunable only whenClassFusionMethod="Bayes"; number of elements is nontunable)ClassFusionWeight(tunable only whenClassFusionMethod="Bayes")HitMissThreshold(tunable only whenTrackLogic="History")StateParameters
AssignmentThresholdConfirmationThresholdDeletionThresholdDetectionProbabilityFalseAlarmRateVolumeBetaMinBranchProbabilityStateParameters
Version History
Introduced in R2024a
See Also
trackerPHD | trackerGNN | trackerJPDA | trackerTOMHT | coder.config (MATLAB Coder) | codegen (MATLAB Coder)
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)