Implementing Time-Based Waypoint Logic Without Clock Block for Code Generation

8 views (last 30 days)
Hi everyone,
I've built a Simulink model for autonomous drone navigation. The drone follows a sequence of waypoints, which are passed based on a time-driven logic: since the distance between consecutive waypoints is approximately constant, the time t needed to cover that distance is estimated and the waypoints are updated every t seconds.
This solution is intentionally simple and avoids more complex implementations such as a threshold method, which would require pose estimation. The timing is handled using a Clock block. I wrote a MATLAB Function that gets the time from the Clock block and, every t seconds, increments the row index that points to the current waypoint in the waypoints matrix. The simulation runs smoothly with PacingRate = 1.
I now need to generate C code to deploy the model on a Raspberry Pi 5, which is connected to the drone’s flight controller. However, I’ve read that the Clock block is not recommended for code generation.
What is the best way to preserve this time-based sequencing while ensuring compatibility with code generation, ideally without having to significantly rework the model?
Thanks in advance for your support.

Accepted Answer

Jacob Mathew
Jacob Mathew on 19 Jun 2025
Hey Elio,
You can replace the Clock block with the Pulse Generator block which supports code generation. The block parameters can be customised where its period property can be set to the variable t which is the constant time that you have mentioned. You can read more about the block at the documentation below:
The other option is to use a MATLAB Function block and write a custom code that generates a similar timing pulse with a time period of t. This requires you to set the model to fixed step and match the step size within the function code as well. You can refer to the following documentation to learn more about the block:
  1 Comment
Elio
Elio on 11 Jul 2025
Sorry for getting back to you so late, I really appreciate your input. I guess I can use the Pulse Generator block to generate a signal every t seconds. However, I would need to adapt the MATLAB Function so that it updates the index each time it receives a signal from the Pulse Generator, and I'm not sure how to do that. Isn't there a way to get the actual elapsed runtime that I can pass to the function, like what happens with the simulation?

Sign in to comment.

More Answers (0)

Categories

Find more on Deployment, Integration, and Supported Hardware in Help Center and File Exchange

Products


Release

R2025a

Community Treasure Hunt

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

Start Hunting!