Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New tutorial on track_visual #102

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
7 changes: 7 additions & 0 deletions manifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,12 @@
<skill>beginner</skill>
</tutorial>

<tutorial title="Tracking visuals" ref='track_visual'>
<markdown version="7.0+">track_visual/tutorial.md</markdown>
<description>Use the graphical interface or SDF files to track visuals with the user camera.</description>
<skill>beginner</skill>
</tutorial>

<tutorial title="Instrument HDF5 Datasets" ref='instrument_hdf5_datasets'>
<markdown version="1.9+">instrument_hdf5_datasets/tutorial.md</markdown>
<description>How to dump simulation data into HDF5 format for benchmark.</description>
Expand Down Expand Up @@ -1032,6 +1038,7 @@
<tutorial>log_filtering</tutorial>
<tutorial>apply_force_torque</tutorial>
<tutorial>instrument_hdf5_datasets</tutorial>
<tutorial>track_visual</tutorial>
</tutorials>
</category>

Expand Down
102 changes: 102 additions & 0 deletions track_visual/files/track_visual.world
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?xml version="1.0" ?>
<sdf version="1.6">
<world name="default">
<!-- A global light source -->
<include>
<uri>model://sun</uri>
</include>
<!-- A ground plane -->
<include>
<uri>model://ground_plane</uri>
</include>

<gui>
<camera name="user_camera">
<pose>-2 0 2 0 0 0</pose>
<track_visual>
<name>box</name>
<static>false</static>
<min_dist>0</min_dist>
<max_dist>8</max_dist>
</track_visual>
</camera>
</gui>

<model name="box">
<pose>0 0 0.5 0 0 0</pose>
<link name="link">
<kinematic>true</kinematic>
<collision name="collision">
<geometry>
<box>
<size>1 1 1</size>
</box>
</geometry>
<surface>
<friction>
<ode>
<mu>0.0</mu>
<mu2>0.0</mu2>
</ode>
</friction>
</surface>
</collision>
<visual name="visual">
<geometry>
<box>
<size>1 1 1</size>
</box>
</geometry>
</visual>
</link>

<!-- Apply a random velocity to the specified link-->
<!-- In this example, we move a box around. A key property of the link
is the frictionless surface -->
<plugin name="random" filename="libRandomVelocityPlugin.so">

<!-- Name of the link in this model that receives the velocity -->
<link>link</link>

<!-- Initial velocity that is applied to the link -->
<initial_velocity>0 0.5 0</initial_velocity>

<!-- Scaling factor that is used to compute a new velocity -->
<velocity_factor>0.5</velocity_factor>

<!-- Time, in seconds, between new velocities -->
<update_period>5</update_period>

<!-- Clamp the Z velocity value to zero. You can also clamp x and
y values -->
<min_z>0</min_z>
<max_z>0</max_z>
</plugin>
</model>

<model name="sphere">
<pose>4 2 0.5 0 0 0</pose>
<link name="link">
<collision name="collision">
<geometry>
<sphere>
<radius>0.5</radius>
</sphere>
</geometry>
</collision>
<visual name="visual">
<geometry>
<sphere>
<radius>0.5</radius>
</sphere>
</geometry>
</visual>
</link>

<plugin name="initial" filename="libInitialVelocityPlugin.so">
<linear>0 0 0</linear>
<angular>0 0 1</angular>
</plugin>
</model>
</world>
</sdf>
Binary file added track_visual/files/tutorialGUIExpanded.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
136 changes: 136 additions & 0 deletions track_visual/tutorial.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
# Overview

This tutorial demonstrates how you can track a visual with the user camera by
using the SDF `<track_visual>` tag or the GUI.

## Quick start

1. Let's start by creating a directory for this tutorial:

~~~
mkdir ~/tutorial_track_visual
cd ~/tutorial_track_visual
~~~

