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

Automatically load a subset of world plugins #281

Merged
merged 32 commits into from
Jan 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
e5d87c5
Separate plugin loading and test loading plugins from the ServerConfig
mjcarroll Feb 21, 2020
501e2a9
Add ability to parse plugin info from string/file and load defaults
mjcarroll Feb 21, 2020
5dc0e2a
Remove default plugins from default.sdf
mjcarroll Feb 21, 2020
1cc4176
Document new functions
mjcarroll Mar 16, 2020
ce20b1e
Remove references to GazeboServer
mjcarroll Mar 16, 2020
85a5be4
Move systems.config to server.config
mjcarroll Mar 16, 2020
f0626f2
Address reviewer feedback
mjcarroll Mar 16, 2020
2c384d7
Code check
mjcarroll Sep 9, 2020
01371ea
Update references to systems to server
mjcarroll Sep 9, 2020
69125c5
Add test configurations.
mjcarroll Sep 18, 2020
87be264
Address reviewer feedback
mjcarroll Sep 18, 2020
a35b04f
Address reviewer feedback and add playback config
mjcarroll Oct 9, 2020
8e89c7f
Fix compilation, remove plugins from an example
chapulina Oct 13, 2020
6393452
Tutorial and tweaks for server config (#405)
chapulina Oct 14, 2020
ae64edb
Update enviornment variable and place in utils
mjcarroll Oct 21, 2020
3aec604
Apply suggestions from code review
mjcarroll Oct 21, 2020
d3fa176
server_playback -> playback_server
mjcarroll Oct 21, 2020
a0b1af4
Remove "resolved" variable
mjcarroll Oct 21, 2020
af0a710
Update error message
mjcarroll Oct 21, 2020
0a4e2d8
Fixup things using Util include
mjcarroll Oct 21, 2020
21b8245
Use common facilities
mjcarroll Oct 21, 2020
e16830d
Reviewer feedback.
mjcarroll Nov 9, 2020
ef6a115
Fix 2 tests
mjcarroll Nov 16, 2020
c974174
Fixup log recording/playback interactions
mjcarroll Dec 18, 2020
1af9321
Linting, documentation, remove debug output
mjcarroll Dec 18, 2020
f939b42
Lint and remove dead code
mjcarroll Dec 18, 2020
79d3a2d
Suggestions to #281 (#508)
chapulina Dec 23, 2020
6e76e7c
Fix logging interaction with loading
mjcarroll Dec 23, 2020
b1597ac
Revert "Fix logging interaction with loading"
mjcarroll Jan 4, 2021
1961be0
Fix log interactions with default plugin loading
mjcarroll Jan 5, 2021
b36e403
Fix codecheck/lint
mjcarroll Jan 5, 2021
8e40b07
Address reviewer feedback
mjcarroll Jan 6, 2021
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
12 changes: 0 additions & 12 deletions examples/worlds/default.sdf
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,6 @@
<max_step_size>0.001</max_step_size>
<real_time_factor>1.0</real_time_factor>
</physics>
<plugin
filename="ignition-gazebo-physics-system"
name="ignition::gazebo::systems::Physics">
</plugin>
<plugin
filename="ignition-gazebo-user-commands-system"
name="ignition::gazebo::systems::UserCommands">
</plugin>
<plugin
filename="ignition-gazebo-scene-broadcaster-system"
name="ignition::gazebo::systems::SceneBroadcaster">
</plugin>

<light type="directional" name="sun">
<cast_shadows>true</cast_shadows>
Expand Down
17 changes: 0 additions & 17 deletions examples/worlds/shapes.sdf
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,6 @@ Try moving a model:
-->
<sdf version="1.6">
<world name="shapes">
<physics name="1ms" type="ignored">
<max_step_size>0.001</max_step_size>
<real_time_factor>1.0</real_time_factor>
</physics>
<plugin
filename="ignition-gazebo-physics-system"
name="ignition::gazebo::systems::Physics">
</plugin>
<plugin
filename="ignition-gazebo-user-commands-system"
name="ignition::gazebo::systems::UserCommands">
</plugin>
<plugin
filename="ignition-gazebo-scene-broadcaster-system"
name="ignition::gazebo::systems::SceneBroadcaster">
</plugin>

<scene>
<ambient>1.0 1.0 1.0</ambient>
<background>0.8 0.8 0.8</background>
Expand Down
2 changes: 2 additions & 0 deletions include/ignition/gazebo/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
ign_install_all_headers()

add_subdirectory(components)

install (FILES server.config playback_server.config DESTINATION ${IGN_DATA_INSTALL_DIR})
57 changes: 57 additions & 0 deletions include/ignition/gazebo/ServerConfig.hh
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,24 @@ namespace ignition
/// \param[in] _info Information about the plugin to load.
public: void AddPlugin(const PluginInfo &_info);

/// \brief Add multiple plugins to the simulation
/// \param[in] _info List of Information about the plugin to load.
public: void AddPlugins(const std::list<PluginInfo> &_plugins);

/// \brief Generate PluginInfo for Log recording based on the
/// internal state of this ServerConfig object:
/// \sa UseLogRecord
/// \sa LogRecordPath
/// \sa LogRecordResources
/// \sa LogRecordCompressPath
/// \sa LogRecordTopics
public: PluginInfo LogRecordPlugin() const;

/// \brief Generate PluginInfo for Log playback based on the
/// internal state of this ServerConfig object:
/// \sa LogPlaybackPath
public: PluginInfo LogPlaybackPlugin() const;

/// \brief Get all the plugins that should be loaded.
/// \return A list of all the plugins specified via
/// AddPlugin(const PluginInfo &).
Expand All @@ -372,6 +390,45 @@ namespace ignition
/// \brief Private data pointer
private: std::unique_ptr<ServerConfigPrivate> dataPtr;
};

