-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
281 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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 @@ | ||
include scenario_execution_x11/lib_osc/*.osc |
This file contains 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,16 @@ | ||
# Scenario Execution Library for X11 | ||
|
||
The `scenario_execution_x11` package provides actions to interact with the X window system. | ||
|
||
It provides the following scenario execution library: | ||
|
||
- `x11.osc`: Actions specific to x11 window system | ||
|
||
|
||
# Run Example | ||
|
||
``` bash | ||
colcon build | ||
sudo apt install mesa-utils | ||
ros2 run scenario_execution_ros scenario_execution_ros libs/scenario_execution_x11/scenarios/example_capture.osc -t | ||
``` |
This file contains 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,18 @@ | ||
<?xml version="1.0"?> | ||
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?> | ||
<package format="3"> | ||
<name>scenario_execution_x11</name> | ||
<version>1.2.0</version> | ||
<description>Scenario Execution library for X11</description> | ||
<author email="[email protected]">Intel Labs</author> | ||
<maintainer email="[email protected]">Intel Labs</maintainer> | ||
<license file="../../LICENSE">Apache-2.0</license> | ||
|
||
<depend>scenario_execution</depend> | ||
|
||
<exec_depend>ffmpeg</exec_depend> | ||
|
||
<export> | ||
<build_type>ament_python</build_type> | ||
</export> | ||
</package> |
Empty file.
21 changes: 21 additions & 0 deletions
21
libs/scenario_execution_x11/scenario_execution_x11/__init__.py
This file contains 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,21 @@ | ||
# Copyright (C) 2024 Intel Corporation | ||
# | ||
# 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 . import actions | ||
|
||
__all__ = [ | ||
'actions' | ||
] |
15 changes: 15 additions & 0 deletions
15
libs/scenario_execution_x11/scenario_execution_x11/actions/__init__.py
This file contains 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,15 @@ | ||
# Copyright (C) 2024 Intel Corporation | ||
# | ||
# 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 |
86 changes: 86 additions & 0 deletions
86
libs/scenario_execution_x11/scenario_execution_x11/actions/capture_screen.py
This file contains 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,86 @@ | ||
# Copyright (C) 2024 Intel Corporation | ||
# | ||
# 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 geometry_msgs.msg import PoseWithCovarianceStamped | ||
from lifecycle_msgs.srv import GetState | ||
from rclpy.node import Node | ||
from rclpy.qos import QoSDurabilityPolicy, QoSHistoryPolicy | ||
from rclpy.qos import QoSProfile, QoSReliabilityPolicy | ||
from rclpy.callback_groups import ReentrantCallbackGroup | ||
from rclpy.time import Time | ||
from rclpy.duration import Duration | ||
from tf2_ros import Buffer | ||
from datetime import datetime, timedelta | ||
import py_trees | ||
import os | ||
|
||
from scenario_execution_ros.actions.common import get_pose_stamped, NamespacedTransformListener | ||
from scenario_execution.actions.run_process import RunProcess | ||
import signal | ||
|
||
class CaptureScreenState(Enum): | ||
IDLE = 1 | ||
CAPTURING = 2 | ||
DONE = 11 | ||
FAILURE = 12 | ||
|
||
class CaptureScreen(RunProcess): | ||
|
||
def __init__(self, output_filename: str, frame_rate: float): | ||
super().__init__("", wait_for_shutdown=True) | ||
self.current_state = CaptureScreenState.IDLE | ||
self.output_dir = "." | ||
|
||
def setup(self, **kwargs): | ||
if "DISPLAY" not in os.environ: | ||
raise ValueError("capture_screen() requires environment variable 'DISPLAY' to be set.") | ||
|
||
if kwargs['output_dir']: | ||
if not os.path.exists(kwargs['output_dir']): | ||
raise ValueError( | ||
f"Specified destination dir '{kwargs['output_dir']}' does not exist") | ||
self.output_dir = kwargs['output_dir'] | ||
|
||
def execute(self, output_filename: str, frame_rate: float): # pylint: disable=arguments-differ | ||
cmd = ["ffmpeg", | ||
"-f", "x11grab", | ||
"-draw_mouse", "0", | ||
"-framerate", str(frame_rate), | ||
"-i", os.environ["DISPLAY"], | ||
"-c:v", "libx264", | ||
"-preset", "veryfast", | ||
"-f", "mp4", | ||
"-nostdin", | ||
"-y", os.path.join(self.output_dir, output_filename)] | ||
self.set_command(cmd) | ||
|
||
def get_logger_stdout(self): | ||
return self.logger.debug | ||
|
||
def get_logger_stderr(self): | ||
return self.logger.debug | ||
|
||
def on_executed(self): | ||
self.current_state = CaptureScreenState.CAPTURING | ||
self.feedback_message = f"Capturing screen..." # pylint: disable= attribute-defined-outside-init | ||
|
||
def on_process_finished(self, ret): | ||
if self.current_state == CaptureScreenState.CAPTURING: | ||
self.feedback_message = f"Capturing screen failed. {self.output[-1]}" # pylint: disable= attribute-defined-outside-init | ||
return py_trees.common.Status.FAILURE |
19 changes: 19 additions & 0 deletions
19
libs/scenario_execution_x11/scenario_execution_x11/get_osc_library.py
This file contains 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,19 @@ | ||
# Copyright (C) 2024 Intel Corporation | ||
# | ||
# 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 | ||
|
||
|
||
def get_osc_library(): | ||
return 'scenario_execution_x11', 'x11.osc' |
6 changes: 6 additions & 0 deletions
6
libs/scenario_execution_x11/scenario_execution_x11/lib_osc/x11.osc
This file contains 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,6 @@ | ||
import osc.standard.base | ||
|
||
action capture_screen: | ||
# create video from screen capture | ||
output_filename: string = "capture.mp4" # the initial pose to set during initialization | ||
frame_rate: float = 25.0 # framerate of the resulting video |
This file contains 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,10 @@ | ||
import osc.helpers | ||
import osc.x11 | ||
|
||
scenario example_x11: | ||
do parallel: | ||
capture_screen() | ||
run_process("glxgears") | ||
serial: | ||
wait elapsed(10s) | ||
emit end |
This file contains 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,4 @@ | ||
[develop] | ||
script_dir=$base/lib/scenario_execution_x11 | ||
[install] | ||
install_scripts=$base/lib/scenario_execution_x11 |
This file contains 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,47 @@ | ||
# Copyright (C) 2024 Intel Corporation | ||
# | ||
# 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 setuptools import find_namespace_packages, setup | ||
|
||
PACKAGE_NAME = 'scenario_execution_x11' | ||
|
||
setup( | ||
name=PACKAGE_NAME, | ||
version='1.2.0', | ||
packages=find_namespace_packages(), | ||
data_files=[ | ||
('share/ament_index/resource_index/packages', | ||
['resource/' + PACKAGE_NAME]), | ||
('share/' + PACKAGE_NAME, ['package.xml']) | ||
], | ||
install_requires=['setuptools'], | ||
zip_safe=True, | ||
maintainer='Intel Labs', | ||
maintainer_email='[email protected]', | ||
description='Scenario Execution library for X11', | ||
license='Apache License 2.0', | ||
tests_require=['pytest'], | ||
include_package_data=True, | ||
entry_points={ | ||
'scenario_execution.actions': [ | ||
'capture_screen = scenario_execution_x11.actions.capture_screen:CaptureScreen', | ||
], | ||
'scenario_execution.osc_libraries': [ | ||
'x11 = ' | ||
'scenario_execution_x11.get_osc_library:get_osc_library', | ||
] | ||
}, | ||
) |