Skip to content

Commit

Permalink
Merge pull request #379 from robotology/feature/remove_ecm_provider
Browse files Browse the repository at this point in the history
Remove the need to use a singleton to get the ECM pointer
  • Loading branch information
diegoferigo authored Aug 24, 2021
2 parents 633f2f5 + 6471ddf commit 450bbf4
Show file tree
Hide file tree
Showing 12 changed files with 119 additions and 632 deletions.
14 changes: 6 additions & 8 deletions python/gym_ignition/runtimes/gazebo_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
# This software may be modified and distributed under the terms of the
# GNU Lesser General Public License v2.1 or any later version.

from typing import Optional

import gym_ignition_models
from gym_ignition import base, utils
from gym_ignition import base
from gym_ignition.base import runtime
from gym_ignition.utils import logger
from gym_ignition.utils.typing import *
Expand Down Expand Up @@ -52,7 +54,7 @@ def __init__(
gym.logger.debug(f"{dict({arg: values[arg] for arg in args})}")

# Gazebo attributes
self._gazebo = None
self._gazebo: Optional[scenario.GazeboSimulator] = None
self._physics_rate = physics_rate
self._real_time_factor = real_time_factor

Expand Down Expand Up @@ -225,18 +227,14 @@ def world(self) -> scenario.World:
if self._gazebo is None:
raise RuntimeError("Gazebo has not yet been created")

# Help type hinting
self._gazebo: scenario.GazeboSimulator

if self._gazebo.initialized():
raise RuntimeError("Gazebo was already initialized, cannot insert world")

if self._world_sdf is None:
self._world_sdf = ""
self._world_name = utils.scenario.get_unique_world_name("default")
self._world_name = "default"
else:
sdf_world_name = scenario.get_world_name_from_sdf(self._world_sdf)
self._world_name = utils.scenario.get_unique_world_name(sdf_world_name)
self._world_name = scenario.get_world_name_from_sdf(self._world_sdf)

# Load the world
ok_world = self._gazebo.insert_world_from_sdf(self._world_sdf, self._world_name)
Expand Down
13 changes: 0 additions & 13 deletions python/gym_ignition/utils/scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,6 @@ def get_unique_model_name(world: scenario.World, model_name: str) -> str:
return model_name_tentative


def get_unique_world_name(world_name: str) -> str:

postfix = 0
world_name_tentative = f"{world_name}"
ecm_singleton = scenario.ECMSingleton_instance()

while world_name_tentative in ecm_singleton.world_names():
postfix += 1
world_name_tentative = f"{world_name}{postfix}"

return world_name_tentative


def init_gazebo_sim(
step_size: float = 0.001, real_time_factor: float = 1.0, steps_per_run: int = 1
) -> Tuple[scenario.GazeboSimulator, Union[scenario.World, core.World]]:
Expand Down
1 change: 0 additions & 1 deletion scenario/bindings/gazebo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ target_link_libraries(${scenario_swig_name}
PUBLIC
ScenarioGazebo::ScenarioGazebo
ScenarioGazebo::GazeboSimulator
ECMSingleton
Python3::Python)
add_library(ScenarioSwig::Gazebo ALIAS gazebo)

Expand Down
9 changes: 0 additions & 9 deletions scenario/bindings/gazebo/gazebo.i
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "scenario/gazebo/Model.h"
#include "scenario/gazebo/utils.h"
#include "scenario/gazebo/World.h"
#include "scenario/plugins/gazebo/ECMSingleton.h"
#include <cstdint>
%}

Expand Down Expand Up @@ -59,7 +58,6 @@ namespace scenario::gazebo::utils {
%rename("") Verbosity;
%rename("") JointLimit;
%rename("") ContactPoint;
%rename("") ECMSingleton;
%rename("") GazeboEntity;
%rename("") PhysicsEngine;
%rename("") GazeboSimulator;
Expand Down Expand Up @@ -105,10 +103,3 @@ namespace scenario::gazebo::utils {

// GazeboSimulator
%include "scenario/gazebo/GazeboSimulator.h"

// ECMSingleton
%ignore scenario::plugins::gazebo::ECMSingleton::clean;
%ignore scenario::plugins::gazebo::ECMSingleton::getECM;
%ignore scenario::plugins::gazebo::ECMSingleton::getEventManager;
%ignore scenario::plugins::gazebo::ECMSingleton::storePtrs;
%include "scenario/plugins/gazebo/ECMSingleton.h"
1 change: 0 additions & 1 deletion scenario/src/gazebo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ target_link_libraries(GazeboSimulator
ScenarioCore::CoreUtils
ScenarioGazebo::ScenarioGazebo
ScenarioGazebo::ExtraComponents
ScenarioGazeboPlugins::ECMSingleton
${ignition-fuel_tools.ignition-fuel_tools})

set_target_properties(GazeboSimulator PROPERTIES
Expand Down
Loading

0 comments on commit 450bbf4

Please sign in to comment.