├── .clang-format ├── .docker ├── Dockerfile ├── base.Dockerfile ├── cicd-devel.Dockerfile ├── cicd-master.Dockerfile ├── docker-compose.yml ├── entrypoint.sh └── setup_virtualenv.sh ├── .github ├── CODEOWNERS ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── release.yml └── workflows │ ├── cicd.yml │ ├── docker.yml │ └── style.yml ├── .gitignore ├── CMakeLists.txt ├── LICENSE ├── README.md ├── docs ├── CMakeLists.txt ├── doxygen │ └── CMakeLists.txt └── sphinx │ ├── CMakeLists.txt │ ├── _templates │ ├── module.rst_t │ ├── package.rst_t │ ├── toc.rst_t │ ├── versioning.html │ └── versions.html │ ├── apidoc │ ├── gym-ignition-environments │ │ ├── gym_ignition_environments.models.rst │ │ ├── gym_ignition_environments.randomizers.rst │ │ ├── gym_ignition_environments.rst │ │ └── gym_ignition_environments.tasks.rst │ ├── gym-ignition │ │ ├── gym_ignition.base.rst │ │ ├── gym_ignition.context.gazebo.rst │ │ ├── gym_ignition.context.rst │ │ ├── gym_ignition.randomizers.model.rst │ │ ├── gym_ignition.randomizers.physics.rst │ │ ├── gym_ignition.randomizers.rst │ │ ├── gym_ignition.rbd.idyntree.rst │ │ ├── gym_ignition.rbd.rst │ │ ├── gym_ignition.rst │ │ ├── gym_ignition.runtimes.rst │ │ ├── gym_ignition.scenario.rst │ │ └── gym_ignition.utils.rst │ └── scenario │ │ ├── scenario.bindings.rst │ │ └── scenario.rst │ ├── breathe │ ├── core.rst │ └── gazebo.rst │ ├── conf.py │ ├── getting_started │ ├── gym-ignition.rst │ ├── manipulation.rst │ └── scenario.rst │ ├── index.html │ ├── index.rst │ ├── info │ ├── faq.rst │ └── limitations.rst │ ├── installation │ ├── developer.rst │ ├── nightly.rst │ ├── stable.rst │ ├── support_policy.rst │ ├── system_configuration.rst │ └── virtual_environment.rst │ ├── what │ ├── what_is_gym_ignition.rst │ └── what_is_scenario.rst │ └── why │ ├── motivations.rst │ ├── why_gym_ignition.rst │ ├── why_ignition_gazebo.rst │ └── why_scenario.rst ├── examples ├── panda_pick_and_place.py └── python │ └── launch_cartpole.py ├── pyproject.toml ├── python ├── gym_ignition │ ├── __init__.py │ ├── base │ │ ├── __init__.py │ │ ├── runtime.py │ │ └── task.py │ ├── context │ │ ├── __init__.py │ │ └── gazebo │ │ │ ├── __init__.py │ │ │ ├── controllers.py │ │ │ └── plugin.py │ ├── randomizers │ │ ├── __init__.py │ │ ├── abc.py │ │ ├── gazebo_env_randomizer.py │ │ ├── model │ │ │ ├── __init__.py │ │ │ └── sdf.py │ │ └── physics │ │ │ ├── __init__.py │ │ │ └── dart.py │ ├── rbd │ │ ├── __init__.py │ │ ├── conversions.py │ │ ├── idyntree │ │ │ ├── __init__.py │ │ │ ├── helpers.py │ │ │ ├── inverse_kinematics_nlp.py │ │ │ ├── kindyncomputations.py │ │ │ └── numpy.py │ │ └── utils.py │ ├── runtimes │ │ ├── __init__.py │ │ ├── gazebo_runtime.py │ │ └── realtime_runtime.py │ ├── scenario │ │ ├── __init__.py │ │ ├── model_with_file.py │ │ └── model_wrapper.py │ └── utils │ │ ├── __init__.py │ │ ├── logger.py │ │ ├── math.py │ │ ├── misc.py │ │ ├── resource_finder.py │ │ ├── scenario.py │ │ └── typing.py └── gym_ignition_environments │ ├── __init__.py │ ├── models │ ├── __init__.py │ ├── cartpole.py │ ├── icub.py │ ├── panda.py │ └── pendulum.py │ ├── randomizers │ ├── __init__.py │ ├── cartpole.py │ └── cartpole_no_rand.py │ └── tasks │ ├── __init__.py │ ├── cartpole_continuous_balancing.py │ ├── cartpole_continuous_swingup.py │ ├── cartpole_discrete_balancing.py │ └── pendulum_swingup.py ├── scenario ├── CMakeLists.txt ├── README.md ├── bindings │ ├── CMakeLists.txt │ ├── __init__.py │ ├── core │ │ ├── CMakeLists.txt │ │ └── core.i │ └── gazebo │ │ ├── CMakeLists.txt │ │ ├── gazebo.i │ │ └── to_gazebo.i ├── cmake │ ├── AddUninstallTarget.cmake │ ├── AliasImportedTarget.cmake │ ├── FindIgnitionDistribution.cmake │ ├── FindPackageHandleStandardArgs.cmake │ ├── FindPackageMessage.cmake │ ├── FindPython │ │ └── Support.cmake │ ├── FindPython3.cmake │ ├── FindSphinx.cmake │ ├── FindSphinxApidoc.cmake │ ├── FindSphinxMultiVersion.cmake │ ├── ImportTargetsCitadel.cmake │ ├── ImportTargetsDome.cmake │ ├── ImportTargetsEdifice.cmake │ └── ImportTargetsFortress.cmake ├── deps │ ├── CMakeLists.txt │ └── clara │ │ └── clara.hpp ├── pyproject.toml ├── setup.cfg ├── setup.py └── src │ ├── CMakeLists.txt │ ├── controllers │ ├── CMakeLists.txt │ ├── include │ │ └── scenario │ │ │ └── controllers │ │ │ ├── ComputedTorqueFixedBase.h │ │ │ ├── Controller.h │ │ │ └── References.h │ └── src │ │ └── ComputedTorqueFixedBase.cpp │ ├── core │ ├── CMakeLists.txt │ ├── include │ │ └── scenario │ │ │ └── core │ │ │ ├── Joint.h │ │ │ ├── Link.h │ │ │ ├── Model.h │ │ │ ├── World.h │ │ │ └── utils │ │ │ ├── Log.h │ │ │ ├── signals.h │ │ │ └── utils.h │ └── src │ │ ├── signals.cpp │ │ └── utils.cpp │ ├── gazebo │ ├── CMakeLists.txt │ ├── include │ │ └── scenario │ │ │ └── gazebo │ │ │ ├── GazeboEntity.h │ │ │ ├── GazeboSimulator.h │ │ │ ├── Joint.h │ │ │ ├── Link.h │ │ │ ├── Log.h │ │ │ ├── Model.h │ │ │ ├── World.h │ │ │ ├── components │ │ │ ├── BasePoseTarget.h │ │ │ ├── BaseWorldAccelerationTarget.h │ │ │ ├── BaseWorldVelocityTarget.h │ │ │ ├── ExternalWorldWrenchCmdWithDuration.h │ │ │ ├── HistoryOfAppliedJointForces.h │ │ │ ├── JointAcceleration.h │ │ │ ├── JointAccelerationTarget.h │ │ │ ├── JointControlMode.h │ │ │ ├── JointController.h │ │ │ ├── JointControllerPeriod.h │ │ │ ├── JointPID.h │ │ │ ├── JointPositionTarget.h │ │ │ ├── JointVelocityTarget.h │ │ │ ├── SimulatedTime.h │ │ │ └── Timestamp.h │ │ │ ├── exceptions.h │ │ │ ├── helpers.h │ │ │ └── utils.h │ └── src │ │ ├── GazeboSimulator.cpp │ │ ├── Joint.cpp │ │ ├── Link.cpp │ │ ├── Model.cpp │ │ ├── World.cpp │ │ ├── helpers.cpp │ │ └── utils.cpp │ └── plugins │ ├── CMakeLists.txt │ ├── ControllerRunner │ ├── CMakeLists.txt │ ├── ControllerRunner.cpp │ ├── ControllerRunner.h │ ├── ControllersFactory.cpp │ └── ControllersFactory.h │ ├── JointController │ ├── CMakeLists.txt │ ├── JointController.cpp │ └── JointController.h │ └── Physics │ ├── CMakeLists.txt │ ├── CanonicalLinkModelTracker.hh │ ├── EntityFeatureMap.hh │ ├── Physics.cc │ └── Physics.hh ├── setup.cfg ├── setup.py └── tests ├── .python ├── __init__.py ├── test_contacts.py ├── test_environments_gazebowrapper.py ├── test_externalforce.py ├── test_joint_force.py ├── test_pendulum_wrt_ground_truth.py ├── test_rates.py ├── test_robot_base.py ├── test_robot_controller.py ├── test_runtimes.py └── utils.py ├── __init__.py ├── assets └── worlds │ └── fuel_support.sdf ├── common ├── __init__.py └── utils.py ├── test_gym_ignition ├── __init__.py ├── test_inverse_kinematics.py ├── test_normalization.py ├── test_reproducibility.py └── test_sdf_randomizer.py └── test_scenario ├── __init__.py ├── test_contacts.py ├── test_custom_controllers.py ├── test_external_wrench.py ├── test_gazebo_simulator.py ├── test_ignition_fuel.py ├── test_link_velocities.py ├── test_model.py ├── test_multi_world.py ├── test_pid_controllers.py ├── test_velocity_direct.py └── test_world.py /.docker/Dockerfile: -------------------------------------------------------------------------------- 1 | ARG from=diegoferigo/gym-ignition:pypi-master 2 | FROM ${from} 3 | 4 | # Install the PyPI package in a virtualenv 5 | ARG pip_options="" 6 | RUN virtualenv -p $(which python3) ${VIRTUAL_ENV} &&\ 7 | python -m pip install --upgrade pip &&\ 8 | pip install ${pip_options} gym-ignition &&\ 9 | rm -r $HOME/.cache/pip 10 | 11 | # Clone the repository 12 | WORKDIR /github 13 | ARG branch="master" 14 | RUN git clone -b ${branch} https://github.com/robotology/gym-ignition /github 15 | 16 | # Reset the entrypoint 17 | ENTRYPOINT [""] 18 | 19 | CMD ["bash"] 20 | -------------------------------------------------------------------------------- /.docker/base.Dockerfile: -------------------------------------------------------------------------------- 1 | ARG from=ubuntu:focal 2 | FROM ${from} 3 | 4 | SHELL ["/bin/bash", "-c"] 5 | 6 | # Setup locales and timezone 7 | ARG TZ=Europe/Rome 8 | ARG DEBIAN_FRONTEND=noninteractive 9 | RUN rm -f /etc/localtime &&\ 10 | ln -s /usr/share/zoneinfo/"${TZ}" /etc/localtime &&\ 11 | apt-get update &&\ 12 | apt-get install -y --no-install-recommends locales locales-all tzdata &&\ 13 | rm -rf /var/lib/apt/lists/* 14 | 15 | # Install tools and toolchain 16 | RUN apt-get update &&\ 17 | apt-get install -y --no-install-recommends \ 18 | wget \ 19 | software-properties-common \ 20 | apt-transport-https \ 21 | apt-utils \ 22 | gnupg2 \ 23 | nano \ 24 | rename \ 25 | source-highlight \ 26 | &&\ 27 | wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | apt-key add - && \ 28 | apt-add-repository "deb https://apt.kitware.com/ubuntu/ `lsb_release -cs` main" &&\ 29 | add-apt-repository ppa:deadsnakes/ppa &&\ 30 | wget -nv -O - http://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - &&\ 31 | apt-add-repository -y "deb http://apt.llvm.org/`lsb_release -cs`/ llvm-toolchain-`lsb_release -cs`-10 main" &&\ 32 | apt-get update &&\ 33 | apt-get install -y --no-install-recommends \ 34 | build-essential \ 35 | clang-10 \ 36 | git \ 37 | cmake \ 38 | cmake-curses-gui \ 39 | ninja-build \ 40 | valgrind \ 41 | libgflags-dev \ 42 | python3-pip \ 43 | python3-wheel \ 44 | python3.8 \ 45 | python3.8-dev \ 46 | libpython3.8-dev \ 47 | virtualenv \ 48 | swig \ 49 | &&\ 50 | rm -rf /var/lib/apt/lists/* 51 | 52 | # Update git (required by actions/checkout) 53 | RUN add-apt-repository ppa:git-core/ppa &&\ 54 | apt-get update &&\ 55 | apt-get install -y --no-install-recommends git &&\ 56 | rm -rf /var/lib/apt/lists/* 57 | 58 | # Common virtualenv properties 59 | ENV VIRTUAL_ENV=/venv 60 | ENV PATH=$VIRTUAL_ENV/bin:$PATH 61 | 62 | CMD ["bash"] 63 | -------------------------------------------------------------------------------- /.docker/cicd-devel.Dockerfile: -------------------------------------------------------------------------------- 1 | ARG from=diegoferigo/gym-ignition:base 2 | FROM ${from} 3 | 4 | RUN pip3 install vcstool colcon-common-extensions &&\ 5 | rm -r $HOME/.cache/pip 6 | 7 | ARG CMAKE_BUILD_TYPE="Release" 8 | ARG ignition_codename="fortress" 9 | ARG IGNITION_DEFAULT_CHANNEL="stable" 10 | 11 | RUN echo "deb http://packages.osrfoundation.org/gazebo/ubuntu-${IGNITION_DEFAULT_CHANNEL} `lsb_release -cs` main" > \ 12 | /etc/apt/sources.list.d/gazebo-${IGNITION_DEFAULT_CHANNEL}.list &&\ 13 | wget http://packages.osrfoundation.org/gazebo.key -O - | apt-key add - &&\ 14 | apt-get update &&\ 15 | mkdir -p /workspace/src &&\ 16 | cd /workspace/src &&\ 17 | wget https://raw.githubusercontent.com/ignition-tooling/gazebodistro/master/collection-${ignition_codename}.yaml &&\ 18 | vcs import < collection-${ignition_codename}.yaml &&\ 19 | apt -y install --no-install-recommends \ 20 | $(sort -u $(find . -iname 'packages-'$(lsb_release -cs)'.apt' -o -iname 'packages.apt') | grep -v -E "dart|^libignition|^libsdformat" | tr '\n' ' ') &&\ 21 | rm -rf /var/lib/apt/lists/* &&\ 22 | cd /workspace &&\ 23 | colcon graph &&\ 24 | colcon build \ 25 | --cmake-args \ 26 | -GNinja \ 27 | -DBUILD_TESTING:BOOL=OFF \ 28 | -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} \ 29 | --merge-install \ 30 | &&\ 31 | find build/ -type f -not -name 'CMakeCache.txt' -delete &&\ 32 | echo "source /workspace/install/setup.bash" >> /etc/bash.bashrc 33 | 34 | # Source /etc/bash.bashrc before each command 35 | SHELL ["/bin/bash", "-i", "-c"] 36 | 37 | COPY entrypoint.sh /entrypoint.sh 38 | COPY setup_virtualenv.sh /setup_virtualenv.sh 39 | RUN chmod 755 /entrypoint.sh 40 | RUN chmod 755 /setup_virtualenv.sh 41 | ENTRYPOINT ["/entrypoint.sh"] 42 | CMD ["bash"] 43 | -------------------------------------------------------------------------------- /.docker/cicd-master.Dockerfile: -------------------------------------------------------------------------------- 1 | ARG from=diegoferigo/gym-ignition:base 2 | FROM ${from} 3 | 4 | # Install ignition gazebo 5 | ARG ignition_codename="fortress" 6 | RUN echo "deb http://packages.osrfoundation.org/gazebo/ubuntu-stable `lsb_release -cs` main" \ 7 | > /etc/apt/sources.list.d/gazebo-stable.list &&\ 8 | wget http://packages.osrfoundation.org/gazebo.key -O - | apt-key add - &&\ 9 | apt-get update &&\ 10 | apt-get install -y --no-install-recommends ignition-${ignition_codename} &&\ 11 | rm -rf /var/lib/apt/lists/* 12 | 13 | COPY entrypoint.sh /entrypoint.sh 14 | COPY setup_virtualenv.sh /setup_virtualenv.sh 15 | RUN chmod 755 /entrypoint.sh 16 | RUN chmod 755 /setup_virtualenv.sh 17 | ENTRYPOINT ["/entrypoint.sh"] 18 | CMD ["bash"] 19 | -------------------------------------------------------------------------------- /.docker/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3.0' 2 | 3 | services: 4 | 5 | base: 6 | build: 7 | args: 8 | from: ubuntu:focal 9 | context: . 10 | dockerfile: base.Dockerfile 11 | image: diegoferigo/gym-ignition:base 12 | 13 | # ====== 14 | # MASTER 15 | # ====== 16 | 17 | ci-master: 18 | build: 19 | args: 20 | from: diegoferigo/gym-ignition:base 21 | ignition_codename: dome 22 | context: . 23 | dockerfile: cicd-master.Dockerfile 24 | image: diegoferigo/gym-ignition:ci-master 25 | 26 | pypi-master: 27 | build: 28 | args: 29 | from: diegoferigo/gym-ignition:base 30 | ignition_codename: dome 31 | context: . 32 | dockerfile: cicd-master.Dockerfile 33 | image: diegoferigo/gym-ignition:pypi-master 34 | 35 | # ===== 36 | # DEVEL 37 | # ===== 38 | 39 | ci-devel: 40 | build: 41 | args: 42 | from: diegoferigo/gym-ignition:base 43 | ignition_codename: fortress 44 | CMAKE_BUILD_TYPE: Debug 45 | context: . 46 | dockerfile: cicd-devel.Dockerfile 47 | image: diegoferigo/gym-ignition:ci-devel 48 | 49 | pypi-devel: 50 | build: 51 | args: 52 | from: diegoferigo/gym-ignition:base 53 | ignition_codename: fortress 54 | CMAKE_BUILD_TYPE: Release 55 | context: . 56 | dockerfile: cicd-devel.Dockerfile 57 | image: diegoferigo/gym-ignition:pypi-devel 58 | 59 | # ==== 60 | # DEMO 61 | # ==== 62 | 63 | latest: 64 | build: 65 | args: 66 | from: diegoferigo/gym-ignition:pypi-master 67 | branch: master 68 | context: . 69 | dockerfile: Dockerfile 70 | image: diegoferigo/gym-ignition:latest 71 | 72 | nightly: 73 | build: 74 | args: 75 | from: diegoferigo/gym-ignition:ci-devel 76 | branch: devel 77 | pip_options: --pre 78 | context: . 79 | dockerfile: Dockerfile 80 | image: diegoferigo/gym-ignition:nightly 81 | -------------------------------------------------------------------------------- /.docker/entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | if [ ! -x "/setup_virtualenv.sh" ] ; then 5 | echo "File '/setup_virtualenv.sh' not found." 6 | exit 1 7 | fi 8 | 9 | # Setup the python virtualenv 10 | bash /setup_virtualenv.sh 11 | 12 | # If a CMD is passed, execute it 13 | exec "$@" 14 | -------------------------------------------------------------------------------- /.docker/setup_virtualenv.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -eu 3 | 4 | # Read the env variable if exists, otherwise fall back to python3 5 | PYTHON_EXE=python${PYTHON_VERSION:-3} 6 | 7 | if [ ! -x $(type -P ${PYTHON_EXE}) ] ; then 8 | echo "Failed to find ${PYTHON_EXE} in PATH" 9 | exit 1 10 | fi 11 | 12 | # Create an empty virtualenv and enable it by default 13 | virtualenv -p $PYTHON_EXE ${VIRTUAL_ENV} 14 | 15 | # Install pytest in the virtual environment 16 | ${VIRTUAL_ENV}/bin/pip3 install pytest 17 | -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | # Default owners 2 | * @diegoferigo 3 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Report a bug 4 | labels: issue::type::bug 5 | --- 6 | 7 | 8 | 9 | ⚠️ If you're not sure whether your problem is a bug, please ask a question in [Discussions][Discussions] instead. 10 | 11 | 12 | 13 | - [ ] I've read the [FAQ][FAQ] 14 | - [ ] I've read the [Support Policy][Support Policy] 15 | - [ ] I've already searched similar [issues][Issues] and [discussions][Discussions] 16 | - [ ] I've already updated to the most recent supported [release][Releases] (either Stable or Nightly) 17 | 18 | [Issues]: https://github.com/robotology/gym-ignition/issues 19 | [Releases]: https://github.com/robotology/gym-ignition/releases 20 | [FAQ]: https://robotology.github.io/gym-ignition/master/info/faq.html 21 | [Discussions]: https://github.com/robotology/gym-ignition/discussions 22 | [Support Policy]: https://robotology.github.io/gym-ignition/master/installation/support_policy.html 23 | 24 | ## Description: 25 | 26 | A clear and concise description of the bug and what should be the expected behavior. 27 | 28 | ## Steps to reproduce 29 | 30 | 1. 31 | 1. 32 | 1. 33 | 34 | or 35 | 36 | ```python 37 | # Insert some code 38 | ``` 39 | 40 | ## Additional context 41 | 42 | 43 | 44 |
45 | Title 46 | 47 | Content 48 | 49 |
50 | 51 | ## Environment 52 | 53 | - OS: 54 | - GPU: 55 | - Python: 56 | - Version: 57 | - Channel: 58 | - [ ] Stable 59 | - [ ] Nightly 60 | - Installation type: 61 | - [ ] User 62 | - [ ] Developer 63 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Request a new feature 4 | labels: issue::type::enhancement 5 | --- 6 | 7 | 8 | 9 | ⚠️ If you're not sure on the specifics of the feature or would like a broader discussion, please consider posting a proposal to [Discussions][Discussions] instead. 10 | 11 | [Discussions]: https://github.com/robotology/gym-ignition/discussions 12 | 13 | ## Summary 14 | 15 | Describe what this new feature is about and the context you would find it useful. 16 | 17 | ## Implementation suggestion 18 | 19 | Provide a suggestion on how to implement this feature, which could help us to speed up the implementation. 20 | 21 | ## Additional context 22 | 23 | Screenshots, videos, links, sketches, ... 24 | -------------------------------------------------------------------------------- /.github/release.yml: -------------------------------------------------------------------------------- 1 | changelog: 2 | exclude: 3 | labels: 4 | - pr::changelog::ignore 5 | authors: [ ] 6 | categories: 7 | - title: Bug fixing and new features 8 | labels: 9 | - pr::changelog::bugfix 10 | - pr::changelog::release 11 | - pr::changelog::feature 12 | - title: Documentation, CI/CD, tests 13 | labels: 14 | - pr::changelog::docs 15 | - pr::changelog::cicd 16 | - pr::changelog::tests 17 | - title: Other changes 18 | labels: 19 | - pr::changelog::other 20 | - title: No category 21 | labels: [ "*" ] 22 | -------------------------------------------------------------------------------- /.github/workflows/docker.yml: -------------------------------------------------------------------------------- 1 | name: Docker Images 2 | 3 | on: 4 | push: 5 | paths: 6 | - ".docker/*" 7 | - ".github/workflows/docker.yml" 8 | branches: ["**"] 9 | tags-ignore: ["**"] 10 | pull_request: 11 | paths: 12 | - ".docker/*" 13 | - ".github/workflows/docker.yml" 14 | workflow_dispatch: 15 | schedule: 16 | # Execute a weekly build on Monday at 2AM UTC 17 | - cron: '0 2 * * 1' 18 | 19 | jobs: 20 | docker: 21 | name: 'diegoferigo/gym-ignition:${{ matrix.tag }}' 22 | runs-on: ubuntu-latest 23 | strategy: 24 | max-parallel: 1 25 | matrix: 26 | baseimage: ['ubuntu:bionic'] 27 | tag: 28 | - base 29 | - ci-master 30 | - ci-devel 31 | - pypi-master 32 | - pypi-devel 33 | #- latest 34 | - nightly 35 | 36 | steps: 37 | 38 | # Use the branch that triggered the workflow for push and pull_request events 39 | - uses: actions/checkout@master 40 | if: github.event_name != 'schedule' 41 | 42 | # Use devel branch for scheduled builds 43 | - uses: actions/checkout@master 44 | with: 45 | ref: 'refs/heads/devel' 46 | if: github.event_name == 'schedule' 47 | 48 | - name: Build 49 | env: 50 | TAG: ${{ matrix.tag }} 51 | run: | 52 | cd .docker 53 | docker-compose build ${TAG} 54 | 55 | - name: Login 56 | if: | 57 | github.repository == 'robotology/gym-ignition' && 58 | github.event_name != 'pull_request' && 59 | (github.event_name == 'schedule' || github.ref == 'refs/heads/devel') 60 | env: 61 | DOCKER_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} 62 | DOCKER_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }} 63 | run: echo ${DOCKER_PASSWORD} | docker login --username ${DOCKER_USERNAME} --password-stdin 64 | 65 | - name: Push 66 | if: | 67 | github.repository == 'robotology/gym-ignition' && 68 | github.event_name != 'pull_request' && 69 | (github.event_name == 'schedule' || github.ref == 'refs/heads/devel') 70 | run: docker push diegoferigo/gym-ignition:${{ matrix.tag }} 71 | -------------------------------------------------------------------------------- /.github/workflows/style.yml: -------------------------------------------------------------------------------- 1 | name: Code Style 2 | 3 | on: 4 | push: 5 | branches: ["**"] 6 | tags-ignore: ["**"] 7 | pull_request: 8 | workflow_dispatch: 9 | 10 | jobs: 11 | 12 | clang-format: 13 | 14 | name: clang-format 15 | runs-on: ubuntu-latest 16 | 17 | steps: 18 | 19 | - name: "🔀 Checkout repository" 20 | uses: actions/checkout@v2 21 | 22 | - name: "⬇️️ Install dependencies" 23 | run: sudo apt-get install -y --no-install-recommends colordiff 24 | 25 | - name: "📝 Format C++" 26 | uses: diegoferigo/gh-action-clang-format@main 27 | id: format 28 | with: 29 | style: file 30 | pattern: | 31 | *.h 32 | *.cpp 33 | 34 | - name: "🔍️ Inspect style diff" 35 | if: failure() 36 | run: printf "${{ steps.format.outputs.diff }}" | colordiff 37 | 38 | black: 39 | 40 | name: black 41 | runs-on: ubuntu-latest 42 | 43 | steps: 44 | 45 | - name: "🔀 Checkout repository" 46 | uses: actions/checkout@v2 47 | 48 | - name: '🐍 Initialize Python' 49 | uses: actions/setup-python@v2 50 | with: 51 | python-version: "3.8" 52 | 53 | - name: "📝 Black Code Formatter" 54 | uses: psf/black@stable 55 | with: 56 | options: --check --diff --color 57 | 58 | isort: 59 | 60 | name: isort 61 | runs-on: ubuntu-latest 62 | 63 | steps: 64 | 65 | - name: "🔀 Checkout repository" 66 | uses: actions/checkout@v2 67 | 68 | - name: '🐍 Initialize Python' 69 | uses: actions/setup-python@v2 70 | with: 71 | python-version: "3.8" 72 | 73 | - name: "📝 isort" 74 | uses: isort/isort-action@master 75 | with: 76 | configuration: --check --diff --color 77 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.mexa64 2 | *.mexmaci64 3 | *.autosave 4 | *.original 5 | *~ 6 | .DS_Store 7 | build* 8 | *.bak 9 | *.old 10 | CMakeLists.txt.* 11 | Copy_of_* 12 | __pycache__ 13 | *.egg-info 14 | *.cache 15 | .idea* 16 | **/dist/* 17 | .egg* 18 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2019 Istituto Italiano di Tecnologia (IIT). All rights reserved. 2 | # This software may be modified and distributed under the terms of the 3 | # GNU Lesser General Public License v2.1 or any later version. 4 | 5 | # This file is here only to allow build systems to find the 6 | # real CMake project that is stored in the scenario/ folder. 7 | cmake_minimum_required(VERSION 3.16) 8 | project(scenario) 9 | add_subdirectory(scenario) 10 | 11 | # The uninstall target resource must be included in the top-level CMakeLists 12 | list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/scenario/cmake) 13 | include(AddUninstallTarget) 14 | 15 | # ============= 16 | # DOCUMENTATION 17 | # ============= 18 | 19 | if(BUILD_DOCS) 20 | add_subdirectory(docs) 21 | endif() 22 | -------------------------------------------------------------------------------- /docs/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT). All rights reserved. 2 | # This software may be modified and distributed under the terms of the 3 | # GNU Lesser General Public License v2.1 or any later version. 4 | 5 | # This variable is filled from the doxygen/ folder. 6 | # Defined here empty to remember that it exists in this scope. 7 | set(DOXYGEN_OUTPUT_DIRECTORY "") 8 | 9 | add_subdirectory(doxygen) 10 | add_subdirectory(sphinx) 11 | -------------------------------------------------------------------------------- /docs/doxygen/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT). All rights reserved. 2 | # This software may be modified and distributed under the terms of the 3 | # GNU Lesser General Public License v2.1 or any later version. 4 | 5 | find_package(Doxygen REQUIRED) 6 | 7 | set(DOXYGEN_GENERATE_XML YES) 8 | set(DOXYGEN_GENERATE_HTML NO) 9 | set(DOXYGEN_GENERATE_LATEX YES) 10 | set(DOXYGEN_FILE_PATTERNS "*.h") 11 | set(DOXYGEN_BUILTIN_STL_SUPPORT YES) 12 | set(DOXYGEN_EXCLUDE_PATTERNS 13 | */components/* */plugins/* */details/* */private/* 14 | */examples/* */tests/* */gympp/*) 15 | 16 | doxygen_add_docs( 17 | doxygen 18 | ${PROJECT_SOURCE_DIR} 19 | COMMENT "Generate man pages" 20 | ) 21 | 22 | # This is required by Sphinx to find Doxygen XMLs 23 | set(DOXYGEN_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} PARENT_SCOPE) 24 | -------------------------------------------------------------------------------- /docs/sphinx/_templates/module.rst_t: -------------------------------------------------------------------------------- 1 | {%- if show_headings %} 2 | {{- [basename, "module"] | join(' ') | e | heading }} 3 | 4 | {% endif -%} 5 | .. automodule:: {{ qualname }} 6 | {%- for option in automodule_options %} 7 | :{{ option }}: 8 | {%- endfor %} 9 | -------------------------------------------------------------------------------- /docs/sphinx/_templates/package.rst_t: -------------------------------------------------------------------------------- 1 | {%- macro automodule(modname, options) -%} 2 | .. automodule:: {{ modname }} 3 | {%- for option in options %} 4 | :{{ option }}: 5 | {%- endfor %} 6 | {%- endmacro %} 7 | 8 | {%- macro toctree(docnames) -%} 9 | .. toctree:: 10 | :maxdepth: {{ maxdepth }} 11 | {% for docname in docnames %} 12 | {{ docname }} 13 | {%- endfor %} 14 | {%- endmacro %} 15 | 16 | {%- if is_namespace %} 17 | {{- [pkgname, "namespace"] | join(" ") | e | heading }} 18 | {% else %} 19 | {{- pkgname | e | heading }} 20 | {% endif %} 21 | 22 | {%- if modulefirst and not is_namespace %} 23 | {{ automodule(pkgname, automodule_options) }} 24 | {% endif %} 25 | 26 | {%- if subpackages %} 27 | 28 | {{ toctree(subpackages) }} 29 | {% endif %} 30 | 31 | {%- if submodules %} 32 | {% if separatemodules %} 33 | {{ toctree(submodules) }} 34 | {% else %} 35 | {%- for submodule in submodules %} 36 | {% if show_headings %} 37 | {{- submodule | e | heading(2) }} 38 | {% endif %} 39 | {{ automodule(submodule, automodule_options) }} 40 | {% endfor %} 41 | {%- endif %} 42 | {%- endif %} 43 | 44 | {%- if not modulefirst and not is_namespace %} 45 | Module contents 46 | --------------- 47 | 48 | {{ automodule(pkgname, automodule_options) }} 49 | {% endif %} 50 | -------------------------------------------------------------------------------- /docs/sphinx/_templates/toc.rst_t: -------------------------------------------------------------------------------- 1 | {{ header | heading }} 2 | 3 | .. toctree:: 4 | :maxdepth: {{ maxdepth }} 5 | {% for docname in docnames %} 6 | {{ docname }} 7 | {%- endfor %} 8 | -------------------------------------------------------------------------------- /docs/sphinx/_templates/versioning.html: -------------------------------------------------------------------------------- 1 | {% if versions %} 2 | 14 | {% endif %} 15 | -------------------------------------------------------------------------------- /docs/sphinx/_templates/versions.html: -------------------------------------------------------------------------------- 1 | {%- if current_version %} 2 |
3 | 4 | Other Versions 5 | v: {{ current_version.name }} 6 | 7 | 8 |
9 | {%- if versions.tags %} 10 |
11 |
Tags
12 | {%- for item in versions.tags %} 13 |
{{ item.name }}
14 | {%- endfor %} 15 |
16 | {%- endif %} 17 | {%- if versions.branches %} 18 |
19 |
Branches
20 | {%- for item in versions.branches %} 21 |
{{ item.name }}
22 | {%- endfor %} 23 |
24 | {%- endif %} 25 |
26 |
27 | {%- endif %} -------------------------------------------------------------------------------- /docs/sphinx/apidoc/gym-ignition-environments/gym_ignition_environments.models.rst: -------------------------------------------------------------------------------- 1 | gym\_ignition\_environments.models 2 | ================================== 3 | 4 | .. automodule:: gym_ignition_environments.models 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | 10 | gym\_ignition\_environments.models.cartpole 11 | ------------------------------------------- 12 | 13 | .. automodule:: gym_ignition_environments.models.cartpole 14 | :members: 15 | :undoc-members: 16 | :show-inheritance: 17 | 18 | gym\_ignition\_environments.models.icub 19 | --------------------------------------- 20 | 21 | .. automodule:: gym_ignition_environments.models.icub 22 | :members: 23 | :undoc-members: 24 | :show-inheritance: 25 | 26 | gym\_ignition\_environments.models.panda 27 | ---------------------------------------- 28 | 29 | .. automodule:: gym_ignition_environments.models.panda 30 | :members: 31 | :undoc-members: 32 | :show-inheritance: 33 | 34 | gym\_ignition\_environments.models.pendulum 35 | ------------------------------------------- 36 | 37 | .. automodule:: gym_ignition_environments.models.pendulum 38 | :members: 39 | :undoc-members: 40 | :show-inheritance: 41 | -------------------------------------------------------------------------------- /docs/sphinx/apidoc/gym-ignition-environments/gym_ignition_environments.randomizers.rst: -------------------------------------------------------------------------------- 1 | gym\_ignition\_environments.randomizers 2 | ======================================= 3 | 4 | .. automodule:: gym_ignition_environments.randomizers 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | 10 | gym\_ignition\_environments.randomizers.cartpole 11 | ------------------------------------------------ 12 | 13 | .. automodule:: gym_ignition_environments.randomizers.cartpole 14 | :members: 15 | :undoc-members: 16 | :show-inheritance: 17 | 18 | gym\_ignition\_environments.randomizers.cartpole\_no\_rand 19 | ---------------------------------------------------------- 20 | 21 | .. automodule:: gym_ignition_environments.randomizers.cartpole_no_rand 22 | :members: 23 | :undoc-members: 24 | :show-inheritance: 25 | -------------------------------------------------------------------------------- /docs/sphinx/apidoc/gym-ignition-environments/gym_ignition_environments.rst: -------------------------------------------------------------------------------- 1 | gym\_ignition\_environments 2 | =========================== 3 | 4 | .. automodule:: gym_ignition_environments 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | 10 | .. toctree:: 11 | :maxdepth: 4 12 | 13 | gym_ignition_environments.models 14 | gym_ignition_environments.randomizers 15 | gym_ignition_environments.tasks 16 | -------------------------------------------------------------------------------- /docs/sphinx/apidoc/gym-ignition-environments/gym_ignition_environments.tasks.rst: -------------------------------------------------------------------------------- 1 | gym\_ignition\_environments.tasks 2 | ================================= 3 | 4 | .. automodule:: gym_ignition_environments.tasks 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | 10 | gym\_ignition\_environments.tasks.cartpole\_continuous\_balancing 11 | ----------------------------------------------------------------- 12 | 13 | .. automodule:: gym_ignition_environments.tasks.cartpole_continuous_balancing 14 | :members: 15 | :undoc-members: 16 | :show-inheritance: 17 | 18 | gym\_ignition\_environments.tasks.cartpole\_continuous\_swingup 19 | --------------------------------------------------------------- 20 | 21 | .. automodule:: gym_ignition_environments.tasks.cartpole_continuous_swingup 22 | :members: 23 | :undoc-members: 24 | :show-inheritance: 25 | 26 | gym\_ignition\_environments.tasks.cartpole\_discrete\_balancing 27 | --------------------------------------------------------------- 28 | 29 | .. automodule:: gym_ignition_environments.tasks.cartpole_discrete_balancing 30 | :members: 31 | :undoc-members: 32 | :show-inheritance: 33 | 34 | gym\_ignition\_environments.tasks.pendulum\_swingup 35 | --------------------------------------------------- 36 | 37 | .. automodule:: gym_ignition_environments.tasks.pendulum_swingup 38 | :members: 39 | :undoc-members: 40 | :show-inheritance: 41 | -------------------------------------------------------------------------------- /docs/sphinx/apidoc/gym-ignition/gym_ignition.base.rst: -------------------------------------------------------------------------------- 1 | gym\_ignition.base 2 | ================== 3 | 4 | .. automodule:: gym_ignition.base 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | 10 | gym\_ignition.base.runtime 11 | -------------------------- 12 | 13 | .. automodule:: gym_ignition.base.runtime 14 | :members: 15 | :undoc-members: 16 | :show-inheritance: 17 | 18 | gym\_ignition.base.task 19 | ----------------------- 20 | 21 | .. automodule:: gym_ignition.base.task 22 | :members: 23 | :undoc-members: 24 | :show-inheritance: 25 | -------------------------------------------------------------------------------- /docs/sphinx/apidoc/gym-ignition/gym_ignition.context.gazebo.rst: -------------------------------------------------------------------------------- 1 | gym\_ignition.context.gazebo 2 | ============================ 3 | 4 | .. automodule:: gym_ignition.context.gazebo 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | 10 | gym\_ignition.context.gazebo.controllers 11 | ---------------------------------------- 12 | 13 | .. automodule:: gym_ignition.context.gazebo.controllers 14 | :members: 15 | :undoc-members: 16 | :show-inheritance: 17 | 18 | gym\_ignition.context.gazebo.plugin 19 | ----------------------------------- 20 | 21 | .. automodule:: gym_ignition.context.gazebo.plugin 22 | :members: 23 | :undoc-members: 24 | :show-inheritance: 25 | -------------------------------------------------------------------------------- /docs/sphinx/apidoc/gym-ignition/gym_ignition.context.rst: -------------------------------------------------------------------------------- 1 | gym\_ignition.context 2 | ===================== 3 | 4 | .. automodule:: gym_ignition.context 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | 10 | .. toctree:: 11 | :maxdepth: 4 12 | 13 | gym_ignition.context.gazebo 14 | -------------------------------------------------------------------------------- /docs/sphinx/apidoc/gym-ignition/gym_ignition.randomizers.model.rst: -------------------------------------------------------------------------------- 1 | gym\_ignition.randomizers.model 2 | =============================== 3 | 4 | .. automodule:: gym_ignition.randomizers.model 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | 10 | gym\_ignition.randomizers.model.sdf 11 | ----------------------------------- 12 | 13 | .. automodule:: gym_ignition.randomizers.model.sdf 14 | :members: 15 | :undoc-members: 16 | :show-inheritance: 17 | -------------------------------------------------------------------------------- /docs/sphinx/apidoc/gym-ignition/gym_ignition.randomizers.physics.rst: -------------------------------------------------------------------------------- 1 | gym\_ignition.randomizers.physics 2 | ================================= 3 | 4 | .. automodule:: gym_ignition.randomizers.physics 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | 10 | gym\_ignition.randomizers.physics.dart 11 | -------------------------------------- 12 | 13 | .. automodule:: gym_ignition.randomizers.physics.dart 14 | :members: 15 | :undoc-members: 16 | :show-inheritance: 17 | -------------------------------------------------------------------------------- /docs/sphinx/apidoc/gym-ignition/gym_ignition.randomizers.rst: -------------------------------------------------------------------------------- 1 | gym\_ignition.randomizers 2 | ========================= 3 | 4 | .. automodule:: gym_ignition.randomizers 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | 10 | .. toctree:: 11 | :maxdepth: 4 12 | 13 | gym_ignition.randomizers.model 14 | gym_ignition.randomizers.physics 15 | 16 | 17 | gym\_ignition.randomizers.abc 18 | ----------------------------- 19 | 20 | .. automodule:: gym_ignition.randomizers.abc 21 | :members: 22 | :undoc-members: 23 | :show-inheritance: 24 | 25 | gym\_ignition.randomizers.gazebo\_env\_randomizer 26 | ------------------------------------------------- 27 | 28 | .. automodule:: gym_ignition.randomizers.gazebo_env_randomizer 29 | :members: 30 | :undoc-members: 31 | :show-inheritance: 32 | -------------------------------------------------------------------------------- /docs/sphinx/apidoc/gym-ignition/gym_ignition.rbd.idyntree.rst: -------------------------------------------------------------------------------- 1 | gym\_ignition.rbd.idyntree 2 | ========================== 3 | 4 | .. automodule:: gym_ignition.rbd.idyntree 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | 10 | gym\_ignition.rbd.idyntree.helpers 11 | ---------------------------------- 12 | 13 | .. automodule:: gym_ignition.rbd.idyntree.helpers 14 | :members: 15 | :undoc-members: 16 | :show-inheritance: 17 | 18 | gym\_ignition.rbd.idyntree.inverse\_kinematics\_nlp 19 | --------------------------------------------------- 20 | 21 | .. automodule:: gym_ignition.rbd.idyntree.inverse_kinematics_nlp 22 | :members: 23 | :undoc-members: 24 | :show-inheritance: 25 | 26 | gym\_ignition.rbd.idyntree.kindyncomputations 27 | --------------------------------------------- 28 | 29 | .. automodule:: gym_ignition.rbd.idyntree.kindyncomputations 30 | :members: 31 | :undoc-members: 32 | :show-inheritance: 33 | 34 | gym\_ignition.rbd.idyntree.numpy 35 | -------------------------------- 36 | 37 | .. automodule:: gym_ignition.rbd.idyntree.numpy 38 | :members: 39 | :undoc-members: 40 | :show-inheritance: 41 | -------------------------------------------------------------------------------- /docs/sphinx/apidoc/gym-ignition/gym_ignition.rbd.rst: -------------------------------------------------------------------------------- 1 | gym\_ignition.rbd 2 | ================= 3 | 4 | .. automodule:: gym_ignition.rbd 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | 10 | .. toctree:: 11 | :maxdepth: 4 12 | 13 | gym_ignition.rbd.idyntree 14 | 15 | 16 | gym\_ignition.rbd.conversions 17 | ----------------------------- 18 | 19 | .. automodule:: gym_ignition.rbd.conversions 20 | :members: 21 | :undoc-members: 22 | :show-inheritance: 23 | 24 | gym\_ignition.rbd.utils 25 | ----------------------- 26 | 27 | .. automodule:: gym_ignition.rbd.utils 28 | :members: 29 | :undoc-members: 30 | :show-inheritance: 31 | -------------------------------------------------------------------------------- /docs/sphinx/apidoc/gym-ignition/gym_ignition.rst: -------------------------------------------------------------------------------- 1 | gym\_ignition 2 | ============= 3 | 4 | .. automodule:: gym_ignition 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | 10 | .. toctree:: 11 | :maxdepth: 4 12 | 13 | gym_ignition.base 14 | gym_ignition.context 15 | gym_ignition.randomizers 16 | gym_ignition.rbd 17 | gym_ignition.runtimes 18 | gym_ignition.scenario 19 | gym_ignition.utils 20 | -------------------------------------------------------------------------------- /docs/sphinx/apidoc/gym-ignition/gym_ignition.runtimes.rst: -------------------------------------------------------------------------------- 1 | gym\_ignition.runtimes 2 | ====================== 3 | 4 | .. automodule:: gym_ignition.runtimes 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | 10 | gym\_ignition.runtimes.gazebo\_runtime 11 | -------------------------------------- 12 | 13 | .. automodule:: gym_ignition.runtimes.gazebo_runtime 14 | :members: 15 | :undoc-members: 16 | :show-inheritance: 17 | 18 | gym\_ignition.runtimes.realtime\_runtime 19 | ---------------------------------------- 20 | 21 | .. automodule:: gym_ignition.runtimes.realtime_runtime 22 | :members: 23 | :undoc-members: 24 | :show-inheritance: 25 | -------------------------------------------------------------------------------- /docs/sphinx/apidoc/gym-ignition/gym_ignition.scenario.rst: -------------------------------------------------------------------------------- 1 | gym\_ignition.scenario 2 | ====================== 3 | 4 | .. automodule:: gym_ignition.scenario 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | 10 | gym\_ignition.scenario.model\_with\_file 11 | ---------------------------------------- 12 | 13 | .. automodule:: gym_ignition.scenario.model_with_file 14 | :members: 15 | :undoc-members: 16 | :show-inheritance: 17 | 18 | gym\_ignition.scenario.model\_wrapper 19 | ------------------------------------- 20 | 21 | .. automodule:: gym_ignition.scenario.model_wrapper 22 | :members: 23 | :undoc-members: 24 | :show-inheritance: 25 | -------------------------------------------------------------------------------- /docs/sphinx/apidoc/gym-ignition/gym_ignition.utils.rst: -------------------------------------------------------------------------------- 1 | gym\_ignition.utils 2 | =================== 3 | 4 | .. automodule:: gym_ignition.utils 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | 10 | gym\_ignition.utils.logger 11 | -------------------------- 12 | 13 | .. automodule:: gym_ignition.utils.logger 14 | :members: 15 | :undoc-members: 16 | :show-inheritance: 17 | 18 | gym\_ignition.utils.math 19 | ------------------------ 20 | 21 | .. automodule:: gym_ignition.utils.math 22 | :members: 23 | :undoc-members: 24 | :show-inheritance: 25 | 26 | gym\_ignition.utils.misc 27 | ------------------------ 28 | 29 | .. automodule:: gym_ignition.utils.misc 30 | :members: 31 | :undoc-members: 32 | :show-inheritance: 33 | 34 | gym\_ignition.utils.resource\_finder 35 | ------------------------------------ 36 | 37 | .. automodule:: gym_ignition.utils.resource_finder 38 | :members: 39 | :undoc-members: 40 | :show-inheritance: 41 | 42 | gym\_ignition.utils.scenario 43 | ---------------------------- 44 | 45 | .. automodule:: gym_ignition.utils.scenario 46 | :members: 47 | :undoc-members: 48 | :show-inheritance: 49 | 50 | gym\_ignition.utils.typing 51 | -------------------------- 52 | 53 | .. automodule:: gym_ignition.utils.typing 54 | :members: 55 | :undoc-members: 56 | :show-inheritance: 57 | -------------------------------------------------------------------------------- /docs/sphinx/apidoc/scenario/scenario.bindings.rst: -------------------------------------------------------------------------------- 1 | scenario.bindings 2 | ================= 3 | 4 | .. automodule:: scenario.bindings 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | 10 | scenario.bindings.core 11 | ---------------------- 12 | 13 | .. automodule:: scenario.bindings.core 14 | :members: 15 | :undoc-members: 16 | :show-inheritance: 17 | 18 | scenario.bindings.gazebo 19 | ------------------------ 20 | 21 | .. automodule:: scenario.bindings.gazebo 22 | :members: 23 | :undoc-members: 24 | :show-inheritance: 25 | -------------------------------------------------------------------------------- /docs/sphinx/apidoc/scenario/scenario.rst: -------------------------------------------------------------------------------- 1 | scenario 2 | ======== 3 | 4 | .. automodule:: scenario 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | 10 | .. toctree:: 11 | :maxdepth: 4 12 | 13 | scenario.bindings 14 | -------------------------------------------------------------------------------- /docs/sphinx/breathe/core.rst: -------------------------------------------------------------------------------- 1 | .. _scenario_core: 2 | 3 | Core 4 | ==== 5 | 6 | .. doxygennamespace:: scenario::core 7 | :project: scenario 8 | :members: 9 | -------------------------------------------------------------------------------- /docs/sphinx/breathe/gazebo.rst: -------------------------------------------------------------------------------- 1 | .. _scenario_gazebo: 2 | 3 | Gazebo 4 | ====== 5 | 6 | .. doxygennamespace:: scenario::gazebo 7 | :project: scenario 8 | :members: 9 | -------------------------------------------------------------------------------- /docs/sphinx/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Redirecting to master branch 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /docs/sphinx/index.rst: -------------------------------------------------------------------------------- 1 | .. _scenario_and_gym_ignition: 2 | 3 | ScenarIO and gym-ignition 4 | ========================= 5 | 6 | This project targets both *control* and *robot learning* research domains: 7 | 8 | - Researchers in robotics and control can simulate their robots with familiar tools like Gazebo and URDF/SDF, 9 | without the need to rely on any middleware. 10 | - Researchers in robot learning can quickly develop new robotic environments that can scale to hundreds of parallel instances. 11 | 12 | We provide two related subprojects to each of these categories: 13 | 14 | 1. **ScenarIO** provides APIs to interface with the robots. 15 | 2. **gym-ignition** helps structuring environments compatible with OpenAI Gym, 16 | while minimizing boilerplate code and providing common rigid-body dynamics utilities. 17 | 18 | Check the sections :ref:`What is ScenarIO ` and 19 | :ref:`What is gym-ignition ` for more details, 20 | and visit :ref:`Motivations ` for an extended overview. 21 | 22 | For a quick practical introduction, visit the :ref:`Getting Started ` page. 23 | 24 | If you use this project for your research, please check the FAQ about :ref:`how to give credit `. 25 | 26 | .. list-table:: 27 | 28 | * - |pendulum_swing| 29 | - |panda_grasping| 30 | - |icub_stepping| 31 | 32 | .. |icub_stepping| image:: https://user-images.githubusercontent.com/469199/99262746-9e021a80-281e-11eb-9df1-d70134b0801a.png 33 | .. |panda_grasping| image:: https://user-images.githubusercontent.com/469199/99263111-0cdf7380-281f-11eb-9cfe-338b2aae0503.png 34 | .. |pendulum_swing| image:: https://user-images.githubusercontent.com/469199/99262383-321fb200-281e-11eb-89cc-cc31f590daa3.png 35 | 36 | .. toctree:: 37 | :hidden: 38 | :maxdepth: 1 39 | :caption: What 40 | 41 | what/what_is_scenario 42 | what/what_is_gym_ignition 43 | 44 | .. toctree:: 45 | :hidden: 46 | :maxdepth: 1 47 | :caption: Why 48 | 49 | why/motivations 50 | why/why_scenario 51 | why/why_ignition_gazebo 52 | why/why_gym_ignition 53 | 54 | .. toctree:: 55 | :hidden: 56 | :maxdepth: 1 57 | :caption: Installation (How) 58 | 59 | installation/support_policy 60 | installation/stable 61 | installation/nightly 62 | installation/developer 63 | 64 | .. toctree:: 65 | :hidden: 66 | :maxdepth: 1 67 | :caption: Getting Started 68 | 69 | getting_started/scenario 70 | getting_started/manipulation 71 | getting_started/gym-ignition 72 | 73 | .. toctree:: 74 | :hidden: 75 | :maxdepth: 2 76 | :caption: ScenarIO C++ API: 77 | 78 | breathe/core 79 | breathe/gazebo 80 | 81 | .. toctree:: 82 | :hidden: 83 | :maxdepth: 2 84 | :caption: Python Packages 85 | 86 | apidoc/scenario/scenario.bindings 87 | apidoc/gym-ignition/gym_ignition 88 | apidoc/gym-ignition-environments/gym_ignition_environments 89 | 90 | .. toctree:: 91 | :hidden: 92 | :maxdepth: 2 93 | :caption: Information 94 | 95 | info/faq 96 | info/limitations 97 | -------------------------------------------------------------------------------- /docs/sphinx/info/limitations.rst: -------------------------------------------------------------------------------- 1 | Limitations 2 | =========== 3 | 4 | Sensors support 5 | --------------- 6 | 7 | Ignition Gazebo supports a wide variety of `sensors `_, 8 | like cameras, lidars, ... 9 | However, ScenarI/O and consequently gym-ignition are not yet able to extract data from sensors. 10 | Follow :issue:`199` if you're interested in sensors support. 11 | 12 | Performance 13 | ----------- 14 | 15 | When operating on a single model, DART provides good enough performance and accuracy for most of the use-cases. 16 | However, we noticed that it does not perform well when many models are inserted in the simulated world, 17 | especially in contact-rich scenarios. 18 | 19 | If your aim is performing simulations for robot learning, we recommend running multiple instances of the simulator, 20 | each of them operating on a world containing a single robot. 21 | 22 | If your aim is simulating a big world where the controlled model can move inside the scene, exploiting a new feature 23 | of Ignition Gazebo called `levels `_ 24 | could be the proper solution. This feature is exploited by the big worlds of `subt `_. 25 | 26 | Instead, if your world has many models and the usage of levels does not apply to your use-case, you can try to switch 27 | the physics backend to an engine that handles better your simulation. 28 | 29 | .. note:: 30 | 31 | At the time of writing only DART is officially supported. 32 | There is some recent activity to implement the bullet physics engine, but this back-and is not yet ready. 33 | As last resort, you can implement a new physics backend following the 34 | `instructions `_. 35 | -------------------------------------------------------------------------------- /docs/sphinx/installation/nightly.rst: -------------------------------------------------------------------------------- 1 | .. _installation_nightly: 2 | 3 | Nightly 4 | ======= 5 | 6 | The nightly channel contains the most recent updates of the project. 7 | As described in the :ref:`support policy `, this channel requires building Ignition from sources. 8 | 9 | We publish updated nightly packages after any pull request merged in the ``devel`` branch. 10 | 11 | .. include:: virtual_environment.rst 12 | 13 | PyPI Package 14 | ************ 15 | 16 | We provide two different packages for ScenarIO and gym-ignition. 17 | 18 | If you are interested in the ScenarIO package, 19 | install the `scenario `_ package from PyPI: 20 | 21 | .. code-block:: bash 22 | 23 | pip install --pre scenario 24 | 25 | Instead, if you are interested in gym-ignition, 26 | install the `gym-ignition `_ package from PyPI: 27 | 28 | .. code-block:: bash 29 | 30 | pip install --pre scenario gym-ignition 31 | 32 | Note that in this case, specifying also the ``scenario`` dependency is necessary, 33 | otherwise ``pip`` will pull the stable package from PyPI. 34 | 35 | .. include:: system_configuration.rst 36 | -------------------------------------------------------------------------------- /docs/sphinx/installation/stable.rst: -------------------------------------------------------------------------------- 1 | .. _installation_stable: 2 | 3 | Stable 4 | ====== 5 | 6 | The stable channel is the easiest way to setup your system. 7 | As described in the :ref:`support policy `, this channel allows installing Ignition from binary packages. 8 | 9 | We publish updated stable packages after any tagged release of the ``master`` branch. 10 | 11 | .. include:: virtual_environment.rst 12 | 13 | PyPI Package 14 | ************ 15 | 16 | We provide two different packages for ScenarIO and gym-ignition. 17 | 18 | If you are interested in the ScenarIO package, 19 | install the `scenario `_ package from PyPI: 20 | 21 | .. code-block:: bash 22 | 23 | pip install scenario 24 | 25 | Instead, if you are interested in gym-ignition, 26 | install the `gym-ignition `_ package from PyPI: 27 | 28 | .. code-block:: bash 29 | 30 | pip install gym-ignition 31 | 32 | It will download and install also ``scenario`` since it depends on it. 33 | -------------------------------------------------------------------------------- /docs/sphinx/installation/support_policy.rst: -------------------------------------------------------------------------------- 1 | .. _support_policy: 2 | 3 | Support policy 4 | ============== 5 | 6 | **gym-ignition** is an hybrid C++ and Python project and it requires finding in the system updated compile and runtime 7 | dependencies, depending on the installation type you select. 8 | 9 | The project mostly supports all the major operating systems. 10 | However, we are currently using and testing only GNU/Linux systems. 11 | We do not yet provide official support to other operating systems. 12 | 13 | The table below recaps the project requirements of the :ref:`Stable ` and :ref:`Nightly ` channels: 14 | 15 | +-------------+-----------------+--------+----------------------+----------+------------+---------+ 16 | | Channel | C++ | Python | Ignition | Ubuntu | macOS [*]_ | Windows | 17 | +=============+=================+========+======================+==========+============+=========+ 18 | | **Stable** | >= gcc8, clang6 | >= 3.8 | `Fortress`_ (binary) | >= 20.04 | No | No | 19 | +-------------+-----------------+--------+----------------------+----------+------------+---------+ 20 | | **Nightly** | >= gcc8, clang6 | >= 3.8 | `Fortress`_ (source) | >= 20.04 | No | No | 21 | +-------------+-----------------+--------+----------------------+----------+------------+---------+ 22 | 23 | .. _`Fortress`: https://ignitionrobotics.org/docs/fortress/install 24 | 25 | .. [*] Ignition officially supports macOS and also ``gym-ignition`` could be installed on this platform. 26 | However, we do not currently test this configuration and we cannot guarantee support. 27 | 28 | .. important:: 29 | 30 | Our policy is to support Ubuntu from the most recent LTS distribution, currently Ubuntu 20.04 Focal. 31 | We typically switch to a new LTS when the first minor release ``YY.MM.1`` is released. 32 | 33 | The Python and compilers policies follow a similar approach, we try to keep them updated as much as 34 | possible following what the supported LTS distribution includes. 35 | 36 | .. note:: 37 | 38 | External contributions to extend the support and provide feedback about other platforms are most welcome. 39 | 40 | .. admonition:: Fun fact 41 | 42 | In the same spirit of `ubuntu/+bug/1 `_, we have our own :issue:`1`. 43 | -------------------------------------------------------------------------------- /docs/sphinx/installation/system_configuration.rst: -------------------------------------------------------------------------------- 1 | System Configuration 2 | ******************** 3 | 4 | This section applies only to the installations that require building Ignition from sources. 5 | 6 | If you installed Ignition from sources, you likely used ``colcon`` and therefore the entire suite was installed in a custom folder called workspace. 7 | The workspace contains all the shared libraries and executables of Ignition, including the plugins loaded during runtime. 8 | Since we cannot know in advance where you created the workspace, ``gym-ignition`` is not able to find the physics plugins. 9 | 10 | After you enabled the workspace by sourcing its bash script, you may need to also export the following variable: 11 | 12 | .. code-block:: bash 13 | 14 | export IGN_GAZEBO_PHYSICS_ENGINE_PATH=${IGN_GAZEBO_PHYSICS_ENGINE_PATH}:${COLCON_PREFIX_PATH}/lib/ign-physics-3/engine-plugins/ 15 | 16 | Make sure to select the folder corresponding to the correct version of ign-physics, otherwise the wrong plugins are found. 17 | -------------------------------------------------------------------------------- /docs/sphinx/installation/virtual_environment.rst: -------------------------------------------------------------------------------- 1 | Virtual Environment (optional) 2 | ****************************** 3 | 4 | This step is optional but highly recommended. 5 | Visit the `virtual environments `_ documentation for more details. 6 | 7 | .. code-block:: bash 8 | 9 | sudo apt install virtualenv 10 | virtualenv -p python3.8 $HOME/venv 11 | source $HOME/venv/bin/activate 12 | 13 | Note that the activation is temporary and it is valid only in the same terminal. 14 | Make sure to execute the next steps in a terminal where the virtual environment is active. 15 | -------------------------------------------------------------------------------- /docs/sphinx/what/what_is_gym_ignition.rst: -------------------------------------------------------------------------------- 1 | .. _what_is_gym_ignition: 2 | 3 | What is gym-ignition? 4 | ===================== 5 | 6 | **gym-ignition** is a framework to create **reproducible robotics environments** for reinforcement learning research. 7 | 8 | It is based on the :ref:`ScenarIO ` project which provides the low-level APIs to interface with the Ignition Gazebo simulator. 9 | By default, RL environments share a lot of boilerplate code, e.g. for initializing the simulator or structuring the classes 10 | to expose the ``gym.Env`` interface. 11 | Gym-ignition provides the :py:class:`~gym_ignition.base.task.Task` and :py:class:`~gym_ignition.base.runtime.Runtime` 12 | abstractions that help you focusing on the development of the decision-making logic rather than engineering. 13 | It includes :py:mod:`~gym_ignition.randomizers` to simplify the implementation of domain randomization 14 | of models, physics, and tasks. 15 | Gym-ignition also provides powerful dynamics algorithms compatible with both fixed-base and floating-based robots by 16 | exploiting `iDynTree `_ and exposing 17 | high-level functionalities (:py:mod:`~gym_ignition.rbd.idyntree`). 18 | 19 | Gym-ignition does not provide out-of-the-box environments ready to be used. 20 | Rather, its aim is simplifying and streamlining their development. 21 | Nonetheless, for illustrative purpose, it includes canonical examples in the 22 | :py:mod:`gym_ignition_environments` package. 23 | -------------------------------------------------------------------------------- /docs/sphinx/what/what_is_scenario.rst: -------------------------------------------------------------------------------- 1 | .. _what_is_scenario: 2 | 3 | What is ScenarIO 4 | ================ 5 | 6 | **ScenarIO** is a C++ abstraction layer to interact with simulated and real robots. 7 | 8 | It mainly provides the following 9 | `C++ interfaces `_: 10 | 11 | - :cpp:class:`scenario::core::World` 12 | - :cpp:class:`scenario::core::Model` 13 | - :cpp:class:`scenario::core::Link` 14 | - :cpp:class:`scenario::core::Joint` 15 | 16 | These interfaces can be implemented to operate on different scenarios, 17 | including robots operating on either simulated worlds or in real-time. 18 | 19 | ScenarIO currently fully implements **Gazebo ScenarIO** (APIs), 20 | a simulated back-end that interacts with `Ignition Gazebo `_. 21 | The result allows stepping the simulator programmatically, ensuring a fully reproducible behaviour. 22 | It relates closely to other projects like 23 | `pybullet `_ and `mujoco-py `_. 24 | 25 | A real-time backend that interacts with the `YARP `_ middleware is under development. 26 | 27 | ScenarIO can be used either from C++ (:ref:`Core APIs `, :ref:`Gazebo APIs `) 28 | or from Python (:py:mod:`~scenario.bindings.core`, :py:mod:`~scenario.bindings.gazebo`). 29 | 30 | If you're interested to know the reasons why we started developing ScenarIO and why we selected Ignition Gazebo 31 | for our simulations, visit the :ref:`Motivations ` section. 32 | -------------------------------------------------------------------------------- /docs/sphinx/why/motivations.rst: -------------------------------------------------------------------------------- 1 | .. _motivations: 2 | 3 | Intro 4 | ===== 5 | 6 | In this section we recap the motivations behind this project. 7 | Choosing the right framework for your research is often challenging and we hope to provide a broader look that could 8 | help deciding whether it meets your needs or not. 9 | 10 | The development of the framework is evolving quickly, and the architecture and motivations described in the 11 | :ref:`reference publication ` are becoming outdated. 12 | While that publication remains the reference in case you use the project for your research, 13 | this section provides a constantly updated description aligned with the most recent development news. 14 | -------------------------------------------------------------------------------- /docs/sphinx/why/why_gym_ignition.rst: -------------------------------------------------------------------------------- 1 | .. _why_gym_ignition: 2 | 3 | Why gym-ignition 4 | ================ 5 | 6 | In the previous sections we described why we developed ScenarIO and why we used Ignition Gazebo to implement its simulation back-end. 7 | While we mentioned few advantages for the robot learning domain, ScenarIO remains a general C++ library that can be used for generic robotic applications. 8 | 9 | The reinforcement learning community, in the past years, converged towards Python for the development of the environments 10 | containing the decision-making logic. 11 | `OpenAI Gym `_ became the reference interface to provide a clear separation between agents and environments. 12 | A widespread interface is powerful because if you implement an environment that exposes the ``gym.Env`` interface, you can then use 13 | all the countless frameworks provided by the community to train a policy selecting your favourite algorithm. 14 | 15 | The Python package ``gym_ignition`` enables you to create robotic environments compatible with OpenAI Gym. 16 | Being based on ScenarIO, it enables to develop environments that can run not only on different physics engines, 17 | but also on real robots. 18 | 19 | You can think of ``gym_ignition`` as a way to help you structuring your environment. 20 | If you know how `pytorch-lightning `_ relates to PyTorch, 21 | the same applies to the interaction between gym-ignition and ScenarIO. 22 | Thanks to the :py:class:`~gym_ignition.base.task.Task` and :py:class:`~gym_ignition.base.runtime.Runtime` interfaces, 23 | ``gym_ignition`` abstracts away all the unnecessary boilerplate that otherwise you have to copy and paste between environments. 24 | 25 | For example, :py:class:`~gym_ignition.runtimes.gazebo_runtime.GazeboRuntime` provides all boilerplate code to take 26 | your implementation of a :py:class:`~gym_ignition.base.task.Task` and simulate it with Ignition Gazebo. 27 | 28 | Furthermore, we provide useful classes with functionalities that are commonly required by robotic environments, like 29 | Inverse Kinematic (:py:class:`~gym_ignition.rbd.idyntree.inverse_kinematics_nlp.InverseKinematicsNLP`) 30 | and multibody dynamics algorithms (:py:class:`~gym_ignition.rbd.idyntree.kindyncomputations.KinDynComputations`) 31 | with full support of floating-base systems. 32 | 33 | .. note:: 34 | 35 | Developing environments for robot learning in C++ is a valid choice and the community has shown different examples. 36 | ScenarIO can be used to develop C++ environments as well, however we find more useful using Python since it allows 37 | a faster prototyping. 38 | 39 | .. note:: 40 | 41 | To the best of our knowledge, the first package that implemented a structure that abstracts the task, the robot, and 42 | the simulator is `openai_ros `_. 43 | We have been inspired by its structure in the early stage of development, and the current interfaces implemented in 44 | gym-ignition are an evolution of the original architecture. 45 | -------------------------------------------------------------------------------- /docs/sphinx/why/why_scenario.rst: -------------------------------------------------------------------------------- 1 | .. _why_scenario: 2 | 3 | Why ScenarIO 4 | ============ 5 | 6 | *SCENe interfAces for Robot Input/Output* is an abstraction layer to interface with robots. 7 | It exposes APIs to interact with a scene, providing a :cpp:class:`~scenario::core::World` that can return 8 | :cpp:class:`~scenario::core::Model` objects, from which you can gather measurements and send commands. 9 | The relevant APIs of ScenarIO are documented in the :ref:`Scenario Core ` section. 10 | 11 | Many simulators already provide an abstraction of different physics engines. 12 | They expose a unified interface that, after selecting the desired back-end, maps its unified methods to those of the 13 | underlying physics engine. The aim of ScenarIO is extending this idea also to real-time robots. 14 | 15 | The simulation backend of ScenarIO communicates with a simulator that itself abstracts physics engines. 16 | This is powerful because, in this way, ScenarIO is independent from the details of the underlying physics engine. 17 | Any current and future physics engine supported by the simulator is compatible with ScenarIO without requiring any 18 | change from our side. 19 | 20 | Regarding real-time robots, the APIs of ScenarIO can be implemented exploiting middlewares like ROS or YARP. 21 | At the time of writing there are no official real-time backends, stay tuned for further updates. 22 | 23 | Once both the simulation and real-time backends are in place, you can then write code to control your robot just once, 24 | it will interact either with the simulated or the real robot depending on the ScenarIO backend you enabled. 25 | 26 | .. note:: 27 | 28 | The ScenarIO interface is flexible and generic. 29 | Let's say you already have built your functionality with the backends we provide, 30 | and you are not happy from the performance of the simulator we used. 31 | You can implement your own simulation backend and run it alongside those we provide. 32 | The same applies to the real-time backend, in case your robot uses a custom middleware or SDK. 33 | 34 | .. tip:: 35 | 36 | So far, we always referred to the C++ abstraction layer provided by ScenarIO. 37 | The interface / implementation pattern is implemented with classic inheritance and polymorphism. 38 | Having such unified interface simplifies the process to expose it to other languages. 39 | Thanks to SWIG, we officially provide Python bindings of ScenarIO, 40 | so that you can prototype your applications even faster! 41 | -------------------------------------------------------------------------------- /examples/python/launch_cartpole.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT). All rights reserved. 2 | # This software may be modified and distributed under the terms of the 3 | # GNU Lesser General Public License v2.1 or any later version. 4 | 5 | import functools 6 | import time 7 | 8 | import gym 9 | from gym_ignition.utils import logger 10 | from gym_ignition_environments import randomizers 11 | 12 | # Set verbosity 13 | logger.set_level(gym.logger.ERROR) 14 | # logger.set_level(gym.logger.DEBUG) 15 | 16 | # Available tasks 17 | env_id = "CartPoleDiscreteBalancing-Gazebo-v0" 18 | # env_id = "CartPoleContinuousBalancing-Gazebo-v0" 19 | # env_id = "CartPoleContinuousSwingup-Gazebo-v0" 20 | 21 | 22 | def make_env_from_id(env_id: str, **kwargs) -> gym.Env: 23 | import gym 24 | import gym_ignition_environments 25 | 26 | return gym.make(env_id, **kwargs) 27 | 28 | 29 | # Create a partial function passing the environment id 30 | make_env = functools.partial(make_env_from_id, env_id=env_id) 31 | 32 | # Wrap the environment with the randomizer. 33 | # This is a simple example no randomization are applied. 34 | env = randomizers.cartpole_no_rand.CartpoleEnvNoRandomizations(env=make_env) 35 | 36 | # Wrap the environment with the randomizer. 37 | # This is a complex example that randomizes both the physics and the model. 38 | # env = randomizers.cartpole.CartpoleEnvRandomizer( 39 | # env=make_env, seed=42, num_physics_rollouts=5) 40 | 41 | # Enable the rendering 42 | # env.render('human') 43 | 44 | # Initialize the seed 45 | env.seed(42) 46 | 47 | for epoch in range(10): 48 | 49 | # Reset the environment 50 | observation = env.reset() 51 | 52 | # Initialize returned values 53 | done = False 54 | totalReward = 0 55 | 56 | while not done: 57 | 58 | # Execute a random action 59 | action = env.action_space.sample() 60 | observation, reward, done, _ = env.step(action) 61 | 62 | # Render the environment. 63 | # It is not required to call this in the loop if physics is not randomized. 64 | # env.render('human') 65 | 66 | # Accumulate the reward 67 | totalReward += reward 68 | 69 | # Print the observation 70 | msg = "" 71 | for value in observation: 72 | msg += "\t%.6f" % value 73 | logger.debug(msg) 74 | 75 | print(f"Reward episode #{epoch}: {totalReward}") 76 | 77 | env.close() 78 | time.sleep(5) 79 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | build-backend = "setuptools.build_meta" 3 | requires = [ 4 | "wheel", 5 | "setuptools>=45", 6 | "setuptools_scm[toml]>=6.0", 7 | "cmake-build-extension", 8 | ] 9 | 10 | [tool.setuptools_scm] 11 | local_scheme = "dirty-tag" 12 | 13 | [tool.black] 14 | line-length = 88 15 | 16 | [tool.isort] 17 | profile = "black" 18 | multi_line_output = 3 19 | 20 | -------------------------------------------------------------------------------- /python/gym_ignition/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2019 Istituto Italiano di Tecnologia (IIT). All rights reserved. 2 | # This software may be modified and distributed under the terms of the 3 | # GNU Lesser General Public License v2.1 or any later version. 4 | 5 | # Workaround for https://github.com/osrf/sdformat/issues/227. 6 | # It has to be done before loading the bindings. 7 | import gym_ignition_models 8 | 9 | gym_ignition_models.setup_environment() 10 | 11 | # Add IGN_GAZEBO_RESOURCE_PATH to the default search path 12 | import os 13 | 14 | from gym_ignition.utils import resource_finder 15 | 16 | if "IGN_GAZEBO_RESOURCE_PATH" in os.environ: 17 | resource_finder.add_path_from_env_var("IGN_GAZEBO_RESOURCE_PATH") 18 | 19 | 20 | def initialize_verbosity() -> None: 21 | 22 | import gym 23 | import gym_ignition.utils.logger 24 | 25 | import scenario 26 | 27 | if scenario.detect_install_mode() is scenario.InstallMode.Developer: 28 | gym_ignition.utils.logger.set_level( 29 | level=gym.logger.INFO, scenario_level=gym.logger.WARN 30 | ) 31 | 32 | elif scenario.detect_install_mode() is scenario.InstallMode.User: 33 | gym_ignition.utils.logger.set_level( 34 | level=gym.logger.WARN, scenario_level=gym.logger.WARN 35 | ) 36 | 37 | else: 38 | raise ValueError(scenario.detect_install_mode()) 39 | 40 | 41 | # Configure default verbosity 42 | initialize_verbosity() 43 | -------------------------------------------------------------------------------- /python/gym_ignition/base/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2019 Istituto Italiano di Tecnologia (IIT). All rights reserved. 2 | # This software may be modified and distributed under the terms of the 3 | # GNU Lesser General Public License v2.1 or any later version. 4 | 5 | # Abstract classes 6 | from . import runtime, task 7 | -------------------------------------------------------------------------------- /python/gym_ignition/context/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT). All rights reserved. 2 | # This software may be modified and distributed under the terms of the 3 | # GNU Lesser General Public License v2.1 or any later version. 4 | 5 | from . import gazebo 6 | -------------------------------------------------------------------------------- /python/gym_ignition/context/gazebo/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT). All rights reserved. 2 | # This software may be modified and distributed under the terms of the 3 | # GNU Lesser General Public License v2.1 or any later version. 4 | 5 | from . import controllers, plugin 6 | -------------------------------------------------------------------------------- /python/gym_ignition/context/gazebo/controllers.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT). All rights reserved. 2 | # This software may be modified and distributed under the terms of the 3 | # GNU Lesser General Public License v2.1 or any later version. 4 | 5 | from dataclasses import dataclass, field 6 | from typing import Iterable, List, Tuple 7 | 8 | from gym_ignition.context.gazebo import plugin 9 | 10 | GRAVITY = (0, 0, -9.80665) 11 | 12 | 13 | @dataclass 14 | class ComputedTorqueFixedBase(plugin.GazeboPlugin): 15 | 16 | urdf: str 17 | kp: List[float] 18 | ki: List[float] 19 | kd: List[float] 20 | joints: List[str] 21 | gravity: Tuple[float, float, float] = field(default_factory=lambda: GRAVITY) 22 | 23 | # Private fields 24 | _name: str = field(init=False, repr=False, default="ComputedTorqueFixedBase") 25 | _plugin_name: str = field(init=False, repr=False, default="ControllerRunner") 26 | _plugin_class: str = field( 27 | init=False, repr=False, default="scenario::plugins::gazebo::ControllerRunner" 28 | ) 29 | 30 | def to_xml(self) -> str: 31 | xml = f""" 32 | 33 | {self._to_str(self.kp)} 34 | {self._to_str(self.ki)} 35 | {self._to_str(self.kd)} 36 | {self.urdf} 37 | {self._to_str(self.joints)} 38 | {self._to_str(self.gravity)} 39 | 40 | """ 41 | 42 | return xml 43 | 44 | @staticmethod 45 | def _to_str(iterable: Iterable) -> str: 46 | 47 | return " ".join([str(el) for el in iterable]) 48 | -------------------------------------------------------------------------------- /python/gym_ignition/context/gazebo/plugin.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT). All rights reserved. 2 | # This software may be modified and distributed under the terms of the 3 | # GNU Lesser General Public License v2.1 or any later version. 4 | 5 | import abc 6 | from dataclasses import dataclass, field 7 | from typing import Tuple 8 | 9 | # Default SDF version used in the serialized XML context 10 | SDF_VERSION = 1.7 11 | 12 | # Read the following for more information about dataclasses internals: 13 | # https://florimond.dev/blog/articles/2018/10/reconciling-dataclasses-and-properties-in-python/ 14 | 15 | 16 | @dataclass 17 | class GazeboPlugin(abc.ABC): 18 | """ 19 | Base class of all World and Model plugins for Ignition Gazebo. 20 | 21 | The Plugin abstract class provides boilerplate code that simplifies and streamlines 22 | the definition of helper classes that insert Ignition Gazebo plugins to either World 23 | or Model objects. 24 | 25 | Classes that inherit from Plugin have to provide the following information: 26 | 27 | 1) All the properties of the plugin as dataclass fields 28 | 2) The private specification of the plugin (plugin name and plugin class) 29 | 3) Optionally: the serialized XML context 30 | 31 | Example: 32 | 33 | .. code-block:: python 34 | 35 | plugin = MyPlugin(my_property=42) 36 | model = MyModel(world=my_world) 37 | 38 | model.insert_model_plugin(*plugin.args()) 39 | """ 40 | 41 | _plugin_name: str = field(init=False, repr=False) 42 | _plugin_class: str = field(init=False, repr=False) 43 | 44 | def to_xml(self) -> str: 45 | """ 46 | Get the XML plugin content. 47 | 48 | Returns: 49 | The XML plugin content. 50 | """ 51 | return "" 52 | 53 | def args(self) -> Tuple[str, str, str]: 54 | """ 55 | Get the arguments passed to the ScenarI/O methods used to insert plugins. 56 | 57 | Returns: 58 | A tuple with the args required to insert the plugin. 59 | """ 60 | return ( 61 | str(self._plugin_name), 62 | str(self._plugin_class), 63 | GazeboPlugin.wrap_in_sdf(self.to_xml()), 64 | ) 65 | 66 | @staticmethod 67 | def wrap_in_sdf(context: str) -> str: 68 | """ 69 | Wrap the XML context inside a SDF root. 70 | 71 | Args: 72 | context: The XML string with the plugin's context. 73 | 74 | Returns: 75 | The plugin's context wrapped inside a SDF root. 76 | """ 77 | 78 | return f"""{context}""" 79 | -------------------------------------------------------------------------------- /python/gym_ignition/randomizers/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT). All rights reserved. 2 | # This software may be modified and distributed under the terms of the 3 | # GNU Lesser General Public License v2.1 or any later version. 4 | 5 | from . import abc, gazebo_env_randomizer, model, physics 6 | -------------------------------------------------------------------------------- /python/gym_ignition/randomizers/model/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT). All rights reserved. 2 | # This software may be modified and distributed under the terms of the 3 | # GNU Lesser General Public License v2.1 or any later version. 4 | 5 | from . import sdf 6 | -------------------------------------------------------------------------------- /python/gym_ignition/randomizers/physics/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT). All rights reserved. 2 | # This software may be modified and distributed under the terms of the 3 | # GNU Lesser General Public License v2.1 or any later version. 4 | 5 | from . import dart 6 | -------------------------------------------------------------------------------- /python/gym_ignition/randomizers/physics/dart.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT). All rights reserved. 2 | # This software may be modified and distributed under the terms of the 3 | # GNU Lesser General Public License v2.1 or any later version. 4 | 5 | import gym_ignition.base.task 6 | from gym_ignition import randomizers 7 | 8 | from scenario import gazebo as scenario 9 | 10 | 11 | class DART(randomizers.abc.PhysicsRandomizer): 12 | """ 13 | Class that configures the Gazebo World of a Task to use the DART physics engine. 14 | 15 | Note: 16 | This class does not apply any physics randomization. 17 | """ 18 | 19 | def __init__(self): 20 | 21 | super().__init__() 22 | 23 | def get_engine(self): 24 | 25 | return scenario.PhysicsEngine_dart 26 | 27 | def randomize_physics(self, task: gym_ignition.base.task.Task, **kwargs) -> None: 28 | 29 | pass 30 | -------------------------------------------------------------------------------- /python/gym_ignition/rbd/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT). All rights reserved. 2 | # This software may be modified and distributed under the terms of the 3 | # GNU Lesser General Public License v2.1 or any later version. 4 | 5 | from . import conversions, idyntree, utils 6 | -------------------------------------------------------------------------------- /python/gym_ignition/rbd/conversions.py: -------------------------------------------------------------------------------- 1 | import abc 2 | from typing import Tuple 3 | 4 | import numpy as np 5 | from scipy.spatial.transform import Rotation 6 | 7 | 8 | class Transform(abc.ABC): 9 | @staticmethod 10 | def from_position_and_quaternion( 11 | position: np.ndarray, quaternion: np.ndarray 12 | ) -> np.ndarray: 13 | 14 | if quaternion.size != 4: 15 | raise ValueError("Quaternion array must have 4 elements") 16 | 17 | rotation = Quaternion.to_rotation(quaternion) 18 | transform = Transform.from_position_and_rotation( 19 | position=position, rotation=rotation 20 | ) 21 | 22 | return transform 23 | 24 | @staticmethod 25 | def from_position_and_rotation( 26 | position: np.ndarray, rotation: np.ndarray 27 | ) -> np.ndarray: 28 | 29 | if position.size != 3: 30 | raise ValueError("Position array must have 3 elements") 31 | 32 | if rotation.shape != (3, 3): 33 | raise ValueError("Rotation must be a square 3x3 matrix") 34 | 35 | transform = np.eye(4) 36 | transform[0:3, 3] = position 37 | transform[0:3, 0:3] = rotation 38 | 39 | return transform 40 | 41 | @staticmethod 42 | def to_position_and_rotation( 43 | transform: np.ndarray, 44 | ) -> Tuple[np.ndarray, np.ndarray]: 45 | 46 | if transform.shape != (4, 4): 47 | raise ValueError("Transform must be a 4x4 matrix") 48 | 49 | position = transform[0:3, 3] 50 | rotation = transform[0:3, 0:3] 51 | 52 | return position, rotation 53 | 54 | @staticmethod 55 | def to_position_and_quaternion( 56 | transform: np.ndarray, 57 | ) -> Tuple[np.ndarray, np.ndarray]: 58 | 59 | p, R = Transform.to_position_and_rotation(transform=transform) 60 | return p, Quaternion.from_matrix(matrix=R) 61 | 62 | 63 | class Quaternion(abc.ABC): 64 | @staticmethod 65 | def to_wxyz(xyzw: np.ndarray) -> np.ndarray: 66 | 67 | if xyzw.shape != (4,): 68 | raise ValueError(xyzw) 69 | 70 | return xyzw[[3, 0, 1, 2]] 71 | 72 | @staticmethod 73 | def to_xyzw(wxyz: np.ndarray) -> np.ndarray: 74 | 75 | if wxyz.shape != (4,): 76 | raise ValueError(wxyz) 77 | 78 | return wxyz[[1, 2, 3, 0]] 79 | 80 | @staticmethod 81 | def to_rotation(quaternion: np.ndarray) -> np.ndarray: 82 | 83 | if quaternion.shape != (4,): 84 | raise ValueError(quaternion) 85 | 86 | xyzw = Quaternion.to_xyzw(quaternion) 87 | 88 | return Rotation.from_quat(xyzw).as_matrix() 89 | 90 | @staticmethod 91 | def from_matrix(matrix: np.ndarray) -> np.ndarray: 92 | 93 | if matrix.shape != (3, 3): 94 | raise ValueError(matrix) 95 | 96 | quaternion_xyzw = Rotation.from_matrix(matrix).as_quat() 97 | quaternion_wxyz = Quaternion.to_wxyz(quaternion_xyzw) 98 | 99 | return quaternion_wxyz 100 | -------------------------------------------------------------------------------- /python/gym_ignition/rbd/idyntree/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT). All rights reserved. 2 | # This software may be modified and distributed under the terms of the 3 | # GNU Lesser General Public License v2.1 or any later version. 4 | 5 | from . import helpers, inverse_kinematics_nlp, kindyncomputations, numpy 6 | -------------------------------------------------------------------------------- /python/gym_ignition/rbd/utils.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2021 Istituto Italiano di Tecnologia (IIT). All rights reserved. 2 | # This software may be modified and distributed under the terms of the 3 | # GNU Lesser General Public License v2.1 or any later version. 4 | 5 | import numpy as np 6 | 7 | 8 | def wedge(vector3: np.ndarray) -> np.ndarray: 9 | """ 10 | Convert a 3D vector to a skew-symmetric matrix. 11 | 12 | Args: 13 | vector3: The 3D vector defining the matrix coefficients. 14 | 15 | Returns: 16 | The skew-symmetric matrix whose elements are created from the input vector. 17 | 18 | Note: 19 | The wedge operator can be useful to compute the cross product of 3D vectors: 20 | :math:`v_1 \\times v_2 = v_1^\\wedge v_2`. 21 | """ 22 | 23 | if vector3.size != 3: 24 | raise ValueError(vector3) 25 | 26 | s = np.zeros(shape=(3, 3)) 27 | s[1, 0] = vector3[2] 28 | s[0, 1] = -vector3[2] 29 | s[0, 2] = vector3[1] 30 | s[2, 0] = -vector3[1] 31 | s[2, 1] = vector3[0] 32 | s[1, 2] = -vector3[0] 33 | 34 | return s 35 | 36 | 37 | def vee(matrix3x3: np.ndarray) -> np.ndarray: 38 | """ 39 | Convert a 3x3 matrix to a 3D vector with the components of its skew-symmetric part. 40 | 41 | Args: 42 | matrix3x3: The input 3x3 matrix. If present, its symmetric part is removed. 43 | 44 | Returns: 45 | The 3D vector defining the skew-symmetric matrix. 46 | 47 | Note: 48 | This is the inverse operator of :py:func:`wedge`. 49 | """ 50 | 51 | if matrix3x3.shape != (3, 3): 52 | raise ValueError(matrix3x3) 53 | 54 | skew_symmetric = extract_skew(matrix3x3) 55 | 56 | return np.array([skew_symmetric[2, 1], skew_symmetric[0, 2], skew_symmetric[1, 0]]) 57 | 58 | 59 | def extract_skew(matrix: np.ndarray) -> np.ndarray: 60 | """ 61 | Extract the skew-symmetric part of a square matrix. 62 | 63 | Args: 64 | matrix: A square matrix. 65 | 66 | Returns: 67 | The skew-symmetric part of the input matrix. 68 | """ 69 | 70 | if matrix.shape[0] != matrix.shape[1]: 71 | raise ValueError(matrix) 72 | 73 | return 0.5 * (matrix - matrix.T) 74 | 75 | 76 | def extract_symm(matrix: np.ndarray) -> np.ndarray: 77 | """ 78 | Extract the symmetric part of a square matrix. 79 | 80 | Args: 81 | matrix: A square matrix. 82 | 83 | Returns: 84 | The symmetric part of the input matrix. 85 | """ 86 | 87 | if matrix.shape[0] != matrix.shape[1]: 88 | raise ValueError(matrix) 89 | 90 | return 0.5 * (matrix + matrix.T) 91 | -------------------------------------------------------------------------------- /python/gym_ignition/runtimes/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2019 Istituto Italiano di Tecnologia (IIT). All rights reserved. 2 | # This software may be modified and distributed under the terms of the 3 | # GNU Lesser General Public License v2.1 or any later version. 4 | 5 | from . import gazebo_runtime, realtime_runtime 6 | -------------------------------------------------------------------------------- /python/gym_ignition/runtimes/realtime_runtime.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2019 Istituto Italiano di Tecnologia (IIT). All rights reserved. 2 | # This software may be modified and distributed under the terms of the 3 | # GNU Lesser General Public License v2.1 or any later version. 4 | 5 | from gym_ignition.base import runtime, task 6 | from gym_ignition.utils.typing import Action, Done, Info, Observation, State 7 | 8 | 9 | class RealTimeRuntime(runtime.Runtime): 10 | """ 11 | Implementation of :py:class:`~gym_ignition.base.runtime.Runtime` for real-time 12 | execution. 13 | 14 | Warning: 15 | This class is not yet complete. 16 | """ 17 | 18 | def __init__(self, task_cls: type, robot_cls: type, agent_rate: float, **kwargs): 19 | 20 | # Build the environment 21 | task_object = task_cls(**kwargs) 22 | 23 | assert isinstance( 24 | task_object, task.Task 25 | ), "'task_cls' object must inherit from Task" 26 | 27 | super().__init__(task=task_object, agent_rate=agent_rate) 28 | 29 | raise NotImplementedError 30 | 31 | # ================= 32 | # Runtime interface 33 | # ================= 34 | 35 | def timestamp(self) -> float: 36 | 37 | raise NotImplementedError 38 | 39 | # ================= 40 | # gym.Env interface 41 | # ================= 42 | 43 | def step(self, action: Action) -> State: 44 | 45 | # Validate action and robot 46 | assert self.action_space.contains(action), "%r (%s) invalid" % ( 47 | action, 48 | type(action), 49 | ) 50 | 51 | # Set the action 52 | ok_action = self.task.set_action(action) 53 | assert ok_action, "Failed to set the action" 54 | 55 | # TODO: realtime step 56 | 57 | # Get the observation 58 | observation = self.task.get_observation() 59 | assert self.observation_space.contains(observation), "%r (%s) invalid" % ( 60 | observation, 61 | type(observation), 62 | ) 63 | 64 | # Get the reward 65 | reward = self.task.get_reward() 66 | assert reward, "Failed to get the reward" 67 | 68 | # Check termination 69 | done = self.task.is_done() 70 | 71 | return State((observation, reward, Done(done), Info({}))) 72 | 73 | def reset(self) -> Observation: 74 | 75 | # Get the observation 76 | observation = self.task.get_observation() 77 | 78 | return Observation(observation) 79 | 80 | def render(self, mode: str = "human", **kwargs) -> None: 81 | raise NotImplementedError 82 | 83 | def close(self) -> None: 84 | raise NotImplementedError 85 | -------------------------------------------------------------------------------- /python/gym_ignition/scenario/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT). All rights reserved. 2 | # This software may be modified and distributed under the terms of the 3 | # GNU Lesser General Public License v2.1 or any later version. 4 | 5 | from . import model_with_file, model_wrapper 6 | -------------------------------------------------------------------------------- /python/gym_ignition/scenario/model_with_file.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT). All rights reserved. 2 | # This software may be modified and distributed under the terms of the 3 | # GNU Lesser General Public License v2.1 or any later version. 4 | 5 | import abc 6 | 7 | 8 | class ModelWithFile(abc.ABC): 9 | def __init__(self): 10 | 11 | super().__init__() 12 | 13 | @classmethod 14 | @abc.abstractmethod 15 | def get_model_file(cls) -> str: 16 | pass 17 | -------------------------------------------------------------------------------- /python/gym_ignition/scenario/model_wrapper.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT). All rights reserved. 2 | # This software may be modified and distributed under the terms of the 3 | # GNU Lesser General Public License v2.1 or any later version. 4 | 5 | import abc 6 | 7 | from scenario import core as scenario 8 | 9 | 10 | class ModelWrapper(scenario.Model, abc.ABC): 11 | def __init__(self, model: scenario.Model): 12 | 13 | # No need to call scenario.Model.__init__()! 14 | abc.ABC.__init__(self) 15 | 16 | self.model = model 17 | 18 | def __getattr__(self, name): 19 | 20 | return getattr(self.model, name) 21 | -------------------------------------------------------------------------------- /python/gym_ignition/utils/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2019 Istituto Italiano di Tecnologia (IIT). All rights reserved. 2 | # This software may be modified and distributed under the terms of the 3 | # GNU Lesser General Public License v2.1 or any later version. 4 | 5 | from . import logger, math, misc, resource_finder, scenario 6 | from .typing import * 7 | -------------------------------------------------------------------------------- /python/gym_ignition/utils/logger.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2019 Istituto Italiano di Tecnologia (IIT). All rights reserved. 2 | # This software may be modified and distributed under the terms of the 3 | # GNU Lesser General Public License v2.1 or any later version. 4 | 5 | import contextlib 6 | import warnings 7 | 8 | import gym 9 | from gym import logger 10 | from gym.logger import debug, error, info 11 | from gym.utils import colorize 12 | 13 | 14 | def custom_formatwarning(msg, *args, **kwargs): 15 | """ 16 | Custom format that overrides :py:func:`warnings.formatwarning`. 17 | """ 18 | 19 | if logger.MIN_LEVEL is logger.DEBUG: 20 | warning = "{}:{} {}: {}\n".format(args[1], args[2], args[0].__name__, msg) 21 | else: 22 | warning = "{}\n".format(msg) 23 | 24 | return warning 25 | 26 | 27 | def warn(msg: str, *args) -> None: 28 | """ 29 | Custom definition of :py:func:`gym.logger.warn` function. 30 | """ 31 | 32 | if logger.MIN_LEVEL <= logger.WARN: 33 | warnings.warn(colorize("%s: %s" % ("WARN", msg % args), "yellow"), stacklevel=2) 34 | 35 | 36 | # Monkey patch warning formatting 37 | warnings.formatwarning = custom_formatwarning 38 | 39 | 40 | def set_level(level: int, scenario_level: int = None) -> None: 41 | """ 42 | Set the verbosity level of both :py:mod:`gym` and :py:mod:`gym_ignition`. 43 | 44 | Accepted values: 45 | 46 | - :py:const:`gym.logger.DEBUG` (10) 47 | - :py:const:`gym.logger.INFO` (20) 48 | - :py:const:`gym.logger.WARN` (30) 49 | - :py:const:`gym.logger.ERROR` (40) 50 | - :py:const:`gym.logger.DISABLED` (50) 51 | 52 | Args: 53 | level: The desired verbosity level. 54 | scenario_level: The desired ScenarIO verbosity level (defaults to ``level``). 55 | """ 56 | 57 | # Set the gym verbosity 58 | logger.set_level(level) 59 | 60 | try: 61 | from scenario import gazebo as scenario 62 | except ImportError: 63 | return 64 | 65 | if scenario_level is None: 66 | scenario_level = level 67 | 68 | # Set the ScenarI/O verbosity 69 | if scenario_level <= logger.DEBUG: 70 | scenario.set_verbosity(scenario.Verbosity_debug) 71 | elif scenario_level <= logger.INFO: 72 | scenario.set_verbosity(scenario.Verbosity_info) 73 | elif scenario_level <= logger.WARN: 74 | scenario.set_verbosity(scenario.Verbosity_warning) 75 | elif scenario_level <= logger.ERROR: 76 | scenario.set_verbosity(scenario.Verbosity_error) 77 | else: 78 | scenario.set_verbosity(scenario.Verbosity_suppress_all) 79 | 80 | 81 | @contextlib.contextmanager 82 | def gym_verbosity(level: int): 83 | 84 | old_level = gym.logger.MIN_LEVEL 85 | gym.logger.set_level(level=level) 86 | yield None 87 | gym.logger.set_level(old_level) 88 | -------------------------------------------------------------------------------- /python/gym_ignition/utils/math.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT). All rights reserved. 2 | # This software may be modified and distributed under the terms of the 3 | # GNU Lesser General Public License v2.1 or any later version. 4 | 5 | from numbers import Number 6 | from typing import List, Union 7 | 8 | import numpy as np 9 | 10 | from scenario import gazebo as scenario 11 | 12 | 13 | def normalize( 14 | input: Union[Number, List[Number], np.ndarray], 15 | low: Union[Number, List[Number], np.ndarray], 16 | high: Union[Number, List[Number], np.ndarray], 17 | ) -> Union[Number, np.ndarray]: 18 | 19 | if low is None or high is None: 20 | return input 21 | 22 | if isinstance(input, Number): 23 | input = [input] 24 | 25 | if isinstance(low, Number): 26 | low = [low] 27 | 28 | if isinstance(high, Number): 29 | high = [high] 30 | 31 | output = scenario.normalize(list(input), list(low), list(high)) 32 | 33 | if len(output) == 1: 34 | return output[0] 35 | else: 36 | return np.array(output) 37 | 38 | 39 | def denormalize( 40 | input: Union[Number, List[Number], np.ndarray], 41 | low: Union[Number, List[Number], np.ndarray], 42 | high: Union[Number, List[Number], np.ndarray], 43 | ) -> Union[Number, np.ndarray]: 44 | 45 | if low is None or high is None: 46 | return input 47 | 48 | if isinstance(input, Number): 49 | input = [input] 50 | 51 | if isinstance(low, Number): 52 | low = [low] 53 | 54 | if isinstance(high, Number): 55 | high = [high] 56 | 57 | output = scenario.denormalize(list(input), list(low), list(high)) 58 | 59 | if len(output) == 1: 60 | return output[0] 61 | else: 62 | return np.array(output) 63 | -------------------------------------------------------------------------------- /python/gym_ignition/utils/misc.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2019 Istituto Italiano di Tecnologia (IIT). All rights reserved. 2 | # This software may be modified and distributed under the terms of the 3 | # GNU Lesser General Public License v2.1 or any later version. 4 | 5 | import tempfile 6 | 7 | 8 | def string_to_file(string: str) -> str: 9 | 10 | handle, tmpfile = tempfile.mkstemp() 11 | 12 | with open(handle, "w") as f: 13 | f.write(string) 14 | 15 | return tmpfile 16 | -------------------------------------------------------------------------------- /python/gym_ignition/utils/resource_finder.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2019 Istituto Italiano di Tecnologia (IIT). All rights reserved. 2 | # This software may be modified and distributed under the terms of the 3 | # GNU Lesser General Public License v2.1 or any later version. 4 | 5 | import os 6 | from os.path import exists, isfile 7 | from typing import List 8 | 9 | from gym_ignition.utils import logger 10 | 11 | GYM_IGNITION_DATA_PATH = [] 12 | 13 | 14 | def get_search_paths() -> List[str]: 15 | global GYM_IGNITION_DATA_PATH 16 | return GYM_IGNITION_DATA_PATH 17 | 18 | 19 | def add_path(data_path: str) -> None: 20 | if not exists(data_path): 21 | logger.warn( 22 | f"The path '{data_path}' does not exist. Not added to the data path." 23 | ) 24 | return 25 | 26 | global GYM_IGNITION_DATA_PATH 27 | 28 | for path in GYM_IGNITION_DATA_PATH: 29 | if path == data_path: 30 | logger.debug(f"The path '{data_path}' is already present in the data path") 31 | return 32 | 33 | logger.debug(f"Adding new search path: '{data_path}'") 34 | GYM_IGNITION_DATA_PATH.append(data_path) 35 | 36 | 37 | def add_path_from_env_var(env_variable: str) -> None: 38 | if env_variable not in os.environ: 39 | logger.warn(f"Failed to find '{env_variable}' environment variable") 40 | return 41 | 42 | # Get the environment variable 43 | env_var_content = os.environ[env_variable] 44 | 45 | # Remove leading ':' characters 46 | if env_var_content[0] == ":": 47 | env_var_content = env_var_content[1:] 48 | 49 | # Split multiple value 50 | env_var_paths = env_var_content.split(":") 51 | 52 | for path in env_var_paths: 53 | add_path(path) 54 | 55 | 56 | def find_resource(file_name: str) -> str: 57 | file_abs_path = "" 58 | global GYM_IGNITION_DATA_PATH 59 | 60 | logger.debug(f"Looking for file '{file_name}'") 61 | 62 | # Handle if the path is absolute 63 | if os.path.isabs(file_name): 64 | if isfile(file_name): 65 | logger.debug(f" Found resource: '{file_name}'") 66 | return file_name 67 | else: 68 | raise FileNotFoundError(f"Failed to find resource '{file_name}'") 69 | 70 | # Handle if the path is relative 71 | for path in GYM_IGNITION_DATA_PATH: 72 | logger.debug(f" Exploring folder '{path}'") 73 | path_with_slash = path if path[-1] == "/" else path + "/" 74 | candidate_abs_path = path_with_slash + file_name 75 | 76 | if isfile(candidate_abs_path): 77 | logger.debug(f" Found resource: '{candidate_abs_path}'") 78 | file_abs_path = candidate_abs_path 79 | break 80 | 81 | if not file_abs_path: 82 | raise FileNotFoundError(f"Failed to find resource '{file_name}'") 83 | 84 | return file_abs_path 85 | -------------------------------------------------------------------------------- /python/gym_ignition/utils/typing.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2019 Istituto Italiano di Tecnologia (IIT). All rights reserved. 2 | # This software may be modified and distributed under the terms of the 3 | # GNU Lesser General Public License v2.1 or any later version. 4 | 5 | from typing import Dict, List, NewType, Tuple, Union 6 | 7 | import gym.spaces 8 | import numpy as np 9 | 10 | Done = NewType("Done", bool) 11 | Info = NewType("Info", Dict) 12 | Reward = NewType("Reward", float) 13 | Observation = NewType("Observation", np.ndarray) 14 | Action = NewType("Action", Union[np.ndarray, np.number]) 15 | 16 | SeedList = NewType("SeedList", List[int]) 17 | 18 | State = NewType("State", Tuple[Observation, Reward, Done, Info]) 19 | 20 | ActionSpace = NewType("ActionSpace", gym.spaces.Space) 21 | ObservationSpace = NewType("ObservationSpace", gym.spaces.Space) 22 | -------------------------------------------------------------------------------- /python/gym_ignition_environments/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT). All rights reserved. 2 | # This software may be modified and distributed under the terms of the 3 | # GNU Lesser General Public License v2.1 or any later version. 4 | 5 | import numpy 6 | from gym.envs.registration import register 7 | 8 | from . import models, randomizers, tasks 9 | 10 | max_float = float(numpy.finfo(numpy.float32).max) 11 | 12 | register( 13 | id="Pendulum-Gazebo-v0", 14 | entry_point="gym_ignition.runtimes.gazebo_runtime:GazeboRuntime", 15 | max_episode_steps=5000, 16 | kwargs={ 17 | "task_cls": tasks.pendulum_swingup.PendulumSwingUp, 18 | "agent_rate": 1000, 19 | "physics_rate": 1000, 20 | "real_time_factor": max_float, 21 | }, 22 | ) 23 | 24 | register( 25 | id="CartPoleDiscreteBalancing-Gazebo-v0", 26 | entry_point="gym_ignition.runtimes.gazebo_runtime:GazeboRuntime", 27 | max_episode_steps=5000, 28 | kwargs={ 29 | "task_cls": tasks.cartpole_discrete_balancing.CartPoleDiscreteBalancing, 30 | "agent_rate": 1000, 31 | "physics_rate": 1000, 32 | "real_time_factor": max_float, 33 | }, 34 | ) 35 | 36 | register( 37 | id="CartPoleContinuousBalancing-Gazebo-v0", 38 | entry_point="gym_ignition.runtimes.gazebo_runtime:GazeboRuntime", 39 | max_episode_steps=5000, 40 | kwargs={ 41 | "task_cls": tasks.cartpole_continuous_balancing.CartPoleContinuousBalancing, 42 | "agent_rate": 1000, 43 | "physics_rate": 1000, 44 | "real_time_factor": max_float, 45 | }, 46 | ) 47 | 48 | register( 49 | id="CartPoleContinuousSwingup-Gazebo-v0", 50 | entry_point="gym_ignition.runtimes.gazebo_runtime:GazeboRuntime", 51 | max_episode_steps=5000, 52 | kwargs={ 53 | "task_cls": tasks.cartpole_continuous_swingup.CartPoleContinuousSwingup, 54 | "agent_rate": 1000, 55 | "physics_rate": 1000, 56 | "real_time_factor": max_float, 57 | }, 58 | ) 59 | -------------------------------------------------------------------------------- /python/gym_ignition_environments/models/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT). All rights reserved. 2 | # This software may be modified and distributed under the terms of the 3 | # GNU Lesser General Public License v2.1 or any later version. 4 | 5 | from . import cartpole, icub, panda, pendulum 6 | -------------------------------------------------------------------------------- /python/gym_ignition_environments/models/cartpole.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT). All rights reserved. 2 | # This software may be modified and distributed under the terms of the 3 | # GNU Lesser General Public License v2.1 or any later version. 4 | 5 | from typing import List 6 | 7 | from gym_ignition.scenario import model_with_file, model_wrapper 8 | from gym_ignition.utils.scenario import get_unique_model_name 9 | 10 | from scenario import core as scenario 11 | 12 | 13 | class CartPole(model_wrapper.ModelWrapper, model_with_file.ModelWithFile): 14 | def __init__( 15 | self, 16 | world: scenario.World, 17 | position: List[float] = (0.0, 0.0, 0.0), 18 | orientation: List[float] = (1.0, 0, 0, 0), 19 | model_file: str = None, 20 | ): 21 | 22 | # Get a unique model name 23 | model_name = get_unique_model_name(world, "cartpole") 24 | 25 | # Initial pose 26 | initial_pose = scenario.Pose(position, orientation) 27 | 28 | # Get the model file (URDF or SDF) and allow to override it 29 | if model_file is None: 30 | model_file = CartPole.get_model_file() 31 | 32 | # Insert the model 33 | ok_model = world.to_gazebo().insert_model(model_file, initial_pose, model_name) 34 | 35 | if not ok_model: 36 | raise RuntimeError("Failed to insert model") 37 | 38 | # Get the model 39 | model = world.get_model(model_name) 40 | 41 | # Initialize base class 42 | super().__init__(model=model) 43 | 44 | @classmethod 45 | def get_model_file(cls) -> str: 46 | 47 | import gym_ignition_models 48 | 49 | return gym_ignition_models.get_model_file("cartpole") 50 | -------------------------------------------------------------------------------- /python/gym_ignition_environments/models/pendulum.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT). All rights reserved. 2 | # This software may be modified and distributed under the terms of the 3 | # GNU Lesser General Public License v2.1 or any later version. 4 | 5 | from typing import List 6 | 7 | from gym_ignition.scenario import model_with_file, model_wrapper 8 | from gym_ignition.utils.scenario import get_unique_model_name 9 | 10 | from scenario import core as scenario 11 | 12 | 13 | class Pendulum(model_wrapper.ModelWrapper, model_with_file.ModelWithFile): 14 | def __init__( 15 | self, 16 | world: scenario.World, 17 | position: List[float] = (0.0, 0.0, 0.0), 18 | orientation: List[float] = (1.0, 0, 0, 0), 19 | model_file: str = None, 20 | ): 21 | 22 | # Get a unique model name 23 | model_name = get_unique_model_name(world, "pendulum") 24 | 25 | # Initial pose 26 | initial_pose = scenario.Pose(position, orientation) 27 | 28 | # Get the model file (URDF or SDF) and allow to override it 29 | if model_file is None: 30 | model_file = Pendulum.get_model_file() 31 | 32 | # Insert the model 33 | ok_model = world.to_gazebo().insert_model(model_file, initial_pose, model_name) 34 | 35 | if not ok_model: 36 | raise RuntimeError("Failed to insert model") 37 | 38 | # Get the model 39 | model = world.get_model(model_name) 40 | 41 | # Initialize base class 42 | super().__init__(model=model) 43 | 44 | @classmethod 45 | def get_model_file(cls) -> str: 46 | 47 | import gym_ignition_models 48 | 49 | return gym_ignition_models.get_model_file("pendulum") 50 | -------------------------------------------------------------------------------- /python/gym_ignition_environments/randomizers/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT). All rights reserved. 2 | # This software may be modified and distributed under the terms of the 3 | # GNU Lesser General Public License v2.1 or any later version. 4 | 5 | from . import cartpole, cartpole_no_rand 6 | -------------------------------------------------------------------------------- /python/gym_ignition_environments/randomizers/cartpole_no_rand.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT). All rights reserved. 2 | # This software may be modified and distributed under the terms of the 3 | # GNU Lesser General Public License v2.1 or any later version. 4 | 5 | from typing import Union 6 | 7 | from gym_ignition.randomizers import gazebo_env_randomizer 8 | from gym_ignition.randomizers.gazebo_env_randomizer import MakeEnvCallable 9 | from gym_ignition_environments import tasks 10 | from gym_ignition_environments.models import cartpole 11 | 12 | # Tasks that are supported by this randomizer. Used for type hinting. 13 | SupportedTasks = Union[ 14 | tasks.cartpole_discrete_balancing.CartPoleDiscreteBalancing, 15 | tasks.cartpole_continuous_swingup.CartPoleContinuousSwingup, 16 | tasks.cartpole_continuous_balancing.CartPoleContinuousBalancing, 17 | ] 18 | 19 | 20 | class CartpoleEnvNoRandomizations(gazebo_env_randomizer.GazeboEnvRandomizer): 21 | """ 22 | Dummy environment randomizer for cartpole tasks. 23 | 24 | Check :py:class:`~gym_ignition_environments.randomizers.cartpole.CartpoleRandomizersMixin` 25 | for an example that randomizes the task, the physics, and the model. 26 | """ 27 | 28 | def __init__(self, env: MakeEnvCallable): 29 | 30 | super().__init__(env=env) 31 | 32 | def randomize_task(self, task: SupportedTasks, **kwargs) -> None: 33 | """ 34 | Prepare the scene for cartpole tasks. It simply removes the cartpole of the 35 | previous rollout and inserts a new one in the default state. Then, the active 36 | Task will reset the state of the cartpole depending on the implemented 37 | decision-making logic. 38 | """ 39 | 40 | if "gazebo" not in kwargs: 41 | raise ValueError("gazebo kwarg not passed to the task randomizer") 42 | 43 | gazebo = kwargs["gazebo"] 44 | 45 | # Remove the model from the simulation 46 | if task.model_name is not None and task.model_name in task.world.model_names(): 47 | 48 | if not task.world.to_gazebo().remove_model(task.model_name): 49 | raise RuntimeError("Failed to remove the cartpole from the world") 50 | 51 | # Execute a paused run to process model removal 52 | if not gazebo.run(paused=True): 53 | raise RuntimeError("Failed to execute a paused Gazebo run") 54 | 55 | # Insert a new cartpole model 56 | model = cartpole.CartPole(world=task.world) 57 | 58 | # Store the model name in the task 59 | task.model_name = model.name() 60 | 61 | # Execute a paused run to process model insertion 62 | if not gazebo.run(paused=True): 63 | raise RuntimeError("Failed to execute a paused Gazebo run") 64 | -------------------------------------------------------------------------------- /python/gym_ignition_environments/tasks/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2019 Istituto Italiano di Tecnologia (IIT). All rights reserved. 2 | # This software may be modified and distributed under the terms of the 3 | # GNU Lesser General Public License v2.1 or any later version. 4 | 5 | from . import ( 6 | cartpole_continuous_balancing, 7 | cartpole_continuous_swingup, 8 | cartpole_discrete_balancing, 9 | pendulum_swingup, 10 | ) 11 | -------------------------------------------------------------------------------- /scenario/bindings/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2019 Istituto Italiano di Tecnologia (IIT). All rights reserved. 2 | # This software may be modified and distributed under the terms of the 3 | # GNU Lesser General Public License v2.1 or any later version. 4 | 5 | # The SWIG bindings are installed as a standalone Python package. 6 | # 7 | # We create with CMake the following structure in the build tree: 8 | # 9 | # /bindings/scenario/ 10 | # ├── bindings 11 | # │ ├── core.py 12 | # │ ├── _core.so 13 | # │ ├── gazebo.py 14 | # │ ├── _gazebo.so 15 | # │ └── __init__.py 16 | # └── __init__.py 17 | # 18 | # That is later installed either in the active virtualenv or packaged 19 | # as a PyPI package. The former is related to the Develop Installation 20 | # and the latter to the User Installation. 21 | # 22 | # Having a working Python package tree in the build folder has multiple 23 | # benefit, including the possibility to use it without installing. 24 | # Beyond this reason, our documentation pipeline requires to import 25 | # a working package from the build tree. 26 | 27 | if(${CMAKE_VERSION} VERSION_GREATER 3.13) 28 | cmake_policy(SET CMP0078 NEW) 29 | endif() 30 | 31 | if(${CMAKE_VERSION} VERSION_GREATER 3.14) 32 | cmake_policy(SET CMP0086 NEW) 33 | endif() 34 | 35 | find_package(SWIG 4.0 REQUIRED) 36 | set(UseSWIG_MODULE_VERSION 2) 37 | include(${SWIG_USE_FILE}) 38 | 39 | # By default, install ScenarIO in the python site-package directory 40 | if(NOT BINDINGS_INSTALL_PREFIX) 41 | set(BINDINGS_INSTALL_PREFIX ${Python3_SITELIB}) 42 | endif() 43 | 44 | # Expose the install prefix as CMake option 45 | set(BINDINGS_INSTALL_PREFIX "${BINDINGS_INSTALL_PREFIX}" 46 | CACHE STRING "Installation prefix of the bindings") 47 | 48 | # Final directory of the "scenario" package 49 | if(NOT SCENARIO_CALL_FROM_SETUP_PY) 50 | set(SCENARIO_PACKAGE_INSTALL_DIR "${BINDINGS_INSTALL_PREFIX}/scenario") 51 | else() 52 | # If packaging for PyPI, install ScenarIO in the temp site-package directory 53 | # created by either setup.py or pip. 54 | # The "scenario/" folder is added by cmake_build_extension 55 | set(SCENARIO_PACKAGE_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}") 56 | endif() 57 | 58 | # Add the SWIG folders 59 | add_subdirectory(core) 60 | if(SCENARIO_USE_IGNITION) 61 | add_subdirectory(gazebo) 62 | endif() 63 | 64 | # Move main init.py file to package root of the build tree 65 | configure_file( 66 | ${CMAKE_CURRENT_SOURCE_DIR}/__init__.py 67 | ${CMAKE_CURRENT_BINARY_DIR}/scenario/__init__.py) 68 | 69 | # Make scenario.bindings a package 70 | file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/scenario/bindings) 71 | file(TOUCH ${CMAKE_CURRENT_BINARY_DIR}/scenario/bindings/__init__.py) 72 | 73 | # Move main init.py file to package root of the install tree 74 | install( 75 | FILES ${CMAKE_CURRENT_SOURCE_DIR}/__init__.py 76 | DESTINATION ${SCENARIO_PACKAGE_INSTALL_DIR} 77 | COMPONENT python) 78 | -------------------------------------------------------------------------------- /scenario/bindings/core/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT). All rights reserved. 2 | # This software may be modified and distributed under the terms of the 3 | # GNU Lesser General Public License v2.1 or any later version. 4 | 5 | set(scenario_swig_name "core") 6 | set_source_files_properties(${scenario_swig_name}.i PROPERTIES CPLUSPLUS ON) 7 | 8 | # The bindings shared library is stored in the Python package of the build tree 9 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/../scenario/bindings) 10 | 11 | swig_add_library(${scenario_swig_name} 12 | TYPE MODULE 13 | LANGUAGE python 14 | OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/../scenario/bindings 15 | OUTFILE_DIR ${CMAKE_CURRENT_BINARY_DIR}/.. 16 | SOURCES ${scenario_swig_name}.i) 17 | add_library(ScenarioSwig::Core ALIAS core) 18 | 19 | target_link_libraries(${scenario_swig_name} PUBLIC 20 | ScenarioCore::ScenarioABC 21 | ScenarioCore::CoreUtils 22 | Python3::Python) 23 | 24 | set_property(TARGET ${scenario_swig_name} PROPERTY 25 | SWIG_USE_TARGET_INCLUDE_DIRECTORIES TRUE) 26 | 27 | set_property(TARGET ${scenario_swig_name} 28 | PROPERTY SWIG_COMPILE_OPTIONS -doxygen) 29 | 30 | # Add the to_gazebo() helpers 31 | if(SCENARIO_USE_IGNITION) 32 | set_property(TARGET ${scenario_swig_name} PROPERTY 33 | SWIG_COMPILE_DEFINITIONS SCENARIO_HAS_GAZEBO) 34 | set_property(TARGET ${scenario_swig_name} PROPERTY 35 | SWIG_DEPENDS "../gazebo/to_gazebo.i") 36 | target_link_libraries(${scenario_swig_name} PUBLIC ScenarioGazebo) 37 | endif() 38 | 39 | # Get the core.py wrapper file 40 | get_property(WRAPPER_PY_FILE TARGET ${scenario_swig_name} PROPERTY SWIG_SUPPORT_FILES) 41 | 42 | install( 43 | TARGETS ${scenario_swig_name} 44 | COMPONENT python 45 | LIBRARY DESTINATION ${SCENARIO_PACKAGE_INSTALL_DIR}/bindings 46 | ARCHIVE DESTINATION ${SCENARIO_PACKAGE_INSTALL_DIR}/bindings 47 | RUNTIME DESTINATION ${SCENARIO_PACKAGE_INSTALL_DIR}/bindings) 48 | 49 | install( 50 | FILES ${WRAPPER_PY_FILE} 51 | DESTINATION ${SCENARIO_PACKAGE_INSTALL_DIR}/bindings 52 | COMPONENT python) 53 | -------------------------------------------------------------------------------- /scenario/bindings/gazebo/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT). All rights reserved. 2 | # This software may be modified and distributed under the terms of the 3 | # GNU Lesser General Public License v2.1 or any later version. 4 | 5 | set(scenario_swig_name "gazebo") 6 | set_source_files_properties(${scenario_swig_name}.i PROPERTIES CPLUSPLUS ON) 7 | 8 | # The bindings shared library is stored in the Python package of the build tree 9 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/../scenario/bindings) 10 | 11 | swig_add_library(${scenario_swig_name} 12 | TYPE MODULE 13 | LANGUAGE python 14 | OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/../scenario/bindings 15 | OUTFILE_DIR ${CMAKE_CURRENT_BINARY_DIR}/.. 16 | SOURCES ${scenario_swig_name}.i) 17 | 18 | target_link_libraries(${scenario_swig_name} 19 | PUBLIC 20 | ScenarioGazebo::ScenarioGazebo 21 | ScenarioGazebo::GazeboSimulator 22 | Python3::Python) 23 | add_library(ScenarioSwig::Gazebo ALIAS gazebo) 24 | 25 | set_property(TARGET ${scenario_swig_name} PROPERTY 26 | SWIG_USE_TARGET_INCLUDE_DIRECTORIES TRUE) 27 | 28 | # https://github.com/swig/swig/issues/672#issuecomment-400577864 29 | set_property(TARGET ${scenario_swig_name} PROPERTY 30 | SWIG_COMPILE_OPTIONS -doxygen -Dfinal) 31 | 32 | # Disable SWIG debug code due to the following error: 33 | # int SWIG_Python_ConvertPtrAndOwn(PyObject *, void **, swig_type_info *, int, int *): 34 | # Assertion `own' failed. 35 | # https://github.com/swig/swig/issues/731 36 | # https://github.com/swig/swig/issues/773 37 | target_compile_definitions(${scenario_swig_name} PRIVATE NDEBUG) 38 | 39 | # Get the gazebo.py wrapper file 40 | get_property(WRAPPER_PY_FILE TARGET ${scenario_swig_name} PROPERTY SWIG_SUPPORT_FILES) 41 | 42 | install( 43 | TARGETS ${scenario_swig_name} 44 | COMPONENT python 45 | LIBRARY DESTINATION ${SCENARIO_PACKAGE_INSTALL_DIR}/bindings 46 | ARCHIVE DESTINATION ${SCENARIO_PACKAGE_INSTALL_DIR}/bindings 47 | RUNTIME DESTINATION ${SCENARIO_PACKAGE_INSTALL_DIR}/bindings) 48 | 49 | install( 50 | FILES ${WRAPPER_PY_FILE} 51 | DESTINATION ${SCENARIO_PACKAGE_INSTALL_DIR}/bindings 52 | COMPONENT python) 53 | -------------------------------------------------------------------------------- /scenario/bindings/gazebo/to_gazebo.i: -------------------------------------------------------------------------------- 1 | %pythonbegin %{ 2 | from typing import Union 3 | %} 4 | 5 | %extend scenario::core::World { 6 | %pythoncode %{ 7 | def to_gazebo(self) -> Union["scenario.bindings.gazebo.World", "scenario.bindings.core.World"]: 8 | import scenario.bindings.gazebo 9 | return scenario.bindings.gazebo.ToGazeboWorld(self) 10 | %} 11 | } 12 | 13 | %extend scenario::core::Model { 14 | %pythoncode %{ 15 | def to_gazebo(self) -> Union["scenario.bindings.gazebo.Model", "scenario.bindings.core.Model"]: 16 | import scenario.bindings.gazebo 17 | return scenario.bindings.gazebo.ToGazeboModel(self) 18 | %} 19 | } 20 | 21 | %extend scenario::core::Joint { 22 | %pythoncode %{ 23 | def to_gazebo(self) -> Union["scenario.bindings.gazebo.Joint", "scenario.bindings.core.Joint"]: 24 | import scenario.bindings.gazebo 25 | return scenario.bindings.gazebo.ToGazeboJoint(self) 26 | %} 27 | } 28 | 29 | %extend scenario::core::Link { 30 | %pythoncode %{ 31 | def to_gazebo(self) -> Union["scenario.bindings.gazebo.Link", "scenario.bindings.core.Link"]: 32 | import scenario.bindings.gazebo 33 | return scenario.bindings.gazebo.ToGazeboLink(self) 34 | %} 35 | } 36 | -------------------------------------------------------------------------------- /scenario/cmake/FindPackageMessage.cmake: -------------------------------------------------------------------------------- 1 | # Distributed under the OSI-approved BSD 3-Clause License. See accompanying 2 | # file Copyright.txt or https://cmake.org/licensing for details. 3 | 4 | #[=======================================================================[.rst: 5 | FindPackageMessage 6 | ------------------ 7 | 8 | .. code-block:: cmake 9 | 10 | find_package_message( "message for user" "find result details") 11 | 12 | This function is intended to be used in FindXXX.cmake modules files. 13 | It will print a message once for each unique find result. This is 14 | useful for telling the user where a package was found. The first 15 | argument specifies the name (XXX) of the package. The second argument 16 | specifies the message to display. The third argument lists details 17 | about the find result so that if they change the message will be 18 | displayed again. The macro also obeys the QUIET argument to the 19 | find_package command. 20 | 21 | Example: 22 | 23 | .. code-block:: cmake 24 | 25 | if(X11_FOUND) 26 | find_package_message(X11 "Found X11: ${X11_X11_LIB}" 27 | "[${X11_X11_LIB}][${X11_INCLUDE_DIR}]") 28 | else() 29 | ... 30 | endif() 31 | #]=======================================================================] 32 | 33 | function(find_package_message pkg msg details) 34 | # Avoid printing a message repeatedly for the same find result. 35 | if(NOT ${pkg}_FIND_QUIETLY) 36 | string(REPLACE "\n" "" details "${details}") 37 | set(DETAILS_VAR FIND_PACKAGE_MESSAGE_DETAILS_${pkg}) 38 | if(NOT "${details}" STREQUAL "${${DETAILS_VAR}}") 39 | # The message has not yet been printed. 40 | message(STATUS "${msg}") 41 | 42 | # Save the find details in the cache to avoid printing the same 43 | # message again. 44 | set("${DETAILS_VAR}" "${details}" 45 | CACHE INTERNAL "Details about finding ${pkg}") 46 | endif() 47 | endif() 48 | endfunction() 49 | -------------------------------------------------------------------------------- /scenario/cmake/FindSphinx.cmake: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT). All rights reserved. 2 | # This software may be modified and distributed under the terms of the 3 | # GNU Lesser General Public License v2.1 or any later version. 4 | 5 | # Look for an executable called sphinx-build 6 | find_program(SPHINX_EXECUTABLE 7 | NAMES sphinx-build 8 | DOC "Path to sphinx-build executable") 9 | 10 | include(FindPackageHandleStandardArgs) 11 | 12 | # Handle standard arguments to find_package like REQUIRED and QUIET 13 | find_package_handle_standard_args(Sphinx 14 | "Failed to find sphinx-build executable" 15 | SPHINX_EXECUTABLE) 16 | -------------------------------------------------------------------------------- /scenario/cmake/FindSphinxApidoc.cmake: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT). All rights reserved. 2 | # This software may be modified and distributed under the terms of the 3 | # GNU Lesser General Public License v2.1 or any later version. 4 | 5 | # Look for an executable called sphinx-apidoc 6 | find_program(SPHINX_APIDOC_EXECUTABLE 7 | NAMES sphinx-apidoc 8 | DOC "Path to sphinx-apidoc executable") 9 | 10 | include(FindPackageHandleStandardArgs) 11 | 12 | # Handle standard arguments to find_package like REQUIRED and QUIET 13 | find_package_handle_standard_args(SphinxApidoc 14 | "Failed to find sphinx-apidoc executable" 15 | SPHINX_APIDOC_EXECUTABLE) 16 | -------------------------------------------------------------------------------- /scenario/cmake/FindSphinxMultiVersion.cmake: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT). All rights reserved. 2 | # This software may be modified and distributed under the terms of the 3 | # GNU Lesser General Public License v2.1 or any later version. 4 | 5 | # Look for an executable called sphinx-multiversion 6 | find_program(SPHINX_MULTIVERSION_EXECUTABLE 7 | NAMES sphinx-multiversion 8 | DOC "Path to sphinx-multiversion executable") 9 | 10 | include(FindPackageHandleStandardArgs) 11 | 12 | # Handle standard arguments to find_package like REQUIRED and QUIET 13 | find_package_handle_standard_args(SphinxMultiVersion 14 | "Failed to find sphinx-multiversion executable" 15 | SPHINX_MULTIVERSION_EXECUTABLE) 16 | -------------------------------------------------------------------------------- /scenario/cmake/ImportTargetsCitadel.cmake: -------------------------------------------------------------------------------- 1 | include(AliasImportedTarget) 2 | 3 | # https://ignitionrobotics.org/docs/citadel/install#citadel-libraries 4 | 5 | alias_imported_target( 6 | PACKAGE_ORIG sdformat9 7 | PACKAGE_DEST sdformat 8 | TARGETS_ORIG sdformat9 9 | TARGETS_DEST sdformat 10 | NAMESPACE_ORIG sdformat9 11 | NAMESPACE_DEST sdformat 12 | REQUIRED TRUE 13 | ) 14 | 15 | alias_imported_target( 16 | PACKAGE_ORIG ignition-gazebo3 17 | PACKAGE_DEST ignition-gazebo 18 | TARGETS_ORIG ignition-gazebo3 core 19 | TARGETS_DEST ignition-gazebo core 20 | NAMESPACE_ORIG ignition-gazebo3 21 | NAMESPACE_DEST ignition-gazebo 22 | REQUIRED TRUE 23 | ) 24 | 25 | alias_imported_target( 26 | PACKAGE_ORIG ignition-common3 27 | PACKAGE_DEST ignition-common 28 | TARGETS_ORIG ignition-common3 29 | TARGETS_DEST ignition-common 30 | NAMESPACE_ORIG ignition-common3 31 | NAMESPACE_DEST ignition-common 32 | REQUIRED TRUE 33 | ) 34 | 35 | alias_imported_target( 36 | PACKAGE_ORIG ignition-sensors3-all 37 | PACKAGE_DEST ignition-sensors-all 38 | TARGETS_ORIG ignition-sensors3-all 39 | TARGETS_DEST ignition-sensors-all 40 | NAMESPACE_ORIG ignition-sensors3 41 | NAMESPACE_DEST ignition-sensors 42 | REQUIRED TRUE 43 | ) 44 | 45 | alias_imported_target( 46 | PACKAGE_ORIG ignition-rendering3 47 | PACKAGE_DEST ignition-rendering 48 | TARGETS_ORIG ignition-rendering3 49 | TARGETS_DEST ignition-rendering 50 | NAMESPACE_ORIG ignition-rendering3 51 | NAMESPACE_DEST ignition-rendering 52 | REQUIRED TRUE 53 | ) 54 | 55 | alias_imported_target( 56 | PACKAGE_ORIG ignition-gazebo3-rendering 57 | PACKAGE_DEST ignition-gazebo-rendering 58 | TARGETS_ORIG ignition-gazebo3-rendering 59 | TARGETS_DEST ignition-gazebo-rendering 60 | NAMESPACE_ORIG ignition-gazebo3 61 | NAMESPACE_DEST ignition-gazebo 62 | REQUIRED TRUE 63 | ) 64 | 65 | alias_imported_target( 66 | PACKAGE_ORIG ignition-physics2 67 | PACKAGE_DEST ignition-physics 68 | TARGETS_ORIG ignition-physics2 69 | TARGETS_DEST ignition-physics 70 | NAMESPACE_ORIG ignition-physics2 71 | NAMESPACE_DEST ignition-physics 72 | REQUIRED TRUE 73 | ) 74 | -------------------------------------------------------------------------------- /scenario/cmake/ImportTargetsDome.cmake: -------------------------------------------------------------------------------- 1 | include(AliasImportedTarget) 2 | 3 | # https://ignitionrobotics.org/docs/dome/install#dome-libraries 4 | 5 | alias_imported_target( 6 | PACKAGE_ORIG sdformat10 7 | PACKAGE_DEST sdformat 8 | TARGETS_ORIG sdformat10 9 | TARGETS_DEST sdformat 10 | NAMESPACE_ORIG sdformat10 11 | NAMESPACE_DEST sdformat 12 | REQUIRED TRUE 13 | ) 14 | 15 | alias_imported_target( 16 | PACKAGE_ORIG ignition-gazebo4 17 | PACKAGE_DEST ignition-gazebo 18 | TARGETS_ORIG ignition-gazebo4 core 19 | TARGETS_DEST ignition-gazebo core 20 | NAMESPACE_ORIG ignition-gazebo4 21 | NAMESPACE_DEST ignition-gazebo 22 | REQUIRED TRUE 23 | ) 24 | 25 | alias_imported_target( 26 | PACKAGE_ORIG ignition-common3 27 | PACKAGE_DEST ignition-common 28 | TARGETS_ORIG ignition-common3 29 | TARGETS_DEST ignition-common 30 | NAMESPACE_ORIG ignition-common3 31 | NAMESPACE_DEST ignition-common 32 | REQUIRED TRUE 33 | ) 34 | 35 | alias_imported_target( 36 | PACKAGE_ORIG ignition-sensors4-all 37 | PACKAGE_DEST ignition-sensors-all 38 | TARGETS_ORIG ignition-sensors4-all 39 | TARGETS_DEST ignition-sensors-all 40 | NAMESPACE_ORIG ignition-sensors4 41 | NAMESPACE_DEST ignition-sensors 42 | REQUIRED TRUE 43 | ) 44 | 45 | alias_imported_target( 46 | PACKAGE_ORIG ignition-rendering4 47 | PACKAGE_DEST ignition-rendering 48 | TARGETS_ORIG ignition-rendering4 49 | TARGETS_DEST ignition-rendering 50 | NAMESPACE_ORIG ignition-rendering4 51 | NAMESPACE_DEST ignition-rendering 52 | REQUIRED TRUE 53 | ) 54 | 55 | alias_imported_target( 56 | PACKAGE_ORIG ignition-gazebo4-rendering 57 | PACKAGE_DEST ignition-gazebo-rendering 58 | TARGETS_ORIG ignition-gazebo4-rendering 59 | TARGETS_DEST ignition-gazebo-rendering 60 | NAMESPACE_ORIG ignition-gazebo4 61 | NAMESPACE_DEST ignition-gazebo 62 | REQUIRED TRUE 63 | ) 64 | 65 | alias_imported_target( 66 | PACKAGE_ORIG ignition-physics3 67 | PACKAGE_DEST ignition-physics 68 | TARGETS_ORIG ignition-physics3 69 | TARGETS_DEST ignition-physics 70 | NAMESPACE_ORIG ignition-physics3 71 | NAMESPACE_DEST ignition-physics 72 | REQUIRED TRUE 73 | ) 74 | 75 | alias_imported_target( 76 | PACKAGE_ORIG ignition-fuel_tools5 77 | PACKAGE_DEST ignition-fuel_tools 78 | TARGETS_ORIG ignition-fuel_tools5 79 | TARGETS_DEST ignition-fuel_tools 80 | NAMESPACE_ORIG ignition-fuel_tools5 81 | NAMESPACE_DEST ignition-fuel_tools 82 | REQUIRED TRUE 83 | ) 84 | -------------------------------------------------------------------------------- /scenario/cmake/ImportTargetsEdifice.cmake: -------------------------------------------------------------------------------- 1 | include(AliasImportedTarget) 2 | 3 | # https://ignitionrobotics.org/docs/edifice/install#edifice-libraries 4 | 5 | alias_imported_target( 6 | PACKAGE_ORIG sdformat11 7 | PACKAGE_DEST sdformat 8 | TARGETS_ORIG sdformat11 9 | TARGETS_DEST sdformat 10 | NAMESPACE_ORIG sdformat11 11 | NAMESPACE_DEST sdformat 12 | REQUIRED TRUE 13 | ) 14 | 15 | alias_imported_target( 16 | PACKAGE_ORIG ignition-gazebo5 17 | PACKAGE_DEST ignition-gazebo 18 | TARGETS_ORIG ignition-gazebo5 core 19 | TARGETS_DEST ignition-gazebo core 20 | NAMESPACE_ORIG ignition-gazebo5 21 | NAMESPACE_DEST ignition-gazebo 22 | REQUIRED TRUE 23 | ) 24 | 25 | alias_imported_target( 26 | PACKAGE_ORIG ignition-common4 27 | PACKAGE_DEST ignition-common 28 | TARGETS_ORIG ignition-common4 29 | TARGETS_DEST ignition-common 30 | NAMESPACE_ORIG ignition-common4 31 | NAMESPACE_DEST ignition-common 32 | REQUIRED TRUE 33 | ) 34 | 35 | alias_imported_target( 36 | PACKAGE_ORIG ignition-sensors5-all 37 | PACKAGE_DEST ignition-sensors-all 38 | TARGETS_ORIG ignition-sensors5-all 39 | TARGETS_DEST ignition-sensors-all 40 | NAMESPACE_ORIG ignition-sensors5 41 | NAMESPACE_DEST ignition-sensors 42 | REQUIRED TRUE 43 | ) 44 | 45 | alias_imported_target( 46 | PACKAGE_ORIG ignition-rendering5 47 | PACKAGE_DEST ignition-rendering 48 | TARGETS_ORIG ignition-rendering5 49 | TARGETS_DEST ignition-rendering 50 | NAMESPACE_ORIG ignition-rendering5 51 | NAMESPACE_DEST ignition-rendering 52 | REQUIRED TRUE 53 | ) 54 | 55 | alias_imported_target( 56 | PACKAGE_ORIG ignition-gazebo5-rendering 57 | PACKAGE_DEST ignition-gazebo-rendering 58 | TARGETS_ORIG ignition-gazebo5-rendering 59 | TARGETS_DEST ignition-gazebo-rendering 60 | NAMESPACE_ORIG ignition-gazebo5 61 | NAMESPACE_DEST ignition-gazebo 62 | REQUIRED TRUE 63 | ) 64 | 65 | alias_imported_target( 66 | PACKAGE_ORIG ignition-physics4 67 | PACKAGE_DEST ignition-physics 68 | TARGETS_ORIG ignition-physics4 69 | TARGETS_DEST ignition-physics 70 | NAMESPACE_ORIG ignition-physics4 71 | NAMESPACE_DEST ignition-physics 72 | REQUIRED TRUE 73 | ) 74 | -------------------------------------------------------------------------------- /scenario/cmake/ImportTargetsFortress.cmake: -------------------------------------------------------------------------------- 1 | include(AliasImportedTarget) 2 | 3 | # https://ignitionrobotics.org/docs/fortress/install#fortress-libraries 4 | 5 | alias_imported_target( 6 | PACKAGE_ORIG sdformat12 7 | PACKAGE_DEST sdformat 8 | TARGETS_ORIG sdformat12 9 | TARGETS_DEST sdformat 10 | NAMESPACE_ORIG sdformat12 11 | NAMESPACE_DEST sdformat 12 | REQUIRED TRUE 13 | ) 14 | 15 | alias_imported_target( 16 | PACKAGE_ORIG ignition-gazebo6 17 | PACKAGE_DEST ignition-gazebo 18 | TARGETS_ORIG ignition-gazebo6 core 19 | TARGETS_DEST ignition-gazebo core 20 | NAMESPACE_ORIG ignition-gazebo6 21 | NAMESPACE_DEST ignition-gazebo 22 | REQUIRED TRUE 23 | ) 24 | 25 | alias_imported_target( 26 | PACKAGE_ORIG ignition-common4 27 | PACKAGE_DEST ignition-common 28 | TARGETS_ORIG ignition-common4 29 | TARGETS_DEST ignition-common 30 | NAMESPACE_ORIG ignition-common4 31 | NAMESPACE_DEST ignition-common 32 | REQUIRED TRUE 33 | ) 34 | 35 | alias_imported_target( 36 | PACKAGE_ORIG ignition-sensors6-all 37 | PACKAGE_DEST ignition-sensors-all 38 | TARGETS_ORIG ignition-sensors6-all 39 | TARGETS_DEST ignition-sensors-all 40 | NAMESPACE_ORIG ignition-sensors6 41 | NAMESPACE_DEST ignition-sensors 42 | REQUIRED TRUE 43 | ) 44 | 45 | alias_imported_target( 46 | PACKAGE_ORIG ignition-rendering6 47 | PACKAGE_DEST ignition-rendering 48 | TARGETS_ORIG ignition-rendering6 49 | TARGETS_DEST ignition-rendering 50 | NAMESPACE_ORIG ignition-rendering6 51 | NAMESPACE_DEST ignition-rendering 52 | REQUIRED TRUE 53 | ) 54 | 55 | alias_imported_target( 56 | PACKAGE_ORIG ignition-gazebo6-rendering 57 | PACKAGE_DEST ignition-gazebo-rendering 58 | TARGETS_ORIG ignition-gazebo6-rendering 59 | TARGETS_DEST ignition-gazebo-rendering 60 | NAMESPACE_ORIG ignition-gazebo6 61 | NAMESPACE_DEST ignition-gazebo 62 | REQUIRED TRUE 63 | ) 64 | 65 | alias_imported_target( 66 | PACKAGE_ORIG ignition-physics5 67 | PACKAGE_DEST ignition-physics 68 | TARGETS_ORIG ignition-physics5 69 | TARGETS_DEST ignition-physics 70 | NAMESPACE_ORIG ignition-physics5 71 | NAMESPACE_DEST ignition-physics 72 | REQUIRED TRUE 73 | ) 74 | -------------------------------------------------------------------------------- /scenario/pyproject.toml: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2021 Istituto Italiano di Tecnologia (IIT). All rights reserved. 2 | # This software may be modified and distributed under the terms of the 3 | # GNU Lesser General Public License v2.1 or any later version. 4 | 5 | [build-system] 6 | build-backend = "setuptools.build_meta" 7 | requires = [ 8 | "wheel", 9 | "setuptools>=45", 10 | "setuptools_scm[toml]>=6.0", 11 | "cmake-build-extension", 12 | "idyntree>=3.1", 13 | ] 14 | 15 | [tool.setuptools_scm] 16 | root = "../" 17 | local_scheme = "dirty-tag" 18 | -------------------------------------------------------------------------------- /scenario/setup.cfg: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2021 Istituto Italiano di Tecnologia (IIT). All rights reserved. 2 | # This software may be modified and distributed under the terms of the 3 | # GNU Lesser General Public License v2.1 or any later version. 4 | 5 | [metadata] 6 | name = scenario 7 | description = SCENe interfAces for Robot Input/Output. 8 | long_description = file: README.md 9 | long_description_content_type = text/markdown 10 | author = Diego Ferigo 11 | author_email = dgferigo@gmail.com 12 | license = LGPL 13 | platforms = any 14 | url = https://github.com/robotology/gym-ignition/tree/master/scenario 15 | 16 | project_urls = 17 | Changelog = https://github.com/robotology/gym-ignition/releases 18 | Tracker = https://github.com/robotology/gym-ignition/issues 19 | Documentation = https://robotology.github.io/gym-ignition 20 | Source = https://github.com/robotology/gym-ignition/tree/master/scenario 21 | 22 | keywords = 23 | robotics 24 | gazebo 25 | ignition 26 | simulation 27 | physics 28 | multibody 29 | dynamics 30 | physics simulation 31 | middleware 32 | real-time 33 | 34 | classifiers = 35 | Development Status :: 5 - Production/Stable 36 | Operating System :: POSIX :: Linux 37 | Topic :: Games/Entertainment :: Simulation 38 | Topic :: Scientific/Engineering :: Artificial Intelligence 39 | Topic :: Scientific/Engineering :: Physics 40 | Topic :: Software Development 41 | Framework :: Robot Framework 42 | Intended Audience :: Developers 43 | Intended Audience :: Science/Research 44 | Programming Language :: C++ 45 | Programming Language :: Python :: 3.8 46 | Programming Language :: Python :: 3.9 47 | Programming Language :: Python :: 3 :: Only 48 | Programming Language :: Python :: Implementation :: CPython 49 | License :: OSI Approved :: GNU Lesser General Public License v2 or later (LGPLv2+) 50 | 51 | [options] 52 | zip_safe = False 53 | python_requires = >=3.8 54 | install_requires = 55 | packaging 56 | -------------------------------------------------------------------------------- /scenario/setup.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2019 Istituto Italiano di Tecnologia (IIT). All rights reserved. 2 | # This software may be modified and distributed under the terms of the 3 | # GNU Lesser General Public License v2.1 or any later version. 4 | 5 | import sys 6 | 7 | import setuptools 8 | from cmake_build_extension import BuildExtension, CMakeExtension 9 | 10 | setuptools.setup( 11 | ext_modules=[ 12 | CMakeExtension( 13 | name="ScenarioCMakeProject", 14 | install_prefix="scenario", 15 | cmake_build_type="Release", 16 | cmake_configure_options=[ 17 | "-DSCENARIO_CALL_FROM_SETUP_PY:BOOL=ON", 18 | "-DSCENARIO_BUILD_SHARED_LIBRARY:BOOL=OFF", 19 | f"-DPython3_EXECUTABLE:PATH={sys.executable}", 20 | ], 21 | cmake_depends_on=["idyntree"], 22 | disable_editable=True, 23 | ) 24 | ], 25 | cmdclass=dict(build_ext=BuildExtension), 26 | ) 27 | -------------------------------------------------------------------------------- /scenario/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT). All rights reserved. 2 | # This software may be modified and distributed under the terms of the 3 | # GNU Lesser General Public License v2.1 or any later version. 4 | 5 | add_subdirectory(core) 6 | 7 | set(SCENARIO_COMPONENTS ScenarioCore) 8 | set(SCENARIO_PRIVATE_DEPENDENCIES "") 9 | 10 | if(SCENARIO_USE_IGNITION) 11 | 12 | option(ENABLE_PROFILER "Enable Ignition Profiler" OFF) 13 | mark_as_advanced(ENABLE_PROFILER) 14 | 15 | add_subdirectory(gazebo) 16 | add_subdirectory(plugins) 17 | add_subdirectory(controllers) 18 | 19 | list(APPEND SCENARIO_COMPONENTS ScenarioGazebo ScenarioControllers) 20 | 21 | endif() 22 | 23 | # Dummy meta target for the top-level EXPORT 24 | add_library(Scenario INTERFACE) 25 | 26 | install( 27 | TARGETS Scenario 28 | EXPORT ScenarioExport) 29 | 30 | install_basic_package_files(Scenario 31 | VERSION ${PROJECT_VERSION} 32 | COMPATIBILITY AnyNewerVersion 33 | EXPORT ScenarioExport 34 | DEPENDENCIES ${SCENARIO_COMPONENTS} 35 | PRIVATE_DEPENDENCIES ${SCENARIO_PRIVATE_DEPENDENCIES} 36 | NAMESPACE Scenario:: 37 | NO_CHECK_REQUIRED_COMPONENTS_MACRO 38 | INSTALL_DESTINATION 39 | ${SCENARIO_INSTALL_LIBDIR}/cmake/Scenario) 40 | -------------------------------------------------------------------------------- /scenario/src/controllers/include/scenario/controllers/ComputedTorqueFixedBase.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT) 3 | * All rights reserved. 4 | * 5 | * This software may be modified and distributed under the terms of the 6 | * GNU Lesser General Public License v2.1 or any later version. 7 | */ 8 | 9 | #ifndef SCENARIO_CONTROLLERS_COMPUTEDTORQUEFIXEDBASE_H 10 | #define SCENARIO_CONTROLLERS_COMPUTEDTORQUEFIXEDBASE_H 11 | 12 | #include "scenario/controllers/Controller.h" 13 | #include "scenario/controllers/References.h" 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | namespace scenario::core { 21 | class Model; 22 | } // namespace scenario::core 23 | 24 | namespace scenario::controllers { 25 | class ControllersFactory; 26 | class ComputedTorqueFixedBase; 27 | } // namespace scenario::controllers 28 | 29 | class scenario::controllers::ComputedTorqueFixedBase final 30 | : public scenario::controllers::Controller 31 | , public scenario::controllers::UseScenarioModel 32 | , public scenario::controllers::SetJointReferences 33 | { 34 | public: 35 | ComputedTorqueFixedBase() = delete; 36 | ComputedTorqueFixedBase(const std::string& urdfFile, 37 | std::shared_ptr model, 38 | const std::vector& kp, 39 | const std::vector& kd, 40 | const std::vector& controlledJoints, 41 | const std::array gravity = g); 42 | ~ComputedTorqueFixedBase() override; 43 | 44 | bool initialize() override; 45 | bool step(const StepSize& dt) override; 46 | bool terminate() override; 47 | 48 | bool updateStateFromModel() override; 49 | 50 | const std::vector& controlledJoints() override; 51 | bool setJointReferences(const JointReferences& jointReferences) override; 52 | 53 | private: 54 | class Impl; 55 | std::unique_ptr pImpl; 56 | }; 57 | 58 | #endif // SCENARIO_CONTROLLERS_COMPUTEDTORQUEFIXEDBASE_H 59 | -------------------------------------------------------------------------------- /scenario/src/controllers/include/scenario/controllers/Controller.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT) 3 | * All rights reserved. 4 | * 5 | * This software may be modified and distributed under the terms of the 6 | * GNU Lesser General Public License v2.1 or any later version. 7 | */ 8 | 9 | #ifndef SCENARIO_CONTROLLERS_CONTROLLER_H 10 | #define SCENARIO_CONTROLLERS_CONTROLLER_H 11 | 12 | #include "scenario/controllers/References.h" 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | namespace scenario::controllers { 20 | class Controller; 21 | class UseScenarioModel; 22 | class SetBaseReferences; 23 | class SetJointReferences; 24 | using ControllerPtr = std::shared_ptr; 25 | constexpr std::array g = {0, 0, -9.80665}; 26 | } // namespace scenario::controllers 27 | 28 | namespace scenario::core { 29 | class Model; 30 | using ModelPtr = std::shared_ptr; 31 | } // namespace scenario::core 32 | 33 | class scenario::controllers::Controller 34 | : public std::enable_shared_from_this 35 | { 36 | public: 37 | using StepSize = std::chrono::duration; 38 | 39 | Controller() = default; 40 | virtual ~Controller() = default; 41 | 42 | virtual bool initialize() = 0; 43 | virtual bool step(const StepSize& dt) = 0; 44 | virtual bool terminate() = 0; 45 | }; 46 | 47 | class scenario::controllers::UseScenarioModel 48 | { 49 | public: 50 | UseScenarioModel() = default; 51 | virtual ~UseScenarioModel() = default; 52 | 53 | virtual bool updateStateFromModel() = 0; 54 | 55 | protected: 56 | core::ModelPtr m_model; 57 | }; 58 | 59 | class scenario::controllers::SetBaseReferences 60 | { 61 | public: 62 | SetBaseReferences() = default; 63 | virtual ~SetBaseReferences() = default; 64 | 65 | virtual bool setBaseReferences(const BaseReferences& jointReferences) = 0; 66 | }; 67 | 68 | class scenario::controllers::SetJointReferences 69 | { 70 | public: 71 | SetJointReferences() = default; 72 | virtual ~SetJointReferences() = default; 73 | 74 | virtual const std::vector& controlledJoints() = 0; 75 | virtual bool setJointReferences(const JointReferences& jointReferences) = 0; 76 | 77 | protected: 78 | std::vector m_controlledJoints; 79 | }; 80 | 81 | #endif // SCENARIO_CONTROLLERS_CONTROLLER_H 82 | -------------------------------------------------------------------------------- /scenario/src/controllers/include/scenario/controllers/References.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT) 3 | * All rights reserved. 4 | * 5 | * This software may be modified and distributed under the terms of the 6 | * GNU Lesser General Public License v2.1 or any later version. 7 | */ 8 | 9 | #ifndef SCENARIO_CONTROLLERS_REFERENCES_H 10 | #define SCENARIO_CONTROLLERS_REFERENCES_H 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | namespace scenario::controllers { 17 | struct BaseReferences; 18 | struct JointReferences; 19 | } // namespace scenario::controllers 20 | 21 | struct scenario::controllers::BaseReferences 22 | { 23 | std::array position = {0, 0, 0}; 24 | std::array orientation = {1, 0, 0, 0}; 25 | std::array linearVelocity = {0, 0, 0}; 26 | std::array angularVelocity = {0, 0, 0}; 27 | std::array linearAcceleration = {0, 0, 0}; 28 | std::array angularAcceleration = {0, 0, 0}; 29 | }; 30 | 31 | struct scenario::controllers::JointReferences 32 | { 33 | JointReferences(const size_t controlledDofs = 0) 34 | { 35 | position = std::vector(controlledDofs, 0.0); 36 | velocity = std::vector(controlledDofs, 0.0); 37 | acceleration = std::vector(controlledDofs, 0.0); 38 | } 39 | 40 | inline bool valid() const 41 | { 42 | size_t dofs = position.size(); 43 | return dofs > 0 && velocity.size() == dofs 44 | && acceleration.size() == dofs; 45 | } 46 | 47 | std::vector position; 48 | std::vector velocity; 49 | std::vector acceleration; 50 | }; 51 | 52 | #endif // SCENARIO_CONTROLLERS_REFERENCES_H 53 | -------------------------------------------------------------------------------- /scenario/src/core/include/scenario/core/World.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT) 3 | * All rights reserved. 4 | * 5 | * This software may be modified and distributed under the terms of the 6 | * GNU Lesser General Public License v2.1 or any later version. 7 | */ 8 | 9 | #ifndef SCENARIO_CORE_WORLD_H 10 | #define SCENARIO_CORE_WORLD_H 11 | 12 | #include "scenario/core/Link.h" 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | namespace scenario::core { 19 | class World; 20 | class Model; 21 | using ModelPtr = std::shared_ptr; 22 | using WorldPtr = std::shared_ptr; 23 | } // namespace scenario::core 24 | 25 | class scenario::core::World 26 | { 27 | public: 28 | World() = default; 29 | virtual ~World() = default; 30 | 31 | /** 32 | * Check if the world is valid. 33 | * 34 | * @return True if the world is valid, false otherwise. 35 | */ 36 | virtual bool valid() const = 0; 37 | 38 | /** 39 | * Get the simulated time. 40 | * 41 | * @note A physics plugin need to be part of the simulation 42 | * in order to make the time flow. 43 | * 44 | * @return The simulated time. 45 | */ 46 | virtual double time() const = 0; 47 | 48 | /** 49 | * Get the name of the world. 50 | * 51 | * @return The name of the world. 52 | */ 53 | virtual std::string name() const = 0; 54 | 55 | /** 56 | * Get the gravity vector. 57 | * @return The gravity vector. 58 | */ 59 | virtual std::array gravity() const = 0; 60 | 61 | /** 62 | * Get the name of the models that are part of the world. 63 | * 64 | * @return The list of model names. 65 | */ 66 | virtual std::vector modelNames() const = 0; 67 | 68 | /** 69 | * Get a model part of the world. 70 | * 71 | * @param modelName The name of the model to get. 72 | * @return The model if it is part of the world, ``nullptr`` otherwise. 73 | */ 74 | virtual ModelPtr getModel(const std::string& modelName) const = 0; 75 | 76 | /** 77 | * Get the models of the world. 78 | * 79 | * @param modelNames Optional vector of considered models. By default, 80 | * ``World::modelNames`` is used. 81 | * @return A vector of pointers to the model objects. 82 | */ 83 | virtual std::vector models( // 84 | const std::vector& modelNames = {}) const = 0; 85 | }; 86 | 87 | #endif // SCENARIO_CORE_WORLD_H 88 | -------------------------------------------------------------------------------- /scenario/src/core/include/scenario/core/utils/Log.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT) 3 | * All rights reserved. 4 | * 5 | * This software may be modified and distributed under the terms of the 6 | * GNU Lesser General Public License v2.1 or any later version. 7 | */ 8 | 9 | #ifndef SCENARIO_CORE_UTILS_LOG 10 | #define SCENARIO_CORE_UTILS_LOG 11 | 12 | // Downstream implementations can override logs and then 13 | // use the include order to select the right log backend 14 | #ifndef SCENARIO_LOG_MACROS_DEFINED 15 | #define SCENARIO_LOG_MACROS_DEFINED 16 | 17 | #include 18 | #define sError std::cerr 19 | #define sWarning std::cerr 20 | #define sMessage std::cout 21 | #define sDebug std::cout 22 | #define sLog std::cout 23 | 24 | #endif // SCENARIO_LOG_MACROS_DEFINED 25 | 26 | #endif // SCENARIO_CORE_UTILS_LOG 27 | -------------------------------------------------------------------------------- /scenario/src/core/include/scenario/core/utils/signals.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT) 3 | * All rights reserved. 4 | * 5 | * This software may be modified and distributed under the terms of the 6 | * GNU Lesser General Public License v2.1 or any later version. 7 | */ 8 | 9 | #ifndef SCENARIO_CORE_UTILS_SIGNALS_H 10 | #define SCENARIO_CORE_UTILS_SIGNALS_H 11 | 12 | #include 13 | #include 14 | 15 | namespace scenario::core::utils { 16 | class SignalManager; 17 | } // namespace scenario::core::utils 18 | 19 | class scenario::core::utils::SignalManager 20 | { 21 | public: 22 | using SignalType = int; 23 | using SignalCallback = std::function; 24 | 25 | SignalManager(); 26 | ~SignalManager(); 27 | 28 | static void ExecuteCallback(SignalType type); 29 | 30 | static SignalManager& Instance(); 31 | SignalCallback getCallback(const SignalType type) const; 32 | SignalCallback setCallback(const SignalType type, 33 | const SignalCallback& callback); 34 | 35 | private: 36 | class Impl; 37 | std::unique_ptr pImpl; 38 | }; 39 | 40 | #endif // SCENARIO_CORE_UTILS_SIGNALS_H 41 | -------------------------------------------------------------------------------- /scenario/src/core/include/scenario/core/utils/utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT) 3 | * All rights reserved. 4 | * 5 | * This software may be modified and distributed under the terms of the 6 | * GNU Lesser General Public License v2.1 or any later version. 7 | */ 8 | 9 | #ifndef SCENARIO_CORE_UTILS_H 10 | #define SCENARIO_CORE_UTILS_H 11 | 12 | #include 13 | 14 | namespace scenario::core::utils { 15 | /** 16 | * Get the install prefix used by the CMake project. 17 | * 18 | * @note It is defined only if the project is installed in 19 | * Developer mode. 20 | * 21 | * @return A string with the install prefix if the project is 22 | * installed in Developer mode, an empty string otherwise. 23 | */ 24 | std::string getInstallPrefix(); 25 | } // namespace scenario::core::utils 26 | 27 | #endif // SCENARIO_CORE_UTILS_H 28 | -------------------------------------------------------------------------------- /scenario/src/core/src/signals.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT) 3 | * All rights reserved. 4 | * 5 | * This software may be modified and distributed under the terms of the 6 | * GNU Lesser General Public License v2.1 or any later version. 7 | */ 8 | 9 | #include "scenario/core/utils/signals.h" 10 | #include "scenario/core/utils/Log.h" 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | namespace scenario::core::detail { 17 | static std::mutex SignalManagerMutex; 18 | } 19 | 20 | using namespace scenario::core::utils; 21 | 22 | class SignalManager::Impl 23 | { 24 | public: 25 | static std::string ToString(const int type); 26 | static std::unordered_map 27 | DefaultTypeToName; 28 | 29 | std::unordered_map callbacks; 30 | }; 31 | 32 | SignalManager::SignalManager() 33 | : pImpl{std::make_unique()} 34 | {} 35 | 36 | SignalManager::~SignalManager() = default; 37 | 38 | void SignalManager::ExecuteCallback(SignalType type) 39 | { 40 | std::lock_guard lock(detail::SignalManagerMutex); 41 | 42 | sDebug << "Received interrupt signal " << Impl::ToString(type) << std::endl; 43 | auto callback = SignalManager::Instance().getCallback(type); 44 | 45 | if (callback) { 46 | sDebug << "Found signal callback" << std::endl; 47 | callback(type); 48 | return; 49 | } 50 | 51 | sDebug << "No callback found" << std::endl; 52 | } 53 | 54 | SignalManager& SignalManager::Instance() 55 | { 56 | static SignalManager instance; 57 | return instance; 58 | } 59 | 60 | SignalManager::SignalCallback 61 | SignalManager::getCallback(const SignalType type) const 62 | { 63 | if (pImpl->callbacks.find(type) != pImpl->callbacks.end()) { 64 | return pImpl->callbacks.at(type); 65 | } 66 | 67 | return nullptr; 68 | } 69 | 70 | SignalManager::SignalCallback 71 | SignalManager::setCallback(const SignalType type, 72 | const SignalManager::SignalCallback& callback) 73 | { 74 | SignalCallback oldCallback = this->getCallback(type); 75 | 76 | std::signal(type, SignalManager::ExecuteCallback); 77 | pImpl->callbacks[type] = callback; 78 | 79 | return oldCallback; 80 | } 81 | 82 | // ============== 83 | // Implementation 84 | // ============== 85 | 86 | std::string SignalManager::Impl::ToString(const int type) 87 | { 88 | if (DefaultTypeToName.find(type) != DefaultTypeToName.end()) { 89 | return DefaultTypeToName.at(type); 90 | } 91 | else { 92 | return std::to_string(type); 93 | } 94 | } 95 | 96 | std::unordered_map 97 | SignalManager::Impl::DefaultTypeToName = { 98 | {SIGABRT, "SIGABRT"}, 99 | {SIGFPE, "SIGFPE"}, 100 | {SIGILL, "SIGILL"}, 101 | {SIGINT, "SIGINT"}, 102 | {SIGSEGV, "SIGSEGV"}, 103 | {SIGTERM, "SIGTERM"}, 104 | }; 105 | -------------------------------------------------------------------------------- /scenario/src/core/src/utils.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT) 3 | * All rights reserved. 4 | * 5 | * This software may be modified and distributed under the terms of the 6 | * GNU Lesser General Public License v2.1 or any later version. 7 | */ 8 | 9 | #include "scenario/core/utils/utils.h" 10 | #include "scenario/core/utils/Log.h" 11 | 12 | using namespace scenario::core; 13 | 14 | std::string utils::getInstallPrefix() 15 | { 16 | #ifdef SCENARIO_CMAKE_INSTALL_PREFIX 17 | return SCENARIO_CMAKE_INSTALL_PREFIX; 18 | #else 19 | // The install prefix of the User installation can be computed 20 | // from the Python module path 21 | return ""; 22 | #endif 23 | } 24 | -------------------------------------------------------------------------------- /scenario/src/gazebo/include/scenario/gazebo/Log.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT) 3 | * All rights reserved. 4 | * 5 | * This project is dual licensed under LGPL v2.1+ or Apache License. 6 | * 7 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 8 | * 9 | * This software may be modified and distributed under the terms of the 10 | * GNU Lesser General Public License v2.1 or any later version. 11 | * 12 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 13 | * 14 | * Licensed under the Apache License, Version 2.0 (the "License"); 15 | * you may not use this file except in compliance with the License. 16 | * You may obtain a copy of the License at 17 | * 18 | * http://www.apache.org/licenses/LICENSE-2.0 19 | * 20 | * Unless required by applicable law or agreed to in writing, software 21 | * distributed under the License is distributed on an "AS IS" BASIS, 22 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 23 | * See the License for the specific language governing permissions and 24 | * limitations under the License. 25 | */ 26 | 27 | #ifndef SCENARIO_GAZEBO_LOG 28 | #define SCENARIO_GAZEBO_LOG 29 | 30 | #ifndef SCENARIO_LOG_MACROS_DEFINED 31 | #define SCENARIO_LOG_MACROS_DEFINED 32 | 33 | #include 34 | #define sError ::ignition::common::Console::err(__FILE__, __LINE__) 35 | #define sWarning ::ignition::common::Console::warn(__FILE__, __LINE__) 36 | #define sMessage ::ignition::common::Console::msg(__FILE__, __LINE__) 37 | #define sDebug ::ignition::common::Console::dbg(__FILE__, __LINE__) 38 | #define sLog ::ignition::common::Console::log(__FILE__, __LINE__) 39 | 40 | #endif // SCENARIO_LOG_MACROS_DEFINED 41 | 42 | #endif // SCENARIO_GAZEBO_LOG 43 | -------------------------------------------------------------------------------- /scenario/src/gazebo/include/scenario/gazebo/components/BasePoseTarget.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT) 3 | * All rights reserved. 4 | * 5 | * This project is dual licensed under LGPL v2.1+ or Apache License. 6 | * 7 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 8 | * 9 | * This software may be modified and distributed under the terms of the 10 | * GNU Lesser General Public License v2.1 or any later version. 11 | * 12 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 13 | * 14 | * Licensed under the Apache License, Version 2.0 (the "License"); 15 | * you may not use this file except in compliance with the License. 16 | * You may obtain a copy of the License at 17 | * 18 | * http://www.apache.org/licenses/LICENSE-2.0 19 | * 20 | * Unless required by applicable law or agreed to in writing, software 21 | * distributed under the License is distributed on an "AS IS" BASIS, 22 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 23 | * See the License for the specific language governing permissions and 24 | * limitations under the License. 25 | */ 26 | 27 | #ifndef IGNITION_GAZEBO_COMPONENTS_BASEPOSETARGET_H 28 | #define IGNITION_GAZEBO_COMPONENTS_BASEPOSETARGET_H 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | namespace ignition::gazebo { 36 | // Inline bracket to help doxygen filtering. 37 | inline namespace IGNITION_GAZEBO_VERSION_NAMESPACE { 38 | namespace components { 39 | /// \brief Base pose target used by floating base controllers. 40 | using BasePoseTarget = 41 | Component; 42 | IGN_GAZEBO_REGISTER_COMPONENT( 43 | "ign_gazebo_components.BasePoseTarget", 44 | BasePoseTarget) 45 | } // namespace components 46 | } // namespace IGNITION_GAZEBO_VERSION_NAMESPACE 47 | } // namespace ignition::gazebo 48 | 49 | #endif // IGNITION_GAZEBO_COMPONENTS_BASEPOSETARGET_H 50 | -------------------------------------------------------------------------------- /scenario/src/gazebo/include/scenario/gazebo/components/BaseWorldAccelerationTarget.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT) 3 | * All rights reserved. 4 | * 5 | * This project is dual licensed under LGPL v2.1+ or Apache License. 6 | * 7 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 8 | * 9 | * This software may be modified and distributed under the terms of the 10 | * GNU Lesser General Public License v2.1 or any later version. 11 | * 12 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 13 | * 14 | * Licensed under the Apache License, Version 2.0 (the "License"); 15 | * you may not use this file except in compliance with the License. 16 | * You may obtain a copy of the License at 17 | * 18 | * http://www.apache.org/licenses/LICENSE-2.0 19 | * 20 | * Unless required by applicable law or agreed to in writing, software 21 | * distributed under the License is distributed on an "AS IS" BASIS, 22 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 23 | * See the License for the specific language governing permissions and 24 | * limitations under the License. 25 | */ 26 | 27 | #ifndef IGNITION_GAZEBO_COMPONENTS_BASEWORLDACCELERATIONTARGET_H 28 | #define IGNITION_GAZEBO_COMPONENTS_BASEWORLDACCELERATIONTARGET_H 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | namespace ignition::gazebo { 37 | // Inline bracket to help doxygen filtering. 38 | inline namespace IGNITION_GAZEBO_VERSION_NAMESPACE { 39 | namespace components { 40 | /// \brief Base world linear acceleration target used by 41 | /// floating base controllers. 42 | using BaseWorldLinearAccelerationTarget = 43 | Component; 45 | IGN_GAZEBO_REGISTER_COMPONENT( 46 | "ign_gazebo_components.BaseWorldLinearAccelerationTarget", 47 | BaseWorldLinearAccelerationTarget) 48 | 49 | /// \brief Base world angular acceleration target used by 50 | /// floating base controllers. 51 | using BaseWorldAngularAccelerationTarget = 52 | Component; 54 | IGN_GAZEBO_REGISTER_COMPONENT( 55 | "ign_gazebo_components." 56 | "BaseWorldAngularAccelerationTargetTarget", 57 | BaseWorldAngularAccelerationTarget) 58 | } // namespace components 59 | } // namespace IGNITION_GAZEBO_VERSION_NAMESPACE 60 | } // namespace ignition::gazebo 61 | 62 | #endif // IGNITION_GAZEBO_COMPONENTS_BASEWORLDACCELERATIONTARGET_H 63 | -------------------------------------------------------------------------------- /scenario/src/gazebo/include/scenario/gazebo/components/BaseWorldVelocityTarget.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT) 3 | * All rights reserved. 4 | * 5 | * This project is dual licensed under LGPL v2.1+ or Apache License. 6 | * 7 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 8 | * 9 | * This software may be modified and distributed under the terms of the 10 | * GNU Lesser General Public License v2.1 or any later version. 11 | * 12 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 13 | * 14 | * Licensed under the Apache License, Version 2.0 (the "License"); 15 | * you may not use this file except in compliance with the License. 16 | * You may obtain a copy of the License at 17 | * 18 | * http://www.apache.org/licenses/LICENSE-2.0 19 | * 20 | * Unless required by applicable law or agreed to in writing, software 21 | * distributed under the License is distributed on an "AS IS" BASIS, 22 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 23 | * See the License for the specific language governing permissions and 24 | * limitations under the License. 25 | */ 26 | 27 | #ifndef IGNITION_GAZEBO_COMPONENTS_BASEWORLDVELOCITYTARGET_H 28 | #define IGNITION_GAZEBO_COMPONENTS_BASEWORLDVELOCITYTARGET_H 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | namespace ignition::gazebo { 37 | // Inline bracket to help doxygen filtering. 38 | inline namespace IGNITION_GAZEBO_VERSION_NAMESPACE { 39 | namespace components { 40 | /// \brief Base world linear velocity target used by 41 | /// floating base controllers. 42 | using BaseWorldLinearVelocityTarget = 43 | Component; 45 | IGN_GAZEBO_REGISTER_COMPONENT( 46 | "ign_gazebo_components.BaseWorldLinearVelocityTarget", 47 | BaseWorldLinearVelocityTarget) 48 | 49 | /// \brief Base world angular velocity target used by 50 | /// floating base controllers. 51 | using BaseWorldAngularVelocityTarget = 52 | Component; 54 | IGN_GAZEBO_REGISTER_COMPONENT( 55 | "ign_gazebo_components." 56 | "BaseWorldAngularVelocityTargetTarget", 57 | BaseWorldAngularVelocityTarget) 58 | } // namespace components 59 | } // namespace IGNITION_GAZEBO_VERSION_NAMESPACE 60 | } // namespace ignition::gazebo 61 | 62 | #endif // IGNITION_GAZEBO_COMPONENTS_BASEWORLDVELOCITYTARGET_H 63 | -------------------------------------------------------------------------------- /scenario/src/gazebo/include/scenario/gazebo/components/ExternalWorldWrenchCmdWithDuration.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT) 3 | * All rights reserved. 4 | * 5 | * This project is dual licensed under LGPL v2.1+ or Apache License. 6 | * 7 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 8 | * 9 | * This software may be modified and distributed under the terms of the 10 | * GNU Lesser General Public License v2.1 or any later version. 11 | * 12 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 13 | * 14 | * Licensed under the Apache License, Version 2.0 (the "License"); 15 | * you may not use this file except in compliance with the License. 16 | * You may obtain a copy of the License at 17 | * 18 | * http://www.apache.org/licenses/LICENSE-2.0 19 | * 20 | * Unless required by applicable law or agreed to in writing, software 21 | * distributed under the License is distributed on an "AS IS" BASIS, 22 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 23 | * See the License for the specific language governing permissions and 24 | * limitations under the License. 25 | */ 26 | 27 | #ifndef IGNITION_GAZEBO_COMPONENTS_EXTERNALWORLDWRENCHCMDWITHDURATION_H 28 | #define IGNITION_GAZEBO_COMPONENTS_EXTERNALWORLDWRENCHCMDWITHDURATION_H 29 | 30 | #include "scenario/gazebo/helpers.h" 31 | 32 | #include 33 | #include 34 | #include 35 | 36 | #include 37 | 38 | namespace ignition::gazebo { 39 | // Inline bracket to help doxygen filtering. 40 | inline namespace IGNITION_GAZEBO_VERSION_NAMESPACE { 41 | namespace components { 42 | /// \brief A component type that contains the external wrench to be 43 | /// applied for a given duration on an entity expressed in 44 | /// the world frame and represented by 45 | /// ignition::msgs::Wrench. Currently this is used for 46 | /// applying wrenches on links. Although the msg::Wrench type 47 | /// has a force_offset member, the value is currently 48 | /// ignored. Instead, the force is applied at the link 49 | /// origin. The wrench uses SI units (N for force and N⋅m for 50 | /// torque). 51 | using ExternalWorldWrenchCmdWithDuration = 52 | Component; 54 | IGN_GAZEBO_REGISTER_COMPONENT( 55 | "ign_gazebo_components.ExternalWorldWrenchCmdWithDuration", 56 | ExternalWorldWrenchCmdWithDuration) 57 | } // namespace components 58 | } // namespace IGNITION_GAZEBO_VERSION_NAMESPACE 59 | } // namespace ignition::gazebo 60 | 61 | #endif // IGNITION_GAZEBO_COMPONENTS_EXTERNALWORLDWRENCHCMDWITHDURATION_H 62 | -------------------------------------------------------------------------------- /scenario/src/gazebo/include/scenario/gazebo/components/HistoryOfAppliedJointForces.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT) 3 | * All rights reserved. 4 | * 5 | * This project is dual licensed under LGPL v2.1+ or Apache License. 6 | * 7 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 8 | * 9 | * This software may be modified and distributed under the terms of the 10 | * GNU Lesser General Public License v2.1 or any later version. 11 | * 12 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 13 | * 14 | * Licensed under the Apache License, Version 2.0 (the "License"); 15 | * you may not use this file except in compliance with the License. 16 | * You may obtain a copy of the License at 17 | * 18 | * http://www.apache.org/licenses/LICENSE-2.0 19 | * 20 | * Unless required by applicable law or agreed to in writing, software 21 | * distributed under the License is distributed on an "AS IS" BASIS, 22 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 23 | * See the License for the specific language governing permissions and 24 | * limitations under the License. 25 | */ 26 | 27 | #ifndef IGNITION_GAZEBO_COMPONENTS_HISTORYOFAPPLIEDJOINTFORCES_H 28 | #define IGNITION_GAZEBO_COMPONENTS_HISTORYOFAPPLIEDJOINTFORCES_H 29 | 30 | #include "scenario/gazebo/helpers.h" 31 | 32 | #include 33 | #include 34 | #include 35 | 36 | namespace ignition::gazebo { 37 | // Inline bracket to help doxygen filtering. 38 | inline namespace IGNITION_GAZEBO_VERSION_NAMESPACE { 39 | namespace components { 40 | /// \brief Fixed-size queue that stores a window of applied joint 41 | /// forces. 42 | /// 43 | /// The queue is associated to a joint and it is filled at each 44 | /// physics step with as many values as degrees of freedom. 45 | using HistoryOfAppliedJointForces = 46 | Component; 48 | IGN_GAZEBO_REGISTER_COMPONENT( 49 | "ign_gazebo_components.HistoryOfAppliedJointForces", 50 | HistoryOfAppliedJointForces) 51 | } // namespace components 52 | } // namespace IGNITION_GAZEBO_VERSION_NAMESPACE 53 | } // namespace ignition::gazebo 54 | 55 | #endif // IGNITION_GAZEBO_COMPONENTS_HISTORYOFAPPLIEDJOINTFORCES_H 56 | -------------------------------------------------------------------------------- /scenario/src/gazebo/include/scenario/gazebo/components/JointAcceleration.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT) 3 | * All rights reserved. 4 | * 5 | * This project is dual licensed under LGPL v2.1+ or Apache License. 6 | * 7 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 8 | * 9 | * This software may be modified and distributed under the terms of the 10 | * GNU Lesser General Public License v2.1 or any later version. 11 | * 12 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 13 | * 14 | * Licensed under the Apache License, Version 2.0 (the "License"); 15 | * you may not use this file except in compliance with the License. 16 | * You may obtain a copy of the License at 17 | * 18 | * http://www.apache.org/licenses/LICENSE-2.0 19 | * 20 | * Unless required by applicable law or agreed to in writing, software 21 | * distributed under the License is distributed on an "AS IS" BASIS, 22 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 23 | * See the License for the specific language governing permissions and 24 | * limitations under the License. 25 | */ 26 | 27 | #ifndef IGNITION_GAZEBO_COMPONENTS_JOINTACCELERATION_H 28 | #define IGNITION_GAZEBO_COMPONENTS_JOINTACCELERATION_H 29 | 30 | #include 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | namespace ignition { 38 | namespace gazebo { 39 | // Inline bracket to help doxygen filtering. 40 | inline namespace IGNITION_GAZEBO_VERSION_NAMESPACE { 41 | namespace components { 42 | /// \brief Joint acceleration in SI units (rad/s/s for revolute, 43 | /// m/s/s for prismatic). The component wraps a std::vector of 44 | /// size equal to the degrees of freedom of the joint. 45 | using JointAcceleration = 46 | Component, 47 | class JointAccelerationTag, 48 | serializers::VectorDoubleSerializer>; 49 | IGN_GAZEBO_REGISTER_COMPONENT( 50 | "ign_gazebo_components.JointAcceleration", 51 | JointAcceleration) 52 | } // namespace components 53 | } // namespace IGNITION_GAZEBO_VERSION_NAMESPACE 54 | } // namespace gazebo 55 | } // namespace ignition 56 | 57 | #endif // IGNITION_GAZEBO_COMPONENTS_JOINTACCELERATION_H 58 | -------------------------------------------------------------------------------- /scenario/src/gazebo/include/scenario/gazebo/components/JointAccelerationTarget.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT) 3 | * All rights reserved. 4 | * 5 | * This project is dual licensed under LGPL v2.1+ or Apache License. 6 | * 7 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 8 | * 9 | * This software may be modified and distributed under the terms of the 10 | * GNU Lesser General Public License v2.1 or any later version. 11 | * 12 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 13 | * 14 | * Licensed under the Apache License, Version 2.0 (the "License"); 15 | * you may not use this file except in compliance with the License. 16 | * You may obtain a copy of the License at 17 | * 18 | * http://www.apache.org/licenses/LICENSE-2.0 19 | * 20 | * Unless required by applicable law or agreed to in writing, software 21 | * distributed under the License is distributed on an "AS IS" BASIS, 22 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 23 | * See the License for the specific language governing permissions and 24 | * limitations under the License. 25 | */ 26 | 27 | #ifndef IGNITION_GAZEBO_COMPONENTS_JOINTACCELERATIONTARGET_H 28 | #define IGNITION_GAZEBO_COMPONENTS_JOINTACCELERATIONTARGET_H 29 | 30 | #include 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | namespace ignition::gazebo { 38 | // Inline bracket to help doxygen filtering. 39 | inline namespace IGNITION_GAZEBO_VERSION_NAMESPACE { 40 | namespace components { 41 | /// \brief Joint acceleration target in SI units (rad/s/s for 42 | /// revolute, m/s/s for prismatic) used by joint 43 | /// controllers. 44 | /// 45 | /// The component wraps a std::vector of size equal to the 46 | /// degrees of freedom of the joint. 47 | using JointAccelerationTarget = 48 | Component, 49 | class JointAccelerationTargetTag, 50 | serializers::VectorDoubleSerializer>; 51 | IGN_GAZEBO_REGISTER_COMPONENT( 52 | "ign_gazebo_components.JointAccelerationTarget", 53 | JointAccelerationTarget) 54 | } // namespace components 55 | } // namespace IGNITION_GAZEBO_VERSION_NAMESPACE 56 | } // namespace ignition::gazebo 57 | 58 | #endif // IGNITION_GAZEBO_COMPONENTS_JOINTACCELERATIONTARGET_H 59 | -------------------------------------------------------------------------------- /scenario/src/gazebo/include/scenario/gazebo/components/JointControlMode.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT) 3 | * All rights reserved. 4 | * 5 | * This project is dual licensed under LGPL v2.1+ or Apache License. 6 | * 7 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 8 | * 9 | * This software may be modified and distributed under the terms of the 10 | * GNU Lesser General Public License v2.1 or any later version. 11 | * 12 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 13 | * 14 | * Licensed under the Apache License, Version 2.0 (the "License"); 15 | * you may not use this file except in compliance with the License. 16 | * You may obtain a copy of the License at 17 | * 18 | * http://www.apache.org/licenses/LICENSE-2.0 19 | * 20 | * Unless required by applicable law or agreed to in writing, software 21 | * distributed under the License is distributed on an "AS IS" BASIS, 22 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 23 | * See the License for the specific language governing permissions and 24 | * limitations under the License. 25 | */ 26 | 27 | #ifndef IGNITION_GAZEBO_COMPONENTS_JOINTCONTROLMODE_H 28 | #define IGNITION_GAZEBO_COMPONENTS_JOINTCONTROLMODE_H 29 | 30 | #include "scenario/gazebo/Joint.h" 31 | 32 | #include 33 | #include 34 | #include 35 | 36 | namespace ignition::gazebo { 37 | // Inline bracket to help doxygen filtering. 38 | inline namespace IGNITION_GAZEBO_VERSION_NAMESPACE { 39 | namespace serializers { 40 | class JointControlModeSerializer; 41 | } // namespace serializers 42 | 43 | namespace components { 44 | /// \brief Joint control mode. 45 | using JointControlMode = Component; 47 | IGN_GAZEBO_REGISTER_COMPONENT( 48 | "ign_gazebo_components.JointControlMode", 49 | JointControlMode) 50 | } // namespace components 51 | } // namespace IGNITION_GAZEBO_VERSION_NAMESPACE 52 | } // namespace ignition::gazebo 53 | 54 | #endif // IGNITION_GAZEBO_COMPONENTS_JOINTCONTROLMODE_H 55 | -------------------------------------------------------------------------------- /scenario/src/gazebo/include/scenario/gazebo/components/JointController.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT) 3 | * All rights reserved. 4 | * 5 | * This project is dual licensed under LGPL v2.1+ or Apache License. 6 | * 7 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 8 | * 9 | * This software may be modified and distributed under the terms of the 10 | * GNU Lesser General Public License v2.1 or any later version. 11 | * 12 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 13 | * 14 | * Licensed under the Apache License, Version 2.0 (the "License"); 15 | * you may not use this file except in compliance with the License. 16 | * You may obtain a copy of the License at 17 | * 18 | * http://www.apache.org/licenses/LICENSE-2.0 19 | * 20 | * Unless required by applicable law or agreed to in writing, software 21 | * distributed under the License is distributed on an "AS IS" BASIS, 22 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 23 | * See the License for the specific language governing permissions and 24 | * limitations under the License. 25 | */ 26 | 27 | #ifndef IGNITION_GAZEBO_COMPONENTS_JOINTCONTROLLER_H 28 | #define IGNITION_GAZEBO_COMPONENTS_JOINTCONTROLLER_H 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | namespace ignition::gazebo { 35 | // Inline bracket to help doxygen filtering. 36 | inline namespace IGNITION_GAZEBO_VERSION_NAMESPACE { 37 | namespace components { 38 | /// \brief Marks whether a model has a JointController plugin. 39 | using JointController = Component; 40 | IGN_GAZEBO_REGISTER_COMPONENT( 41 | "ign_gazebo_components.JointController", 42 | JointController) 43 | } // namespace components 44 | } // namespace IGNITION_GAZEBO_VERSION_NAMESPACE 45 | } // namespace ignition::gazebo 46 | 47 | #endif // IGNITION_GAZEBO_COMPONENTS_JOINTCONTROLLER_H 48 | -------------------------------------------------------------------------------- /scenario/src/gazebo/include/scenario/gazebo/components/JointControllerPeriod.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT) 3 | * All rights reserved. 4 | * 5 | * This project is dual licensed under LGPL v2.1+ or Apache License. 6 | * 7 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 8 | * 9 | * This software may be modified and distributed under the terms of the 10 | * GNU Lesser General Public License v2.1 or any later version. 11 | * 12 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 13 | * 14 | * Licensed under the Apache License, Version 2.0 (the "License"); 15 | * you may not use this file except in compliance with the License. 16 | * You may obtain a copy of the License at 17 | * 18 | * http://www.apache.org/licenses/LICENSE-2.0 19 | * 20 | * Unless required by applicable law or agreed to in writing, software 21 | * distributed under the License is distributed on an "AS IS" BASIS, 22 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 23 | * See the License for the specific language governing permissions and 24 | * limitations under the License. 25 | */ 26 | 27 | #ifndef IGNITION_GAZEBO_COMPONENTS_JOINTCONTROLLERPERIOD_H 28 | #define IGNITION_GAZEBO_COMPONENTS_JOINTCONTROLLERPERIOD_H 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | #include 36 | 37 | namespace ignition::gazebo { 38 | // Inline bracket to help doxygen filtering. 39 | inline namespace IGNITION_GAZEBO_VERSION_NAMESPACE { 40 | namespace components { 41 | /// \brief Joint controller period in seconds. 42 | using JointControllerPeriod = 43 | Component; 45 | IGN_GAZEBO_REGISTER_COMPONENT( 46 | "ign_gazebo_components.JointControllerPeriod", 47 | JointControllerPeriod) 48 | } // namespace components 49 | } // namespace IGNITION_GAZEBO_VERSION_NAMESPACE 50 | } // namespace ignition::gazebo 51 | 52 | #endif // IGNITION_GAZEBO_COMPONENTS_JOINTCONTROLLERPERIOD_H 53 | -------------------------------------------------------------------------------- /scenario/src/gazebo/include/scenario/gazebo/components/JointPID.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT) 3 | * All rights reserved. 4 | * 5 | * This project is dual licensed under LGPL v2.1+ or Apache License. 6 | * 7 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 8 | * 9 | * This software may be modified and distributed under the terms of the 10 | * GNU Lesser General Public License v2.1 or any later version. 11 | * 12 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 13 | * 14 | * Licensed under the Apache License, Version 2.0 (the "License"); 15 | * you may not use this file except in compliance with the License. 16 | * You may obtain a copy of the License at 17 | * 18 | * http://www.apache.org/licenses/LICENSE-2.0 19 | * 20 | * Unless required by applicable law or agreed to in writing, software 21 | * distributed under the License is distributed on an "AS IS" BASIS, 22 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 23 | * See the License for the specific language governing permissions and 24 | * limitations under the License. 25 | */ 26 | 27 | #ifndef IGNITION_GAZEBO_COMPONENTS_JOINTPID_H 28 | #define IGNITION_GAZEBO_COMPONENTS_JOINTPID_H 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | namespace ignition::gazebo { 36 | // Inline bracket to help doxygen filtering. 37 | inline namespace IGNITION_GAZEBO_VERSION_NAMESPACE { 38 | namespace components { 39 | /// \brief Joint PID controller. 40 | using JointPID = Component; 41 | IGN_GAZEBO_REGISTER_COMPONENT("ign_gazebo_components.JointPID", 42 | JointPID) 43 | } // namespace components 44 | } // namespace IGNITION_GAZEBO_VERSION_NAMESPACE 45 | } // namespace ignition::gazebo 46 | 47 | #endif // IGNITION_GAZEBO_COMPONENTS_JOINTPID_H 48 | -------------------------------------------------------------------------------- /scenario/src/gazebo/include/scenario/gazebo/components/JointPositionTarget.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT) 3 | * All rights reserved. 4 | * 5 | * This project is dual licensed under LGPL v2.1+ or Apache License. 6 | * 7 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 8 | * 9 | * This software may be modified and distributed under the terms of the 10 | * GNU Lesser General Public License v2.1 or any later version. 11 | * 12 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 13 | * 14 | * Licensed under the Apache License, Version 2.0 (the "License"); 15 | * you may not use this file except in compliance with the License. 16 | * You may obtain a copy of the License at 17 | * 18 | * http://www.apache.org/licenses/LICENSE-2.0 19 | * 20 | * Unless required by applicable law or agreed to in writing, software 21 | * distributed under the License is distributed on an "AS IS" BASIS, 22 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 23 | * See the License for the specific language governing permissions and 24 | * limitations under the License. 25 | */ 26 | 27 | #ifndef IGNITION_GAZEBO_COMPONENTS_JOINTPOSITIONTARGET_H 28 | #define IGNITION_GAZEBO_COMPONENTS_JOINTPOSITIONTARGET_H 29 | 30 | #include 31 | 32 | #include 33 | #include 34 | #include 35 | 36 | namespace ignition::gazebo { 37 | // Inline bracket to help doxygen filtering. 38 | inline namespace IGNITION_GAZEBO_VERSION_NAMESPACE { 39 | namespace components { 40 | /// \brief Joint position target in SI units (rad for revolute, 41 | /// m for prismatic) used by joint controllers. 42 | /// 43 | /// The component wraps a std::vector of size equal to the 44 | /// degrees of freedom of the joint. 45 | using JointPositionTarget = 46 | Component, class JointPositionTargetTag>; 47 | IGN_GAZEBO_REGISTER_COMPONENT( 48 | "ign_gazebo_components.JointPositionTarget", 49 | JointPositionTarget) 50 | } // namespace components 51 | } // namespace IGNITION_GAZEBO_VERSION_NAMESPACE 52 | } // namespace ignition::gazebo 53 | 54 | #endif // IGNITION_GAZEBO_COMPONENTS_JOINTPOSITIONTARGET_H 55 | -------------------------------------------------------------------------------- /scenario/src/gazebo/include/scenario/gazebo/components/JointVelocityTarget.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT) 3 | * All rights reserved. 4 | * 5 | * This project is dual licensed under LGPL v2.1+ or Apache License. 6 | * 7 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 8 | * 9 | * This software may be modified and distributed under the terms of the 10 | * GNU Lesser General Public License v2.1 or any later version. 11 | * 12 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 13 | * 14 | * Licensed under the Apache License, Version 2.0 (the "License"); 15 | * you may not use this file except in compliance with the License. 16 | * You may obtain a copy of the License at 17 | * 18 | * http://www.apache.org/licenses/LICENSE-2.0 19 | * 20 | * Unless required by applicable law or agreed to in writing, software 21 | * distributed under the License is distributed on an "AS IS" BASIS, 22 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 23 | * See the License for the specific language governing permissions and 24 | * limitations under the License. 25 | */ 26 | 27 | #ifndef IGNITION_GAZEBO_COMPONENTS_JOINTVELOCITYTARGET_H 28 | #define IGNITION_GAZEBO_COMPONENTS_JOINTVELOCITYTARGET_H 29 | 30 | #include 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | namespace ignition::gazebo { 38 | // Inline bracket to help doxygen filtering. 39 | inline namespace IGNITION_GAZEBO_VERSION_NAMESPACE { 40 | namespace components { 41 | /// \brief Joint velocity target in SI units (rad/s for 42 | /// revolute, m/s for prismatic) used by joint 43 | /// controllers. 44 | /// 45 | /// The component wraps a std::vector of size equal to the 46 | /// degrees of freedom of the joint. 47 | using JointVelocityTarget = 48 | Component, 49 | class JointVelocityTargetTag, 50 | serializers::VectorDoubleSerializer>; 51 | IGN_GAZEBO_REGISTER_COMPONENT( 52 | "ign_gazebo_components.JointVelocityTarget", 53 | JointVelocityTarget) 54 | } // namespace components 55 | } // namespace IGNITION_GAZEBO_VERSION_NAMESPACE 56 | } // namespace ignition::gazebo 57 | 58 | #endif // IGNITION_GAZEBO_COMPONENTS_JOINTVELOCITYTARGET_H 59 | -------------------------------------------------------------------------------- /scenario/src/gazebo/include/scenario/gazebo/components/SimulatedTime.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT) 3 | * All rights reserved. 4 | * 5 | * This project is dual licensed under LGPL v2.1+ or Apache License. 6 | * 7 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 8 | * 9 | * This software may be modified and distributed under the terms of the 10 | * GNU Lesser General Public License v2.1 or any later version. 11 | * 12 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 13 | * 14 | * Licensed under the Apache License, Version 2.0 (the "License"); 15 | * you may not use this file except in compliance with the License. 16 | * You may obtain a copy of the License at 17 | * 18 | * http://www.apache.org/licenses/LICENSE-2.0 19 | * 20 | * Unless required by applicable law or agreed to in writing, software 21 | * distributed under the License is distributed on an "AS IS" BASIS, 22 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 23 | * See the License for the specific language governing permissions and 24 | * limitations under the License. 25 | */ 26 | 27 | #ifndef IGNITION_GAZEBO_COMPONENTS_SIMULATEDTIME_H 28 | #define IGNITION_GAZEBO_COMPONENTS_SIMULATEDTIME_H 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | #include 35 | 36 | namespace ignition::gazebo { 37 | // Inline bracket to help doxygen filtering. 38 | inline namespace IGNITION_GAZEBO_VERSION_NAMESPACE { 39 | namespace components { 40 | /// \brief A component that holds the world's simulated time in 41 | /// seconds. 42 | using SimulatedTime = Component; 44 | IGN_GAZEBO_REGISTER_COMPONENT("ign_gazebo_components.SimulatedTime", 45 | SimulatedTime) 46 | } // namespace components 47 | } // namespace IGNITION_GAZEBO_VERSION_NAMESPACE 48 | } // namespace ignition::gazebo 49 | 50 | #endif // IGNITION_GAZEBO_COMPONENTS_SIMULATEDTIME_H 51 | -------------------------------------------------------------------------------- /scenario/src/gazebo/include/scenario/gazebo/components/Timestamp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT) 3 | * All rights reserved. 4 | * 5 | * This project is dual licensed under LGPL v2.1+ or Apache License. 6 | * 7 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 8 | * 9 | * This software may be modified and distributed under the terms of the 10 | * GNU Lesser General Public License v2.1 or any later version. 11 | * 12 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 13 | * 14 | * Licensed under the Apache License, Version 2.0 (the "License"); 15 | * you may not use this file except in compliance with the License. 16 | * You may obtain a copy of the License at 17 | * 18 | * http://www.apache.org/licenses/LICENSE-2.0 19 | * 20 | * Unless required by applicable law or agreed to in writing, software 21 | * distributed under the License is distributed on an "AS IS" BASIS, 22 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 23 | * See the License for the specific language governing permissions and 24 | * limitations under the License. 25 | */ 26 | 27 | #ifndef IGNITION_GAZEBO_COMPONENTS_TIMESTAMP_H 28 | #define IGNITION_GAZEBO_COMPONENTS_TIMESTAMP_H 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | #include 35 | 36 | namespace ignition::gazebo { 37 | // Inline bracket to help doxygen filtering. 38 | inline namespace IGNITION_GAZEBO_VERSION_NAMESPACE { 39 | namespace components { 40 | /// \brief A component that could store a timestamp. 41 | using Timestamp = Component; 43 | IGN_GAZEBO_REGISTER_COMPONENT("ign_gazebo_components.Timestamp", 44 | Timestamp) 45 | } // namespace components 46 | } // namespace IGNITION_GAZEBO_VERSION_NAMESPACE 47 | } // namespace ignition::gazebo 48 | 49 | #endif // IGNITION_GAZEBO_COMPONENTS_TIMESTAMP_H 50 | -------------------------------------------------------------------------------- /scenario/src/plugins/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT) 2 | # All rights reserved. 3 | # 4 | # This project is dual licensed under LGPL v2.1+ or Apache License. 5 | # 6 | # - - - - - - - - - - - - - - - - - - 7 | # 8 | # This software may be modified and distributed under the terms of the 9 | # GNU Lesser General Public License v2.1 or any later version. 10 | # 11 | # - - - - - - - - - - - - - - - - - - 12 | # 13 | # Licensed under the Apache License, Version 2.0 (the "License"); 14 | # you may not use this file except in compliance with the License. 15 | # You may obtain a copy of the License at 16 | # 17 | # http://www.apache.org/licenses/LICENSE-2.0 18 | # 19 | # Unless required by applicable law or agreed to in writing, software 20 | # distributed under the License is distributed on an "AS IS" BASIS, 21 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | # See the License for the specific language governing permissions and 23 | # limitations under the License. 24 | 25 | add_subdirectory(Physics) 26 | add_subdirectory(JointController) 27 | add_subdirectory(ControllerRunner) 28 | -------------------------------------------------------------------------------- /scenario/src/plugins/ControllerRunner/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT) 2 | # All rights reserved. 3 | # 4 | # This project is dual licensed under LGPL v2.1+ or Apache License. 5 | # 6 | # - - - - - - - - - - - - - - - - - - 7 | # 8 | # This software may be modified and distributed under the terms of the 9 | # GNU Lesser General Public License v2.1 or any later version. 10 | # 11 | # - - - - - - - - - - - - - - - - - - 12 | # 13 | # Licensed under the Apache License, Version 2.0 (the "License"); 14 | # you may not use this file except in compliance with the License. 15 | # You may obtain a copy of the License at 16 | # 17 | # http://www.apache.org/licenses/LICENSE-2.0 18 | # 19 | # Unless required by applicable law or agreed to in writing, software 20 | # distributed under the License is distributed on an "AS IS" BASIS, 21 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | # See the License for the specific language governing permissions and 23 | # limitations under the License. 24 | 25 | # ================== 26 | # ControllersFactory 27 | # ================== 28 | 29 | add_library(ControllersFactory STATIC 30 | ControllersFactory.h 31 | ControllersFactory.cpp) 32 | 33 | target_link_libraries(ControllersFactory 34 | PUBLIC 35 | ${sdformat.sdformat} 36 | ScenarioCore::ScenarioABC 37 | ScenarioControllers::ControllersABC 38 | PRIVATE 39 | ScenarioGazebo::ScenarioGazebo 40 | ScenarioControllers::ComputedTorqueFixedBase) 41 | 42 | target_include_directories(ControllersFactory PRIVATE 43 | $) 44 | 45 | # ================ 46 | # ControllerRunner 47 | # ================ 48 | 49 | add_library(ControllerRunner SHARED 50 | ControllerRunner.h 51 | ControllerRunner.cpp) 52 | 53 | target_link_libraries(ControllerRunner 54 | PUBLIC 55 | ${ignition-gazebo.core} 56 | PRIVATE 57 | ScenarioGazebo::ScenarioGazebo 58 | ScenarioGazebo::ExtraComponents 59 | ScenarioControllers::ControllersABC 60 | ControllersFactory) 61 | 62 | target_include_directories(ControllerRunner PRIVATE 63 | $) 64 | 65 | # =================== 66 | # Install the targets 67 | # =================== 68 | 69 | install( 70 | TARGETS ControllerRunner 71 | LIBRARY DESTINATION ${SCENARIO_INSTALL_LIBDIR}/scenario/plugins 72 | ARCHIVE DESTINATION ${SCENARIO_INSTALL_LIBDIR}/scenario/plugins 73 | RUNTIME DESTINATION ${SCENARIO_INSTALL_BINDIR}) 74 | -------------------------------------------------------------------------------- /scenario/src/plugins/ControllerRunner/ControllerRunner.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT) 3 | * All rights reserved. 4 | * 5 | * This project is dual licensed under LGPL v2.1+ or Apache License. 6 | * 7 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 8 | * 9 | * This software may be modified and distributed under the terms of the 10 | * GNU Lesser General Public License v2.1 or any later version. 11 | * 12 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 13 | * 14 | * Licensed under the Apache License, Version 2.0 (the "License"); 15 | * you may not use this file except in compliance with the License. 16 | * You may obtain a copy of the License at 17 | * 18 | * http://www.apache.org/licenses/LICENSE-2.0 19 | * 20 | * Unless required by applicable law or agreed to in writing, software 21 | * distributed under the License is distributed on an "AS IS" BASIS, 22 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 23 | * See the License for the specific language governing permissions and 24 | * limitations under the License. 25 | */ 26 | 27 | #ifndef SCENARIO_PLUGINS_GAZEBO_CONTROLLERRUNNER_H 28 | #define SCENARIO_PLUGINS_GAZEBO_CONTROLLERRUNNER_H 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | #include 37 | 38 | namespace scenario::plugins::gazebo { 39 | class ControllerRunner; 40 | } // namespace scenario::plugins::gazebo 41 | 42 | class scenario::plugins::gazebo::ControllerRunner final 43 | : public ignition::gazebo::System 44 | , public ignition::gazebo::ISystemConfigure 45 | , public ignition::gazebo::ISystemPreUpdate 46 | { 47 | public: 48 | ControllerRunner(); 49 | ~ControllerRunner() override; 50 | 51 | void Configure(const ignition::gazebo::Entity& entity, 52 | const std::shared_ptr& sdf, 53 | ignition::gazebo::EntityComponentManager& ecm, 54 | ignition::gazebo::EventManager& eventMgr) override; 55 | 56 | void PreUpdate(const ignition::gazebo::UpdateInfo& info, 57 | ignition::gazebo::EntityComponentManager& ecm) override; 58 | 59 | private: 60 | class Impl; 61 | std::unique_ptr pImpl = nullptr; 62 | }; 63 | 64 | #endif // SCENARIO_PLUGINS_GAZEBO_CONTROLLERRUNNER_H 65 | -------------------------------------------------------------------------------- /scenario/src/plugins/ControllerRunner/ControllersFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT) 3 | * All rights reserved. 4 | * 5 | * This project is dual licensed under LGPL v2.1+ or Apache License. 6 | * 7 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 8 | * 9 | * This software may be modified and distributed under the terms of the 10 | * GNU Lesser General Public License v2.1 or any later version. 11 | * 12 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 13 | * 14 | * Licensed under the Apache License, Version 2.0 (the "License"); 15 | * you may not use this file except in compliance with the License. 16 | * You may obtain a copy of the License at 17 | * 18 | * http://www.apache.org/licenses/LICENSE-2.0 19 | * 20 | * Unless required by applicable law or agreed to in writing, software 21 | * distributed under the License is distributed on an "AS IS" BASIS, 22 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 23 | * See the License for the specific language governing permissions and 24 | * limitations under the License. 25 | */ 26 | 27 | #ifndef SCENARIO_PLUGINS_CONTROLLERSFACTORY_H 28 | #define SCENARIO_PLUGINS_CONTROLLERSFACTORY_H 29 | 30 | #include "scenario/controllers/Controller.h" 31 | #include "scenario/core/Model.h" 32 | 33 | #include 34 | 35 | #include 36 | 37 | namespace scenario::plugins::gazebo { 38 | class ControllersFactory; 39 | } // namespace scenario::plugins::gazebo 40 | 41 | class scenario::plugins::gazebo::ControllersFactory 42 | { 43 | public: 44 | ControllersFactory(); 45 | ~ControllersFactory(); 46 | 47 | static ControllersFactory& Instance(); 48 | controllers::ControllerPtr get(const sdf::ElementPtr context, 49 | scenario::core::ModelPtr model); 50 | 51 | private: 52 | class Impl; 53 | std::unique_ptr pImpl; 54 | }; 55 | 56 | #endif // SCENARIO_PLUGINS_CONTROLLERSFACTORY_H 57 | -------------------------------------------------------------------------------- /scenario/src/plugins/JointController/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT) 2 | # All rights reserved. 3 | # 4 | # This project is dual licensed under LGPL v2.1+ or Apache License. 5 | # 6 | # - - - - - - - - - - - - - - - - - - 7 | # 8 | # This software may be modified and distributed under the terms of the 9 | # GNU Lesser General Public License v2.1 or any later version. 10 | # 11 | # - - - - - - - - - - - - - - - - - - 12 | # 13 | # Licensed under the Apache License, Version 2.0 (the "License"); 14 | # you may not use this file except in compliance with the License. 15 | # You may obtain a copy of the License at 16 | # 17 | # http://www.apache.org/licenses/LICENSE-2.0 18 | # 19 | # Unless required by applicable law or agreed to in writing, software 20 | # distributed under the License is distributed on an "AS IS" BASIS, 21 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | # See the License for the specific language governing permissions and 23 | # limitations under the License. 24 | 25 | # =============== 26 | # JointController 27 | # =============== 28 | 29 | add_library(JointController SHARED 30 | JointController.h 31 | JointController.cpp) 32 | 33 | target_link_libraries(JointController 34 | PUBLIC 35 | ${ignition-gazebo.core} 36 | PRIVATE 37 | ScenarioGazebo::ScenarioGazebo 38 | ScenarioGazebo::ExtraComponents) 39 | 40 | target_include_directories(JointController PRIVATE 41 | $) 42 | 43 | # =================== 44 | # Install the targets 45 | # =================== 46 | 47 | install( 48 | TARGETS JointController 49 | LIBRARY DESTINATION ${SCENARIO_INSTALL_LIBDIR}/scenario/plugins 50 | ARCHIVE DESTINATION ${SCENARIO_INSTALL_LIBDIR}/scenario/plugins 51 | RUNTIME DESTINATION ${SCENARIO_INSTALL_BINDIR}/scenario/plugins) 52 | -------------------------------------------------------------------------------- /scenario/src/plugins/JointController/JointController.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT) 3 | * All rights reserved. 4 | * 5 | * This project is dual licensed under LGPL v2.1+ or Apache License. 6 | * 7 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 8 | * 9 | * This software may be modified and distributed under the terms of the 10 | * GNU Lesser General Public License v2.1 or any later version. 11 | * 12 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 13 | * 14 | * Licensed under the Apache License, Version 2.0 (the "License"); 15 | * you may not use this file except in compliance with the License. 16 | * You may obtain a copy of the License at 17 | * 18 | * http://www.apache.org/licenses/LICENSE-2.0 19 | * 20 | * Unless required by applicable law or agreed to in writing, software 21 | * distributed under the License is distributed on an "AS IS" BASIS, 22 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 23 | * See the License for the specific language governing permissions and 24 | * limitations under the License. 25 | */ 26 | 27 | #ifndef SCENARIO_PLUGINS_GAZEBO_JOINTCONTROLLER_H 28 | #define SCENARIO_PLUGINS_GAZEBO_JOINTCONTROLLER_H 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | #include 37 | 38 | namespace scenario::plugins::gazebo { 39 | class JointController; 40 | } // namespace scenario::plugins::gazebo 41 | 42 | class scenario::plugins::gazebo::JointController final 43 | : public ignition::gazebo::System 44 | , public ignition::gazebo::ISystemConfigure 45 | , public ignition::gazebo::ISystemPreUpdate 46 | { 47 | private: 48 | class Impl; 49 | std::unique_ptr pImpl = nullptr; 50 | 51 | public: 52 | JointController(); 53 | ~JointController() override; 54 | 55 | void Configure(const ignition::gazebo::Entity& entity, 56 | const std::shared_ptr& sdf, 57 | ignition::gazebo::EntityComponentManager& ecm, 58 | ignition::gazebo::EventManager& eventMgr) override; 59 | 60 | void PreUpdate(const ignition::gazebo::UpdateInfo& info, 61 | ignition::gazebo::EntityComponentManager& ecm) override; 62 | }; 63 | 64 | #endif // SCENARIO_PLUGINS_GAZEBO_JOINTCONTROLLER_H 65 | -------------------------------------------------------------------------------- /scenario/src/plugins/Physics/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT) 2 | # All rights reserved. 3 | # 4 | # This project is dual licensed under LGPL v2.1+ or Apache License. 5 | # 6 | # - - - - - - - - - - - - - - - - - - 7 | # 8 | # This software may be modified and distributed under the terms of the 9 | # GNU Lesser General Public License v2.1 or any later version. 10 | # 11 | # - - - - - - - - - - - - - - - - - - 12 | # 13 | # Licensed under the Apache License, Version 2.0 (the "License"); 14 | # you may not use this file except in compliance with the License. 15 | # You may obtain a copy of the License at 16 | # 17 | # http://www.apache.org/licenses/LICENSE-2.0 18 | # 19 | # Unless required by applicable law or agreed to in writing, software 20 | # distributed under the License is distributed on an "AS IS" BASIS, 21 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | # See the License for the specific language governing permissions and 23 | # limitations under the License. 24 | 25 | # ============= 26 | # PhysicsSystem 27 | # ============= 28 | 29 | add_library(PhysicsSystem SHARED 30 | Physics.hh 31 | EntityFeatureMap.hh 32 | CanonicalLinkModelTracker.hh 33 | Physics.cc) 34 | 35 | target_link_libraries(PhysicsSystem 36 | PUBLIC 37 | ${ignition-gazebo.core} 38 | ${ignition-physics.ignition-physics} 39 | PRIVATE 40 | ScenarioGazebo::ScenarioGazebo 41 | ScenarioGazebo::ExtraComponents) 42 | 43 | target_include_directories(PhysicsSystem PRIVATE 44 | $) 45 | 46 | if(ENABLE_PROFILER) 47 | target_compile_definitions(PhysicsSystem PRIVATE "IGN_PROFILER_ENABLE=1") 48 | endif() 49 | 50 | # =================== 51 | # Install the targets 52 | # =================== 53 | 54 | install( 55 | TARGETS PhysicsSystem 56 | LIBRARY DESTINATION ${SCENARIO_INSTALL_LIBDIR}/scenario/plugins 57 | ARCHIVE DESTINATION ${SCENARIO_INSTALL_LIBDIR}/scenario/plugins 58 | RUNTIME DESTINATION ${SCENARIO_INSTALL_BINDIR}/scenario/plugins) 59 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2021 Istituto Italiano di Tecnologia (IIT). All rights reserved. 2 | # This software may be modified and distributed under the terms of the 3 | # GNU Lesser General Public License v2.1 or any later version. 4 | 5 | [metadata] 6 | name = gym_ignition 7 | description = A toolkit for developing OpenAI Gym environments simulated with Ignition Gazebo. 8 | long_description = file: README.md 9 | long_description_content_type = text/markdown 10 | author = Diego Ferigo 11 | author_email = dgferigo@gmail.com 12 | license = LGPL 13 | license_file = LICENSE 14 | platforms = any 15 | url = https://github.com/robotology/gym-ignition 16 | 17 | project_urls = 18 | Changelog = https://github.com/robotology/gym-ignition/releases 19 | Tracker = https://github.com/robotology/gym-ignition/issues 20 | Documentation = https://robotology.github.io/gym-ignition 21 | Source = https://github.com/robotology/gym-ignition 22 | 23 | keywords = 24 | openai 25 | gym 26 | reinforcement learning 27 | rl 28 | environment 29 | gazebo 30 | robotics 31 | ignition 32 | humanoid 33 | panda 34 | icub 35 | urdf 36 | sdf 37 | 38 | classifiers = 39 | Development Status :: 5 - Production/Stable 40 | Operating System :: POSIX :: Linux 41 | Topic :: Games/Entertainment :: Simulation 42 | Topic :: Scientific/Engineering :: Artificial Intelligence 43 | Topic :: Scientific/Engineering :: Physics 44 | Topic :: Software Development 45 | Framework :: Robot Framework 46 | Intended Audience :: Developers 47 | Intended Audience :: Science/Research 48 | Programming Language :: Python :: 3.8 49 | Programming Language :: Python :: 3.9 50 | Programming Language :: Python :: 3 :: Only 51 | Programming Language :: Python :: Implementation :: CPython 52 | License :: OSI Approved :: GNU Lesser General Public License v2 or later (LGPLv2+) 53 | 54 | [options] 55 | zip_safe = False 56 | packages = find: 57 | package_dir = 58 | =python 59 | python_requires = >=3.8 60 | install_requires = 61 | scenario >= 1.3.2.dev 62 | gym >= 0.13.1 63 | numpy 64 | scipy 65 | gym_ignition_models 66 | lxml 67 | idyntree 68 | 69 | [options.packages.find] 70 | where = python 71 | 72 | [options.extras_require] 73 | testing = 74 | pytest 75 | pytest-xvfb 76 | pytest-icdiff 77 | website = 78 | sphinx 79 | sphinx-book-theme 80 | sphinx-autodoc-typehints 81 | sphinx_fontawesome 82 | sphinx-multiversion 83 | sphinx-tabs 84 | breathe 85 | all = 86 | %(testing)s 87 | %(website)s 88 | 89 | [tool:pytest] 90 | addopts = -rsxX -v --strict-markers 91 | testpaths = tests 92 | markers = 93 | scenario: Select the tests in the 'tests/test_scenario/' folder. 94 | gym_ignition: Select the tests in the 'tests/test_gym_ignition/' folder. 95 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2019 Istituto Italiano di Tecnologia (IIT). All rights reserved. 2 | # This software may be modified and distributed under the terms of the 3 | # GNU Lesser General Public License v2.1 or any later version. 4 | 5 | import setuptools 6 | 7 | setuptools.setup() 8 | -------------------------------------------------------------------------------- /tests/.python/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robotology-legacy/gym-ignition/4bc8e0465eed68911434485ba0b9c0a6740d516e/tests/.python/__init__.py -------------------------------------------------------------------------------- /tests/.python/test_contacts.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2019 Istituto Italiano di Tecnologia (IIT). All rights reserved. 2 | # This software may be modified and distributed under the terms of the 3 | # GNU Lesser General Public License v2.1 or any later version. 4 | 5 | import tempfile 6 | 7 | import numpy as np 8 | 9 | from . import utils 10 | 11 | 12 | def test_contacts(): 13 | # Get the simulator 14 | gazebo = utils.Gazebo(physics_rate=1000, iterations=1, rtf=100) 15 | 16 | # Create the first cube and insert it in the simulation 17 | cube1 = utils.CubeGazeboRobot( 18 | gazebo=gazebo.simulator, initial_position=np.array([0, 0, 1.0]) 19 | ) 20 | 21 | # Create the second cube and insert it in the simulation 22 | cube2 = utils.CubeGazeboRobot( 23 | gazebo=gazebo.simulator, initial_position=np.array([0, 0, 2.5]) 24 | ) 25 | 26 | # Execute the first simulation step 27 | gazebo.step() 28 | 29 | # The cubes should be falling without contacts 30 | assert len(cube1.links_in_contact()) == 0 31 | assert len(cube2.links_in_contact()) == 0 32 | 33 | # Perform 500 steps. 34 | for _ in range(500): 35 | gazebo.step() 36 | 37 | # Cube1 should be touching ground 38 | assert len(cube1.links_in_contact()) == 1 39 | assert cube1.links_in_contact()[0] == "cube" 40 | contact_data1 = cube1.contact_data("cube") 41 | assert len(contact_data1) > 0 42 | assert contact_data1[0].bodyA == cube1.name() + "::cube_collision" 43 | assert contact_data1[0].bodyB == "ground_plane::collision" 44 | 45 | # Cube 2 should be still floating 46 | assert len(cube2.links_in_contact()) == 0 47 | assert len(cube2.contact_data("cube")) == 0 48 | 49 | # Perform 500 steps. 50 | for _ in range(500): 51 | gazebo.step() 52 | 53 | # Now cube2 should be in contact with cube1 54 | assert len(cube2.links_in_contact()) == 1 55 | assert cube2.links_in_contact()[0] == "cube" 56 | contact_data2 = cube2.contact_data("cube") 57 | assert len(contact_data2) > 0 58 | assert contact_data2[0].bodyA == cube2.name() + "::cube_collision" 59 | assert contact_data2[0].bodyB == cube1.name() + "::cube_collision" 60 | 61 | # And cube1 should be in contact with cube2 and ground_plane 62 | assert len(cube1.links_in_contact()) == 1 63 | assert cube1.links_in_contact()[0] == "cube" 64 | contact_data1 = cube1.contact_data("cube") 65 | assert len(contact_data1) == 2 66 | 67 | for contact in contact_data1: 68 | assert contact.bodyA == cube1.name() + "::cube_collision" 69 | assert ( 70 | contact.bodyB == cube2.name() + "::cube_collision" 71 | or contact.bodyB == "ground_plane::collision" 72 | ) 73 | -------------------------------------------------------------------------------- /tests/.python/test_environments_gazebowrapper.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2019 Istituto Italiano di Tecnologia (IIT). All rights reserved. 2 | # This software may be modified and distributed under the terms of the 3 | # GNU Lesser General Public License v2.1 or any later version. 4 | 5 | import gym 6 | import pytest 7 | from gym_ignition.utils import logger 8 | 9 | # Set verbosity 10 | logger.set_level(gym.logger.DEBUG) 11 | 12 | 13 | def template_run_environment(env_name): 14 | logger.info(f"Testing environment '{env_name}'") 15 | env = gym.make(env_name) 16 | assert env, f"Failed to create '{env_name}' environment" 17 | 18 | observation = env.observation_space.sample() 19 | assert observation.size > 0, "The sampled observation is empty" 20 | 21 | observation = env.reset() 22 | assert observation.size > 0, "The observation is empty" 23 | 24 | for _ in range(10): 25 | action = env.action_space.sample() 26 | state, reward, done, _ = env.step(action) 27 | assert state.size > 0, "The environment didn't return a valid state" 28 | 29 | env.close() 30 | 31 | 32 | @pytest.mark.parametrize( 33 | "env_name", 34 | [ 35 | "CartPoleDiscrete-Gazebo-v0", 36 | "CartPoleContinuous-Gazebo-v0", 37 | "Pendulum-Gazebo-v0", 38 | ], 39 | ) 40 | def test_environment(env_name: str): 41 | template_run_environment(env_name) 42 | -------------------------------------------------------------------------------- /tests/.python/test_externalforce.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT). All rights reserved. 2 | # This software may be modified and distributed under the terms of the 3 | # GNU Lesser General Public License v2.1 or any later version. 4 | 5 | import tempfile 6 | 7 | import numpy as np 8 | 9 | from . import utils 10 | 11 | 12 | def test_external_force(): 13 | # Get the simulator 14 | gazebo = utils.Gazebo(physics_rate=1000, iterations=1, rtf=100) 15 | 16 | # Create the first cube and insert it in the simulation 17 | cube = utils.CubeGazeboRobot( 18 | gazebo=gazebo.simulator, initial_position=np.array([0, 0, 1.0]) 19 | ) 20 | 21 | # Execute the first simulation step 22 | gazebo.step() 23 | 24 | # Get the position of the cube 25 | position, _ = cube.base_pose() 26 | assert position[0] == 0.0 27 | assert position[1] == 0.0 28 | 29 | # Apply a force for 1 second 30 | num_steps = 100 31 | f_x = 50.0 32 | f_y = -f_x / 10 33 | 34 | for _ in range(num_steps): 35 | ok_w = cube.apply_external_force( 36 | "cube", np.array([f_x, f_y, 0]), np.array([0.0, 0, 0]) 37 | ) 38 | assert ok_w 39 | 40 | # Step the simulation 41 | gazebo.step() 42 | 43 | # Get the position of the cube 44 | position, _ = cube.base_pose() 45 | print(position) 46 | assert position[0] > 0.0 47 | assert position[1] < 0.0 48 | assert np.allclose(-position[0], 10 * position[1]) 49 | -------------------------------------------------------------------------------- /tests/.python/test_joint_force.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT). All rights reserved. 2 | # This software may be modified and distributed under the terms of the 3 | # GNU Lesser General Public License v2.1 or any later version. 4 | 5 | from gym_ignition.base.robot.robot_joints import JointControlMode 6 | 7 | from . import utils 8 | 9 | 10 | def test_joint_force(): 11 | # Get the simulator 12 | gazebo = utils.Gazebo(physics_rate=1000, iterations=1) 13 | 14 | # Insert the robot 15 | pendulum = utils.get_pendulum(simulator=gazebo) 16 | 17 | # Configure the robot 18 | ok_mode = pendulum.set_joint_control_mode("pivot", JointControlMode.TORQUE) 19 | assert ok_mode 20 | 21 | # Step the simulator 22 | gazebo.step() 23 | 24 | # No references set 25 | assert pendulum.joint_force("pivot") == 0.0 26 | 27 | # Step the simulator 28 | gazebo.step() 29 | 30 | # Set a reference. No force reference yet applied. 31 | torque = 42.42 32 | pendulum.set_joint_force("pivot", torque) 33 | assert pendulum.joint_force("pivot") == 0.0 34 | 35 | # Step the simulator. Now the force reference should have been actuated and after 36 | # the physics step it should be returned by the method. 37 | gazebo.step() 38 | assert pendulum.joint_force("pivot") == torque 39 | 40 | # Step again the simulator. No force reference has been specified and the method 41 | # should return zero. 42 | gazebo.step() 43 | assert pendulum.joint_force("pivot") == 0.0 44 | 45 | # Close the simulator 46 | gazebo.close() 47 | 48 | 49 | def test_joint_force_multiple_iterations(): 50 | # Get the simulator 51 | gazebo = utils.Gazebo(physics_rate=1000, iterations=2) 52 | 53 | # Insert the robot 54 | pendulum = utils.get_pendulum(simulator=gazebo) 55 | pendulum.set_joint_control_mode("pivot", JointControlMode.TORQUE) 56 | 57 | # Step the simulator 58 | gazebo.step() 59 | 60 | # No references set 61 | assert pendulum.joint_force("pivot") == 0.0 62 | 63 | # Step the simulator 64 | gazebo.step() 65 | 66 | # Set a reference. No force reference yet applied. 67 | torque = 42.42 68 | pendulum.set_joint_force("pivot", torque) 69 | assert pendulum.joint_force("pivot") == 0.0 70 | 71 | # Step the simulator. 72 | # Note that since gazebo was configured with multiple iterations, 73 | # the force is applied only in the first one and we still read zero! 74 | gazebo.step() 75 | assert pendulum.joint_force("pivot") == 0.0 76 | 77 | # Step again the simulator 78 | gazebo.step() 79 | assert pendulum.joint_force("pivot") == 0.0 80 | 81 | # Close the simulator 82 | gazebo.close() 83 | -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2019 Istituto Italiano di Tecnologia (IIT). All rights reserved. 2 | # This software may be modified and distributed under the terms of the 3 | # GNU Lesser General Public License v2.1 or any later version. 4 | 5 | from . import common 6 | -------------------------------------------------------------------------------- /tests/assets/worlds/fuel_support.sdf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | https://fuel.ignitionrobotics.org/1.0/OpenRobotics/models/Ground Plane 6 | 7 | 8 | https://fuel.ignitionrobotics.org/1.0/OpenRobotics/models/Sun 9 | 10 | 11 | 0 0 0.5 0 0 0 12 | 13 | 14 | 15 | 16 | 1 1 1 17 | 18 | 19 | 20 | 21 | 22 | 23 | 1 1 1 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /tests/common/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT). All rights reserved. 2 | # This software may be modified and distributed under the terms of the 3 | # GNU Lesser General Public License v2.1 or any later version. 4 | 5 | from . import utils 6 | -------------------------------------------------------------------------------- /tests/test_gym_ignition/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2019 Istituto Italiano di Tecnologia (IIT). All rights reserved. 2 | # This software may be modified and distributed under the terms of the 3 | # GNU Lesser General Public License v2.1 or any later version. 4 | -------------------------------------------------------------------------------- /tests/test_gym_ignition/test_normalization.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT). All rights reserved. 2 | # This software may be modified and distributed under the terms of the 3 | # GNU Lesser General Public License v2.1 or any later version. 4 | 5 | import pytest 6 | 7 | pytestmark = pytest.mark.gym_ignition 8 | 9 | from gym_ignition.utils.math import denormalize, normalize 10 | 11 | test_matrix = [ 12 | # Float, None 13 | (1, None, None, 1), 14 | (1, 0, None, 1), 15 | (1, None, 0, 1), 16 | # Float / Float 17 | (0, -1, 1, 0), 18 | (-1, -1, 1, -1), 19 | (1, -1, 1, 1), 20 | # List / Float 21 | ([-1, 0, 1, 2], -2, 2, [-0.5, 0, 0.5, 1]), 22 | ([-1, 0, 1, 2], -2.0, 2.0, [-0.5, 0, 0.5, 1]), 23 | ([-1.0, 0, 1, 2], -2, 2, [-0.5, 0, 0.5, 1]), 24 | ([-1.0, 0, 1, 2], 1, 1, [-1.0, 0, 1, 2]), 25 | # List / List 26 | ([-1, 0, 2.0], [-1, -2, 1], [-1, 4, 3], [-1, -0.3333333, 0]), 27 | ] 28 | 29 | 30 | @pytest.mark.parametrize("input,low, high, output", test_matrix) 31 | def test_normalization(input, low, high, output): 32 | 33 | normalized_input = normalize(input=input, low=low, high=high) 34 | 35 | assert output == pytest.approx(normalized_input) 36 | assert input == pytest.approx( 37 | denormalize(input=normalized_input, low=low, high=high) 38 | ) 39 | -------------------------------------------------------------------------------- /tests/test_gym_ignition/test_reproducibility.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT). All rights reserved. 2 | # This software may be modified and distributed under the terms of the 3 | # GNU Lesser General Public License v2.1 or any later version. 4 | 5 | import pytest 6 | 7 | pytestmark = pytest.mark.gym_ignition 8 | 9 | import gym 10 | from gym_ignition.utils.logger import set_level 11 | from gym_ignition_environments import randomizers 12 | 13 | # Set the verbosity 14 | set_level(gym.logger.DEBUG) 15 | 16 | 17 | def make_env(**kwargs) -> gym.Env: 18 | 19 | import gym 20 | import gym_ignition_environments 21 | 22 | return gym.make("CartPoleDiscreteBalancing-Gazebo-v0", **kwargs) 23 | 24 | 25 | @pytest.mark.parametrize("num_physics_rollouts", [0, 2]) 26 | def test_reproducibility(num_physics_rollouts: int): 27 | 28 | env1 = randomizers.cartpole.CartpoleEnvRandomizer( 29 | env=make_env, num_physics_rollouts=num_physics_rollouts 30 | ) 31 | 32 | env2 = randomizers.cartpole.CartpoleEnvRandomizer( 33 | env=make_env, num_physics_rollouts=num_physics_rollouts 34 | ) 35 | 36 | assert env1 != env2 37 | 38 | # Seed the environment 39 | env1.seed(42) 40 | env2.seed(42) 41 | 42 | for _ in range(5): 43 | 44 | # Reset the environments 45 | observation1 = env1.reset() 46 | observation2 = env2.reset() 47 | assert observation1 == pytest.approx(observation2) 48 | 49 | # Initialize returned values 50 | done = False 51 | 52 | while not done: 53 | 54 | # Sample a random action 55 | action1 = env1.action_space.sample() 56 | action2 = env2.action_space.sample() 57 | assert action1 == pytest.approx(action2) 58 | 59 | # Step the environment 60 | observation1, reward1, done1, info1 = env1.step(action1) 61 | observation2, reward2, done2, info2 = env2.step(action2) 62 | 63 | assert done1 == pytest.approx(done2) 64 | assert info1 == pytest.approx(info2) 65 | assert reward1 == pytest.approx(reward2) 66 | assert observation1 == pytest.approx(observation2) 67 | 68 | done = done1 69 | 70 | env1.close() 71 | env2.close() 72 | -------------------------------------------------------------------------------- /tests/test_scenario/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT). All rights reserved. 2 | # This software may be modified and distributed under the terms of the 3 | # GNU Lesser General Public License v2.1 or any later version. 4 | -------------------------------------------------------------------------------- /tests/test_scenario/test_external_wrench.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2021 Istituto Italiano di Tecnologia (IIT). All rights reserved. 2 | # This software may be modified and distributed under the terms of the 3 | # GNU Lesser General Public License v2.1 or any later version. 4 | 5 | import pytest 6 | 7 | pytestmark = pytest.mark.scenario 8 | 9 | from typing import Tuple 10 | 11 | import numpy as np 12 | 13 | from scenario import core 14 | from scenario import gazebo as scenario 15 | 16 | from ..common import utils 17 | from ..common.utils import default_world_fixture as default_world 18 | 19 | # Set the verbosity 20 | scenario.set_verbosity(scenario.Verbosity_debug) 21 | 22 | 23 | @pytest.mark.parametrize("default_world", [(1.0 / 1_000, 1.0, 1)], indirect=True) 24 | def test_fixed_base(default_world: Tuple[scenario.GazeboSimulator, scenario.World]): 25 | 26 | # Get the simulator and the world 27 | gazebo, world = default_world 28 | 29 | # Insert a sphere 30 | pose = core.Pose([0, 0.0, 1.0], [1.0, 0, 0, 0]) 31 | assert world.insert_model_from_string( 32 | utils.SphereURDF(mass=10.0).urdf(), pose, "sphere" 33 | ) 34 | assert "sphere" in world.model_names() 35 | 36 | # Get the sphere 37 | sphere = world.get_model("sphere") 38 | link = sphere.get_link("sphere").to_gazebo() 39 | 40 | # Get the initial z position 41 | initial_height = link.position()[2] 42 | 43 | # Apply a vertical force that counterbalances gravity 44 | assert link.apply_world_force( 45 | force=-np.array(world.gravity()) * sphere.total_mass(), duration=0.5 46 | ) 47 | 48 | # Run the simulation for a while 49 | for _ in range(500): 50 | gazebo.run() 51 | assert link.position()[2] == pytest.approx(initial_height) 52 | 53 | # Run the simulation for a while 54 | for _ in range(500): 55 | gazebo.run() 56 | assert link.position()[2] < initial_height 57 | -------------------------------------------------------------------------------- /tests/test_scenario/test_ignition_fuel.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT). All rights reserved. 2 | # This software may be modified and distributed under the terms of the 3 | # GNU Lesser General Public License v2.1 or any later version. 4 | 5 | import pytest 6 | 7 | pytestmark = pytest.mark.scenario 8 | 9 | from pathlib import Path 10 | 11 | from scenario import core 12 | from scenario import gazebo as scenario 13 | 14 | from ..common import utils 15 | from ..common.utils import gazebo_fixture as gazebo 16 | 17 | # Set the verbosity 18 | scenario.set_verbosity(scenario.Verbosity_debug) 19 | 20 | 21 | # See https://github.com/robotology/gym-ignition/pull/339#issuecomment-828300490 22 | @pytest.mark.xfail(strict=False) 23 | @pytest.mark.parametrize( 24 | "gazebo", [(0.001, 1.0, 1)], indirect=True, ids=utils.id_gazebo_fn 25 | ) 26 | def test_download_model_from_fuel(gazebo: scenario.GazeboSimulator): 27 | 28 | assert gazebo.initialize() 29 | 30 | # Get the default world 31 | world = gazebo.get_world() 32 | 33 | # Download a model from Fuel (testing a name with spaces) 34 | model_name = "Electrical Box" 35 | model_sdf = scenario.get_model_file_from_fuel( 36 | f"https://fuel.ignitionrobotics.org/openrobotics/models/{model_name}", False 37 | ) 38 | assert model_sdf 39 | 40 | assert world.insert_model(model_sdf, core.Pose_identity()) 41 | assert model_name in world.model_names() 42 | 43 | # Insert another model changing its name 44 | other_model_name = "my_box" 45 | other_model_pose = core.Pose([3.0, 0.0, 0.0], [1.0, 0, 0, 0]) 46 | assert world.insert_model(model_sdf, other_model_pose, other_model_name) 47 | assert other_model_name in world.model_names() 48 | 49 | assert gazebo.run() 50 | 51 | 52 | @pytest.mark.parametrize( 53 | "gazebo", [(0.001, 1.0, 1)], indirect=True, ids=utils.id_gazebo_fn 54 | ) 55 | def test_fuel_world(gazebo: scenario.GazeboSimulator): 56 | # (setup) load a world that includes a fuel model 57 | worlds_folder = Path(__file__) / ".." / ".." / "assets" / "worlds" 58 | world_file = worlds_folder / "fuel_support.sdf" 59 | assert gazebo.insert_world_from_sdf(str(world_file.resolve())) 60 | assert gazebo.initialize() 61 | assert gazebo.run(paused=True) 62 | 63 | # the actual test 64 | assert "ground_plane" in gazebo.get_world().model_names() 65 | --------------------------------------------------------------------------------