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

Update gazebo scene viewer tutorial #147

Merged
merged 2 commits into from
Sep 28, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion examples/gazebo_scene_viewer/CameraWindow.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
#include <ignition/rendering/Camera.hh>
#include <ignition/rendering/Image.hh>
#include <ignition/rendering/Scene.hh>
#include <ignition/rendering.hh>

#include "SceneManager.hh"

Expand Down
6 changes: 5 additions & 1 deletion examples/gazebo_scene_viewer/GazeboDemo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
#include <gazebo/common/Console.hh>
#include <gazebo/transport/TransportIface.hh>

#include <ignition/rendering.hh>
#include <ignition/rendering/Camera.hh>
#include <ignition/rendering/RenderingIface.hh>
#include <ignition/rendering/RenderEngine.hh>
#include <ignition/rendering/Scene.hh>
#include <ignition/rendering/Visual.hh>

#include "CameraWindow.hh"
#include "SceneManager.hh"
Expand Down
6 changes: 5 additions & 1 deletion examples/gazebo_scene_viewer/GazeboWorldDemo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
#include <ignition/common/Console.hh>
#include <gazebo/transport/TransportIface.hh>

#include <ignition/rendering.hh>
#include <ignition/rendering/Camera.hh>
#include <ignition/rendering/RenderingIface.hh>
#include <ignition/rendering/RenderEngine.hh>
#include <ignition/rendering/Scene.hh>
#include <ignition/rendering/Visual.hh>

#include "CameraWindow.hh"
#include "SceneManager.hh"
Expand Down
13 changes: 8 additions & 5 deletions examples/gazebo_scene_viewer/SceneManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
#include <ignition/common/MeshManager.hh>
#include <ignition/common/Console.hh>
#include <ignition/math/Helpers.hh>
#include <ignition/rendering.hh>

#include <ignition/rendering/Camera.hh>
#include <ignition/rendering/Scene.hh>
#include <ignition/rendering/Visual.hh>

#include "SceneManager.hh"
#include "SceneManagerPrivate.hh"
Expand Down Expand Up @@ -1812,8 +1815,8 @@ CurrentSceneManager::~CurrentSceneManager()
void CurrentSceneManager::OnPoseUpdate(::ConstPosesStampedPtr &_posesMsg)
{
// record pose timestamp
this->timePosesReceived = math::secNsecToDuration(
_posesMsg->time().sec(), _posesMsg->time().nsec());
this->timePosesReceived = std::chrono::seconds(_posesMsg->time().sec()) +
std::chrono::nanoseconds(_posesMsg->time().nsec());
chapulina marked this conversation as resolved.
Show resolved Hide resolved

// process each pose in message
for (int i = 0; i < _posesMsg->pose_size(); ++i)
Expand Down Expand Up @@ -2051,8 +2054,8 @@ void NewSceneManager::ProcessPoses()
void NewSceneManager::ProcessPoses(const gazebo::msgs::PosesStamped &_posesMsg)
{
// record pose timestamp
this->timePosesReceived = math::secNsecToDuration(
_posesMsg.time().sec(), _posesMsg.time().nsec());
this->timePosesReceived = std::chrono::seconds(_posesMsg.time().sec()) +
std::chrono::nanoseconds(_posesMsg.time().nsec());

// process each pose in list
for (int i = 0; i < _posesMsg.pose_size(); ++i)
Expand Down
42 changes: 21 additions & 21 deletions tutorials/11_gazebo_scene_viewer_tutorial.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,6 @@
\page gazebo_scene_viewer Gazebo scene viewer

The Gazebo scene viewer examples allow us to visualize Gazebo using the Ignition Rendering library.

## Code

The `SceneManager` class defined in `SceneManager.hh`, `SceneManagerPrivate.hh` and `SceneManager.cc` manages a collection of scenes.
The class provides a single interface for modifications, allowing multiple scenes to stay synchronized.
It will allow us to receive data from Gazebo and update the render window each time that the examples receive a new scene. **This class currently consumes Gazebo-specific protobuf messages**.

The following list will describe some methods:

- **void SceneManagerPrivate::Init()**: It initializes the communication with Gazebo. It will create some subscribers to receive data about poses, light, models, joints, visual or sensors.

\snippet examples/gazebo_scene_viewer/SceneManager.cc init scene manager

- **void SubSceneManager::ProcessMessages()**: This method will process the messages received from Gazebo. Calling the right primitive to render lights, models, joints, visuals, sensors or poses of the different object received.
\snippet examples/gazebo_scene_viewer/SceneManager.cc process message
For example, if the Gazebo scene contains a cylinder the following method will be called:
\snippet examples/gazebo_scene_viewer/SceneManager.cc process cylinder

- **void CurrentSceneManager::OnPoseUpdate(::ConstPosesStampedPtr &_posesMsg)**: This method is called when the subscriber receives a new pose message.
\snippet examples/gazebo_scene_viewer/SceneManager.cc on update pose
The Gazebo scene viewer examples allow us to visualize Gazebo simulation using the Ignition Rendering library.

## Compile and run the example

Expand Down Expand Up @@ -70,3 +50,23 @@ Launch the example to visualize the objects:
You can use the `Tab` button to change the rendering engine.

![](img/gazebo_scene_viewer2_demo.gif)
chapulina marked this conversation as resolved.
Show resolved Hide resolved

## Code

The `SceneManager` class defined in `SceneManager.hh`, `SceneManagerPrivate.hh` and `SceneManager.cc` manages a collection of scenes.
The class provides a single interface for modifications, allowing multiple scenes to stay synchronized.
It will allow us to receive data from Gazebo and update the render window each time that the examples receive a new scene. **This class currently consumes Gazebo-specific protobuf messages**.

The following list will describe some methods:

- **void SceneManagerPrivate::Init()**: It initializes the communication with Gazebo. It will create some subscribers to receive data about poses, light, models, joints, visual or sensors.

\snippet examples/gazebo_scene_viewer/SceneManager.cc init scene manager

- **void SubSceneManager::ProcessMessages()**: This method will process the messages received from Gazebo. Calling the right primitive to render lights, models, joints, visuals, sensors or poses of the different object received.
\snippet examples/gazebo_scene_viewer/SceneManager.cc process message
For example, if the Gazebo scene contains a cylinder the following method will be called:
\snippet examples/gazebo_scene_viewer/SceneManager.cc process cylinder

- **void CurrentSceneManager::OnPoseUpdate(::ConstPosesStampedPtr &_posesMsg)**: This method is called when the subscriber receives a new pose message.
\snippet examples/gazebo_scene_viewer/SceneManager.cc on update pose