Implementing Time-Based Waypoint Logic Without Clock Block for Code Generation
조회 수: 8 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
채택된 답변
Jacob Mathew
2025년 6월 19일
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:
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Deployment, Integration, and Supported Hardware에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!