Simulink: How to run simulation in real time

9 次查看(过去 30 天)
I am using the joystick input block from the 3d animation library, and I am using it to control a robot arm imported from solidworks using the simmechanics simscape package. The coordiantes of the end effector are displayed in a simulink display sink block.
The problem is that the simulation runs much faster than real time, so I puch the joystick up, and the coordiates of the end effector respond imediately, and it would seem like the robot arm had lifted in a fraction of a second, however if you look at the simulation time it has taken about 10 seconds.
the Mechanics explorer window records the simulation and can play it back in real time, but because it is a recording it is completley out of sinc with my actions on the joystick.
I need the simulink simulation to run in real time, how do I do this?
Thanks!
EDIT:
I have found a temporary solution. I changed the simulation to fixed step, and then by trial and error changed the value of the step size so the simulation time roughly matches real time. Also, as long as the simulation time is slighlty slower than real time, the mechanics exploer window plays the simulation at its most recent values, so it is completley in sync with the joystick inputs. However, I would still like a propper way to play the simulation in real time as this method isn't perfect.

回答(1 个)

Jan Houska
Jan Houska 2015-1-27
You may want to try Real-Time Windows Target www.mathworks.com/products/rtwt . It contains a block to synchronize model execution with real time.
  3 个评论
Jan Houska
Jan Houska 2015-1-29
The name of the block is Real-Time Sync and you just put it in your model. Its Sample time parameter specifies synchronization granularity (how often you synchronize) - the default of 0.1 should be a good starting point.
You will need to install Real-Time Windows Target real-time kernel if you haven't installed it already - this is done by
rtwintgt -setup

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Model Preparation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by