Array iteration using a for loop in stateflow

7 views (last 30 days)
Hello everyone, I am trying to import the trajectories of my robot in order to simulate the robot dynamically. My goal is to simulate the robot during every trajectory consecutively and to save the dynamic results, torques etc. the problem is I have a big amount of trajectory (44608 different trajectories for a 6 axis robot so 44608x6 matrix of waypoints) Also each trajectory's timepoints are like this 0:0.1:4 (41 step) and timepoints matrix is 1x44608. What I want is to utilize stateflow in order to run the simulation for each row of the waypoints matrix and each 41 row of the time matrix. I tried using for each loop but It doesn't work with minimum jerk polynomial trajectory block that interpolates the qd and qdd. I am open to suggestions !

Accepted Answer

Yash
Yash on 26 Mar 2024
Given the complexity and the size of your data (44608 different trajectories for a 6-axis robot), a direct for loop approach might not be the most efficient or feasible solution, especially if you're dealing with Simulink models which are generally designed to run simulations over time rather than iterate through loops like traditional programming scripts. Instead of trying to loop through trajectories directly in Simulink or Stateflow, use a MATLAB script to manage this. The script can load each trajectory, set it as a parameter in the Simulink model, and then run the simulation.
Given the large number of simulations, consider using MATLAB's parallel processing capabilities to run multiple simulations simultaneously. This can significantly reduce the overall computation time. Remember to use parfor carefully, ensuring your MATLAB session has access to multiple cores and that there's no data dependency between iterations that could cause issues.

More Answers (0)

Categories

Find more on Stateflow in Help Center and File Exchange

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!