Skip to content

Commit 07fdc7a

Browse files
committed
tutorial.md edited online with Bitbucket
1 parent 924e13f commit 07fdc7a

File tree

1 file changed

+44
-97
lines changed

1 file changed

+44
-97
lines changed

fluids/tutorial.md

Lines changed: 44 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,69 @@
1-
# Gazebo Fluid Simulation Plugin using the Fluidix library #
1+
# Introduction
22

33
The package allows the simulation of fluids in Gazebo. The fluid particle interactions are computed on the GPU
44
using the [Fluidix](http://onezero.ca/documentation/) library (if a nvidia GPU is not available the simulation will run in CPU mode).
55

6-
The fluid simulation runs as a separate physics engine which interacts with the rigid body physics engine of Gazebo through an interface (`include/FluidEngine.hh`). The interaction includes collision detection and the application of forces and torques from the fluid on the rigid objects.
6+
**Prerequisites:**
7+
* Get the package from [bitbucket](https://bitbucket.org/ahaidu/gz_fluid).
8+
* Install [CUDA](https://developer.nvidia.com/cuda-downloads) (recommended 6.0).
9+
* Install [Fluidix](http://onezero.ca/documentation/).
10+
* Go through the basic Gazebo tutorials, especially through [world plugins](http://gazebosim.org/tutorials?tut=plugins_world), [system plugins](http://gazebosim.org/tutorials?tut=system_plugin), [transport library](http://gazebosim.org/tutorials?cat=transport) examples.
11+
* For deeper understanding of the particle simulation look through some [Fluidix examples](http://onezero.ca/sample/?id=general_basic).
712

8-
The core of the fluid simulation is written in the `src/FluidEngine.cu` cuda file, it is built upon the [basic SPH example](http://onezero.ca/sample/?id=general_sph).
13+
# How the package works
914

10-
The package contains two plugins, one world plugin for updating the fluid and its interactions (`FluidWorldPlugin.cc`). And one client based system plugin for visualizing the fluid particles(`FluidVisPlugin.cc`).
15+
The fluid simulation runs as a separate physics engine which interacts with the rigid body physics engine of Gazebo through an interface (`include/FluidEngine.hh`).
16+
The interaction includes:
17+
* collision detection
18+
* forces / torques application on the rigid objects
19+
* visualization of the particles
1120

12-
### Installation requirements:
21+
The core of the fluid simulation is written in the `src/FluidEngine.cu` cuda file and it is built upon the [basic SPH example](http://onezero.ca/sample/?id=general_sph).
1322

14-
* Install [Gazebo](http://gazebosim.org/)
15-
* Install [CUDA](https://developer.nvidia.com/cuda-downloads) (recommended 6.0)
16-
* Install [Fluidix](http://onezero.ca/documentation/)
23+
The package contains two plugins, one world plugin for updating the fluid and its interactions (`FluidWorldPlugin.cc`). And one GUI system plugin for visualizing the fluid particles(`FluidVisPlugin.cc`).
1724

18-
### Buid instructions:
25+
## Build instructions
1926

27+
* in a terminal go to the downloaded `gz_fluid` folder and run the following commands
2028
* $ mkdir build
2129
* $ cd build
2230
* $ cmake ..
2331
* $ make
2432

25-
26-
### Running the plugin:
33+
## Running the plugin:
2734

2835
* set the gazebo plugin paths
2936
* add the plugin to your world file (e.g worlds/fluid.world), or use one of the world examples from the package
30-
* run gazebo server with the world plugin $ gzserver worlds/fluid.world
31-
* run gazebo client with the system plugin $ gzclient -g build/libFluidVisPlugin.so
37+
* run gazebo server with the world plugin:
38+
* $ gzserver worlds/fluid.world
39+
* run gazebo client with the system plugin:
40+
* $ gzclient -g build/libFluidVisPlugin.so
3241

3342

34-
### Changing simulation:
43+
## How to specify fluid parameters
3544

3645
* change fluid plugin parameters from the sdf tags:
3746
* `<world_position>` and `<world_size>` set the fluid worlds center position and its size
3847
* `<fluid_position>` and `<fluid_volume>` set the center position of the fluid and its volume to be filled with particles
3948
* `<particle_nr>` if set to `0`, the given volume will be filled with fluid particles, otherwise the given particle number will be spawned.
49+
50+
~~~
51+
<plugin name="FluidWorldPlugin" filename="libFluidWorldPlugin.so">
52+
<world_position>0 0 5.01</world_position>
53+
<world_size>1.5 1 10</world_size>
54+
<fluid_position>-0.5 0.0 0.8</fluid_position>
55+
<fluid_volume>0.4 0.95 0.5</fluid_volume>
56+
<particle_nr>0</particle_nr>
57+
</plugin>
58+
~~~
4059

4160
* by changing the source code from FluidWorldPlugin.cc
4261

4362

4463

64+
# To know:
4565

46-
### TODOs:
47-
48-
* implementing a newer SPH: [PCISPH](https://sph-sjtu-f06.googlecode.com/files/a40-solenthaler.pdf) or [IISPH](http://cg.informatik.uni-freiburg.de/publications/2013_TVCG_IISPH.pdf) for faster simulation and no compression of the fluid. This can be done in the `src/FluidEngine.cu` file by changing the algorithm.
49-
50-
* currently the simulation only has the box implemented as a standard shape, see `FluidEngine::AddMovableBox` from `src/FluidEngine.cu`, it is implemented similarly to this [example](http://onezero.ca/sample/?id=init_manual). Using the same idea the rest of the collision types can be implemented as well: cylinder, sphere, plane. After implementation these need to be added in the `FluidWorldPlugin::CreateFluidCollision` method, similarly to the `box` type.
51-
52-
* the force and torque interaction is done via the particle collisions, pressure force from the liquid is not taken into account.
53-
54-
### To know:
66+
### Collisions meshes
5567

5668
* in order for the fluid simulation to detect collisions gazebo needs to use `.stl` files for collision.
5769

@@ -61,96 +73,31 @@ The package contains two plugins, one world plugin for updating the fluid and it
6173
* in CMakeLists.txt, the cuda compiler might need graphics card specific flags:
6274

6375
`SET(CUDA_NVCC_FLAGS "-arch;sm_30 -use_fast_math -lm -ldl -lrt -Xcompiler \"-fPIC\"")`
64-
76+
6577
### Some code explanation:
6678

6779
* The world plugin `FluidWorldPlugin.cc`:
80+
6881
* in the constructor the fluid engine is initialized
6982
* in `FluidWorldPlugin::Load` the sdf parameters are loaded, the fluid world is created, fluid is added, the objects from the environment are recreated in the fluid environment (when possible)
7083
* in `FluidWorldPlugin::Init` the publishers of the objects and fluids particles positions are initialized
7184
* `FluidWorldPlugin::OnUpdate` is called every world update event, there the fluid engine is updated one timestamp, a msg is sent for the rendering plugin with all the new particles position, and computed forces and torques are applied on the rigid objects.
7285

7386
* The system plugin `FluidVisPlugin.cc`, used for rendering the fluid:
87+
7488
* in `FluidVisPlugin::Load` the arguments (if given) are loaded for the type of rendering, `sphere` or default `point`. When sphere is selected the rendering gets slower if many particles are loaded.
7589
* in `FluidVisPlugin::Init` the subscribes for the fluid particle positions are loaded.
7690
* in `FluidVisPlugin::RenderAsPointsUpdate` or `FluidVisPlugin::RenderAsSpheresUpdate`, (depending on the rendering type) if a new message with the particle positions is available, these will be rendered.
7791

78-
* The fluid simulation engine `FluidEngine.cc`:
79-
80-
81-
82-
83-
84-
85-
86-
87-
88-
89-
90-
92+
* The fluid simulation engine `FluidEngine.cu` is similar to the SPH example from Fluidix.
9193

92-
# Overview
9394

94-
**Prerequisites:** [Attach a Mesh as Visual](http://gazebosim.org/tutorials/?tut=attach_meshes)
9595

96-
This tutorials demonstrates how the user can create composite models directly from other models in the [Gazebo Model Database](http://gazebosim.org/user_guide/started__models__database.html) by using the `<include>` tags and [`<joint>`](http://gazebosim.org/sdf/1.4.html#joint309) to connect different components of a composite model.
96+
# Unfinished parts, TODOs:
97+
If somebody is interested in further contributing to the package, many features still need work:
9798

98-
## Adding a Laser
99-
100-
Adding a laser to a robot, or any model, is simply a matter of including the sensor in the model.
101-
102-
1. Go into your model directory from the previous tutorial:
103-
104-
cd ~/.gazebo/models/my_robot
105-
106-
1. Open `model.sdf` in your favorite editor.
107-
108-
1. Add the following lines directly before the `</model>` tag near the end of the file.
109-
110-
~~~
111-
<include>
112-
<uri>model://hokuyo</uri>
113-
<pose>0.2 0 0.2 0 0 0</pose>
114-
</include>
115-
<joint name="hokuyo_joint" type="revolute">
116-
<child>hokuyo::link</child>
117-
<parent>chassis</parent>
118-
<axis>
119-
<xyz>0 0 1</xyz>
120-
<limit>
121-
<upper>0</upper>
122-
<lower>0</lower>
123-
</limit>
124-
</axis>
125-
</joint>
126-
~~~
127-
128-
The `<include>` block tells Gazebo to find a model, and insert it at a given `<pose>` relative to the parent model. In this case we place the hokuyo laser forward and above the robot. The `<uri>` block tells gazebo where to find the model inside its model database (note, you can see a listing of the model database uri used by these tutorials at [here](http://gazebosim.org/models/), and the corresponding [mercurial repository](https://bitbucket.org/osrf/gazebo_models).
129-
130-
The new `<joint>` connects the inserted hokuyo laser onto the chassis of the robot. The joint has and `<upper>` and `<lower>` limit of zero to prevent it from moving.
131-
132-
The `<child>` name in the joint is derived from the [hokuyo model's SDF](https://bitbucket.org/osrf/gazebo_models/src/6cd587c0a30e/hokuyo/model.sdf?at=default), which begins with:
133-
134-
~~~
135-
<?xml version="1.0" ?>
136-
<sdf version="1.4">
137-
<model name="hokuyo">
138-
<link name="link">
139-
~~~
140-
141-
When the hokuyo model is inserted, the hokuyo's links are namespaced with their model name. In this case the model name is `hokuyo`, so each link in the hokuyo model is prefaced with `hokuyo::`.
142-
143-
1. Now start gazebo, and add the robot to the simulation using the Insert tab on the GUI. You should see the robot with a laser attached.
144-
145-
[[file:files/Add_laser_pioneer.png|640px]]
146-
147-
1. (Optional) Try adding a camera to the robot. The camera's model URI is `model://camera`, it should have been locally caches for you in:
148-
149-
ls ~/.gazebo/models/camera/
150-
151-
152-
For reference, the SDF documentation can be found [here](http://gazebosim.org/sdf/).
99+
* implementing a newer SPH: [PCISPH](https://sph-sjtu-f06.googlecode.com/files/a40-solenthaler.pdf) or [IISPH](http://cg.informatik.uni-freiburg.de/publications/2013_TVCG_IISPH.pdf) for faster simulation and no compression of the fluid. This can be done in the `src/FluidEngine.cu` file by changing the algorithm.
153100

154-
## Next
101+
* currently the simulation only has the box implemented as a standard shape, see `FluidEngine::AddMovableBox` from `src/FluidEngine.cu`, it is implemented similarly to this [example](http://onezero.ca/sample/?id=init_manual). Using the same idea the rest of the collision types can be implemented as well: cylinder, sphere, plane. After implementation these need to be added in the `FluidWorldPlugin::CreateFluidCollision` method, similarly to the `box` type.
155102

156-
[Next: Make a Simple Gripper](http://gazebosim.org/tutorials/?tut=simple_gripper)
103+
* the force and torque interaction is done via the particles surface collisions, pressure force from the liquid is not taken into account. A fancier algorithm would greatly increase realism.

0 commit comments

Comments
 (0)