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

add tests for scenario_execution_gazebo #93

Merged
merged 19 commits into from
Jun 20, 2024
40 changes: 36 additions & 4 deletions .github/workflows/test_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ jobs:
Xvfb :1 -screen 0 800x600x16 &
export DISPLAY=:1.0
export -n CYCLONEDDS_URI
export ROS_DOMAIN_ID=119
export ROS_DOMAIN_ID=2
export IGN_PARTITION=${HOSTNAME}:${GITHUB_RUN_ID}
sed -i 's/60s/600s/g' examples/example_nav2/example_nav2.osc
# shellcheck disable=SC1083
Expand Down Expand Up @@ -263,7 +263,7 @@ jobs:
Xvfb :1 -screen 0 800x600x16 &
export DISPLAY=:1.0
export -n CYCLONEDDS_URI
export ROS_DOMAIN_ID=119
export ROS_DOMAIN_ID=2
export IGN_PARTITION=${HOSTNAME}:${GITHUB_RUN_ID}
sed -i 's/120s/600s/g' examples/example_simulation/scenarios/example_simulation.osc
# shellcheck disable=SC1083
Expand Down Expand Up @@ -296,7 +296,7 @@ jobs:
Xvfb :1 -screen 0 800x600x16 &
export DISPLAY=:1.0
export -n CYCLONEDDS_URI
export ROS_DOMAIN_ID=119
export ROS_DOMAIN_ID=2
export IGN_PARTITION=${HOSTNAME}:${GITHUB_RUN_ID}
sed -i 's/240s/900s/g' examples/example_multi_robot/example_multi_robot.osc
# shellcheck disable=SC1083
Expand All @@ -307,8 +307,40 @@ jobs:
with:
name: test-example-multirobot-result
path: test_example_multirobot/test.xml
test-scenario-execution-gazebo:
needs: [build]
runs-on: intellabs-01
container:
image: ghcr.io/intellabs/scenario-execution:humble
credentials:
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Restore cache
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
key: ${{ runner.os }}-build-${{ github.run_number }}
path: .
- name: Test Scenario Execution Gazebo
shell: bash
run: |
source /opt/ros/humble/setup.bash
source install/setup.bash
Xvfb :1 -screen 0 800x600x16 &
export DISPLAY=:1.0
export -n CYCLONEDDS_URI
export ROS_DOMAIN_ID=2
export IGN_PARTITION=${HOSTNAME}:${GITHUB_RUN_ID}
# shellcheck disable=SC1083
scenario_batch_execution -i simulation/gazebo/test_scenario_execution_gazebo/scenarios/ -o test_scenario_execution_gazebo -- ros2 launch tb4_sim_scenario sim_nav_scenario_launch.py scenario:={SCENARIO} output_dir:={OUTPUT_DIR} spawn:=False nav2:=False
- name: Upload result
uses: actions/upload-artifact@ef09cdac3e2d3e60d8ccadda691f4f1cec5035cb
if: always()
with:
name: test-example-simulation-result
path: test_example_simulation/test.xml
tests:
needs: [test-scenario-execution, test-scenario-execution-ros, scenario-files-validation, test-example-scenario, test-example-library, test-example-variation, test-example-nav2, test-example-simulation, test-example-multirobot]
needs: [test-scenario-execution, test-scenario-execution-ros, scenario-files-validation, test-example-scenario, test-example-library, test-example-variation, test-example-nav2, test-example-simulation, test-example-multirobot, test-scenario-execution-gazebo]
runs-on: intellabs-01
if: ${{ always() }}
steps:
Expand Down
18 changes: 16 additions & 2 deletions docs/libraries.rst
Original file line number Diff line number Diff line change
Expand Up @@ -248,16 +248,30 @@ Waits for an actor to exist within simulation.

Delete an object from the simulation.

- ``entity_name``: Entity name within simulation
- ``world_name: string``: Gazebo world name (default: ``default``)

