Add Port to SimMechanics Body Block programmatically

5 次查看(过去 30 天)
Hi, currently I am trying to add new CS Ports or the CG Port to a SimMechanics Body block programmatically. Therefore I type into the command line of Matlab: set_param('mdl/Body','CG','Left$CG$[0 0 0]$WORLD$WORLD$m$[0 0 0]$Euler X-Y-Z$deg$WORLD$true$none'). After setting the parameter, there is no error or something. But the parameter change is not taking any effect visually. Only if I open the block parameters and press OK the new Port shows up in the diagram (the hook of "show port" is already set, due to the parameter change).
Does anyone know how the parameter change takes effect (visually) immediately without manual action?
Thank you very much for your help!

回答(2 个)

Ryan G
Ryan G 2013-5-17
This is a tough one for me, but I'll try to get you started. I should mention that SimMechanics 2G is now available too.
If you use the function:
get(gcbh,'Ports')
It will display the ports on each side as part of this vector. For me it was
[0 0 0 0 0 1 1 0]
When I updated the block it was
[0 0 0 0 0 2 1 0]
So you would think you could just update this. Unfortunately it appears to be read-only. So I'm not sure how to bypass that. You can modify the xml, which I assume you know about since the set_param command you gave could only be figured out if you understand the model xml. That being said, I highly suggest you avoid doing that if at all possible.

Christopher
Christopher 2013-5-21
Hi Ryan - thanks for your very quick response! We both figured out the same ;) So you would suggest to use SimMechanics Gen2? Would this solve my problem? Or the other way around: Is SimMechanics Gen2 more suitable for a programmatically creation of systems?
Thank you very very much for your help!!
Regards, Chris
  3 个评论
Christopher
Christopher 2013-6-19
Ok, I switched to SimMechanics Gen 2 but now I realized, it's not possible to simulate effects like friction or something like that. That means I have to use Gen 1. Do you know if it is possible to close Simulink Block Properties dialog boxes with saving the data? Then it would be possible. So I need a command to close the dialog boxes with a click on "OK" programmatically.
Kind regards, Chris
Ryan G
Ryan G 2013-6-19
What is the problem with simulating friction? How are you doing it in 1G that 2G can't do (I'm confident it can). I took a look at more options for the 1G port, but no luck.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Simscape Multibody 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by