Editing MGED CMD simulate

From BRL-CAD

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 1: Line 1:
 
[[category:tutorials]]
 
[[category:tutorials]]
  
BRL-CAD recently integrated a new command into '''mged''', the '''simulate''' command, which allows for rigid-body physics simulations. This tutorial demonstrates the usage of the '''simulate''' command with a simple scene.
+
BRL-CAD recently integrated a new command in its mged tool, the simulate command. Those are the steps one should follow in order to run a simulation in the mged tool.
  
{|align="right"
+
First open the mged tool, if you have BRL-CAD installed on your Linux system it should be easy, just type mged in a terminal and a mged terminal should open.
|[[Image:Simulation_1.png|thumb|256px|Cube falling to the ground plane modeled and rendered in BRL-CAD]]
 
|}
 
  
First, open the '''mged''' interface and create a new database. Next we want to add some geometry to the database. In the command window we will now type the following series of commands:
 
<br>
 
 
{|align="left"
 
{|align="left"
 
  |<pre>
 
  |<pre>
mged> units m
+
brlcad@brlcad: mged
mged> in cube.s rpp -1 1 -1 1 -1 1
 
mged> r cube.r u cube.s
 
mged> attr set cube.r simulate::type region
 
 
</pre>
 
</pre>
 
|}
 
|}
<br style="clear: both" />
 
This will create a cube primitive and a containing region. We will use the region later to apply material appearances. We also set the '''simulate::type''' attribute so that the '''simulate''' command regards all primitives within this region as one object.
 
  
<br style="clear: both" />
+
In the mged terminal select the File menu, and then on the New... (file dialog button). A window will appear and a name for your new database will be required. For the purpose of this tutorial we will name the new database, sim1. Introduce the chosen name (sim1) in the "File name:" field and hit save.
Now we want to add a fixed "ground" object to our simulation. BRL-CAD's simulated gravity acts in the ''x''-''y'' axis, so our ground plane should be parallel to this axis.
+
Now you have opened a new database. Next we want to add some geometry to the database. Something that we will have to simulate on.  
<br>
+
In the mged command window we will now type the following series of commands :
 +
 
 
{|align="left"
 
{|align="left"
 
  |<pre>
 
  |<pre>
mged> in ground.s rpp -15 15 -15 15 -1 1
+
mged> in
mged> r ground.r u ground.s
+
Enter name of solid: box
mged> attr set ground.r simulate::type region
+
Enter solid type: rpp
 +
Enter XMIN, XMAX, YMIN, YMAX, ZMIN, ZMAX: -1 1 0 5 -1 1
 
</pre>
 
</pre>
 
|}
 
|}
  
<br style="clear: both" />
+
The "in" command creates new geometry, it allows the user to type in the arguments to create a shape with the name provided by the second argument, in the example above is the name provided when "Enter name of solid:" appears on the screen. The arguments of the in command can be provided one by one, as in the example above or in one single line, like in the example below:
  
We will also add an attribute specifying that this object's position is fixed:
 
<br>
 
 
{|align="left"
 
{|align="left"
 
  |<pre>
 
  |<pre>
mged> attr set ground.r simulate::mass 0.0
+
mged> in box rpp -1 1 0 5 -1 1
 
</pre>
 
</pre>
 
|}
 
|}
<br style="clear: both" />
 
  
We can also give the cube an initial angular velocity (linear velocity can be applied in a similar way):
+
We have so far a box, now we want to add a ground plane to our simulation.
<br>
+
 
 +
 
 
{|align="left"
 
{|align="left"
 
  |<pre>
 
  |<pre>
mged> attr set cube.r simulate::angular_velocity <2.0,-1.0,3.0>
+
mged> in ground rpp -15 15 -1 1 -15 15
 
</pre>
 
</pre>
 
|}
 
|}
<br style="clear: both" />
 
  
Now we will add some material appearances to the objects:
+
You should see now 2 boxes on your screen, one perpendicular on the other one, with a little overlap between them.
<br>
+
Using the sed command we will select the box and translate it 100 units on the Y axis.
 +
 
 
{|align="left"
 
{|align="left"
 
  |<pre>
 
  |<pre>
mged> mater cube.r "plastic {tr 0.2 re 0.2}" 255 0 0 y
+
mged> sed box
mged> mater ground.r "plastic {tr 0.2 re 0.2}" 0 0 255 y
+
mged> tra 0 100 0
 +
mged> accept
 
</pre>
 
</pre>
 
|}
 
|}
<br style="clear: both" />
 
  
To specify our simulated system we will define a combination containing both objects. This combination will be modified in-place during the simulation.
+
To be able to run the simulate command our geometry shapes should be grouped in regions to do this we will use the "r" command and create 2 regions for the box and the ground shapes.
We will also change the units of gravity for the simulation to be
+
 
