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

Refactor plugin model #246

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion src/rosdiscover/interpreter/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def key(x: NodeConfig) -> str:
# now that all nodes have been initialised, load all plugins
for node_context in self.nodes.values():
for plugin in node_context._plugins:
plugin.load(self)
plugin.load(self, node_context)

def _create_nodelet_manager(self,
name: str,
Expand Down
20 changes: 19 additions & 1 deletion src/rosdiscover/interpreter/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
import abc
import typing

from loguru import logger

from . import NodeContext

if typing.TYPE_CHECKING:
from .interpreter import Interpreter

Expand All @@ -12,6 +16,20 @@ class ModelPlugin(abc.ABC):
"""Models the architectural effects of a dynamically-loaded node plugin
(e.g., a Gazebo plugin)."""
@abc.abstractmethod
def load(self, interpreter: 'Interpreter') -> None:
def load(self, interpreter: 'Interpreter', context: NodeContext) -> None:
"""Simulates the effects of loading this plugin in a given context."""
...


class DynamicPlugin(type, ModelPlugin):
"""
Models dynamically loaded plugins, taking in a name of the plygin that
will be recovered when the plugin is loaded
"""

def load(self, interpreter: 'Interpreter', context: NodeContext) -> None:
logger.warning("Dynamic loading of plugins for {name} not implemented")


def generate_dynamic_plugin(plugin_name: str) -> type:
return type(f"{plugin_name}DynamicPlugin", (DynamicPlugin), {'plugin_name': plugin_name})
4 changes: 2 additions & 2 deletions src/rosdiscover/models/plugins/navigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ class StaticLayerPlugin(NavigationPlugin):
node_name: str = attr.ib()
reference_name: t.Optional[str] = attr.ib()

def load(self, interpreter: Interpreter) -> None:
move_base = get_move_base(interpreter, self.node_name)
def load(self, interpreter: Interpreter, c: NodeContext) -> None:
move_base = c # get_move_base(interpreter, self.node_name)

move_base.read('~unknown_cost_value', -1)
move_base.read('~lethal_cost_value', 100)
Expand Down