Implement ros timers in stateflow
4 views (last 30 days)
Show older comments
Problem
I want to create a stateflow chart that triggers a controller (enabled/function-call subsystem) every 100ms. However, if certain conditions are met during the intermediate time between controller runs, the controller must be called and afterwards, the timer must be resetted. (Reset the controller)
I tried to make an simplified version of the above, however it does not work as expected.
- The controller is not activated every 100ms.
- After resetting, the controller is left in an activated state, while i want the activation to be just for a timestep. (the outport of the function-call subsystem resets to zero when disabed).
Also, the version is R2022b, but i couldn't put it when i sumbitted the question.
Current program
Where the stateflow chart (Controller Governor) is the following:
What i get is (vs what i expect to get is the following):
Background and general goal
I am trying to simulate an MPC controller (which i intent to port to ros) in simscape. The weights and setpoints of the MPC change depending on its current position in the workspace. I want to create "interrupting" logic that detects if i should change the weights of the MPC based on the current position.
In cpp the above could be achieved with that:
```
ros::Timer timer = nh.createTimer(ros::Duration(0.1), run_controller);
while(ros::ok()){
resetting = check_reseting_conditions();
if (resetting==true){
timer.stop();
run_controller();
timer.start();
}
}
```
0 Comments
Answers (1)
Poorna
on 17 May 2024
Edited: Poorna
on 17 May 2024
Hi Michail,
It will be easier for the community to answer your queries if you attach the model to try it. Creating a model from the picture would be time consuming.
For the first query, did you set the sample time of the system appropriately. make sure that it is discrete enough(atleast 100 msec) so that the stateflow transition happens as expected.
For the second query instead of using a "event" to trigger a transition. Try using the "rising" function in stateflow to detect edge rises.
Also, you should try making your chart a little more clear and try to add another state as below:
The above one works for me and produces the expected output. Here, 'reset' is the reset signal directly fed to the stateflow chart.
To know more about the "rising" function, refer to the following documentation:
Hope this Helps!
0 Comments
See Also
Categories
Find more on Complex Logic in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!