Add Port to SimMechanics Body Block programmatically

2 views (last 30 days)
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!

Answers (2)

Ryan G
Ryan G on 17 May 2013
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 on 21 May 2013
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 Comments
Christopher
Christopher on 19 Jun 2013
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 on 19 Jun 2013
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.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!