MATLAB Answers

0

What's the best way to control the time and input data of a model from another model or Matlab?

Asked by Nico Spo on 6 Oct 2017
Latest activity Commented on by Nico Spo on 6 Oct 2017
I want to run a simulation that is practically controlled from another PC (e.g. ROS node).
The other PC would irregularly send new input data for the simulation, which should be stored somewhere (this would be for example an array of setpoint value for specific times, e.g.
t | y_setpoint(t)
-------------------
0.1 | 5
0.2 | 6
0.3 | 6
Furthermore, the other PC should control when the simulation runs - it should be able to give the command
REMOTE: Run the simulation for one time step (until t=0.1)
and receive some output values:
SIM_PC: y_actual(0.1) = 3.78
The main simulation should then pause until another command
REMOTE: Run the simulation for one time step (until t=0.2)
comes in. SIM_PC responds as before:
SIM_PC: y_actual(0.2) = 4.35
When the simulation is paused, the simulation PC still needs to listen to new input from the remote PC of course, e.g.:
t | y_setpoint(t)
-------------------
0.3 | 5
0.4 | 5.5
What would be the most elegant/easy way to implement something like this?

  0 Comments

Sign in to comment.

1 Answer

Answer by Cam Salzberger on 6 Oct 2017
 Accepted Answer

Hello Nico,
The easiest and most elegant way would be to use the Robotics System Toolbox subscribe and publish functionality. The subscriber could have a callback that starts the model (assuming a Simulink model here). Once the model is done running, it can then publish the output as another ROS message to be received by the other computer. If you really need to pause and resume the model at particular timesteps, there are some ideas here.
If you are looking to modify the model while its running from the other computer, you could add a Subscribe block to the model to update values.
Hope that helps to get you started!
-Cam

  1 Comment

Thank you. I was already aware of the Robotics System Toolbox, so the pausing and resuming was the main problem. I think I might be able make everything simpler by putting my "main simulation" into an enabled subsystem, and using the ROS subscriber/publisher functions on a higher level to control that subsystem.

Sign in to comment.