simulation.utils.basics package

Submodules

simulation.utils.basics.init_options module

Classes:

InitOptions()

class InitOptions[source]

Bases: object

Methods:

from_dict(**kwargs)

Create instance from relevant keywords in dictionary.

_from_yaml(file_path[, loader])

Helper method to allow passing a custom cls instead of being forced to use the classmethod syntax.

from_yaml(file_path[, loader])

Load instance from a yaml file.

classmethod from_dict(**kwargs: Dict[str, Any])[source]

Create instance from relevant keywords in dictionary.

Instead of passing exactly the arguments defined by the class’ __init__, this allows to pass a dictionary of many more values and the function will then only pass the correct arguments to the class’ __init__.

Example

>>> from simulation.utils.basics.init_options import InitOptions
>>> class SomeClass(InitOptions):
...
...     def __init__(self, arg1, arg2):
...         self.arg1 = arg1
...         self.arg2 = arg2
...
...
>>> many_args = {"arg1": 1, "arg2": 2, "arg3": 3}
... # This will raise an exception because __init__ does not expect arg3!
>>> try:
...     SomeClass(**many_args)
... except TypeError:
...     pass
... # However this will work:
>>> something = SomeClass.from_dict(**many_args)
Parameters

**kwargs – Keyword arguments matching the constructor’s variables.

_from_yaml(file_path: str, loader: yaml.loader.Loader = <class 'yaml.loader.SafeLoader'>)[source]

Helper method to allow passing a custom cls instead of being forced to use the classmethod syntax.

classmethod from_yaml(file_path: str, loader: yaml.loader.Loader = <class 'yaml.loader.SafeLoader'>)[source]

Load instance from a yaml file.

Only fields that are defined within the __init__ are loaded.

Parameters

file_path – Location of the yaml file.

simulation.utils.basics.ros_cmd module

Classes:

ROSCmd(cmd_base, *, env_vars, Any], **ros_args)

Holds data for a ROS command and makes it executable.

class ROSCmd(cmd_base: str, *, env_vars: Dict[str, Any], **ros_args)[source]

Bases: object

Holds data for a ROS command and makes it executable.

Attributes:

cmd_base

Command string without any arguments.

env_vars

Environment variables that should be set prior to running the command.

ros_args

ROS arguments passed when running the command.

Methods:

get_cmd()

Create the command string.

run([capture_output, shell, text])

Prepare and run the command.

cmd_base: str

Command string without any arguments.

env_vars: Dict[str, Any] = None

Environment variables that should be set prior to running the command.

ros_args: Dict[str, Any] = None

ROS arguments passed when running the command.

get_cmd()str[source]

Create the command string.

run(capture_output=True, shell=True, text=True)Tuple[int, str][source]

Prepare and run the command.

Returns

Returncode and std output.

simulation.utils.basics.save_options module

Classes:

SaveOptions()

class SaveOptions[source]

Bases: object

Methods:

save_as_yaml(file_path[, custom_dict, dumper])

Save to file as yaml.

save_as_yaml(file_path: str, custom_dict: Optional[Dict[str, Any]] = None, dumper=<class 'yaml.dumper.SafeDumper'>)[source]

Save to file as yaml.

This dumps the complete class dict to a yaml file.

Parameters

file_path – Path to file.

Module contents