-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Louise Poubel <[email protected]>
- Loading branch information
Showing
6 changed files
with
130 additions
and
61 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
8 changes: 5 additions & 3 deletions
8
examples/plugin/Hello_world/CMakeLists.txt → examples/plugin/hello_world/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,17 @@ | ||
cmake_minimum_required(VERSION 3.10.2 FATAL_ERROR) | ||
|
||
ign_find_package(ignition-cmake2 REQUIRED) | ||
find_package(ignition-cmake2 REQUIRED) | ||
|
||
project(Hello_world) | ||
|
||
find_package(ignition-plugin1 REQUIRED COMPONENTS register) | ||
ign_find_package(ignition-plugin1 REQUIRED COMPONENTS register) | ||
set(IGN_PLUGIN_VER ${ignition-plugin1_VERSION_MAJOR}) | ||
|
||
ign_find_package(ignition-gazebo4 REQUIRED) | ||
set(IGN_GAZEBO_VER ${ignition-gazebo4_VERSION_MAJOR}) | ||
|
||
add_library(HelloWorld SHARED HelloWorld) | ||
set_property(TARGET HelloWorld PROPERTY CXX_STANDARD 17) | ||
target_link_libraries(HelloWorld | ||
PRIVATE ignition-plugin${IGN_PLUGIN_VER}::ignition-plugin${IGN_PLUGIN_VER} | ||
PRIVATE ignition-gazebo4::ignition-gazebo4) | ||
PRIVATE ignition-gazebo${IGN_GAZEBO_VER}::ignition-gazebo${IGN_GAZEBO_VER}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright (C) 2021 Open Source Robotics Foundation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
// We'll use a string and the ignmsg command below for a brief example. | ||
// Remove these includes if your plugin doesn't need them. | ||
#include <string> | ||
#include <ignition/common/Console.hh> | ||
|
||
// This header is required to register plugins. It's good practice to place it | ||
// in the cc file, like it's done here. | ||
#include <ignition/plugin/Register.hh> | ||
|
||
// Don't forget to include the plugin's header. | ||
#include "HelloWorld.hh" | ||
|
||
// This is required to register the plugin. Make sure the interfaces match | ||
// what's in the header. | ||
IGNITION_ADD_PLUGIN( | ||
hello_world::HelloWorld, | ||
ignition::gazebo::System, | ||
hello_world::HelloWorld::ISystemPostUpdate) | ||
|
||
using namespace hello_world; | ||
|
||
// Here we implement the PostUpdate function, which is called at every | ||
// iteration. | ||
void HelloWorld::PostUpdate(const ignition::gazebo::UpdateInfo &_info, | ||
const ignition::gazebo::EntityComponentManager &/*_ecm*/) | ||
{ | ||
// This is a simple example of how to get information from UpdateInfo. | ||
std::string msg = "Hello, world! Simulation is "; | ||
if (!_info.paused) | ||
msg += "not "; | ||
msg += "paused."; | ||
|
||
// Messages printed with ignmsg only show when running with verbosity 3 or | ||
// higher (i.e. ign gazebo -v 3) | ||
ignmsg << msg << std::endl; | ||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Hello world | ||
|
||
This example contains the bare minimum that's necessary to create a Gazebo | ||
system plugin. | ||
|
||
## Build | ||
|
||
From the root of the `ign-gazebo` repository, do the following to build the example: | ||
|
||
~~~ | ||
cd ign-gazebo/examples/plugins/hello_world | ||
mkdir build | ||
cd build | ||
cmake .. | ||
make | ||
~~~ | ||
|
||
This will generate the `HelloWorld` library under `build`. | ||
|
||
## Run | ||
|
||
The plugin must be attached to an entity to be loaded. This is demonstrated in | ||
the `hello_world_plugin.sdf` file that's going to be loaded. | ||
|
||
Before starting Gazebo, we must make sure it can find the plugin by doing: | ||
|
||
~~~ | ||
cd ign-gazebo/examples/plugins/hello_world | ||
export IGN_GAZEBO_SYSTEM_PLUGIN_PATH=`pwd`/build | ||
~~~ | ||
|
||
Then load the example world: | ||
|
||
ign gazebo -v 3 hello_world_plugin.sdf | ||
|
||
You should see green messages on the terminal like: | ||
|
||
``` | ||
[Msg] Hello, world! Simulation is paused. | ||
``` | ||
|
||
Toggle the play / pause buttons to see the message change. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" ?> | ||
<sdf version="1.6"> | ||
<world name="default"> | ||
<!-- | ||
System plugins can be loaded from <plugin> tags attached to entities like | ||
the world, models, visuals, etc. | ||
--> | ||
<plugin filename="HelloWorld" name="hello_world::HelloWorld"> | ||
</plugin> | ||
</world> | ||
</sdf> |