This tutorial demonstrates building a custom world using SDF. It also provides a simple example on how to sense object interactions and manipulate object color using the simulation world API.
We assume that you have already completed the installation step and the world API tutorials.
The full world API documentation can be found here.
The documentation for building a Gazebo world using SDF format can be found here.
First, build a world using SDF:
Error: Unable to access https://github.com/osrf/gazebo_tutorials/raw/haptix_world_sim_api/haptix_world_sim_api/files/custom_haptix.world
Note that this world file is very similar to the default arat.world, with the main difference being the addition of the sphere_visual_model
:
<model name="sphere_visual_model">
<pose>0.4 0.0 1.2 0 0 3.1416</pose>
<link name="sphere_link">
<visual name="sphere_visual">
<geometry>
<sphere>
<radius>0.03</radius>
</sphere>
</geometry>
<material>
<script>
<uri>file://media/materials/scripts/gazebo.material</uri>
<name>Gazebo/Green</name>
</script>
</material>
</visual>
<collision name="sphere_visual">
<geometry>
<sphere>
<radius>0.03</radius>
</sphere>
</geometry>
</collision>
</link>
<static>1</static>
</model>
Next, write a simple Octave/Matlab to sense contact state on the visual sphere model, and change the color of the sphere from green to red when it comes into contact with other objects:
Error: Unable to access https://github.com/osrf/gazebo_tutorials/raw/haptix_world_sim_api/haptix_world_sim_api/files/custom_world.m
Download tutorial files:
Using the same world as the Matlab example above, and write a simple C code to sense contact state on the visual sphere model, and change the color of the sphere from green to red when it comes into contact with other objects:
Error: Unable to access https://github.com/osrf/gazebo_tutorials/raw/haptix_world_sim_api/haptix_world_sim_api/files/custom_world.c
Build custom_world.c
as you would with any Haptix C API code as shown in Compile section under the Haptix C API tutorial.
Download tutorial files:
To run the example, start gazebo in terminal:
gazebo custom_haptix.world
First see world API tutorial Example section on how to run Matlab or Octave scripts.
Next, invoke the custom_world.m
script in Matlab or Octave command prompt
and the sphere should change color from green to red as the hand passes through it:
Hint for linux users, at octave or matlab prompt, add path to haptix scripts:
path('[replace with your path to install]/lib/x86_64-linux-gnu/haptix-comm/octave', path)
path('[replace with path to your custom_world.m]', path)
before running custom_world.m
.
Run compiled binary from custom_world.c
as you would with any Haptix C API code as shown in Running the simulation section under the Haptix C API tutorial.