``osc_object.spawn()``
""""""""""""""""""""""

Spawn an actor within simulation by using the ``model`` and ``namespace`` of the associated actor.
Spawn an actor within simulation.

- ``spawn_pose: pose_3d``: Pose of the spawned actor.
- ``world_name: string``: Gazebo world name (default: ``default``)
- ``xacro_arguments: string``: Comma-separated list of argument key:=value pairs
- ``model: string``: Model definition
- ``xacro_arguments: string``: (optional) Comma-separated list of argument key:=value pairs

.. note::

The model definition can be specified in different formats:

- ``file://<path-to-model>``: Local path to model file
- ``model://<path-to-model>``: Path relative to available model search paths
- ``<package-name>://<path-to-model>``: Path relative to an available package (e.g. :repo_link:`simulation/gazebo/test_scenario_execution_gazebo/scenarios/test_spawn_exists_delete.osc`)
- ``https:://fuel``: Model from `fuel.gazebosim.org <https://app.gazebosim.org/>`__ (e.g. ``https://fuel.gazebosim.org/1.0/OpenRobotics/models/Beer``)

If the file ending is ``.xacro`` the model is forwarded to `xacro <https://wiki.ros.org/xacro>`__ before getting spawned.


``wait_for_sim()``
""""""""""""""""""
Expand Down
4 changes: 0 additions & 4 deletions scenario_execution_gazebo/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,12 @@

<exec_depend>rclpy</exec_depend>
<exec_depend>py_trees</exec_depend>
<exec_depend>nav2_bringup</exec_depend>
<exec_depend>turtlebot4_navigation</exec_depend>

<test_depend>ament_copyright</test_depend>
<test_depend>ament_flake8</test_depend>
<test_depend>ament_pep257</test_depend>
<test_depend>python3-pytest</test_depend>

<depend>ignition-fortress</depend>

<export>
<build_type>ament_python</build_type>
</export>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ class GazeboActorExists(RunProcess):

"""

