forked from cps-test-lab/scenario-execution
-
Notifications
You must be signed in to change notification settings - Fork 0
New Gazebo actions without actor #3
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
Open
adivardi
wants to merge
3
commits into
enway-devel
Choose a base branch
from
av/new_gz_actions
base: enway-devel
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
libs/scenario_execution_gazebo/scenario_execution_gazebo/actions/gazebo_delete_entity.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| # Copyright (C) 2026 Enway GmbH | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions | ||
| # and limitations under the License. | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
|
|
||
| from enum import Enum | ||
| from typing import Optional | ||
|
|
||
| import py_trees | ||
| from scenario_execution.actions.run_process import RunProcess | ||
|
|
||
|
|
||
| class DeleteActionState(Enum): | ||
| """States for executing a delete-entity in gazebo.""" | ||
|
|
||
| IDLE = 1 | ||
| WAITING_FOR_RESPONSE = 2 | ||
| DONE = 3 | ||
| FAILURE = 4 | ||
|
|
||
|
|
||
| class GazeboDeleteEntity(RunProcess): | ||
| """Class to delete an entity in gazebo.""" | ||
|
|
||
| def __init__(self) -> None: | ||
| super().__init__() | ||
| self.entity_name: Optional[str] = None | ||
| self.current_state = DeleteActionState.IDLE | ||
|
|
||
| def execute(self, entity_name: str, world_name: str): # pylint: disable=arguments-differ | ||
| super().execute(wait_for_shutdown=True) | ||
| self.entity_name = entity_name | ||
| self.world_name = world_name | ||
|
|
||
| self.set_command(["gz", "service", "-s", f"/world/{self.world_name}/remove", | ||
| "--reqtype", "gz.msgs.Entity", | ||
| "--reptype", "gz.msgs.Boolean", | ||
| "--timeout", "1000", "--req", f'name: "{self.entity_name}" type: MODEL']) | ||
|
|
||
| def on_executed(self) -> None: | ||
| """Hook when process gets executed.""" | ||
| self.feedback_message = ( | ||
| f"Waiting for entity '{self.entity_name}' to be deleted" # pylint: disable= attribute-defined-outside-init | ||
| ) | ||
| self.current_state = DeleteActionState.WAITING_FOR_RESPONSE | ||
|
|
||
| def on_process_finished(self, ret: int) -> py_trees.common.Status: | ||
| """Check result of process.""" | ||
| if self.current_state == DeleteActionState.WAITING_FOR_RESPONSE: | ||
| if ret == 0: | ||
| while True: | ||
| try: | ||
| line = self.output.popleft() | ||
| line = line.lower() | ||
| if "error" in line or "timed out" in line: | ||
| # pylint: disable-next= attribute-defined-outside-init | ||
| self.feedback_message = f"Found error output while executing '{self.get_command()}'" | ||
| self.current_state = DeleteActionState.FAILURE | ||
| return py_trees.common.Status.FAILURE | ||
| except IndexError: | ||
| break | ||
| self.feedback_message = f"Successfully deleted entity '{self.entity_name}'" | ||
| self.current_state = DeleteActionState.DONE | ||
| return py_trees.common.Status.SUCCESS | ||
| else: | ||
| self.feedback_message = f"Deleting '{self.entity_name}' failed with {ret}" | ||
| self.current_state = DeleteActionState.FAILURE | ||
| return py_trees.common.Status.FAILURE | ||
| else: | ||
| return py_trees.common.Status.INVALID |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.