/// \brief Parse plugins from XML configuration file.
/// \param[in] _fname Absolute path to the configuration file to parse.
/// \return A list of all of the plugins found in the configuration file
std::list<ServerConfig::PluginInfo>
mjcarroll marked this conversation as resolved.
Show resolved Hide resolved
IGNITION_GAZEBO_VISIBLE
parsePluginsFromFile(const std::string &_fname);

/// \brief Parse plugins from XML configuration string.
/// \param[in] _str XML configuration content to parse
/// \return A list of all of the plugins found in the configuration string.
std::list<ServerConfig::PluginInfo>
IGNITION_GAZEBO_VISIBLE
parsePluginsFromString(const std::string &_str);

/// \brief Load plugin information, following ordering.
///
/// This method is used when no plugins are found in an SDF
/// file to load either a default or custom set of plugins.
///
/// The following order is used to resolve:
/// 1. Config file located at IGN_GAZEBO_SERVER_CONFIG_PATH environment
/// variable.
/// * If IGN_GAZEBO_SERVER_CONFIG_PATH is set but empty, no plugins
/// are loaded.
/// 2. File at ${IGN_HOMEDIR}/.ignition/gazebo/server.config
/// 3. File at ${IGN_DATA_INSTALL_DIR}/server.config
///
/// If any of the above files exist but are empty, resolution
/// stops and the plugin list will be empty.
///
//
/// \param[in] _isPlayback Is the server in playback mode. If so, fallback
/// to playback_server.config.
//
/// \return A list of plugins to load, based on above ordering
std::list<ServerConfig::PluginInfo>
IGNITION_GAZEBO_VISIBLE
loadPluginInfo(bool _isPlayback = false);
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions include/ignition/gazebo/Util.hh
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ namespace ignition
/// `<include>`
const std::string kSdfPathEnv{"SDF_PATH"};

/// \breif Environment variable holding server config paths.
const std::string kServerConfigPathEnv{"IGN_GAZEBO_SERVER_CONFIG_PATH"};