2. Download this file:
[`track_visual.world`](http://bitbucket.org/osrf/gazebo_tutorials/raw/default/track_visual/files/track_visual.world)
into the current directory. You can use this command:

~~~
wget http://bitbucket.org/osrf/gazebo_tutorials/raw/default/track_visual/files/track_visual.world
~~~

You should get this world file:

<include src='http://bitbucket.org/osrf/gazebo_tutorials/raw/default/track_visual/files/track_visual.world' />

3. Start gazebo:

~~~
gazebo track_visual.world
~~~

You should see a cube moving randomly around the world's origin.

## The world explained

Let's go further and understand the different elements of the `track_visual.world`.

<include from='/ <gui/' to='/</name>/' src='http://bitbucket.org/osrf/gazebo_tutorials/raw/default/track_visual/files/track_visual.world' />

Within the `track_visual` tag, you can see how to select a visual by specifying a `<name>` tag. The visual will be tracked from startup. The camera will follow the model by changing its orientation.

<include from='/ <static/' to='/</max_dist>/' src='http://bitbucket.org/osrf/gazebo_tutorials/raw/default/track_visual/files/track_visual.world' />

Because `<static>` is set to `false`, the position of the camera may vary but the distance between the camera and the model origin will depend on the value of the `min_dist` and `max_dist` elements.

Now change `<static>` to `true`:

<gui>
<camera name="user_camera">
<track_visual>
<name>box</name>
<static>true</static>
</track_visual>
</camera>
</gui>

Relaunch Gazebo. The position of the camera is now fixed relatively to the model being tracked.

By default, the camera is located 5 meters behind and 1 meter above the model. Try changing its location by specifying a `<xyz>` tag:

<gui>
<camera name="user_camera">
<track_visual>
<name>box</name>
<static>true</static>
<xyz>3 2 5</xyz>
</track_visual>
</camera>
</gui>

Relaunch Gazebo. The camera is now located 3 meters in front, 2 meters to the left, and 5 meters above the tracked model.

Finally, we introduce the `<use_model_frame>` tag whose default value is `true`. When the `<static>` tag is `true`, this element specifies whether the coordinates provided by `<xyz>` are relative to the model reference frame or the world reference frame. Try changing the value of the `<use_model_frame>` tag:

<gui>
<camera name="user_camera">
<track_visual>
<name>box</name>
<static>true</static>
<use_model_frame>false</use_model_frame>
<xyz>0 0 10</xyz>
</track_visual>
</camera>
</gui>

Relaunch Gazebo. The camera is now staying 10 meters above the origin.

To illustrate the last element `<inherit_yaw>`, we will track a sphere instead of a cube. Change `<name>` to `sphere` and make sure that `<static>` and `<use_model_frame>` are set to `true`:

<gui>
<camera name="user_camera">
<track_visual>
<name>sphere</name>
<static>true</static>
<use_model_frame>true</use_model_frame>
<xyz>-3 0 0</xyz>
</track_visual>
</camera>
</gui>

Relaunch Gazebo. You should now see a sphere rotating in front of the camera. By default, the camera is configured to ignore the pitch, roll and yaw of the model. To inherit the yaw rotation of the visual, simply set the `<inherit_yaw>` tag to `true`:

<gui>
<camera name="user_camera">
<track_visual>
<name>sphere</name>
<static>true</static>
<use_model_frame>true</use_model_frame>
<xyz>-3 0 0</xyz>
<inherit_yaw>true</inherit_yaw>
</track_visual>
</camera>
</gui>

Relaunch Gazebo. The camera should now rotate around the sphere as it turns around.

Below is the complete list of elements that can be set within `<track_visual>`:

* `<name>`: Name of the tracked visual. If no name is provided, the remaining settings will be applied whenever tracking is triggered in the GUI. This parameter is never ignored.
* `<static>`: If set to `true`, the position of the camera is fixed relatively to the model or to the world, depending on the value of the `<use_model_frame>` element. Otherwise, the position of the camera may vary but the distance between the camera and the model will depend on the value of the `<min_dist>` and `<max_dist>` elements. In any case, the camera will always follow the model by changing its orientation. This parameter is never ignored.
* `<min_dist>`: Minimum distance between the camera and the tracked visual. This parameter is ignored when `<static>` is `true`.
* `<max_dist>`: Maximum distance between the camera and the tracked visual. This parameter is ignored when `<static>` is `true`.
* `<use_model_frame>`: If set to `true`, the position of the camera is relative to the model reference frame, which means that its position relative to the model will not change. Otherwise, the position of the camera is relative to the world reference frame, which means that its position relative to the world will not change. This parameter is ignored when `<static>` is `false`.
* `<xyz>`: The position of the camera's reference frame. If `<use_model_frame>` is set to `true`, the position is relative to the model reference frame, otherwise it represents world coordinates. This parameter is ignored when `<static>` is `false`.
* `<inherit_yaw>`: If set to `true`, the camera will inherit the yaw rotation of the tracked model. This parameter is ignored when `<static>` is `false` or when `<use_model_frame>` is `false`. In other words, it is only used if `<static>` and `<use_model_frame>` are both `true`.

## Dynamic Reconfigure

The camera properties can be adjusted dynamically within Gazebo.

In the `World` tab, select the `GUI` item. A list of GUI properties will be displayed in the list box below. Click the triangle to expand the properties if needed.

[[file:files/tutorialGUIExpanded.png|257px]]

These properties allow you to dynamically change the parameters defined in `<track_visual>`. They will be applied whenever a model is being followed by the camera.