Implement ros timers in stateflow
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.
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();
}
}
“`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.
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();
}
}
“` 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.
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();
}
}
“` timer, stateflow, simulink, temporal logic MATLAB Answers — New Questions