acceleration in mm/s/s due to the small scale of our model.
 
<br>
 
 
{|align="left"
 
{|align="left"
 
  |<pre>
 
  |<pre>
mged> comb system.c u cube.r u ground.r
+
mged> r region1.r u box
mged> attr set system.c simulate::gravity <0,0,-9.80665>
+
mged> r region2.r u ground
 
</pre>
 
</pre>
 
|}
 
|}
<br style="clear: both" />
 
  
We will now select the cube and translate it 50 units "up" along the ''y''-axis.
+
Now we are ready to run the simulate command:
<br>
+
 
 
{|align="left"
 
{|align="left"
 
  |<pre>
 
  |<pre>
mged> B system.c
+
mged> simulate 100
mged> oed /system.c/cube.r cube.s
 
mged> tra 0 0 50
 
mged> accept
 
 
</pre>
 
</pre>
 
|}
 
|}
<br style="clear: both" />
 
  
In order to see what we did so far we should set the view for the geometry we have so far. We will use an "ae 35 15", that means the azimuth angle is at 35 degrees and the elevation at 15 degrees. The angle of elevation of an object as seen by an observer is the angle between the horizontal and the line from the object to the observer's eye (the line of sight).The azimuth of an object is the angular distance along the horizon to the location of the object.We will use "autoview" command to reset the view size and the view center such that all displayed objects are within the view. And then we will do a translation on the Y axis.
+
After the simulation runs its course, we will use the "who" command to find out what objects are being displayed.
<br>
+
 
 
{|align="left"
 
{|align="left"
 
  |<pre>
 
  |<pre>
mged> ae 35 15
+
mged> who
mged> autoview
 
mged> tra 0 10 0
 
 
</pre>
 
</pre>
 
|}
 
|}
<br style="clear: both" />
+
 
Now we can save this view for later:
+
You should get the following answer:
<br>
+
 
 
{|align="left"
 
{|align="left"
 
  |<pre>
 
  |<pre>
mged> saveview ae3515.rt
+
box ground sim.c
 
</pre>
 
</pre>
 
|}
 
|}
<br style="clear: both" />
 
  
Now we are ready to run the simulate command. To preserve our configuration we will first create a copy of our combination.
+
Now, we don't really want to display the box and the ground shapes, we already have them in the sim.c group so we will unload all the geometry(using the "Z" command) and will load only the simulate geometry(using the "draw sim.c" command).
<br>
+
 
 
{|align="left"
 
{|align="left"
 
  |<pre>
 
  |<pre>
mged> cp system.c output.c
+
mged> Z
mged> B output.c
+
mged> draw sim.c
mged> simulate output.c 10.0
 
 
</pre>
 
</pre>
 
|}
 
|}
<br style="clear: both" />
 
This will evaluate 10 seconds of simulated physics.
 
  
In order to create an animation from your simulation, you will have to run the script below (note that it requires ImageMagick): (in progress)
+
 
 +
Now to actually see the simulation we will raytrace it, using the "rt" command.
 +
 
 +
{|align="left"
 +
|<pre>
 +
mged> rt
 +
</pre>
 +
|}

Please note that all contributions to BRL-CAD may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see BRL-CAD:Copyrights for details). Do not submit copyrighted work without permission!

To edit this page, please answer the question that appears below (more info):

Cancel Editing help (opens in new window)