Why does code generation fail with Property "pLastTimeStamp" is undefined on some execution paths when using "predictTracksToTime" in Radar Toolbox R2025b?

When generating code for a model that uses a "radarTracker" object in Radar Toolbox R2025b, code generation fails with the following error:
Property 'pLastTimeStamp' is undefined on some execution paths but is used inside the called function.
For code generation, all variables must be fully defined before use.
This error occurs when calling the "predictTracksToTime" function, even though the model runs correctly in normal simulation.
How can this error be resolved?

 Accepted Answer

Cause of the Issue
This issue occurs with Radar Toolbox R2025b because code generation cannot verify that the tracker has been stepped at least once before calling "predictTracksToTime".
Internally, tracker objects rely on state variables (such as timestamps) that are initialized during the first call to the tracker’s step method. During normal MATLAB execution, this ordering is often implicit and does not cause problems. However, during code generation, all internal state must be provably initialized on all execution paths.
If "predictTracksToTime" is called before the tracker has been stepped, code generation cannot guarantee that internal properties (for example, "pLastTimeStamp") are defined, which results in the error.
Suggested Workflow
To resolve this issue, explicitly step the tracker once immediately after construction and then reset it. This ensures the tracker’s internal state is initialized in a way that code generation can verify, while preserving the intended runtime behavior.
% Create tracker object (use default or generic settings)
tracker = radarTracker;
% Perform a one-time dummy step to initialize internal state
dummyDetection = objectDetection(0, [0; 0; 0]);
tracker({dummyDetection}, 0, zeros(0,1));
% Reset the tracker to preserve initial runtime behavior
reset(tracker);
This ensures that:
  • The tracker’s internal timestamp and state variables are initialized.
  • Code generation can confirm all required properties are defined.
  • Runtime behavior remains functionally equivalent to the original design.

More Answers (0)

Categories

Products

Release

R2025b

Community Treasure Hunt

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

Start Hunting!