def __init__(self, entity_name: str, world_name: str):
def __init__(self, name, entity_name: str, world_name: str):
"""
init
"""
super().__init__('GazeboActorExistsAction')
super().__init__(name)
self.entity_name = entity_name
self.node = None
self.set_command(["ign", "topic", "-t", "/world/" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class GazeboDeleteActor(RunProcess):

"""

def __init__(self, name, entity_name: str, world_name: str):
def __init__(self, name, associated_actor, entity_name: str, world_name: str):
"""
init
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ action actor_exists:

action osc_actor.delete:
# Delete an actor from simulation
entity_name: string # name of the actor within simulation
world_name: string = 'default' # simulation world name

action osc_actor.spawn:
# Spawn a simulation entity, uses namespace of entity
# Spawn a simulation entity.
spawn_pose: pose_3d # position at which the object gets spawned
world_name: string = 'default' # simulation world name
model: string # model definition
Expand Down
12 changes: 1 addition & 11 deletions scenario_execution_gazebo/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
# SPDX-License-Identifier: Apache-2.0

""" Setup python package """
from glob import glob
import os
from setuptools import find_namespace_packages, setup

PACKAGE_NAME = 'scenario_execution_gazebo'
Expand All @@ -28,15 +26,7 @@
data_files=[
('share/ament_index/resource_index/packages',
['resource/' + PACKAGE_NAME]),
('share/' + PACKAGE_NAME, ['package.xml']),
(os.path.join('share', PACKAGE_NAME, 'scenarios'), glob('scenarios/*.osc')),
(os.path.join('share', PACKAGE_NAME, 'launch'), glob('launch/*launch.py')),
(os.path.join('share', PACKAGE_NAME, 'params'), glob('params/*.yaml')),
(os.path.join('share', PACKAGE_NAME, 'models'), glob('models/*.sdf*')),
(os.path.join('share', PACKAGE_NAME, 'models'), glob('models/*.dae*')),
(os.path.join('share', PACKAGE_NAME, 'models'), glob('models/*.png*')),
(os.path.join('share', PACKAGE_NAME, 'worlds'), glob('worlds/*.world')),
(os.path.join('share', PACKAGE_NAME, 'worlds'), glob('worlds/*.model'))
('share/' + PACKAGE_NAME, ['package.xml'])
],
install_requires=['setuptools'],
zip_safe=True,
Expand Down
9 changes: 7 additions & 2 deletions simulation/gazebo/tb4_sim_scenario/launch/nav2_launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument
from launch.actions import IncludeLaunchDescription
from launch.conditions import IfCondition
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch.substitutions import LaunchConfiguration, PathJoinSubstitution

Expand All @@ -34,8 +35,10 @@
DeclareLaunchArgument('model', default_value='standard',
choices=['standard', 'lite'],
description='Turtlebot4 Model'),
DeclareLaunchArgument('launch_simulation', default_value='True',
description='Set "false" to skip simulation startup.'),

DeclareLaunchArgument('nav2', default_value='True',
description='Set "False" to skip nav2 startup.'),

DeclareLaunchArgument('headless', default_value='True',
description='Start Igniton GUI or not'),

Expand All @@ -59,9 +62,11 @@ def generate_launch_description():

# Launch args
map_yaml = LaunchConfiguration('map_yaml')
nav2 = LaunchConfiguration('nav2')

nav2_bringup = IncludeLaunchDescription(
PythonLaunchDescriptionSource([PathJoinSubstitution([pkg_nav2_bringup, 'launch', 'bringup_launch.py'])]),
condition=IfCondition(nav2),
launch_arguments={
'map': PathJoinSubstitution([pkg_tb4_nav, 'maps', map_yaml]),
'use_sim_time': 'True',
Expand Down
3 changes: 3 additions & 0 deletions simulation/gazebo/test_scenario_execution_gazebo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Tests of Scenario Execution Library for Gazebo

The `test_scenario_execution_gazebo` package provides test scenarios to test `scenario_execution_gazebo` within the `tb4_sim_scenario` setup.
35 changes: 35 additions & 0 deletions simulation/gazebo/test_scenario_execution_gazebo/models/box.sdf
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version='1.0'?>
<sdf version="1.4">
<model name="my_model">
<pose>0 0 0.5 0 0 0</pose>
<static>true</static>
<link name="link">
<inertial>
<mass>1.0</mass>
<inertia> <!-- inertias are tricky to compute -->
<!-- http://gazebosim.org/tutorials?tut=inertia&cat=build_robot -->
<ixx>0.083</ixx> <!-- for a box: ixx = 0.083 * mass * (y*y + z*z) -->
<ixy>0.0</ixy> <!-- for a box: ixy = 0 -->
<ixz>0.0</ixz> <!-- for a box: ixz = 0 -->
<iyy>0.083</iyy> <!-- for a box: iyy = 0.083 * mass * (x*x + z*z) -->
<iyz>0.0</iyz> <!-- for a box: iyz = 0 -->
<izz>0.083</izz> <!-- for a box: izz = 0.083 * mass * (x*x + y*y) -->
</inertia>
</inertial>
<collision name="collision">
<geometry>
<box>
<size>1 1 1</size>
</box>
</geometry>
</collision>
<visual name="visual">
<geometry>
<box>
<size>1 1 1</size>
</box>
</geometry>
</visual>
</link>
</model>
</sdf>
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version='1.0'?>
<sdf version="1.4" xmlns:xacro="http://www.ros.org/wiki/xacro">

<xacro:arg name="box_width_length" default="" />
<xacro:arg name="box_height" default="" />

<xacro:property name="box_width_length" value="$(arg box_width_length)"/>
<xacro:property name="box_height" value="$(arg box_height)"/>
<model name="my_model">
<pose>0 0 0.5 0 0 0</pose>
<static>true</static>
<link name="link">
<inertial>
<mass>1.0</mass>
<inertia> <!-- inertias are tricky to compute -->
<!-- http://gazebosim.org/tutorials?tut=inertia&cat=build_robot -->
<ixx>0.083</ixx> <!-- for a box: ixx = 0.083 * mass * (y*y + z*z) -->
<ixy>0.0</ixy> <!-- for a box: ixy = 0 -->
<ixz>0.0</ixz> <!-- for a box: ixz = 0 -->
<iyy>0.083</iyy> <!-- for a box: iyy = 0.083 * mass * (x*x + z*z) -->
<iyz>0.0</iyz> <!-- for a box: iyz = 0 -->
<izz>0.083</izz> <!-- for a box: izz = 0.083 * mass * (x*x + y*y) -->
</inertia>
</inertial>
<collision name="collision">
<geometry>
<box>
<size>${box_width_length} ${box_height}</size>
</box>
</geometry>
</collision>
<visual name="visual">
<geometry>
<box>
<size>${box_width_length} ${box_height}</size>
</box>
</geometry>
</visual>
</link>
</model>
</sdf>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" ?>
<sdf version="1.6">
<actor name="actor1">
<pose>0 0 0 0 0 0</pose>
<skin>
<filename>file://walk.dae</filename>
<scale>1.0</scale>
</skin>
<animation name="NAME">
<filename>file://walk.dae</filename>
<scale>1.000000</scale>
<interpolate_x>true</interpolate_x>
</animation>
<script>
<trajectory id="0" type="NAME">
<waypoint>
<time>0</time>
<pose>0 2 0 0 0 -1.57</pose>
</waypoint>
<waypoint>
<time>2</time>
<pose>0 -2 0 0 0 -1.57</pose>
</waypoint>
</trajectory>
</script>
</actor>
</sdf>
23 changes: 23 additions & 0 deletions simulation/gazebo/test_scenario_execution_gazebo/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?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>test_scenario_execution_gazebo</name>
<version>1.1.0</version>
<description>Tests for Scenario Execution library for Gazebo</description>
<author email="[email protected]">Intel Labs</author>
<maintainer email="[email protected]">Intel Labs</maintainer>
<license file="../../../LICENSE">Apache-2.0</license>

<exec_depend>rclpy</exec_depend>
<exec_depend>scenario_execution_gazebo</exec_depend>
<exec_depend>tb4_sim_scenario</exec_depend>

<test_depend>ament_copyright</test_depend>
<test_depend>ament_flake8</test_depend>
<test_depend>ament_pep257</test_depend>
<test_depend>python3-pytest</test_depend>

<export>
<build_type>ament_python</build_type>
</export>
</package>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import osc.gazebo

scenario test_spawn_and_exists:

test_obstacle: osc_actor

do parallel:
test_obstacle.spawn(
spawn_pose: pose_3d(position: position_3d(x: 1m, y: 0m, z: 1m)),
world_name: 'maze',
model: 'test_scenario_execution_gazebo://models/box.sdf')
test_case: serial:
wait elapsed(5s)
test: actor_exists(
entity_name: 'test_obstacle',
world_name: 'maze')
delete_obstacle: test_obstacle.delete(
world_name: 'maze',
entity_name: 'test_obstacle')
success: emit end
time_out: serial:
wait elapsed(30s)
emit fail
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import osc.gazebo

scenario test_spawn_xacro_with_parameters:

test_obstacle: osc_actor

do parallel:
test_obstacle.spawn(
spawn_pose: pose_3d(position: position_3d(z: 2m)),
world_name: 'maze',
xacro_arguments: 'box_width_length:=1 1,box_height:=4',
model: 'test_scenario_execution_gazebo://models/box.sdf.xacro')
test_case: serial:
test: actor_exists(
entity_name: 'test_obstacle',
world_name: 'maze')
success: emit end
time_out: serial:
wait elapsed(30s)
time_out_shutdown: emit fail
Loading
Loading