/// \brief Environment variable holding paths to custom rendering engine
/// plugins.
const std::string kRenderPluginPathEnv{"IGN_GAZEBO_RENDER_ENGINE_PATH"};
Expand Down
1 change: 1 addition & 0 deletions include/ignition/gazebo/config.hh.in
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#define IGNITION_GAZEBO_GUI_CONFIG_PATH "${CMAKE_INSTALL_PREFIX}/${IGN_DATA_INSTALL_DIR}/gui"
#define IGNITION_GAZEBO_SYSTEM_CONFIG_PATH "${CMAKE_INSTALL_PREFIX}/${IGN_DATA_INSTALL_DIR}/systems"
mjcarroll marked this conversation as resolved.
Show resolved Hide resolved
#define IGNITION_GAZEBO_SERVER_CONFIG_PATH "${CMAKE_INSTALL_PREFIX}/${IGN_DATA_INSTALL_DIR}"
#define IGN_GAZEBO_PLUGIN_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${IGN_LIB_INSTALL_DIR}/ign-${IGN_DESIGNATION}-${PROJECT_VERSION_MAJOR}/plugins"
#define IGN_GAZEBO_GUI_PLUGIN_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${IGN_LIB_INSTALL_DIR}/ign-${IGN_DESIGNATION}-${PROJECT_VERSION_MAJOR}/plugins/gui"
#define IGN_GAZEBO_WORLD_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${IGN_DATA_INSTALL_DIR}/worlds"
Expand Down
14 changes: 14 additions & 0 deletions include/ignition/gazebo/playback_server.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<server_config>
<plugins>
<plugin entity_name="*"
entity_type="world"
filename="ignition-gazebo-user-commands-system"
name="ignition::gazebo::systems::UserCommands">
</plugin>
<plugin entity_name="*"
entity_type="world"
filename="ignition-gazebo-scene-broadcaster-system"
name="ignition::gazebo::systems::SceneBroadcaster">
</plugin>
chapulina marked this conversation as resolved.
Show resolved Hide resolved
</plugins>
</server_config>
19 changes: 19 additions & 0 deletions include/ignition/gazebo/server.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<server_config>
<plugins>
<plugin entity_name="*"
entity_type="world"
filename="ignition-gazebo-physics-system"
name="ignition::gazebo::systems::Physics">
</plugin>
<plugin entity_name="*"
entity_type="world"
filename="ignition-gazebo-user-commands-system"
name="ignition::gazebo::systems::UserCommands">
</plugin>
<plugin entity_name="*"
entity_type="world"
filename="ignition-gazebo-scene-broadcaster-system"
name="ignition::gazebo::systems::SceneBroadcaster">
</plugin>
</plugins>
</server_config>
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ set (gtest_sources
SdfEntityCreator_TEST.cc
SdfGenerator_TEST.cc
Server_TEST.cc
ServerConfig_TEST.cc
SimulationRunner_TEST.cc
System_TEST.cc
SystemLoader_TEST.cc
Expand Down
45 changes: 3 additions & 42 deletions src/Server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,53 +59,14 @@ std::string findFuelResourceSdf(const std::string &_path)
/// \brief This struct provides access to the default world.
struct DefaultWorld
{
/// \brief Get the default plugins as a string.
/// \return An SDF string that contains the default plugins.
public: static std::string &DefaultPlugins(const ServerConfig &_config)
{
std::vector<std::string> pluginsV = {
{
std::string("<plugin filename='ignition-gazebo") +
IGNITION_GAZEBO_MAJOR_VERSION_STR + "-scene-broadcaster-system' "
"name='ignition::gazebo::systems::SceneBroadcaster'></plugin>"
},
{
std::string("<plugin filename='ignition-gazebo") +
IGNITION_GAZEBO_MAJOR_VERSION_STR + "-user-commands-system' " +
"name='ignition::gazebo::systems::UserCommands'></plugin>"
}
};

// The set of default gazebo plugins.
if (_config.LogPlaybackPath().empty())
{
pluginsV.push_back(std::string("<plugin filename='ignition-gazebo") +
IGNITION_GAZEBO_MAJOR_VERSION_STR + "-physics-system' "
"name='ignition::gazebo::systems::Physics'></plugin>");
}

// Playback plugin
else
{
pluginsV.push_back(std::string("<plugin filename='ignition-gazebo") +
IGNITION_GAZEBO_MAJOR_VERSION_STR + "-log-system' "
"name='ignition::gazebo::systems::LogPlayback'><path>" +
_config.LogPlaybackPath() + "</path></plugin>");
}

static std::string plugins = std::accumulate(pluginsV.begin(),
pluginsV.end(), std::string(""));
return plugins;
}

/// \brief Get the default world as a string.
/// Plugins will be loaded from the server.config file.
/// \return An SDF string that contains the default world.
public: static std::string &World(const ServerConfig &_config)
public: static std::string &World()
{
static std::string world = std::string("<?xml version='1.0'?>"
"<sdf version='1.6'>"
"<world name='default'>") +
DefaultPlugins(_config) +
"</world>"
"</sdf>";

Expand Down Expand Up @@ -211,7 +172,7 @@ Server::Server(const ServerConfig &_config)
ignmsg << "Loading default world.\n";
// Load an empty world.
/// \todo(nkoenig) Add a "AddWorld" function to sdf::Root.
errors = this->dataPtr->sdfRoot.LoadSdfString(DefaultWorld::World(_config));
errors = this->dataPtr->sdfRoot.LoadSdfString(DefaultWorld::World());
}

if (!errors.empty())
Expand Down
Loading