Skip to content

Commit

Permalink
feat(arcor2_runtime): param to disable communication with Scene
Browse files Browse the repository at this point in the history
  • Loading branch information
ZdenekM committed Jan 3, 2024
1 parent aef50c7 commit ec11291
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/python/arcor2_runtime/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.0
1.1.0
28 changes: 23 additions & 5 deletions src/python/arcor2_runtime/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,24 @@ def stream_joints(robot_inst: Robot) -> None:


class Resources:
__slots__ = ("project", "scene", "objects", "args", "executor", "_stream_futures")
__slots__ = ("project", "scene", "objects", "args", "executor", "_stream_futures", "interact_with_scene_service")

def __init__(
self,
apply_action_mapping: bool = True,
scene_start_timeout: rest.OptTimeout = None,
interact_with_scene_service: bool = True,
) -> None:
"""Initializes Resources class.
:param apply_action_mapping: Action mapping (name to id) can be disabled when there are no actions.
:param scene_start_timeout: Timeout for calling /system/start on the Scene service.
:param interact_with_scene_service: when set to False, no call to the Scene service will be made.
:return:
"""

self.interact_with_scene_service = interact_with_scene_service

def __init__(self, apply_action_mapping: bool = True, scene_start_timeout: rest.OptTimeout = None) -> None:
models: dict[str, None | Models] = {}

scene = self.read_project_data(Scene.__name__.lower(), Scene)
Expand Down Expand Up @@ -163,7 +178,8 @@ def __init__(self, apply_action_mapping: bool = True, scene_start_timeout: rest.
print_event(package_info_event)

# in order to prepare a clean environment (clears all configurations and all collisions)
scene_service.stop()
if self.interact_with_scene_service:
scene_service.stop()

self.executor = concurrent.futures.ThreadPoolExecutor()
futures: list[concurrent.futures.Future] = []
Expand Down Expand Up @@ -205,7 +221,8 @@ def __init__(self, apply_action_mapping: bool = True, scene_start_timeout: rest.
# the first exception will be available as __context__
raise ResourcesException(" ".join([str(e) for e in exceptions]), exceptions) from exceptions[0]

scene_service.start(scene_start_timeout)
if self.interact_with_scene_service:
scene_service.start(scene_start_timeout)

self._stream_futures: list[concurrent.futures.Future] = []

Expand Down Expand Up @@ -261,7 +278,8 @@ def __exit__(
# this intentionally ignores KeyboardInterrupt (derived from BaseException)
print_exception(ex_value)

scene_service.stop()
if self.interact_with_scene_service:
scene_service.stop()
self.cleanup_all_objects()

return True
6 changes: 6 additions & 0 deletions src/python/arcor2_scene/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [1.1.0] - 2024-01-03

### Changed

- Parameter `interact_with_scene_service` added to the `Resources` class.

## [1.0.0] - 2023-02-14

### Changed
Expand Down

0 comments on commit ec11291

Please sign in to comment.