Main Content

generateCode

Generate code for tracker object and object functions

Since R2024a

    Description

    generateCode(tracker,fileName) generates code from the tracker specified in 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(tracker,fileName,Name=Value) specifies code generation properties using one or more name-value arguments. Unspecified properties have default values.

    codegenArg = generateCode(___) returns the arguments used by the code generation function codegen. Use codegenArg to regenerate code from the entry-point functions.

    Note

    You must have a MATLAB® Coder™ license to use this object function.

    example

    Examples

    collapse all

    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

    collapse all

    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 FunctionsSupport and Limitations
    stepFull support.
    resetFull support.
    getPropertyFull support.
    setPropertyFull support.
    initializeTrackgenerateCode does not support the syntax with function input argument filter.
    confirmTracktrackID must be uint32, single, or double.
    deleteTracktrackID must be uint32, single, or double.
    getTrackFilterPropertiestrackID must be uint32, single, or double. generateCode supports only one filter property in a call.
    setTrackFilterPropertiestrackID must be uint32, single, or double. generateCode supports only one filter property in a call.
    predictTracksToTimeInput argument time must belong to the same class as detection.Measurement.
    trackerJPDA Object FunctionsSupport and Limitations
    stepFull support.
    resetFull support.
    getPropertyFull support.
    setPropertyFull support.
    initializeTrackgenerateCode does not support the syntax with function input argument filter.
    confirmTracktrackID must be uint32, single, or double.
    deleteTracktrackID must be uint32, single, or double.
    getTrackFilterPropertiestrackID must be uint32, single, or double. generateCode supports only one filter property in a call.
    setTrackFilterPropertiestrackID must be uint32, single, or double. generateCode supports only one filter property in a call.
    predictTracksToTimeInput argument time must belongs to the same class as detection.Measurement.
    trackerPHD Object FunctionsSupport and Limitations
    stepFull support.
    resetFull support.
    getPropertyFull support.
    setPropertyFull support.
    initializeTrack
    • generateCode does not support the syntax with function input argument filter.

    • The internal probability hypothesis density filter of the PHD tracker must be gmphd

    deleteTracktrackID must be uint32, single, or double.
    predictTracksToTimeInput argument time must belongs to the same class as detection.Measurement.
    trackerTOMHT Object FunctionsSupport and Limitations
    stepFull support.
    resetFull support.
    getPropertyFull support.
    setPropertyFull support.
    initializeTrackgenerateCode does not support the syntax with function input argument filter.
    deleteTracktrackID must be uint32, single, or double.
    getTrackFilterPropertiestrackID must be uint32, single, or double.
    setTrackFilterPropertiestrackID must be uint32, single, or double. generateCode supports only one filter property in a call.
    predictTracksToTimeInput argument time must be in the same class as detection.Measurement.
    getBranchesFull support.
    confirmBranchbranchID must be uint32, single, or double.
    initializeBranchgenerateCode does not support the syntax with function input argument filter. trackID and branchID must be uint32, single, or double.
    deleteBranchbranchID must be uint32, single, or double.

    Output Arguments

    collapse all

    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.

    • generateCode behavior is guaranteed only for trackerGNN, trackerJPDA, trackerTOMHT, and trackerPHD. If your tracker is inherited, generateCode can fail or generate code only for tracker functions of supported classes that can generate code.

    More About

    collapse all

    getProperty

    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".

    setProperty

    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].

    List of tunable properties of trackerGNN, trackerJPDA, and trackerTOMHT

    trackerGNN

    • AssignmentThreshold

    • ConfirmationThreshold (tunable only when TrackLogic="Score")

    • DeletionThreshold (tunable only when TrackLogic="Score")

    • DetectionProbability

    • FalseAlarmRate

    • Volume

    • Beta

    • InitialClassProbabilities (the values are tunable only when ClassFusionMethod="Bayes"; number of elements is nontunable)

    • ClassFusionWeight (tunable only when ClassFusionMethod="Bayes")

    • StateParameters

    trackerJPDA

    • AssignmentThreshold

    • ConfirmationThreshold (tunable only when TrackLogic="Integrated")

    • DeletionThreshold (tunable only when TrackLogic="Integrated")

    • DetectionProbability

    • InitializationThreshold

    • ClutterDensity

    • NewTargetDensity

    • DeathRate

    • InitialClassProbabilities (the values are tunable only when ClassFusionMethod="Bayes"; number of elements is nontunable)

    • ClassFusionWeight (tunable only when ClassFusionMethod="Bayes")

    • HitMissThreshold (tunable only when TrackLogic="History")

    • StateParameters

    trackerTOMHT

    • AssignmentThreshold

    • ConfirmationThreshold

    • DeletionThreshold

    • DetectionProbability

    • FalseAlarmRate

    • Volume

    • Beta

    • MinBranchProbability

    • StateParameters

    Version History

    Introduced in R2024a

    See Also

    | | | | (MATLAB Coder) | (MATLAB Coder)