├── .gitattributes ├── .github ├── dependabot.yml └── workflows │ ├── bazel_download.yml │ ├── ci.yml │ ├── cmake_installed.yml │ ├── cmake_installed_apt.yml │ ├── pip.yml │ ├── poetry.yml │ └── stale.yml ├── Jenkinsfile ├── LICENSE ├── README.md ├── drake_bazel_download ├── .bazelrc ├── .bazelversion ├── .clang-format ├── .github │ ├── ci_build_test │ ├── ubuntu_setup │ └── workflows │ │ └── ci.yml ├── .gitignore ├── BUILD.bazel ├── CPPLINT.cfg ├── LICENSE ├── MODULE.bazel ├── README.md ├── apps │ ├── BUILD.bazel │ ├── exec.sh │ ├── find_resource_test.cc │ ├── find_resource_test.py │ ├── import_all_test.py │ ├── include_paths_test.cc │ └── simple_logging_example.py ├── drake.BUILD.bazel ├── eigen.BUILD.bazel ├── eigen.bzl └── setup │ ├── install_bazelisk │ └── install_prereqs ├── drake_bazel_external ├── .bazelignore ├── .bazelproject ├── .bazelrc ├── .bazelversion ├── .clang-format ├── .github │ ├── ci_build_test │ ├── setup │ └── ubuntu_setup ├── .gitignore ├── BUILD.bazel ├── CPPLINT.cfg ├── LICENSE ├── MODULE.bazel ├── README.md ├── apps │ ├── BUILD.bazel │ ├── exec.sh │ ├── find_resource_test.py │ ├── import_all_test.py │ ├── simple_adder-inl.h │ ├── simple_adder.cc │ ├── simple_adder.h │ ├── simple_adder_py.cc │ ├── simple_adder_py_test.py │ ├── simple_adder_test.cc │ ├── simple_continuous_time_system.cc │ └── simple_logging_example.py └── setup │ └── install_prereqs ├── drake_bazel_external_legacy ├── .bazelignore ├── .bazelproject ├── .bazelrc ├── .bazelversion ├── .clang-format ├── .github │ ├── ci_build_test │ ├── setup │ └── ubuntu_setup ├── .gitignore ├── BUILD.bazel ├── CPPLINT.cfg ├── LICENSE ├── README.md ├── WORKSPACE ├── apps │ ├── BUILD.bazel │ ├── exec.sh │ ├── find_resource_test.py │ ├── import_all_test.py │ ├── simple_adder-inl.h │ ├── simple_adder.cc │ ├── simple_adder.h │ ├── simple_adder_py.cc │ ├── simple_adder_py_test.py │ ├── simple_adder_test.cc │ ├── simple_continuous_time_system.cc │ └── simple_logging_example.py ├── environ.bzl └── setup │ └── install_prereqs ├── drake_cmake_external ├── .clang-format ├── .github │ ├── ci_build_test │ ├── setup │ └── ubuntu_setup ├── .gitignore ├── CMakeLists.txt ├── CPPLINT.cfg ├── LICENSE ├── README.md ├── drake_external_examples │ ├── CMakeLists.txt │ ├── import_all_test.py │ ├── simple_continuous_time_system.cc │ └── solver_disabled_test.py └── setup │ └── install_prereqs ├── drake_cmake_installed ├── .clang-format ├── .github │ ├── ci_build_test │ ├── ubuntu_setup │ └── workflows │ │ └── ci.yml ├── .gitignore ├── CMakeLists.txt ├── CPPLINT.cfg ├── LICENSE ├── README.md ├── setup │ └── install_prereqs ├── src │ ├── CMakeLists.txt │ ├── find_resource │ │ ├── CMakeLists.txt │ │ ├── README.md │ │ ├── find_resource_example.cc │ │ └── find_resource_example.py │ ├── import_all_test.py │ ├── particle │ │ ├── CMakeLists.txt │ │ ├── particle.cc │ │ ├── particle.h │ │ ├── particle.py │ │ ├── particle_test.cc │ │ └── particle_test.py │ ├── simple_bindings │ │ ├── CMakeLists.txt │ │ ├── simple_bindings.cc │ │ └── simple_bindings_test.py │ └── simple_continuous_time_system │ │ ├── CMakeLists.txt │ │ ├── README.md │ │ └── simple_continuous_time_system.cc └── third_party │ ├── CMakeLists.txt │ └── googletest │ ├── LICENSE │ ├── gtest-all.cc │ └── gtest │ └── gtest.h ├── drake_cmake_installed_apt ├── .clang-format ├── .github │ ├── ci_build_test │ ├── ubuntu_apt_setup │ └── workflows │ │ └── ci.yml ├── .gitignore ├── CMakeLists.txt ├── CPPLINT.cfg ├── LICENSE ├── README.md ├── src │ ├── CMakeLists.txt │ ├── particle.cc │ ├── particle.h │ ├── particle.py │ ├── particle_test.cc │ └── particle_test.py └── third_party │ ├── cmake │ └── 3.12 │ │ ├── Copyright.txt │ │ └── Modules │ │ ├── FindPython.cmake │ │ └── FindPython │ │ └── Support.cmake │ └── googletest │ └── 1.10 │ ├── LICENSE │ └── googletest │ ├── include │ └── gtest │ │ └── gtest.h │ └── src │ └── gtest-all.cc ├── drake_pip ├── .github │ ├── ci_build_test │ ├── ubuntu_setup │ └── workflows │ │ └── ci.yml ├── LICENSE ├── README.md ├── requirements.txt ├── setup │ ├── install_prereqs │ └── setup_env └── src │ ├── particle.py │ └── particle_test.py ├── drake_poetry ├── .github │ ├── ci_build_test │ ├── setup │ └── workflows │ │ └── ci.yml ├── LICENSE ├── README.md ├── pyproject.toml ├── setup │ └── install_prereqs └── src │ ├── particle.py │ └── particle_test.py └── private ├── README.md └── test └── file_sync_test.py /.gitattributes: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT-0 2 | 3 | WORKSPACE diff=bazel 4 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | --- 2 | version: 2 3 | updates: 4 | # This updates official GitHub Actions used in CI, e.g. actions/checkout, 5 | # actions/setup-python. 6 | - package-ecosystem: github-actions 7 | directory: / 8 | schedule: 9 | interval: weekly 10 | -------------------------------------------------------------------------------- /.github/workflows/bazel_download.yml: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT-0 2 | 3 | --- 4 | name: ci 5 | on: 6 | workflow_call: 7 | 8 | jobs: 9 | ubuntu_jammy_bazel_download: 10 | name: ubuntu 22.04 jammy 11 | runs-on: ubuntu-latest 12 | container: ubuntu:jammy 13 | steps: 14 | - name: checkout 15 | uses: actions/checkout@v4 16 | - name: setup 17 | working-directory: drake_bazel_download 18 | run: | 19 | args=() 20 | if [[ '${{ github.event.inputs.linux_jammy_package_tar }}' != '' ]]; then 21 | args+=(--package-url ${{ github.event.inputs.linux_jammy_package_tar }}) 22 | fi 23 | .github/ubuntu_setup "${args[@]}" 24 | shell: bash 25 | - name: install_bazelisk 26 | working-directory: drake_bazel_download 27 | run: setup/install_bazelisk 28 | shell: bash 29 | - name: bazel_download build and test 30 | working-directory: drake_bazel_download 31 | run: .github/ci_build_test 32 | shell: bash 33 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT-0 2 | 3 | --- 4 | name: ci 5 | on: 6 | push: 7 | branches: 8 | - main 9 | pull_request: 10 | branches: 11 | - main 12 | schedule: 13 | - cron: '0 12 * * *' 14 | workflow_dispatch: 15 | inputs: 16 | linux_jammy_package_tar: 17 | description: 'Drake linux-jammy-*-packaging .tar.gz artifact URL' 18 | required: false 19 | linux_jammy_package_deb: 20 | description: 'Drake linux-jammy-*-packaging .deb artifact URL' 21 | required: false 22 | mac_arm_sonoma_package_tar: 23 | description: 'Drake mac-arm-sonoma-*-packaging .tar.gz artifact URL' 24 | required: false 25 | linux_jammy_wheel: 26 | description: 'Drake linux-jammy-*-wheel-*-release Python 3.10 artifact URL' 27 | required: false 28 | mac_arm_sonoma_wheel: 29 | description: 'Drake mac-arm-sonoma-*-wheel-*-release Python 3.13 artifact URL' 30 | required: false 31 | concurrency: 32 | # Cancel previous CI runs when additional commits are added to a pull request. 33 | # This will not cancel CI runs associated with `schedule` or `push`. 34 | group: ${{ github.head_ref || github.run_id }} 35 | cancel-in-progress: true 36 | jobs: 37 | cmake_installed: 38 | uses: ./.github/workflows/cmake_installed.yml 39 | bazel_download: 40 | uses: ./.github/workflows/bazel_download.yml 41 | cmake_installed_apt: 42 | uses: ./.github/workflows/cmake_installed_apt.yml 43 | pip: 44 | uses: ./.github/workflows/pip.yml 45 | poetry: 46 | uses: ./.github/workflows/poetry.yml 47 | file_sync: 48 | name: file sync 49 | runs-on: ubuntu-latest 50 | steps: 51 | - name: checkout 52 | uses: actions/checkout@v4 53 | - name: setup 54 | uses: actions/setup-python@v5 55 | with: 56 | python-version: '3.13' 57 | - name: file_sync test 58 | run: | 59 | pip install ruamel.yaml 60 | python ./private/test/file_sync_test.py 61 | -------------------------------------------------------------------------------- /.github/workflows/cmake_installed.yml: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT-0 2 | 3 | --- 4 | name: ci 5 | on: 6 | workflow_call: 7 | 8 | jobs: 9 | macos_sonoma_arm_cmake_installed: 10 | name: macos sonoma 14 arm 11 | runs-on: macos-14 12 | steps: 13 | - name: checkout 14 | uses: actions/checkout@v4 15 | # See issue https://github.com/actions/setup-python/issues/577. There is 16 | # some kind of environment conflict between the symlinks found in the 17 | # GitHub Actions runner and `brew upgrade python` where `brew` detects and 18 | # refuses to overwrite symlinks. The cause for our runs is not clear, 19 | # we do not use that action, but if that issue is closed this section 20 | # can be removed. 21 | - name: sanitize GHA / brew python environment 22 | run: | 23 | # Remove the symlinks that cause issues. 24 | find /usr/local/bin -lname '*/Library/Frameworks/Python.framework/*' -delete 25 | sudo rm -rf /Library/Frameworks/Python.framework/ 26 | - name: setup 27 | working-directory: drake_cmake_installed 28 | run: | 29 | args=() 30 | if [[ '${{ github.event.inputs.mac_arm_sonoma_package_tar }}' != '' ]]; then 31 | args+=(--package-url ${{ github.event.inputs.mac_arm_sonoma_package_tar }}) 32 | fi 33 | setup/install_prereqs "${args[@]}" 34 | shell: zsh -efuo pipefail {0} 35 | - name: cmake_installed build and test 36 | working-directory: drake_cmake_installed 37 | run: .github/ci_build_test 38 | shell: zsh -efuo pipefail {0} 39 | ubuntu_jammy_cmake_installed: 40 | name: ubuntu 22.04 jammy 41 | runs-on: ubuntu-latest 42 | container: ubuntu:jammy 43 | steps: 44 | - name: checkout 45 | uses: actions/checkout@v4 46 | - name: setup 47 | working-directory: drake_cmake_installed 48 | run: | 49 | args=() 50 | if [[ '${{ github.event.inputs.linux_jammy_package_tar }}' != '' ]]; then 51 | args+=(--package-url ${{ github.event.inputs.linux_jammy_package_tar }}) 52 | fi 53 | .github/ubuntu_setup "${args[@]}" 54 | shell: bash 55 | - name: cmake_installed build and test 56 | working-directory: drake_cmake_installed 57 | run: .github/ci_build_test 58 | shell: bash 59 | -------------------------------------------------------------------------------- /.github/workflows/cmake_installed_apt.yml: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT-0 2 | 3 | --- 4 | name: ci 5 | on: 6 | workflow_call: 7 | 8 | jobs: 9 | ubuntu_jammy_cmake_installed_apt: 10 | name: ubuntu 22.04 jammy 11 | runs-on: ubuntu-latest 12 | container: ubuntu:jammy 13 | steps: 14 | - name: checkout 15 | uses: actions/checkout@v4 16 | - name: setup 17 | working-directory: drake_cmake_installed_apt 18 | run: | 19 | args=() 20 | if [[ '${{ github.event.inputs.linux_jammy_package_deb }}' != '' ]]; then 21 | args+=(--package-url ${{ github.event.inputs.linux_jammy_package_deb }}) 22 | fi 23 | .github/ubuntu_apt_setup "${args[@]}" 24 | shell: bash 25 | - name: cmake_installed_apt build and test 26 | working-directory: drake_cmake_installed_apt 27 | run: .github/ci_build_test 28 | shell: bash 29 | -------------------------------------------------------------------------------- /.github/workflows/pip.yml: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT-0 2 | 3 | --- 4 | name: ci 5 | on: 6 | workflow_call: 7 | 8 | jobs: 9 | macos_sonoma_arm_pip: 10 | name: macos sonoma 14 arm 11 | runs-on: macos-14 12 | env: 13 | PYTHON_VERSION: '3.13' 14 | steps: 15 | - name: checkout 16 | uses: actions/checkout@v4 17 | # See issue https://github.com/actions/setup-python/issues/577. There is 18 | # some kind of environment conflict between the symlinks found in the 19 | # GitHub Actions runner and `brew upgrade python` where `brew` detects and 20 | # refuses to overwrite symlinks. The cause for our runs is not clear, 21 | # we do not use that action, but if that issue is closed this section 22 | # can be removed. 23 | - name: sanitize GHA / brew python environment 24 | run: | 25 | # Remove the symlinks that cause issues. 26 | find /usr/local/bin -lname '*/Library/Frameworks/Python.framework/*' -delete 27 | sudo rm -rf /Library/Frameworks/Python.framework/ 28 | - name: python setup 29 | uses: actions/setup-python@v5 30 | with: 31 | python-version: ${{ env.PYTHON_VERSION }} 32 | - name: venv setup and install 33 | working-directory: drake_pip 34 | run: | 35 | args=(--python-version $PYTHON_VERSION) 36 | if [[ '${{ github.event.inputs.mac_arm_sonoma_wheel }}' != '' ]]; then 37 | args+=(--wheel-url ${{ github.event.inputs.mac_arm_sonoma_wheel }}) 38 | fi 39 | setup/setup_env "${args[@]}" 40 | shell: zsh -eufo pipefail {0} 41 | - name: pip build and test 42 | working-directory: drake_pip 43 | run: .github/ci_build_test 44 | shell: zsh -efuo pipefail {0} 45 | ubuntu_jammy_pip: 46 | name: ubuntu 22.04 jammy 47 | runs-on: ubuntu-latest 48 | container: ubuntu:jammy 49 | steps: 50 | - name: checkout 51 | uses: actions/checkout@v4 52 | - name: pip setup 53 | working-directory: drake_pip 54 | run: | 55 | args=() 56 | if [[ '${{ github.event.inputs.linux_jammy_wheel }}' != '' ]]; then 57 | args+=(--wheel-url ${{ github.event.inputs.linux_jammy_wheel }}) 58 | fi 59 | .github/ubuntu_setup "${args[@]}" 60 | shell: bash 61 | - name: pip build and test 62 | working-directory: drake_pip 63 | run: .github/ci_build_test 64 | shell: bash 65 | -------------------------------------------------------------------------------- /.github/workflows/poetry.yml: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT-0 2 | 3 | --- 4 | name: ci 5 | on: 6 | workflow_call: 7 | 8 | jobs: 9 | macos_sonoma_arm_poetry: 10 | name: macos sonoma 14 arm 11 | runs-on: macos-14 12 | env: 13 | PYTHON_VERSION: '3.13' 14 | steps: 15 | - name: checkout 16 | uses: actions/checkout@v4 17 | # See issue https://github.com/actions/setup-python/issues/577. There is 18 | # some kind of environment conflict between the symlinks found in the 19 | # GitHub Actions runner and `brew upgrade python` where `brew` detects and 20 | # refuses to overwrite symlinks. The cause for our runs is not clear, 21 | # we do not use that action, but if that issue is closed this section 22 | # can be removed. 23 | - name: sanitize GHA / brew python environment 24 | run: | 25 | # Remove the symlinks that cause issues. 26 | find /usr/local/bin -lname '*/Library/Frameworks/Python.framework/*' -delete 27 | sudo rm -rf /Library/Frameworks/Python.framework/ 28 | - name: python setup 29 | uses: actions/setup-python@v5 30 | with: 31 | python-version: ${{ env.PYTHON_VERSION }} 32 | - name: poetry setup 33 | working-directory: drake_poetry 34 | run: | 35 | .github/setup 36 | args=(--python-version $PYTHON_VERSION) 37 | if [[ '${{ github.event.inputs.mac_arm_sonoma_wheel }}' != '' ]]; then 38 | args+=(--wheel-url ${{ github.event.inputs.mac_arm_sonoma_wheel }}) 39 | fi 40 | setup/install_prereqs "${args[@]}" 41 | shell: zsh -efuo pipefail {0} 42 | - name: poetry test 43 | working-directory: drake_poetry 44 | run: .github/ci_build_test 45 | shell: zsh -efuo pipefail {0} 46 | ubuntu_jammy_poetry: 47 | name: ubuntu 22.04 jammy 48 | runs-on: ubuntu-latest 49 | container: ubuntu:jammy 50 | steps: 51 | - name: checkout 52 | uses: actions/checkout@v4 53 | # setup and test must occur in one step 54 | # because when poetry is installed, the update to PATH 55 | # does not persist between steps on GHA 56 | - name: poetry setup and test 57 | working-directory: drake_poetry 58 | run: | 59 | .github/setup 60 | source $HOME/.profile 61 | args=() 62 | if [[ '${{ github.event.inputs.linux_jammy_wheel }}' != '' ]]; then 63 | args+=(--wheel-url ${{ github.event.inputs.linux_jammy_wheel }}) 64 | fi 65 | setup/install_prereqs "${args[@]}" 66 | .github/ci_build_test 67 | shell: bash 68 | -------------------------------------------------------------------------------- /.github/workflows/stale.yml: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT-0 2 | 3 | --- 4 | name: stale 5 | on: 6 | schedule: 7 | - cron: '30 1 * * *' 8 | jobs: 9 | stale: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - uses: actions/stale@v9 13 | with: 14 | days-before-issue-close: -1 15 | days-before-issue-stale: -1 16 | days-before-pr-close: 14 17 | days-before-pr-stale: 180 18 | repo-token: ${{ secrets.GITHUB_TOKEN }} 19 | stale-pr-label: 'result: stale' 20 | stale-pr-message: > 21 | Thank you for your contribution. This pull request has been open for 22 | 180 days without activity and so is considered stale. It will be 23 | automatically closed in 14 days unless you comment or remove the 24 | "result: stale" label. 25 | -------------------------------------------------------------------------------- /Jenkinsfile: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env groovy 2 | 3 | /* SPDX-License-Identifier: MIT-0 */ 4 | 5 | if (env.BRANCH_NAME == 'main') { 6 | def triggers = [] 7 | triggers << cron('H H(7-8) * * *') 8 | properties ([ 9 | pipelineTriggers(triggers) 10 | ]) 11 | } 12 | 13 | def examples = ['drake_bazel_external', 'drake_bazel_external_legacy', 'drake_cmake_external'] 14 | def jobs = [:] 15 | 16 | for (example in examples) { 17 | def name = example 18 | jobs[name] = { 19 | node('linux-jammy-unprovisioned') { 20 | timeout(600) { 21 | ansiColor('xterm') { 22 | try { 23 | dir('src') { 24 | stage('checkout') { 25 | checkout scm 26 | } 27 | } 28 | dir('src/' + name) { 29 | stage(name + ' setup') { 30 | sh '.github/setup' 31 | } 32 | stage(name + ' build and test') { 33 | sh '.github/ci_build_test' 34 | } 35 | } 36 | } catch (e) { 37 | if (env.BRANCH_NAME == 'main') { 38 | emailext ( 39 | subject: "Build failed in Jenkins: ${env.JOB_NAME} #${env.BUILD_NUMBER}", 40 | body: "See <${env.BUILD_URL}display/redirect?page=changes>", 41 | recipientProviders: [[$class: 'DevelopersRecipientProvider']], 42 | to: '$DEFAULT_RECIPIENTS', 43 | ) 44 | } 45 | throw e 46 | } 47 | } 48 | } 49 | } 50 | } 51 | } 52 | 53 | parallel jobs 54 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2017-2025 by the drake-external-examples developers. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so. 9 | 10 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 11 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 12 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 13 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 14 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 15 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 16 | SOFTWARE. 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Drake External Examples 2 | 3 | Examples of how to use [Drake](https://github.com/RobotLocomotion/drake) in your 4 | own project: 5 | 6 | * [`drake_bazel_external`](./drake_bazel_external) 7 | * [`drake_bazel_download`](./drake_bazel_download) 8 | * [`drake_cmake_external`](./drake_cmake_external) 9 | * [`drake_cmake_installed`](./drake_cmake_installed) 10 | * [`drake_cmake_installed_apt`](./drake_cmake_installed_apt) 11 | * [`drake_pip`](./drake_pip) 12 | * [`drake_poetry`](./drake_poetry) 13 | 14 | ## Continuous Integration 15 | 16 | Scripts are provided for Jenkins or GitHub Actions, depending on the example, 17 | in each example's respective subdirectory under `.github/`. 18 | See the `Jenkinsfile` and the top-level `.github/workflows/ci.yml` 19 | for a complete overview of each respective pipeline. 20 | The intended purpose of each is described below: 21 | 22 | * GitHub Actions: exemplifies how to put a project depending on a Drake installation on GitHub Actions 23 | * Jenkins: provides complete coverage of additional external example projects 24 | 25 | | **Subproject** | **GitHub Actions** | **Jenkins** | 26 | |:---:|:---:|:---:| 27 | | `drake_bazel_external` | - | o | 28 | | `drake_bazel_download` | o | - | 29 | | `drake_cmake_external` | - | o | 30 | | `drake_cmake_installed` | o | - | 31 | | `drake_cmake_installed_apt` | o | - | 32 | | `drake_pip` | o | - | 33 | | `drake_poetry` | o | - | 34 | || ![GitHub Actions](https://img.shields.io/github/actions/workflow/status/RobotLocomotion/drake-external-examples/ci.yml?branch=main) | [![Jenkins](https://img.shields.io/jenkins/build.svg?jobUrl=https://drake-jenkins.csail.mit.edu/job/RobotLocomotion/job/drake-external-examples/job/main)](https://drake-jenkins.csail.mit.edu/job/RobotLocomotion/job/drake-external-examples/) | 35 | 36 | 37 | Note, the GitHub Actions jobs only build and test `drake_bazel_download`, 38 | `drake_cmake_installed`, `drake_cmake_installed_apt`, `drake_pip`, and 39 | `drake_poetry`, since these are the exemplary cases for lightweight, 40 | open-source builds on public CI servers. 41 | -------------------------------------------------------------------------------- /drake_bazel_download/.bazelrc: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT-0 2 | 3 | # Default to an optimized build. 4 | build --compilation_mode=opt 5 | 6 | # Default build options. 7 | build --strip=never 8 | 9 | # Default test options. 10 | build --test_output=errors 11 | build --test_summary=terse 12 | 13 | # Use C++20. 14 | build --cxxopt=-std=c++20 15 | build --host_cxxopt=-std=c++20 16 | 17 | # https://github.com/bazelbuild/bazel/issues/1164 18 | build --action_env=CCACHE_DISABLE=1 19 | 20 | # For Ubuntu builds, this flag can cut build times in half. For macOS builds, 21 | # this flag might cause build errors. We suggest turning it on if and only if 22 | # your project doesn't use macOS. 23 | ## build --force_pic=yes 24 | 25 | # TODO(jwnimmer-tri) We should see if we can reuse more of Drake's 26 | # customizations somehow. 27 | 28 | # Try to import user-specific configuration local to workspace. 29 | try-import %workspace%/user.bazelrc 30 | -------------------------------------------------------------------------------- /drake_bazel_download/.bazelversion: -------------------------------------------------------------------------------- 1 | 8.2.1 2 | -------------------------------------------------------------------------------- /drake_bazel_download/.clang-format: -------------------------------------------------------------------------------- 1 | # -*- mode: yaml -*- 2 | # vi: set ft=yaml : 3 | # SPDX-License-Identifier: MIT-0 4 | 5 | --- 6 | BasedOnStyle: Google 7 | --- 8 | Language: Cpp 9 | DerivePointerAlignment: false 10 | PointerAlignment: Left 11 | 12 | IncludeCategories: 13 | - Regex: '^[<"](aio|arpa/inet|assert|complex|cpio|ctype|curses|dirent|dlfcn|errno|fcntl|fenv|float|fmtmsg|fnmatch|ftw|glob|grp|iconv|inttypes|iso646|langinfo|libgen|limits|locale|math|monetary|mqueue|ndbm|netdb|net/if|netinet/in|netinet/tcp|nl_types|poll|pthread|pwd|regex|sched|search|semaphore|setjmp|signal|spawn|stdalign|stdarg|stdatomic|stdbool|stddef|stdint|stdio|stdlib|stdnoreturn|string|strings|stropts|sys/ipc|syslog|sys/mman|sys/msg|sys/resource|sys/select|sys/sem|sys/shm|sys/socket|sys/stat|sys/statvfs|sys/time|sys/times|sys/types|sys/uio|sys/un|sys/utsname|sys/wait|tar|term|termios|tgmath|threads|time|trace|uchar|ulimit|uncntrl|unistd|utime|utmpx|wchar|wctype|wordexp)\.h[">]$' 14 | Priority: 10 15 | - Regex: '^[<"](algorithm|array|atomic|bitset|cassert|ccomplex|cctype|cerrno|cfenv|cfloat|chrono|cinttypes|ciso646|climits|clocale|cmath|codecvt|complex|condition_variable|csetjmp|csignal|cstdalign|cstdarg|cstdbool|cstddef|cstdint|cstdio|cstdlib|cstring|ctgmath|ctime|cuchar|cwchar|cwctype|deque|exception|forward_list|fstream|functional|future|initializer_list|iomanip|ios|iosfwd|iostream|istream|iterator|limits|list|locale|map|memory|mutex|new|numeric|ostream|queue|random|ratio|regex|scoped_allocator|set|shared_mutex|sstream|stack|stdexcept|streambuf|string|strstream|system_error|thread|tuple|type_traits|typeindex|typeinfo|unordered_map|unordered_set|utility|valarray|vector)[">]$' 16 | Priority: 20 17 | - Regex: '^<' 18 | Priority: 30 19 | - Regex: '^"(drake|drake_external_examples)' 20 | Priority: 50 21 | - Regex: '^"' 22 | Priority: 40 23 | -------------------------------------------------------------------------------- /drake_bazel_download/.github/ci_build_test: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # SPDX-License-Identifier: MIT-0 3 | 4 | set -euxo pipefail 5 | 6 | # Use what we installed to $HOME/drake, 7 | # rather than the URL to the most recent nightly release 8 | # found in drake_bazel_download/MODULE.bazel. 9 | drake_override_flag="--override_repository=+_repo_rules2+drake=$HOME/drake" 10 | 11 | # Setup $HOME/drake as a Bazel workspace via 12 | # BUILD and WORKSPACE files. 13 | ln -sf $(realpath drake.BUILD.bazel) "$HOME/drake/BUILD.bazel" 14 | touch "$HOME/drake/WORKSPACE.bazel" 15 | 16 | bazel version 17 | bazel test "${drake_override_flag}" //... 18 | -------------------------------------------------------------------------------- /drake_bazel_download/.github/ubuntu_setup: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # SPDX-License-Identifier: MIT-0 3 | 4 | set -euxo pipefail 5 | 6 | echo 'APT::Acquire::Retries "4";' > /etc/apt/apt.conf.d/80-acquire-retries 7 | echo 'APT::Get::Assume-Yes "true";' > /etc/apt/apt.conf.d/90-get-assume-yes 8 | 9 | export DEBIAN_FRONTEND='noninteractive' 10 | 11 | setup/install_prereqs "$@" 12 | -------------------------------------------------------------------------------- /drake_bazel_download/.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT-0 2 | 3 | --- 4 | name: ci 5 | on: 6 | push: 7 | branches: 8 | - main 9 | pull_request: 10 | branches: 11 | - main 12 | schedule: 13 | - cron: '0 12 * * *' 14 | workflow_dispatch: 15 | inputs: 16 | linux_jammy_package_tar: 17 | description: 'Drake linux-jammy-*-packaging .tar.gz artifact URL' 18 | required: false 19 | concurrency: 20 | # Cancel previous CI runs when additional commits are added to a pull request. 21 | # This will not cancel CI runs associated with `schedule` or `push`. 22 | group: ${{ github.head_ref || github.run_id }} 23 | cancel-in-progress: true 24 | jobs: 25 | ubuntu_jammy_bazel_download: 26 | name: ubuntu 22.04 jammy 27 | runs-on: ubuntu-latest 28 | container: ubuntu:jammy 29 | steps: 30 | - name: checkout 31 | uses: actions/checkout@v4 32 | - name: setup 33 | working-directory: drake_bazel_download 34 | run: | 35 | args=() 36 | if [[ '${{ github.event.inputs.linux_jammy_package_tar }}' != '' ]]; then 37 | args+=(--package-url ${{ github.event.inputs.linux_jammy_package_tar }}) 38 | fi 39 | .github/ubuntu_setup "${args[@]}" 40 | shell: bash 41 | - name: install_bazelisk 42 | working-directory: drake_bazel_download 43 | run: setup/install_bazelisk 44 | shell: bash 45 | - name: bazel_download build and test 46 | working-directory: drake_bazel_download 47 | run: .github/ci_build_test 48 | shell: bash 49 | -------------------------------------------------------------------------------- /drake_bazel_download/.gitignore: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT-0 2 | 3 | /MODULE.bazel.lock 4 | /bazel-* 5 | /user.bazelrc 6 | -------------------------------------------------------------------------------- /drake_bazel_download/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT-0 2 | 3 | # We must opt-out of the py_exec_tools_toolchain, otherwise rules_python will 4 | # download a random copy from the internet that doesn't work correctly in CI. 5 | # 6 | # The py_exec_tools_toolchain is used to byte-compile python sources during 7 | # the build step (vs the first time they are run) for improved performance. 8 | # We don't need that optimization in this project. 9 | 10 | load( 11 | "@rules_python//python:py_exec_tools_toolchain.bzl", 12 | "py_exec_tools_toolchain", 13 | ) 14 | 15 | py_exec_tools_toolchain( 16 | name = "python_no_exec_tools", 17 | exec_interpreter = "@rules_python//python:none", 18 | ) 19 | 20 | toolchain( 21 | name = "python_no_exec_tools_toolchain", 22 | toolchain = ":python_no_exec_tools", 23 | toolchain_type = "@rules_python//python:exec_tools_toolchain_type", 24 | ) 25 | -------------------------------------------------------------------------------- /drake_bazel_download/CPPLINT.cfg: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT-0 2 | 3 | set noparent 4 | 5 | filter=-build/c++11 6 | filter=-build/header_guard 7 | filter=-build/include_subdir 8 | -------------------------------------------------------------------------------- /drake_bazel_download/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2017-2025 by the drake-external-examples developers. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so. 9 | 10 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 11 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 12 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 13 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 14 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 15 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 16 | SOFTWARE. 17 | -------------------------------------------------------------------------------- /drake_bazel_download/MODULE.bazel: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT-0 2 | 3 | module(name = "drake_external_examples") 4 | 5 | # Add the Bazel rulesets we need. 6 | bazel_dep(name = "rules_cc", version = "0.0.17") 7 | bazel_dep(name = "rules_python", version = "0.40.0") 8 | 9 | # Use the host system python. 10 | register_toolchains("@bazel_tools//tools/python:autodetecting_toolchain") 11 | 12 | # Disable the exec tools toolchain. 13 | register_toolchains("//:python_no_exec_tools_toolchain") 14 | 15 | # Use the host system Eigen. 16 | local_eigen_repositiory = use_repo_rule("//:eigen.bzl", "local_eigen_repository") 17 | local_eigen_repositiory(name = "eigen") 18 | 19 | # Use a downloaded, pre-compiled build of Drake. 20 | http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") 21 | http_archive( 22 | name = "drake", 23 | urls = [ 24 | # This URL refers to the most recent nightly build of Drake (which is 25 | # helpful for our CI test coverage). Users will probably want to pin 26 | # this to a specific release version, instead. To find those URLs, 27 | # refer to https://github.com/RobotLocomotion/drake/releases. 28 | "https://drake-packages.csail.mit.edu/drake/nightly/drake-latest-jammy.tar.gz" 29 | ], 30 | build_file = "drake.BUILD.bazel", 31 | strip_prefix = "drake", 32 | ) 33 | -------------------------------------------------------------------------------- /drake_bazel_download/README.md: -------------------------------------------------------------------------------- 1 | # Bazel Project with Drake as a Precompiled External 2 | 3 | This pulls in a downloaded or installed binary build of Drake via the Bazel 4 | workspace mechanism. 5 | 6 | For an introduction to Bazel, refer to 7 | [Getting Started with Bazel](https://bazel.build/start). 8 | 9 | ## Instructions 10 | 11 | First, run the `install_prereqs` script to download the 12 | Drake source to `$HOME/drake/`. This also runs Drake's 13 | setup script to install the required Ubuntu packages: 14 | 15 | ```bash 16 | setup/install_prereqs 17 | ``` 18 | 19 | Additionally, if you don't already have bazel or bazelisk installed, then install bazelisk: 20 | 21 | ```bash 22 | setup/install_bazelisk 23 | ``` 24 | 25 | Then, to build and test all apps: 26 | 27 | ```bash 28 | bazel test //... 29 | ``` 30 | 31 | As an example to run a binary directly: 32 | 33 | ```bash 34 | bazel run //apps:simple_logging_example 35 | ``` 36 | 37 | You may also run the binary directly per the `bazel-bin/...` path that the 38 | above command prints out; however, be aware that your working directories may 39 | cause differences. This is important when using tools like 40 | `drake::FindResource` / `pydrake.common.FindResource`. 41 | You may generally want to stick to using `bazel run` when able. 42 | -------------------------------------------------------------------------------- /drake_bazel_download/apps/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT-0 2 | 3 | load("@rules_python//python:defs.bzl", "py_binary", "py_test") 4 | 5 | # Make a simple Python application. 6 | py_binary( 7 | name = "simple_logging_example", 8 | srcs = ["simple_logging_example.py"], 9 | deps = [ 10 | "@drake//:pydrake", 11 | ], 12 | ) 13 | 14 | # Check that third-party include paths work properly. 15 | cc_test( 16 | name = "include_paths_test", 17 | srcs = ["include_paths_test.cc"], 18 | deps = [ 19 | "@drake//:drake_shared_library", 20 | ], 21 | ) 22 | 23 | # This ensures that downstream Bazel projects can use Drake's `find_resource` 24 | # functionality without needing to resort to environment variables. 25 | py_test( 26 | name = "find_resource_py_test", 27 | main = "find_resource_test.py", 28 | srcs = ["find_resource_test.py"], 29 | deps = [ 30 | "@drake//:pydrake", 31 | ], 32 | ) 33 | 34 | cc_test( 35 | name = "find_resource_cc_test", 36 | srcs = ["find_resource_test.cc"], 37 | deps = [ 38 | "@drake//:drake_shared_library", 39 | ] 40 | ) 41 | 42 | sh_test( 43 | name = "simple_logging_example_test", 44 | size = "small", 45 | srcs = ["exec.sh"], 46 | args = ["$(location :simple_logging_example)"], 47 | data = [":simple_logging_example"], 48 | ) 49 | 50 | py_test( 51 | name = "import_all_py_test", 52 | main = "import_all_test.py", 53 | srcs = ["import_all_test.py"], 54 | deps = [ 55 | "@drake//:pydrake", 56 | ], 57 | ) 58 | -------------------------------------------------------------------------------- /drake_bazel_download/apps/exec.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # SPDX-License-Identifier: MIT-0 3 | 4 | # Proxy script for things such as passing a `py_binary` to a `sh_test`, since 5 | # we cannot list the Python binary in `srcs` for the test. 6 | exec "$@" 7 | -------------------------------------------------------------------------------- /drake_bazel_download/apps/find_resource_test.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT-0 2 | 3 | #include "drake/common/find_resource.h" 4 | #include "drake/common/text_logging.h" 5 | 6 | int main() 7 | { 8 | drake::logging::set_log_level("debug"); 9 | drake::FindResourceOrThrow("drake/examples/pendulum/Pendulum.urdf"); 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /drake_bazel_download/apps/find_resource_test.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT-0 2 | 3 | """ 4 | Provides an example (and test) of finding resources with Python from a Bazel 5 | project. 6 | """ 7 | 8 | import logging 9 | 10 | from pydrake.common import FindResourceOrThrow 11 | 12 | # If you have trouble finding resources, you can enable debug logging to see 13 | # how `FindResource*` is searching. 14 | logging.getLogger("drake").setLevel(logging.DEBUG) 15 | 16 | FindResourceOrThrow("drake/examples/pendulum/Pendulum.urdf") 17 | -------------------------------------------------------------------------------- /drake_bazel_download/apps/import_all_test.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT-0 2 | 3 | """ 4 | Provides an example of importing all modules available in pydrake. 5 | """ 6 | 7 | import pydrake.all 8 | -------------------------------------------------------------------------------- /drake_bazel_download/apps/include_paths_test.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT-0 2 | 3 | // This test program checks that Drake headers that include third-party headers 4 | // can be successfully included when using drake_bazel_download. It serves as 5 | // a regression test for Drake moreso than an example program for end-users. 6 | 7 | #include "drake/common/drake_assert.h" 8 | #include "drake/common/eigen_types.h" 9 | #include "drake/common/text_logging.h" 10 | #include "drake/manipulation/kuka_iiwa/iiwa_status_receiver.h" 11 | 12 | int main() { 13 | // Check eigen-related include paths. 14 | drake::VectorX empty; 15 | DRAKE_DEMAND(empty.size() == 0); 16 | 17 | // Check lcm-related include paths. 18 | const drake::manipulation::kuka_iiwa::IiwaStatusReceiver iiwa; 19 | DRAKE_DEMAND(iiwa.num_input_ports() > 0); 20 | 21 | // Check fmt- and spdlog-related include paths. 22 | drake::log()->info("Info check {}", "passed"); 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /drake_bazel_download/apps/simple_logging_example.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT-0 2 | 3 | """ 4 | Provides an example of using pydrake from a Bazel external. 5 | """ 6 | 7 | from __future__ import print_function 8 | 9 | import numpy as np 10 | 11 | from pydrake.systems.analysis import Simulator 12 | from pydrake.systems.framework import ( 13 | DiagramBuilder, 14 | ) 15 | from pydrake.systems.primitives import ( 16 | ConstantVectorSource, 17 | VectorLogSink, 18 | ) 19 | 20 | 21 | def main(): 22 | builder = DiagramBuilder() 23 | source = builder.AddSystem(ConstantVectorSource([10.])) 24 | logger = builder.AddSystem(VectorLogSink(1)) 25 | builder.Connect(source.get_output_port(0), logger.get_input_port(0)) 26 | diagram = builder.Build() 27 | 28 | simulator = Simulator(diagram) 29 | simulator.AdvanceTo(1) 30 | 31 | x = logger.FindLog(simulator.get_context()).data() 32 | print("Output values: {}".format(x)) 33 | assert np.allclose(x, 10.) 34 | 35 | 36 | if __name__ == "__main__": 37 | main() 38 | -------------------------------------------------------------------------------- /drake_bazel_download/drake.BUILD.bazel: -------------------------------------------------------------------------------- 1 | # -*- bazel -*- 2 | 3 | load("@rules_cc//cc:defs.bzl", "cc_library") 4 | load("@rules_python//python:defs.bzl", "py_library") 5 | 6 | package(default_visibility = ["//visibility:private"]) 7 | 8 | # --- Resources stuff --- 9 | 10 | _RUNFILES = glob([ 11 | "share/drake/**", 12 | ], exclude = [ 13 | "share/drake/common/**", 14 | "share/drake/setup/**", 15 | "share/drake/tutorials/**", 16 | ], allow_empty = False) 17 | 18 | filegroup( 19 | name = "_runfiles", 20 | srcs = _RUNFILES, 21 | ) 22 | 23 | # --- C++ stuff --- 24 | 25 | _DRAKE_SHLIBS = glob([ 26 | "lib/libdrake*.so", 27 | ], allow_empty = False) 28 | 29 | _THIRD_SHLIBS = glob([ 30 | # For Mosek (not enabled by default). 31 | "lib/libtbb*.so*", 32 | "lib/libmosek64*.so*", 33 | # For Gurobi (not enabled by default). 34 | "lib/libgurobi*.so*", 35 | ], allow_empty = True) 36 | 37 | cc_library( 38 | name = "_drake_headers", 39 | hdrs = glob(["include/drake/**"]), 40 | strip_include_prefix = "include", 41 | ) 42 | 43 | [ 44 | cc_import( 45 | name = "_imported{}".format(shlib), 46 | shared_library = shlib, 47 | ) 48 | for shlib in _DRAKE_SHLIBS + _THIRD_SHLIBS 49 | ] 50 | 51 | cc_library( 52 | name = "drake_shared_library", 53 | data = [ 54 | ":_runfiles", 55 | ], 56 | deps = [ 57 | ":_drake_headers", 58 | "@eigen", 59 | ] + [ 60 | ":_imported{}".format(shlib) 61 | for shlib in _DRAKE_SHLIBS + _THIRD_SHLIBS 62 | ], 63 | visibility = ["//visibility:public"], 64 | ) 65 | 66 | # --- Python stuff --- 67 | 68 | _PYDRAKE_PYS = glob([ 69 | "lib/python3.*/site-packages/**/*.py", 70 | ], allow_empty = False) 71 | 72 | _PYDRAKE_SOS = glob([ 73 | "lib/python3.*/site-packages/**/*.so", 74 | ], allow_empty = False) 75 | 76 | _IMPORT = _PYDRAKE_PYS[0][:len("lib/python3.##/site-packages")] 77 | 78 | py_library( 79 | name = "pydrake", 80 | visibility = ["//visibility:public"], 81 | srcs = _PYDRAKE_PYS, 82 | data = _PYDRAKE_SOS + _DRAKE_SHLIBS + _THIRD_SHLIBS + [ 83 | ":_runfiles", 84 | ], 85 | imports = [_IMPORT], 86 | ) 87 | -------------------------------------------------------------------------------- /drake_bazel_download/eigen.BUILD.bazel: -------------------------------------------------------------------------------- 1 | # -*- bazel -*- 2 | 3 | cc_library( 4 | name = "eigen", 5 | hdrs = glob(["include/Eigen/**", "include/unsupported/Eigen/**"], allow_empty = False), 6 | strip_include_prefix = "include", 7 | visibility = ["//visibility:public"], 8 | ) 9 | -------------------------------------------------------------------------------- /drake_bazel_download/eigen.bzl: -------------------------------------------------------------------------------- 1 | def _impl(repo_ctx): 2 | repo_ctx.symlink("/usr/include/eigen3", "include") 3 | repo_ctx.symlink(Label("@//:eigen.BUILD.bazel"), "BUILD.bazel") 4 | 5 | local_eigen_repository = repository_rule( 6 | implementation = _impl, 7 | ) 8 | -------------------------------------------------------------------------------- /drake_bazel_download/setup/install_bazelisk: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # TODO(jwnimmer-tri) Drake's install_prereqs script should offer to perform 4 | # this install step for us, but it doesn't -- so we need this work-around 5 | # in the meantime. 6 | 7 | set -euxo pipefail 8 | 9 | maybe_sudo= 10 | if [[ "${EUID}" -ne 0 ]]; then 11 | maybe_sudo=sudo 12 | fi 13 | 14 | wget -O bazelisk.deb \ 15 | https://github.com/bazelbuild/bazelisk/releases/download/v1.24.0/bazelisk-amd64.deb 16 | ${maybe_sudo} dpkg -i bazelisk.deb 17 | rm -f bazelisk.deb 18 | -------------------------------------------------------------------------------- /drake_bazel_download/setup/install_prereqs: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright (c) 2020, Massachusetts Institute of Technology. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # 9 | # * Redistributions of source code must retain the above copyright notice, this 10 | # list of conditions and the following disclaimer. 11 | # 12 | # * Redistributions in binary form must reproduce the above copyright notice, 13 | # this list of conditions and the following disclaimer in the documentation 14 | # and/or other materials provided with the distribution. 15 | # 16 | # * Neither the name of the copyright holder nor the names of its contributors 17 | # may be used to endorse or promote products derived from this software 18 | # without specific prior written permission. 19 | # 20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | # POSSIBILITY OF SUCH DAMAGE. 31 | 32 | set -euxo pipefail 33 | 34 | package_url= 35 | 36 | while [ "${1:-}" != "" ]; do 37 | case "$1" in 38 | --package-url) 39 | shift 40 | if [[ $# -eq 0 ]]; then 41 | echo 'No argument specified for --package-url' >&2 42 | exit 1 43 | fi 44 | package_url="$1" 45 | ;; 46 | *) 47 | echo 'Invalid command line argument' >&2 48 | exit 1 49 | esac 50 | shift 51 | done 52 | 53 | maybe_sudo= 54 | if [[ "${EUID}" -ne 0 ]]; then 55 | maybe_sudo=sudo 56 | fi 57 | 58 | ${maybe_sudo} apt-get update 59 | ${maybe_sudo} apt-get install --no-install-recommends lsb-release 60 | 61 | if [[ "$(lsb_release -sc)" != 'jammy' ]]; then 62 | echo 'This script requires Ubuntu 22.04 (Jammy)' >&2 63 | exit 3 64 | fi 65 | 66 | ${maybe_sudo} apt-get install --no-install-recommends $(cat <]$' 14 | Priority: 10 15 | - Regex: '^[<"](algorithm|array|atomic|bitset|cassert|ccomplex|cctype|cerrno|cfenv|cfloat|chrono|cinttypes|ciso646|climits|clocale|cmath|codecvt|complex|condition_variable|csetjmp|csignal|cstdalign|cstdarg|cstdbool|cstddef|cstdint|cstdio|cstdlib|cstring|ctgmath|ctime|cuchar|cwchar|cwctype|deque|exception|forward_list|fstream|functional|future|initializer_list|iomanip|ios|iosfwd|iostream|istream|iterator|limits|list|locale|map|memory|mutex|new|numeric|ostream|queue|random|ratio|regex|scoped_allocator|set|shared_mutex|sstream|stack|stdexcept|streambuf|string|strstream|system_error|thread|tuple|type_traits|typeindex|typeinfo|unordered_map|unordered_set|utility|valarray|vector)[">]$' 16 | Priority: 20 17 | - Regex: '^<' 18 | Priority: 30 19 | - Regex: '^"(drake|drake_external_examples)' 20 | Priority: 50 21 | - Regex: '^"' 22 | Priority: 40 23 | -------------------------------------------------------------------------------- /drake_bazel_external/.github/ci_build_test: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # SPDX-License-Identifier: MIT-0 3 | 4 | set -euxo pipefail 5 | 6 | # Use what we downloaded to drake_bazel_external/drake, 7 | # rather than the URL to the latest Drake master branch 8 | # found in drake_bazel_external/MODULE.bazel. 9 | override_module_flag="--override_module=drake=drake" 10 | 11 | bazel version 12 | bazel test "${override_module_flag}" //... 13 | -------------------------------------------------------------------------------- /drake_bazel_external/.github/setup: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # SPDX-License-Identifier: MIT-0 3 | 4 | set -euxo pipefail 5 | 6 | # CI setup 7 | sudo .github/ubuntu_setup 8 | 9 | # drake source setup 10 | setup/install_prereqs "$@" 11 | -------------------------------------------------------------------------------- /drake_bazel_external/.github/ubuntu_setup: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # SPDX-License-Identifier: MIT-0 3 | 4 | set -euxo pipefail 5 | 6 | if [[ "${EUID:-}" -ne 0 ]]; then 7 | echo 'This script must be run as root' >&2 8 | exit 2 9 | fi 10 | 11 | echo 'APT::Acquire::Retries "4";' > /etc/apt/apt.conf.d/80-acquire-retries 12 | echo 'APT::Get::Assume-Yes "true";' > /etc/apt/apt.conf.d/90-get-assume-yes 13 | 14 | export DEBIAN_FRONTEND='noninteractive' 15 | 16 | apt-get update 17 | apt-get install --no-install-recommends lsb-release 18 | 19 | if [[ "$(lsb_release -sc)" != 'jammy' ]]; then 20 | echo 'This script requires Ubuntu 22.04 (Jammy)' >&2 21 | exit 3 22 | fi 23 | -------------------------------------------------------------------------------- /drake_bazel_external/.gitignore: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT-0 2 | 3 | /bazel-* 4 | /user.bazelrc 5 | /MODULE.bazel.lock 6 | -------------------------------------------------------------------------------- /drake_bazel_external/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT-0 2 | 3 | # This is an empty BUILD file, to ensure that this project's root directory is 4 | # a Bazel package. 5 | -------------------------------------------------------------------------------- /drake_bazel_external/CPPLINT.cfg: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT-0 2 | 3 | set noparent 4 | 5 | filter=-build/c++11 6 | filter=-build/header_guard 7 | filter=-build/include_subdir 8 | -------------------------------------------------------------------------------- /drake_bazel_external/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2017-2025 by the drake-external-examples developers. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so. 9 | 10 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 11 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 12 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 13 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 14 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 15 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 16 | SOFTWARE. 17 | -------------------------------------------------------------------------------- /drake_bazel_external/MODULE.bazel: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT-0 2 | 3 | module(name = "drake_external_examples") 4 | 5 | # If you don't want to support building on macOS, you may remove the next line. 6 | # Note that it must appear prior to loading "rules_cc", per the documentation: 7 | # https://github.com/bazelbuild/apple_support?tab=readme-ov-file#bazel-7-setup 8 | bazel_dep(name = "apple_support", version = "1.17.1") 9 | 10 | # Add the Bazel rules we need. 11 | bazel_dep(name = "rules_cc", version = "0.0.17") 12 | bazel_dep(name = "rules_python", version = "0.40.0") 13 | 14 | # Here we introduce Drake as a module dependency, but note that Drake is not 15 | # published to any Bazel registry. Below, we'll override it with a github 16 | # source archive. 17 | bazel_dep(name = "drake") 18 | 19 | # By default, this example always uses the latest Drake master branch. 20 | DRAKE_COMMIT = "master" 21 | DRAKE_CHECKSUM = None 22 | 23 | # You can choose a specific revision of Drake to use, e.g.: 24 | # DRAKE_COMMIT = "19bb4703fdf4950d4b3530d496d8a0ff1ca5fc22" 25 | # DRAKE_CHECKSUM = "489d255db3cb1c8ff7a91ae0f961d76b6083a1d4a3f58150371b4b359683adb6" 26 | # 27 | # You can also use DRAKE_COMMIT to choose a Drake release; e.g.: 28 | # DRAKE_COMMIT = "v0.15.0" 29 | # DRAKE_CHECKSUM = "... TBD ..." 30 | # 31 | # Before changing the COMMIT, temporarily uncomment the next line so that Bazel 32 | # displays the suggested new value for the CHECKSUM. 33 | # DRAKE_CHECKSUM = "0" * 64 34 | 35 | # This declares the `@drake` module as a source code archive from github. 36 | # See README.md for instructions to use a local path, instead. 37 | archive_override( 38 | module_name = "drake", 39 | urls = [x.format(DRAKE_COMMIT) for x in [ 40 | "https://github.com/RobotLocomotion/drake/archive/{}.tar.gz", 41 | ]], 42 | sha256 = DRAKE_CHECKSUM, 43 | strip_prefix = "drake-{}".format(DRAKE_COMMIT.lstrip("v")), 44 | ) 45 | 46 | # Use the host system /usr/bin/python3. 47 | python_repository = use_repo_rule( 48 | "@drake//tools/workspace/python:repository.bzl", 49 | "python_repository", 50 | ) 51 | 52 | python_repository( 53 | name = "python", 54 | linux_interpreter_path = "/usr/bin/python3", 55 | requirements_flavor = "build", 56 | ) 57 | 58 | register_toolchains("@python//:all") 59 | -------------------------------------------------------------------------------- /drake_bazel_external/README.md: -------------------------------------------------------------------------------- 1 | # Bazel Project with Drake as an External 2 | 3 | This pulls in Drake and builds it from source via Bazel's module mechanism. 4 | 5 | For an introduction to Bazel, refer to 6 | [Getting Started with Bazel](https://bazel.build/start). 7 | 8 | ## Instructions 9 | 10 | First, run the `install_prereqs` script to download 11 | the Drake source to `drake/` (from the current directory). 12 | This also runs Drake's setup script to install the required Ubuntu packages: 13 | 14 | ```bash 15 | setup/install_prereqs 16 | ``` 17 | 18 | Then, to build and test all apps: 19 | 20 | ```bash 21 | bazel test //... 22 | ``` 23 | 24 | As an example to run a binary directly: 25 | 26 | ```bash 27 | bazel run //apps:simple_logging_example 28 | ``` 29 | 30 | You may also run the binary directly per the `bazel-bin/...` path that the 31 | above command prints out; however, be aware that your working directories may 32 | cause differences. This is important when using tools like 33 | `drake::FindResource` / `pydrake.common.FindResource`. 34 | You may generally want to stick to using `bazel run` when able. 35 | 36 | ### Using a local checkout of Drake 37 | 38 | To use Drake sources on disk instead of downloaded from github, pass the flag 39 | ``--override_module=drake=/home/user/stuff/drake`` to bazel on the command line 40 | or add a line such as the following to ``user.bazelrc`` in the current directory: 41 | 42 | ```bash 43 | build --override_module=drake=/home/user/stuff/drake 44 | ``` 45 | 46 | ## Python Versions 47 | 48 | By default, Python 3 is the Python interpreter that Drake will use when built 49 | with Bazel. To see which Python versions are supported, see the 50 | [supported configurations](https://drake.mit.edu/developers.html#supported-configurations). 51 | -------------------------------------------------------------------------------- /drake_bazel_external/apps/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT-0 2 | 3 | load("@drake//tools/skylark:py.bzl", "py_binary", "py_test") 4 | load("@drake//tools/skylark:pybind.bzl", "pybind_py_library") 5 | 6 | # Compile a sample application. 7 | cc_binary( 8 | name = "simple_continuous_time_system", 9 | srcs = ["simple_continuous_time_system.cc"], 10 | deps = [ 11 | "@drake//systems/analysis", 12 | "@drake//systems/framework", 13 | ], 14 | ) 15 | 16 | # Make a simple Python application. 17 | py_binary( 18 | name = "simple_logging_example", 19 | srcs = ["simple_logging_example.py"], 20 | deps = [ 21 | "@drake//bindings/pydrake", 22 | ], 23 | ) 24 | 25 | # This ensures that downstream Bazel projects can use Drake's `find_resource` 26 | # functionality without needing to resort to environment variables. 27 | py_test( 28 | name = "find_resource_test", 29 | srcs = ["find_resource_test.py"], 30 | deps = [ 31 | "@drake//bindings/pydrake", 32 | ], 33 | ) 34 | 35 | # Run the applications to make sure they complete successfully. 36 | # N.B. For actual development, you should prefer language-specific test rules, 37 | # such as `cc_test` and `py_test`. 38 | sh_test( 39 | name = "simple_continuous_time_system_test", 40 | size = "small", 41 | srcs = [":simple_continuous_time_system"], 42 | ) 43 | 44 | sh_test( 45 | name = "simple_logging_example_test", 46 | size = "small", 47 | srcs = ["exec.sh"], 48 | args = ["$(location :simple_logging_example)"], 49 | data = [":simple_logging_example"], 50 | ) 51 | 52 | # For custom bindings, you *must* link against `drake_shared_library` for *all* 53 | # C++ libraries; not doing so will lead to ODR (One Definition Rule) linking 54 | # issues. 55 | cc_library( 56 | name = "simple_adder", 57 | srcs = [ 58 | # While the `*-inl.h` pattern is not required, this does ensure that we 59 | # test separate compilation and linking. 60 | "simple_adder.cc", 61 | "simple_adder-inl.h", 62 | ], 63 | hdrs = [ 64 | "simple_adder.h", 65 | ], 66 | deps = [ 67 | # N.B. Per the above comment, this does NOT link to static libraries 68 | # (e.g. "@drake//systems/analysis"). 69 | "@drake//:drake_shared_library", 70 | ], 71 | ) 72 | 73 | # Show that the C++ functionality works as-is. 74 | cc_test( 75 | name = "simple_adder_test", 76 | srcs = ["simple_adder_test.cc"], 77 | deps = [":simple_adder"], 78 | ) 79 | 80 | pybind_py_library( 81 | name = "simple_adder_py", 82 | cc_so_name = "simple_adder", 83 | cc_srcs = ["simple_adder_py.cc"], 84 | cc_deps = [ 85 | ":simple_adder", 86 | "@drake//bindings/pydrake/common:cpp_template_pybind", 87 | "@drake//bindings/pydrake/common:default_scalars_pybind", 88 | ], 89 | py_deps = ["@drake//bindings/pydrake"], 90 | py_imports = ["."], 91 | ) 92 | 93 | # Mimic the C++ test in Python to show the bindings. 94 | py_test( 95 | name = "simple_adder_py_test", 96 | srcs = ["simple_adder_py_test.py"], 97 | deps = [":simple_adder_py"], 98 | ) 99 | 100 | py_test( 101 | name = "import_all_test", 102 | srcs = ["import_all_test.py"], 103 | deps = [ 104 | "@drake//bindings/pydrake", 105 | ], 106 | ) 107 | -------------------------------------------------------------------------------- /drake_bazel_external/apps/exec.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # SPDX-License-Identifier: MIT-0 3 | 4 | # Proxy script for things such as passing a `py_binary` to a `sh_test`, since 5 | # we cannot list the Python binary in `srcs` for the test. 6 | exec "$@" 7 | -------------------------------------------------------------------------------- /drake_bazel_external/apps/find_resource_test.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT-0 2 | 3 | """ 4 | Provides an example (and test) of finding resources with Python from a Bazel 5 | project. 6 | """ 7 | 8 | import logging 9 | 10 | from pydrake.common import FindResourceOrThrow 11 | 12 | # If you have trouble finding resources, you can enable debug logging to see 13 | # how `FindResource*` is searching. 14 | logging.getLogger("drake").setLevel(logging.DEBUG) 15 | 16 | FindResourceOrThrow("drake/examples/pendulum/Pendulum.urdf") 17 | -------------------------------------------------------------------------------- /drake_bazel_external/apps/import_all_test.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT-0 2 | 3 | """ 4 | Provides an example of importing all modules available in pydrake. 5 | """ 6 | 7 | import pydrake.all 8 | -------------------------------------------------------------------------------- /drake_bazel_external/apps/simple_adder-inl.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT-0 2 | 3 | /** 4 | * @file 5 | * Provides an example of creating a simple Drake C++ system that will later be 6 | * bound. 7 | * 8 | * This is the definition portion of the -inl.h pattern: 9 | * http://drake.mit.edu/cxx_inl.html#cxx-inl-files 10 | */ 11 | 12 | #include "simple_adder.h" 13 | 14 | namespace drake_external_examples { 15 | 16 | using drake::systems::BasicVector; 17 | using drake::systems::Context; 18 | using drake::systems::LeafSystem; 19 | using drake::systems::kVectorValued; 20 | 21 | template 22 | SimpleAdder::SimpleAdder(T add) 23 | : add_(add) { 24 | this->DeclareInputPort("in", kVectorValued, 1); 25 | this->DeclareVectorOutputPort( 26 | "out", BasicVector(1), &SimpleAdder::CalcOutput); 27 | } 28 | 29 | template 30 | void SimpleAdder::CalcOutput( 31 | const Context& context, BasicVector* output) const { 32 | auto u = this->get_input_port(0).Eval(context); 33 | auto&& y = output->get_mutable_value(); 34 | y.array() = u.array() + add_; 35 | } 36 | 37 | } // namespace drake_external_examples 38 | -------------------------------------------------------------------------------- /drake_bazel_external/apps/simple_adder.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT-0 2 | 3 | /** 4 | * @file 5 | * Provides an example of creating a simple Drake C++ system that will later be 6 | * bound. 7 | * 8 | * This is the instantiation portion of the -inl.h pattern: 9 | * http://drake.mit.edu/cxx_inl.html#cxx-inl-files 10 | */ 11 | 12 | #include "simple_adder-inl.h" 13 | 14 | #include 15 | 16 | DRAKE_DEFINE_CLASS_TEMPLATE_INSTANTIATIONS_ON_DEFAULT_SCALARS( 17 | class ::drake_external_examples::SimpleAdder); 18 | -------------------------------------------------------------------------------- /drake_bazel_external/apps/simple_adder.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT-0 2 | 3 | /** 4 | * @file 5 | * Provides an example of creating a simple Drake C++ system that will later be 6 | * bound. 7 | * 8 | * This is the header portion of the -inl.h pattern: 9 | * http://drake.mit.edu/cxx_inl.html#cxx-inl-files 10 | */ 11 | 12 | #include 13 | 14 | namespace drake_external_examples { 15 | 16 | /// Adds a constant to an input. 17 | template 18 | class SimpleAdder : public drake::systems::LeafSystem { 19 | public: 20 | explicit SimpleAdder(T add); 21 | 22 | private: 23 | void CalcOutput( 24 | const drake::systems::Context& context, 25 | drake::systems::BasicVector* output) const; 26 | 27 | const T add_{}; 28 | }; 29 | 30 | } // namespace drake_external_examples 31 | -------------------------------------------------------------------------------- /drake_bazel_external/apps/simple_adder_py.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT-0 2 | 3 | /** 4 | * @file 5 | * Provides an example of binding a simple Drake C++ system in pybind11, to be 6 | * used with pydrake. 7 | */ 8 | 9 | #include 10 | 11 | #include "drake/bindings/pydrake/common/cpp_template_pybind.h" 12 | #include "drake/bindings/pydrake/common/default_scalars_pybind.h" 13 | 14 | #include "simple_adder.h" 15 | 16 | namespace py = pybind11; 17 | 18 | using drake::pydrake::CommonScalarPack; 19 | using drake::pydrake::DefineTemplateClassWithDefault; 20 | using drake::pydrake::GetPyParam; 21 | using drake::systems::LeafSystem; 22 | 23 | namespace drake_external_examples { 24 | namespace { 25 | 26 | PYBIND11_MODULE(simple_adder, m) { 27 | m.doc() = "Example module interfacing with pydrake and Drake C++"; 28 | 29 | py::module::import("pydrake.systems.framework"); 30 | 31 | auto bind_common_scalar_types = [m](auto dummy) { 32 | using T = decltype(dummy); 33 | 34 | DefineTemplateClassWithDefault, LeafSystem>( 35 | m, "SimpleAdder", GetPyParam()) 36 | .def(py::init(), py::arg("add")); 37 | }; 38 | type_visit(bind_common_scalar_types, CommonScalarPack{}); 39 | } 40 | 41 | } // namespace 42 | } // namespace drake_external_examples 43 | -------------------------------------------------------------------------------- /drake_bazel_external/apps/simple_adder_py_test.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT-0 2 | 3 | """ 4 | Provides an example of using pybind11-bound Drake C++ system with pydrake. 5 | """ 6 | 7 | from __future__ import print_function 8 | 9 | from simple_adder import SimpleAdder, SimpleAdder_ 10 | 11 | import numpy as np 12 | 13 | from pydrake.autodiffutils import AutoDiffXd 14 | from pydrake.symbolic import Expression 15 | from pydrake.systems.analysis import Simulator 16 | from pydrake.systems.framework import DiagramBuilder 17 | from pydrake.systems.primitives import ( 18 | ConstantVectorSource, 19 | VectorLogSink, 20 | ) 21 | 22 | 23 | def main(): 24 | # Simulate with doubles. 25 | builder = DiagramBuilder() 26 | source = builder.AddSystem(ConstantVectorSource([10.])) 27 | adder = builder.AddSystem(SimpleAdder(100.)) 28 | builder.Connect(source.get_output_port(0), adder.get_input_port(0)) 29 | logger = builder.AddSystem(VectorLogSink(1)) 30 | builder.Connect(adder.get_output_port(0), logger.get_input_port(0)) 31 | diagram = builder.Build() 32 | 33 | simulator = Simulator(diagram) 34 | simulator.AdvanceTo(1) 35 | 36 | x = logger.FindLog(simulator.get_context()).data() 37 | print("Output values: {}".format(x)) 38 | assert np.allclose(x, 110.) 39 | 40 | # Compute outputs with AutoDiff and Symbolic. 41 | for T in (AutoDiffXd, Expression): 42 | adder_T = SimpleAdder_[T](100.) 43 | context = adder_T.CreateDefaultContext() 44 | adder_T.get_input_port().FixValue(context, [10.]) 45 | output = adder_T.AllocateOutput() 46 | adder_T.CalcOutput(context, output) 47 | # N.B. At present, you cannot get a reference to existing AutoDiffXd 48 | # or Expression numpy arrays, so we will explictly copy the vector: 49 | # https://github.com/RobotLocomotion/drake/issues/8116 50 | value, = output.get_vector_data(0).CopyToVector() 51 | assert isinstance(value, T) 52 | print("Output from {}: {}".format(type(adder_T), repr(value))) 53 | 54 | 55 | if __name__ == "__main__": 56 | main() 57 | -------------------------------------------------------------------------------- /drake_bazel_external/apps/simple_adder_test.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT-0 2 | 3 | /** 4 | * @file 5 | * Provides an example of testing a custom C++ Drake system which will also 6 | * be bound in Python. 7 | */ 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include "simple_adder.h" 18 | 19 | using drake::systems::Simulator; 20 | using drake::systems::DiagramBuilder; 21 | using drake::systems::ConstantVectorSource; 22 | using drake::systems::VectorLogSink; 23 | 24 | namespace drake_external_examples { 25 | namespace { 26 | 27 | int DoMain() { 28 | DiagramBuilder builder; 29 | auto source = builder.AddSystem>( 30 | Eigen::VectorXd::Constant(1, 10.)); 31 | auto adder = builder.AddSystem>(100.); 32 | builder.Connect(source->get_output_port(), adder->get_input_port(0)); 33 | auto logger = builder.AddSystem>(1); 34 | builder.Connect(adder->get_output_port(0), logger->get_input_port()); 35 | auto diagram = builder.Build(); 36 | 37 | Simulator simulator(*diagram); 38 | simulator.AdvanceTo(1); 39 | 40 | auto x = logger->FindLog(simulator.get_context()).data(); 41 | Eigen::VectorXd x_expected = Eigen::Vector2d(110., 110.); 42 | std::cout << "Output values: " << x << std::endl; 43 | DRAKE_DEMAND(x.isApprox(x_expected.transpose())); 44 | 45 | return 0; 46 | } 47 | 48 | } // namespace 49 | } // namespace drake_external_examples 50 | 51 | int main() { 52 | return drake_external_examples::DoMain(); 53 | } 54 | -------------------------------------------------------------------------------- /drake_bazel_external/apps/simple_continuous_time_system.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT-0 2 | 3 | // Simple Continuous Time System Example 4 | // 5 | // This is meant to be a sort of "hello world" example for the drake::system 6 | // classes. It defines a very simple continuous time system and simulates it 7 | // from a given initial condition. 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | namespace drake_external_examples { 19 | namespace systems { 20 | 21 | // Simple Continuous Time System 22 | // xdot = -x + x³ 23 | // y = x 24 | class SimpleContinuousTimeSystem : public drake::systems::LeafSystem { 25 | public: 26 | SimpleContinuousTimeSystem() { 27 | DeclareVectorOutputPort("y", drake::systems::BasicVector(1), 28 | &SimpleContinuousTimeSystem::CopyStateOut); 29 | DeclareContinuousState(1); // One state variable. 30 | } 31 | 32 | private: 33 | // xdot = -x + x³ 34 | void DoCalcTimeDerivatives( 35 | const drake::systems::Context& context, 36 | drake::systems::ContinuousState* derivatives) const override { 37 | const double x = context.get_continuous_state()[0]; 38 | const double xdot = -x + std::pow(x, 3.0); 39 | (*derivatives)[0] = xdot; 40 | } 41 | 42 | // y = x 43 | void CopyStateOut(const drake::systems::Context& context, 44 | drake::systems::BasicVector* output) const { 45 | const double x = context.get_continuous_state()[0]; 46 | (*output)[0] = x; 47 | } 48 | }; 49 | 50 | } // namespace systems 51 | } // namespace drake_external_examples 52 | 53 | int main() { 54 | // Create the simple system. 55 | drake_external_examples::systems::SimpleContinuousTimeSystem system; 56 | 57 | // Create the simulator. 58 | drake::systems::Simulator simulator(system); 59 | 60 | // Set the initial conditions x(0). 61 | drake::systems::ContinuousState& state = 62 | simulator.get_mutable_context().get_mutable_continuous_state(); 63 | state[0] = 0.9; 64 | 65 | // Simulate for 10 seconds. 66 | simulator.AdvanceTo(10); 67 | 68 | // Make sure the simulation converges to the stable fixed point at x = 0. 69 | DRAKE_DEMAND(state[0] < 1.0e-4); 70 | 71 | return 0; 72 | } 73 | -------------------------------------------------------------------------------- /drake_bazel_external/apps/simple_logging_example.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT-0 2 | 3 | """ 4 | Provides an example of using pydrake from a Bazel external. 5 | """ 6 | 7 | from __future__ import print_function 8 | 9 | import numpy as np 10 | 11 | from pydrake.systems.analysis import Simulator 12 | from pydrake.systems.framework import ( 13 | DiagramBuilder, 14 | ) 15 | from pydrake.systems.primitives import ( 16 | ConstantVectorSource, 17 | VectorLogSink, 18 | ) 19 | 20 | 21 | def main(): 22 | builder = DiagramBuilder() 23 | source = builder.AddSystem(ConstantVectorSource([10.])) 24 | logger = builder.AddSystem(VectorLogSink(1)) 25 | builder.Connect(source.get_output_port(0), logger.get_input_port(0)) 26 | diagram = builder.Build() 27 | 28 | simulator = Simulator(diagram) 29 | simulator.AdvanceTo(1) 30 | 31 | x = logger.FindLog(simulator.get_context()).data() 32 | print("Output values: {}".format(x)) 33 | assert np.allclose(x, 10.) 34 | 35 | 36 | if __name__ == "__main__": 37 | main() 38 | -------------------------------------------------------------------------------- /drake_bazel_external/setup/install_prereqs: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # SPDX-License-Identifier: MIT-0 4 | 5 | set -euxo pipefail 6 | 7 | drake_commit_hash='master' 8 | 9 | while [ "${1:-}" != "" ]; do 10 | case "$1" in 11 | --drake-commit-hash) 12 | shift 13 | if [[ $# -eq 0 ]]; then 14 | echo 'No argument specified for --drake-commit-hash' >&2 15 | exit 1 16 | fi 17 | drake_commit_hash="$1" 18 | ;; 19 | *) 20 | echo 'Invalid command line argument' >&2 21 | exit 1 22 | esac 23 | shift 24 | done 25 | 26 | maybe_sudo= 27 | if [[ "${EUID}" -ne 0 ]]; then 28 | maybe_sudo=sudo 29 | fi 30 | 31 | ${maybe_sudo} apt-get install --no-install-recommends $(cat <]$' 14 | Priority: 10 15 | - Regex: '^[<"](algorithm|array|atomic|bitset|cassert|ccomplex|cctype|cerrno|cfenv|cfloat|chrono|cinttypes|ciso646|climits|clocale|cmath|codecvt|complex|condition_variable|csetjmp|csignal|cstdalign|cstdarg|cstdbool|cstddef|cstdint|cstdio|cstdlib|cstring|ctgmath|ctime|cuchar|cwchar|cwctype|deque|exception|forward_list|fstream|functional|future|initializer_list|iomanip|ios|iosfwd|iostream|istream|iterator|limits|list|locale|map|memory|mutex|new|numeric|ostream|queue|random|ratio|regex|scoped_allocator|set|shared_mutex|sstream|stack|stdexcept|streambuf|string|strstream|system_error|thread|tuple|type_traits|typeindex|typeinfo|unordered_map|unordered_set|utility|valarray|vector)[">]$' 16 | Priority: 20 17 | - Regex: '^<' 18 | Priority: 30 19 | - Regex: '^"(drake|drake_external_examples)' 20 | Priority: 50 21 | - Regex: '^"' 22 | Priority: 40 23 | -------------------------------------------------------------------------------- /drake_bazel_external_legacy/.github/ci_build_test: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # SPDX-License-Identifier: MIT-0 3 | 4 | set -euxo pipefail 5 | 6 | # Use what we downloaded to drake_bazel_external_legacy/drake, 7 | # rather than the URL to the latest Drake master branch 8 | # found in drake_bazel_external_legacy/WORKSPACE. 9 | export EXAMPLES_LOCAL_DRAKE_PATH=$(realpath drake) 10 | 11 | bazel version 12 | bazel test //... 13 | -------------------------------------------------------------------------------- /drake_bazel_external_legacy/.github/setup: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # SPDX-License-Identifier: MIT-0 3 | 4 | set -euxo pipefail 5 | 6 | # CI setup 7 | sudo .github/ubuntu_setup 8 | 9 | # drake source setup 10 | setup/install_prereqs "$@" 11 | -------------------------------------------------------------------------------- /drake_bazel_external_legacy/.github/ubuntu_setup: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # SPDX-License-Identifier: MIT-0 3 | 4 | set -euxo pipefail 5 | 6 | if [[ "${EUID:-}" -ne 0 ]]; then 7 | echo 'This script must be run as root' >&2 8 | exit 2 9 | fi 10 | 11 | echo 'APT::Acquire::Retries "4";' > /etc/apt/apt.conf.d/80-acquire-retries 12 | echo 'APT::Get::Assume-Yes "true";' > /etc/apt/apt.conf.d/90-get-assume-yes 13 | 14 | export DEBIAN_FRONTEND='noninteractive' 15 | 16 | apt-get update 17 | apt-get install --no-install-recommends lsb-release 18 | 19 | if [[ "$(lsb_release -sc)" != 'jammy' ]]; then 20 | echo 'This script requires Ubuntu 22.04 (Jammy)' >&2 21 | exit 3 22 | fi 23 | -------------------------------------------------------------------------------- /drake_bazel_external_legacy/.gitignore: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT-0 2 | 3 | /bazel-* 4 | /user.bazelrc 5 | -------------------------------------------------------------------------------- /drake_bazel_external_legacy/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT-0 2 | 3 | # This is an empty BUILD file, to ensure that this project's root directory is 4 | # a Bazel package. 5 | -------------------------------------------------------------------------------- /drake_bazel_external_legacy/CPPLINT.cfg: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT-0 2 | 3 | set noparent 4 | 5 | filter=-build/c++11 6 | filter=-build/header_guard 7 | filter=-build/include_subdir 8 | -------------------------------------------------------------------------------- /drake_bazel_external_legacy/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2017-2025 by the drake-external-examples developers. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so. 9 | 10 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 11 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 12 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 13 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 14 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 15 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 16 | SOFTWARE. 17 | -------------------------------------------------------------------------------- /drake_bazel_external_legacy/README.md: -------------------------------------------------------------------------------- 1 | # Bazel Project with Drake as an External (legacy style) 2 | 3 | This pulls in Drake and builds it from source via Bazel's WORKSPACE mechanism, 4 | which is deprecated as of Bazel 8 and will be removed in Bazel 9. Therefore, 5 | we do not recommend using this example for new projects; instead, refer to 6 | the `drake_bazel_external` example. The legacy example primarily serves 7 | as a regression test for the deprecated behavior, and therefore uses Drake's 8 | minimum supported Bazel version. 9 | 10 | For an introduction to Bazel, refer to 11 | [Getting Started with Bazel](https://bazel.build/start). 12 | 13 | ## Instructions 14 | 15 | First, run the `install_prereqs` script to download the 16 | Drake source to `drake/` (from the current directory). 17 | This also runs Drake's setup script to install the required Ubuntu packages: 18 | 19 | ```bash 20 | setup/install_prereqs 21 | ``` 22 | 23 | Then, to build and test all apps: 24 | 25 | ```bash 26 | bazel test //... 27 | ``` 28 | 29 | As an example to run a binary directly: 30 | 31 | ```bash 32 | bazel run //apps:simple_logging_example 33 | ``` 34 | 35 | You may also run the binary directly per the `bazel-bin/...` path that the 36 | above command prints out; however, be aware that your working directories may 37 | cause differences. This is important when using tools like 38 | `drake::FindResource` / `pydrake.common.FindResource`. 39 | You may generally want to stick to using `bazel run` when able. 40 | 41 | ## Python Versions 42 | 43 | By default, Python 3 is the Python interpreter that Drake will use when built 44 | with Bazel. To see which Python versions are supported, see the 45 | [supported configurations](https://drake.mit.edu/developers.html#supported-configurations). 46 | -------------------------------------------------------------------------------- /drake_bazel_external_legacy/WORKSPACE: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT-0 2 | 3 | workspace(name = "drake_external_examples") 4 | 5 | DRAKE_COMMIT = "master" 6 | DRAKE_CHECKSUM = "" 7 | 8 | # Or choose a specific revision of Drake to use. 9 | # DRAKE_COMMIT = "be4f658487f739ba04ec079de46f9459b719636d" 10 | # DRAKE_CHECKSUM = "31ec8f87df3ceb6516de3c33a14c5d59ac5c003b4faf93ac526877d2e150b394" 11 | # 12 | # You can also use DRAKE_COMMIT to choose a Drake release; eg: 13 | # DRAKE_COMMIT = "v0.15.0" 14 | # 15 | # Before changing the COMMIT, temporarily uncomment the next line so that Bazel 16 | # displays the suggested new value for the CHECKSUM. 17 | # DRAKE_CHECKSUM = "0" * 64 18 | 19 | # Or to temporarily build against a local checkout of Drake, at the bash prompt 20 | # set an environment variable before building: 21 | # export EXAMPLES_LOCAL_DRAKE_PATH=/home/user/stuff/drake 22 | 23 | # Load an environment variable. 24 | load("//:environ.bzl", "environ_repository") 25 | environ_repository(name = "environ", vars = ["EXAMPLES_LOCAL_DRAKE_PATH"]) 26 | load("@environ//:environ.bzl", EXAMPLES_LOCAL_DRAKE_PATH = "EXAMPLES_LOCAL_DRAKE_PATH") 27 | 28 | # This declares the `@drake` repository as an http_archive from github, 29 | # iff EXAMPLES_LOCAL_DRAKE_PATH is unset. When it is set, this declares a 30 | # `@drake_ignored` package which is never referenced, and thus is ignored. 31 | load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") 32 | http_archive( 33 | name = "drake" if not EXAMPLES_LOCAL_DRAKE_PATH else "drake_ignored", 34 | urls = [x.format(DRAKE_COMMIT) for x in [ 35 | "https://github.com/RobotLocomotion/drake/archive/{}.tar.gz", 36 | ]], 37 | sha256 = DRAKE_CHECKSUM, 38 | strip_prefix = "drake-{}".format(DRAKE_COMMIT.lstrip("v")), 39 | ) 40 | 41 | # This declares the `@drake` repository as a local directory, 42 | # iff EXAMPLES_LOCAL_DRAKE_PATH is set. When it is unset, this declares a 43 | # `@drake_ignored` package which is never referenced, and thus is ignored. 44 | local_repository( 45 | name = "drake" if EXAMPLES_LOCAL_DRAKE_PATH else "drake_ignored", 46 | path = EXAMPLES_LOCAL_DRAKE_PATH, 47 | ) 48 | print("Using EXAMPLES_LOCAL_DRAKE_PATH={}".format(EXAMPLES_LOCAL_DRAKE_PATH)) if EXAMPLES_LOCAL_DRAKE_PATH else None # noqa 49 | 50 | # Reference external software libraries, tools, and toolchains per Drake's 51 | # defaults. Some software will come from the host system (Ubuntu or macOS); 52 | # other software will be downloaded in source or binary form from GitHub or 53 | # other sites. 54 | load("@drake//tools/workspace:default.bzl", "add_default_workspace") 55 | add_default_workspace() 56 | -------------------------------------------------------------------------------- /drake_bazel_external_legacy/apps/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT-0 2 | 3 | load("@drake//tools/skylark:py.bzl", "py_binary", "py_test") 4 | load("@drake//tools/skylark:pybind.bzl", "pybind_py_library") 5 | 6 | # Compile a sample application. 7 | cc_binary( 8 | name = "simple_continuous_time_system", 9 | srcs = ["simple_continuous_time_system.cc"], 10 | deps = [ 11 | "@drake//systems/analysis", 12 | "@drake//systems/framework", 13 | ], 14 | ) 15 | 16 | # Make a simple Python application. 17 | py_binary( 18 | name = "simple_logging_example", 19 | srcs = ["simple_logging_example.py"], 20 | deps = [ 21 | "@drake//bindings/pydrake", 22 | ], 23 | ) 24 | 25 | # This ensures that downstream Bazel projects can use Drake's `find_resource` 26 | # functionality without needing to resort to environment variables. 27 | py_test( 28 | name = "find_resource_test", 29 | srcs = ["find_resource_test.py"], 30 | deps = [ 31 | "@drake//bindings/pydrake", 32 | ], 33 | ) 34 | 35 | # Run the applications to make sure they complete successfully. 36 | # N.B. For actual development, you should prefer language-specific test rules, 37 | # such as `cc_test` and `py_test`. 38 | sh_test( 39 | name = "simple_continuous_time_system_test", 40 | size = "small", 41 | srcs = [":simple_continuous_time_system"], 42 | ) 43 | 44 | sh_test( 45 | name = "simple_logging_example_test", 46 | size = "small", 47 | srcs = ["exec.sh"], 48 | args = ["$(location :simple_logging_example)"], 49 | data = [":simple_logging_example"], 50 | ) 51 | 52 | # For custom bindings, you *must* link against `drake_shared_library` for *all* 53 | # C++ libraries; not doing so will lead to ODR (One Definition Rule) linking 54 | # issues. 55 | cc_library( 56 | name = "simple_adder", 57 | srcs = [ 58 | # While the `*-inl.h` pattern is not required, this does ensure that we 59 | # test separate compilation and linking. 60 | "simple_adder.cc", 61 | "simple_adder-inl.h", 62 | ], 63 | hdrs = [ 64 | "simple_adder.h", 65 | ], 66 | deps = [ 67 | # N.B. Per the above comment, this does NOT link to static libraries 68 | # (e.g. "@drake//systems/analysis"). 69 | "@drake//:drake_shared_library", 70 | ], 71 | ) 72 | 73 | # Show that the C++ functionality works as-is. 74 | cc_test( 75 | name = "simple_adder_test", 76 | srcs = ["simple_adder_test.cc"], 77 | deps = [":simple_adder"], 78 | ) 79 | 80 | pybind_py_library( 81 | name = "simple_adder_py", 82 | cc_so_name = "simple_adder", 83 | cc_srcs = ["simple_adder_py.cc"], 84 | cc_deps = [ 85 | ":simple_adder", 86 | "@drake//bindings/pydrake/common:cpp_template_pybind", 87 | "@drake//bindings/pydrake/common:default_scalars_pybind", 88 | ], 89 | py_deps = ["@drake//bindings/pydrake"], 90 | py_imports = ["."], 91 | ) 92 | 93 | # Mimic the C++ test in Python to show the bindings. 94 | py_test( 95 | name = "simple_adder_py_test", 96 | srcs = ["simple_adder_py_test.py"], 97 | deps = [":simple_adder_py"], 98 | ) 99 | 100 | py_test( 101 | name = "import_all_test", 102 | srcs = ["import_all_test.py"], 103 | deps = [ 104 | "@drake//bindings/pydrake", 105 | ], 106 | ) 107 | -------------------------------------------------------------------------------- /drake_bazel_external_legacy/apps/exec.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # SPDX-License-Identifier: MIT-0 3 | 4 | # Proxy script for things such as passing a `py_binary` to a `sh_test`, since 5 | # we cannot list the Python binary in `srcs` for the test. 6 | exec "$@" 7 | -------------------------------------------------------------------------------- /drake_bazel_external_legacy/apps/find_resource_test.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT-0 2 | 3 | """ 4 | Provides an example (and test) of finding resources with Python from a Bazel 5 | project. 6 | """ 7 | 8 | import logging 9 | 10 | from pydrake.common import FindResourceOrThrow 11 | 12 | # If you have trouble finding resources, you can enable debug logging to see 13 | # how `FindResource*` is searching. 14 | logging.getLogger("drake").setLevel(logging.DEBUG) 15 | 16 | FindResourceOrThrow("drake/examples/pendulum/Pendulum.urdf") 17 | -------------------------------------------------------------------------------- /drake_bazel_external_legacy/apps/import_all_test.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT-0 2 | 3 | """ 4 | Provides an example of importing all modules available in pydrake. 5 | """ 6 | 7 | import pydrake.all 8 | -------------------------------------------------------------------------------- /drake_bazel_external_legacy/apps/simple_adder-inl.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT-0 2 | 3 | /** 4 | * @file 5 | * Provides an example of creating a simple Drake C++ system that will later be 6 | * bound. 7 | * 8 | * This is the definition portion of the -inl.h pattern: 9 | * http://drake.mit.edu/cxx_inl.html#cxx-inl-files 10 | */ 11 | 12 | #include "simple_adder.h" 13 | 14 | namespace drake_external_examples { 15 | 16 | using drake::systems::BasicVector; 17 | using drake::systems::Context; 18 | using drake::systems::LeafSystem; 19 | using drake::systems::kVectorValued; 20 | 21 | template 22 | SimpleAdder::SimpleAdder(T add) 23 | : add_(add) { 24 | this->DeclareInputPort("in", kVectorValued, 1); 25 | this->DeclareVectorOutputPort( 26 | "out", BasicVector(1), &SimpleAdder::CalcOutput); 27 | } 28 | 29 | template 30 | void SimpleAdder::CalcOutput( 31 | const Context& context, BasicVector* output) const { 32 | auto u = this->get_input_port(0).Eval(context); 33 | auto&& y = output->get_mutable_value(); 34 | y.array() = u.array() + add_; 35 | } 36 | 37 | } // namespace drake_external_examples 38 | -------------------------------------------------------------------------------- /drake_bazel_external_legacy/apps/simple_adder.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT-0 2 | 3 | /** 4 | * @file 5 | * Provides an example of creating a simple Drake C++ system that will later be 6 | * bound. 7 | * 8 | * This is the instantiation portion of the -inl.h pattern: 9 | * http://drake.mit.edu/cxx_inl.html#cxx-inl-files 10 | */ 11 | 12 | #include "simple_adder-inl.h" 13 | 14 | #include 15 | 16 | DRAKE_DEFINE_CLASS_TEMPLATE_INSTANTIATIONS_ON_DEFAULT_SCALARS( 17 | class ::drake_external_examples::SimpleAdder); 18 | -------------------------------------------------------------------------------- /drake_bazel_external_legacy/apps/simple_adder.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT-0 2 | 3 | /** 4 | * @file 5 | * Provides an example of creating a simple Drake C++ system that will later be 6 | * bound. 7 | * 8 | * This is the header portion of the -inl.h pattern: 9 | * http://drake.mit.edu/cxx_inl.html#cxx-inl-files 10 | */ 11 | 12 | #include 13 | 14 | namespace drake_external_examples { 15 | 16 | /// Adds a constant to an input. 17 | template 18 | class SimpleAdder : public drake::systems::LeafSystem { 19 | public: 20 | explicit SimpleAdder(T add); 21 | 22 | private: 23 | void CalcOutput( 24 | const drake::systems::Context& context, 25 | drake::systems::BasicVector* output) const; 26 | 27 | const T add_{}; 28 | }; 29 | 30 | } // namespace drake_external_examples 31 | -------------------------------------------------------------------------------- /drake_bazel_external_legacy/apps/simple_adder_py.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT-0 2 | 3 | /** 4 | * @file 5 | * Provides an example of binding a simple Drake C++ system in pybind11, to be 6 | * used with pydrake. 7 | */ 8 | 9 | #include 10 | 11 | #include "drake/bindings/pydrake/common/cpp_template_pybind.h" 12 | #include "drake/bindings/pydrake/common/default_scalars_pybind.h" 13 | 14 | #include "simple_adder.h" 15 | 16 | namespace py = pybind11; 17 | 18 | using drake::pydrake::CommonScalarPack; 19 | using drake::pydrake::DefineTemplateClassWithDefault; 20 | using drake::pydrake::GetPyParam; 21 | using drake::systems::LeafSystem; 22 | 23 | namespace drake_external_examples { 24 | namespace { 25 | 26 | PYBIND11_MODULE(simple_adder, m) { 27 | m.doc() = "Example module interfacing with pydrake and Drake C++"; 28 | 29 | py::module::import("pydrake.systems.framework"); 30 | 31 | auto bind_common_scalar_types = [m](auto dummy) { 32 | using T = decltype(dummy); 33 | 34 | DefineTemplateClassWithDefault, LeafSystem>( 35 | m, "SimpleAdder", GetPyParam()) 36 | .def(py::init(), py::arg("add")); 37 | }; 38 | type_visit(bind_common_scalar_types, CommonScalarPack{}); 39 | } 40 | 41 | } // namespace 42 | } // namespace drake_external_examples 43 | -------------------------------------------------------------------------------- /drake_bazel_external_legacy/apps/simple_adder_py_test.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT-0 2 | 3 | """ 4 | Provides an example of using pybind11-bound Drake C++ system with pydrake. 5 | """ 6 | 7 | from __future__ import print_function 8 | 9 | from simple_adder import SimpleAdder, SimpleAdder_ 10 | 11 | import numpy as np 12 | 13 | from pydrake.autodiffutils import AutoDiffXd 14 | from pydrake.symbolic import Expression 15 | from pydrake.systems.analysis import Simulator 16 | from pydrake.systems.framework import DiagramBuilder 17 | from pydrake.systems.primitives import ( 18 | ConstantVectorSource, 19 | VectorLogSink, 20 | ) 21 | 22 | 23 | def main(): 24 | # Simulate with doubles. 25 | builder = DiagramBuilder() 26 | source = builder.AddSystem(ConstantVectorSource([10.])) 27 | adder = builder.AddSystem(SimpleAdder(100.)) 28 | builder.Connect(source.get_output_port(0), adder.get_input_port(0)) 29 | logger = builder.AddSystem(VectorLogSink(1)) 30 | builder.Connect(adder.get_output_port(0), logger.get_input_port(0)) 31 | diagram = builder.Build() 32 | 33 | simulator = Simulator(diagram) 34 | simulator.AdvanceTo(1) 35 | 36 | x = logger.FindLog(simulator.get_context()).data() 37 | print("Output values: {}".format(x)) 38 | assert np.allclose(x, 110.) 39 | 40 | # Compute outputs with AutoDiff and Symbolic. 41 | for T in (AutoDiffXd, Expression): 42 | adder_T = SimpleAdder_[T](100.) 43 | context = adder_T.CreateDefaultContext() 44 | adder_T.get_input_port().FixValue(context, [10.]) 45 | output = adder_T.AllocateOutput() 46 | adder_T.CalcOutput(context, output) 47 | # N.B. At present, you cannot get a reference to existing AutoDiffXd 48 | # or Expression numpy arrays, so we will explictly copy the vector: 49 | # https://github.com/RobotLocomotion/drake/issues/8116 50 | value, = output.get_vector_data(0).CopyToVector() 51 | assert isinstance(value, T) 52 | print("Output from {}: {}".format(type(adder_T), repr(value))) 53 | 54 | 55 | if __name__ == "__main__": 56 | main() 57 | -------------------------------------------------------------------------------- /drake_bazel_external_legacy/apps/simple_adder_test.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT-0 2 | 3 | /** 4 | * @file 5 | * Provides an example of testing a custom C++ Drake system which will also 6 | * be bound in Python. 7 | */ 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include "simple_adder.h" 18 | 19 | using drake::systems::Simulator; 20 | using drake::systems::DiagramBuilder; 21 | using drake::systems::ConstantVectorSource; 22 | using drake::systems::VectorLogSink; 23 | 24 | namespace drake_external_examples { 25 | namespace { 26 | 27 | int DoMain() { 28 | DiagramBuilder builder; 29 | auto source = builder.AddSystem>( 30 | Eigen::VectorXd::Constant(1, 10.)); 31 | auto adder = builder.AddSystem>(100.); 32 | builder.Connect(source->get_output_port(), adder->get_input_port(0)); 33 | auto logger = builder.AddSystem>(1); 34 | builder.Connect(adder->get_output_port(0), logger->get_input_port()); 35 | auto diagram = builder.Build(); 36 | 37 | Simulator simulator(*diagram); 38 | simulator.AdvanceTo(1); 39 | 40 | auto x = logger->FindLog(simulator.get_context()).data(); 41 | Eigen::VectorXd x_expected = Eigen::Vector2d(110., 110.); 42 | std::cout << "Output values: " << x << std::endl; 43 | DRAKE_DEMAND(x.isApprox(x_expected.transpose())); 44 | 45 | return 0; 46 | } 47 | 48 | } // namespace 49 | } // namespace drake_external_examples 50 | 51 | int main() { 52 | return drake_external_examples::DoMain(); 53 | } 54 | -------------------------------------------------------------------------------- /drake_bazel_external_legacy/apps/simple_continuous_time_system.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT-0 2 | 3 | // Simple Continuous Time System Example 4 | // 5 | // This is meant to be a sort of "hello world" example for the drake::system 6 | // classes. It defines a very simple continuous time system and simulates it 7 | // from a given initial condition. 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | namespace drake_external_examples { 19 | namespace systems { 20 | 21 | // Simple Continuous Time System 22 | // xdot = -x + x³ 23 | // y = x 24 | class SimpleContinuousTimeSystem : public drake::systems::LeafSystem { 25 | public: 26 | SimpleContinuousTimeSystem() { 27 | DeclareVectorOutputPort("y", drake::systems::BasicVector(1), 28 | &SimpleContinuousTimeSystem::CopyStateOut); 29 | DeclareContinuousState(1); // One state variable. 30 | } 31 | 32 | private: 33 | // xdot = -x + x³ 34 | void DoCalcTimeDerivatives( 35 | const drake::systems::Context& context, 36 | drake::systems::ContinuousState* derivatives) const override { 37 | const double x = context.get_continuous_state()[0]; 38 | const double xdot = -x + std::pow(x, 3.0); 39 | (*derivatives)[0] = xdot; 40 | } 41 | 42 | // y = x 43 | void CopyStateOut(const drake::systems::Context& context, 44 | drake::systems::BasicVector* output) const { 45 | const double x = context.get_continuous_state()[0]; 46 | (*output)[0] = x; 47 | } 48 | }; 49 | 50 | } // namespace systems 51 | } // namespace drake_external_examples 52 | 53 | int main() { 54 | // Create the simple system. 55 | drake_external_examples::systems::SimpleContinuousTimeSystem system; 56 | 57 | // Create the simulator. 58 | drake::systems::Simulator simulator(system); 59 | 60 | // Set the initial conditions x(0). 61 | drake::systems::ContinuousState& state = 62 | simulator.get_mutable_context().get_mutable_continuous_state(); 63 | state[0] = 0.9; 64 | 65 | // Simulate for 10 seconds. 66 | simulator.AdvanceTo(10); 67 | 68 | // Make sure the simulation converges to the stable fixed point at x = 0. 69 | DRAKE_DEMAND(state[0] < 1.0e-4); 70 | 71 | return 0; 72 | } 73 | -------------------------------------------------------------------------------- /drake_bazel_external_legacy/apps/simple_logging_example.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT-0 2 | 3 | """ 4 | Provides an example of using pydrake from a Bazel external. 5 | """ 6 | 7 | from __future__ import print_function 8 | 9 | import numpy as np 10 | 11 | from pydrake.systems.analysis import Simulator 12 | from pydrake.systems.framework import ( 13 | DiagramBuilder, 14 | ) 15 | from pydrake.systems.primitives import ( 16 | ConstantVectorSource, 17 | VectorLogSink, 18 | ) 19 | 20 | 21 | def main(): 22 | builder = DiagramBuilder() 23 | source = builder.AddSystem(ConstantVectorSource([10.])) 24 | logger = builder.AddSystem(VectorLogSink(1)) 25 | builder.Connect(source.get_output_port(0), logger.get_input_port(0)) 26 | diagram = builder.Build() 27 | 28 | simulator = Simulator(diagram) 29 | simulator.AdvanceTo(1) 30 | 31 | x = logger.FindLog(simulator.get_context()).data() 32 | print("Output values: {}".format(x)) 33 | assert np.allclose(x, 10.) 34 | 35 | 36 | if __name__ == "__main__": 37 | main() 38 | -------------------------------------------------------------------------------- /drake_bazel_external_legacy/environ.bzl: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT-0 2 | 3 | # Write out a repository that contains: 4 | # - An empty BUILD file, to define a package. 5 | # - An environ.bzl file with variable assignments for each ENV_NAMES item. 6 | def _impl(repository_ctx): 7 | vars = repository_ctx.attr.vars 8 | bzl_content = [] 9 | for key in vars: 10 | value = repository_ctx.os.environ.get(key, "") 11 | bzl_content.append("{}='{}'\n".format(key, value)) 12 | repository_ctx.file( 13 | "BUILD.bazel", 14 | content = "\n", 15 | executable = False, 16 | ) 17 | repository_ctx.file( 18 | "environ.bzl", 19 | content = "".join(bzl_content), 20 | executable = False, 21 | ) 22 | 23 | _string_list = attr.string_list() 24 | 25 | def environ_repository(name = None, vars = []): 26 | """Provide specific environment variables for use in a WORKSPACE file. 27 | The `vars` are the environment variables to provide. 28 | 29 | Example: 30 | environ_repository(name = "foo", vars = ["BAR", "BAZ"]) 31 | load("@foo//:environ.bzl", "BAR", "BAZ") 32 | print(BAR) 33 | """ 34 | rule = repository_rule( 35 | implementation = _impl, 36 | attrs = { 37 | "vars": _string_list, 38 | }, 39 | local = True, 40 | environ = vars, 41 | ) 42 | rule( 43 | name = name, 44 | vars = vars, 45 | ) 46 | -------------------------------------------------------------------------------- /drake_bazel_external_legacy/setup/install_prereqs: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # SPDX-License-Identifier: MIT-0 4 | 5 | set -euxo pipefail 6 | 7 | drake_commit_hash='master' 8 | 9 | while [ "${1:-}" != "" ]; do 10 | case "$1" in 11 | --drake-commit-hash) 12 | shift 13 | if [[ $# -eq 0 ]]; then 14 | echo 'No argument specified for --drake-commit-hash' >&2 15 | exit 1 16 | fi 17 | drake_commit_hash="$1" 18 | ;; 19 | *) 20 | echo 'Invalid command line argument' >&2 21 | exit 1 22 | esac 23 | shift 24 | done 25 | 26 | maybe_sudo= 27 | if [[ "${EUID}" -ne 0 ]]; then 28 | maybe_sudo=sudo 29 | fi 30 | 31 | ${maybe_sudo} apt-get install --no-install-recommends $(cat <]$' 14 | Priority: 10 15 | - Regex: '^[<"](algorithm|array|atomic|bitset|cassert|ccomplex|cctype|cerrno|cfenv|cfloat|chrono|cinttypes|ciso646|climits|clocale|cmath|codecvt|complex|condition_variable|csetjmp|csignal|cstdalign|cstdarg|cstdbool|cstddef|cstdint|cstdio|cstdlib|cstring|ctgmath|ctime|cuchar|cwchar|cwctype|deque|exception|forward_list|fstream|functional|future|initializer_list|iomanip|ios|iosfwd|iostream|istream|iterator|limits|list|locale|map|memory|mutex|new|numeric|ostream|queue|random|ratio|regex|scoped_allocator|set|shared_mutex|sstream|stack|stdexcept|streambuf|string|strstream|system_error|thread|tuple|type_traits|typeindex|typeinfo|unordered_map|unordered_set|utility|valarray|vector)[">]$' 16 | Priority: 20 17 | - Regex: '^<' 18 | Priority: 30 19 | - Regex: '^"(drake|drake_external_examples)' 20 | Priority: 50 21 | - Regex: '^"' 22 | Priority: 40 23 | -------------------------------------------------------------------------------- /drake_cmake_external/.github/ci_build_test: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # SPDX-License-Identifier: MIT-0 3 | 4 | set -euxo pipefail 5 | 6 | drake_commit_hash= 7 | 8 | while [ "${1:-}" != "" ]; do 9 | case "$1" in 10 | --drake-commit-hash) 11 | shift 12 | if [[ $# -eq 0 ]]; then 13 | echo 'No argument specified for --drake-commit-hash' >&2 14 | exit 1 15 | fi 16 | drake_commit_hash="$1" 17 | ;; 18 | *) 19 | echo 'Invalid command line argument' >&2 20 | exit 1 21 | esac 22 | shift 23 | done 24 | 25 | cmake --version 26 | 27 | mkdir build 28 | pushd build 29 | 30 | export LD_LIBRARY_PATH="${PWD}/install/lib${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}" 31 | 32 | cmake_args=() 33 | if [[ ! -z "${drake_commit_hash}" ]]; then 34 | # Use a specific commit of Drake source, 35 | # rather than the latest from master. 36 | cmake_args+=(-DDRAKE_COMMIT_HASH=${drake_commit_hash}) 37 | fi 38 | 39 | cmake .. "${cmake_args[@]}" 40 | cmake --build . 41 | 42 | cd drake_external_examples 43 | ctest -V . 44 | 45 | popd 46 | 47 | chmod -R a+w build || true 48 | rm -rf build 49 | -------------------------------------------------------------------------------- /drake_cmake_external/.github/setup: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # SPDX-License-Identifier: MIT-0 3 | 4 | set -euxo pipefail 5 | 6 | # CI setup 7 | sudo .github/ubuntu_setup 8 | 9 | # drake source setup 10 | setup/install_prereqs "$@" 11 | 12 | # Provide regression coverage for the WITH_USER_...=ON options by un-installing 13 | # packages that should not be necessary in this particular build flavor. This 14 | # example configures them to be built from source. 15 | sudo apt-get remove libeigen3-dev libfmt-dev libspdlog-dev 16 | sudo apt-get autoremove 17 | -------------------------------------------------------------------------------- /drake_cmake_external/.github/ubuntu_setup: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # SPDX-License-Identifier: MIT-0 3 | 4 | set -euxo pipefail 5 | 6 | if [[ "${EUID:-}" -ne 0 ]]; then 7 | echo 'This script must be run as root' >&2 8 | exit 2 9 | fi 10 | 11 | echo 'APT::Acquire::Retries "4";' > /etc/apt/apt.conf.d/80-acquire-retries 12 | echo 'APT::Get::Assume-Yes "true";' > /etc/apt/apt.conf.d/90-get-assume-yes 13 | 14 | export DEBIAN_FRONTEND='noninteractive' 15 | 16 | apt-get update 17 | apt-get install --no-install-recommends lsb-release 18 | 19 | if [[ "$(lsb_release -sc)" != 'jammy' ]]; then 20 | echo 'This script requires Ubuntu 22.04 (Jammy)' >&2 21 | exit 3 22 | fi 23 | -------------------------------------------------------------------------------- /drake_cmake_external/.gitignore: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT-0 2 | 3 | /.idea/ 4 | /build/ 5 | /cmake-build-*/ 6 | -------------------------------------------------------------------------------- /drake_cmake_external/CPPLINT.cfg: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT-0 2 | 3 | set noparent 4 | 5 | filter=-build/c++11 6 | filter=-build/header_guard 7 | filter=-build/include_subdir 8 | -------------------------------------------------------------------------------- /drake_cmake_external/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2017-2025 by the drake-external-examples developers. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so. 9 | 10 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 11 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 12 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 13 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 14 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 15 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 16 | SOFTWARE. 17 | -------------------------------------------------------------------------------- /drake_cmake_external/README.md: -------------------------------------------------------------------------------- 1 | # CMake Project with Drake as an External 2 | 3 | This pulls in Drake using the CMake `ExternalProject_Add(drake)` mechanism. 4 | 5 | ## Instructions 6 | 7 | First, run the `install_prereqs` script to download the 8 | Drake source to `drake/` (from the current directory). 9 | This also runs Drake's setup script to install the required Ubuntu packages: 10 | 11 | ```bash 12 | setup/install_prereqs 13 | ``` 14 | 15 | Keep in mind that within the top-level CMakeLists, the drake source is once 16 | again downloaded as an external project. If the CMakeLists is modified to use 17 | a specific version of drake other than master, and any dependencies have 18 | changed within that version, then the script ran above must also be modified. 19 | 20 | Once all necessary dependencies have been installed, build and run tests 21 | using CMake: 22 | 23 | ```bash 24 | mkdir build 25 | cd build 26 | cmake .. 27 | cmake --build . 28 | 29 | cd drake_external_examples 30 | ctest -V . 31 | ``` 32 | 33 | ### Using a specific commit of Drake 34 | 35 | To use Drake sources from a specific commit, pass two cache variables to 36 | CMake (from either the CLI or the GUI): 37 | 38 | * `DRAKE_COMMIT_HASH`: the commit hash 39 | * `DRAKE_COMMIT_SHA256`: the checksum of the archive downloaded from GitHub 40 | (download https://github.com/RobotLocomotion/drake/archive/.tar.gz 41 | and use `shasum -a 256 'xxx.tar.gz'`) 42 | -------------------------------------------------------------------------------- /drake_cmake_external/drake_external_examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT-0 2 | 3 | cmake_minimum_required(VERSION 3.16) 4 | project(drake_external_examples) 5 | 6 | find_package(drake CONFIG REQUIRED) 7 | 8 | find_package(Python3 ${drake_PYTHON_VERSION} EXACT REQUIRED COMPONENTS Interpreter Development) 9 | 10 | get_filename_component(DRAKE_PYTHONPATH 11 | "${drake_DIR}/../../python${drake_PYTHON_VERSION}/site-packages" 12 | REALPATH 13 | ) 14 | 15 | add_executable(simple_continuous_time_system simple_continuous_time_system.cc) 16 | target_link_libraries(simple_continuous_time_system drake::drake) 17 | 18 | include(CTest) 19 | 20 | add_test(NAME simple_continuous_time_system 21 | COMMAND simple_continuous_time_system 22 | ) 23 | add_test(NAME import_all_test COMMAND 24 | "${Python3_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/import_all_test.py" 25 | ) 26 | set_tests_properties(import_all_test PROPERTIES 27 | ENVIRONMENT "PYTHONPATH=${DRAKE_PYTHONPATH}" 28 | ) 29 | 30 | add_test(NAME solver_disabled_test 31 | COMMAND Python3::Interpreter -B -m unittest solver_disabled_test 32 | ) 33 | set_tests_properties(solver_disabled_test PROPERTIES 34 | ENVIRONMENT "PYTHONPATH=${DRAKE_PYTHONPATH}" 35 | LABELS small 36 | REQUIRED_FILES "${CMAKE_CURRENT_SOURCE_DIR}/solver_disabled_test.py" 37 | TIMEOUT 60 38 | WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" 39 | ) 40 | -------------------------------------------------------------------------------- /drake_cmake_external/drake_external_examples/import_all_test.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT-0 2 | 3 | """ 4 | Provides an example of importing all modules available in pydrake. 5 | """ 6 | 7 | import pydrake.all 8 | -------------------------------------------------------------------------------- /drake_cmake_external/drake_external_examples/simple_continuous_time_system.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT-0 2 | 3 | // Simple Continuous Time System Example 4 | // 5 | // This is meant to be a sort of "hello world" example for the drake::system 6 | // classes. It defines a very simple continuous time system and simulates it 7 | // from a given initial condition. 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | namespace drake_external_examples { 19 | namespace systems { 20 | 21 | // Simple Continuous Time System 22 | // xdot = -x + x³ 23 | // y = x 24 | class SimpleContinuousTimeSystem : public drake::systems::LeafSystem { 25 | public: 26 | SimpleContinuousTimeSystem() { 27 | DeclareVectorOutputPort("y", drake::systems::BasicVector(1), 28 | &SimpleContinuousTimeSystem::CopyStateOut); 29 | DeclareContinuousState(1); // One state variable. 30 | } 31 | 32 | private: 33 | // xdot = -x + x³ 34 | void DoCalcTimeDerivatives( 35 | const drake::systems::Context& context, 36 | drake::systems::ContinuousState* derivatives) const override { 37 | const double x = context.get_continuous_state()[0]; 38 | const double xdot = -x + std::pow(x, 3.0); 39 | (*derivatives)[0] = xdot; 40 | } 41 | 42 | // y = x 43 | void CopyStateOut(const drake::systems::Context& context, 44 | drake::systems::BasicVector* output) const { 45 | const double x = context.get_continuous_state()[0]; 46 | (*output)[0] = x; 47 | } 48 | }; 49 | 50 | } // namespace systems 51 | } // namespace drake_external_examples 52 | 53 | int main() { 54 | // Create the simple system. 55 | drake_external_examples::systems::SimpleContinuousTimeSystem system; 56 | 57 | // Create the simulator. 58 | drake::systems::Simulator simulator(system); 59 | 60 | // Set the initial conditions x(0). 61 | drake::systems::ContinuousState& state = 62 | simulator.get_mutable_context().get_mutable_continuous_state(); 63 | state[0] = 0.9; 64 | 65 | // Simulate for 10 seconds. 66 | simulator.AdvanceTo(10); 67 | 68 | // Make sure the simulation converges to the stable fixed point at x = 0. 69 | DRAKE_DEMAND(state[0] < 1.0e-4); 70 | 71 | return 0; 72 | } 73 | -------------------------------------------------------------------------------- /drake_cmake_external/drake_external_examples/solver_disabled_test.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT-0 2 | 3 | """ 4 | Our CMakeLists.txt file disabled the CSDP solver as part of the Drake build. 5 | Here, we'll check that the opt-out succeeded. 6 | """ 7 | 8 | import unittest 9 | 10 | from pydrake.solvers import CsdpSolver 11 | 12 | class TestCsdpSolver(unittest.TestCase): 13 | def test_unavailable(self): 14 | solver = CsdpSolver() 15 | self.assertFalse(solver.available()) 16 | 17 | if __name__ == '__main__': 18 | unittest.main() 19 | -------------------------------------------------------------------------------- /drake_cmake_external/setup/install_prereqs: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # SPDX-License-Identifier: MIT-0 4 | 5 | set -euxo pipefail 6 | 7 | drake_commit_hash='master' 8 | 9 | while [ "${1:-}" != "" ]; do 10 | case "$1" in 11 | --drake-commit-hash) 12 | shift 13 | if [[ $# -eq 0 ]]; then 14 | echo 'No argument specified for --drake-commit-hash' >&2 15 | exit 1 16 | fi 17 | drake_commit_hash="$1" 18 | ;; 19 | *) 20 | echo 'Invalid command line argument' >&2 21 | exit 1 22 | esac 23 | shift 24 | done 25 | 26 | maybe_sudo= 27 | if [[ "${EUID}" -ne 0 ]]; then 28 | maybe_sudo=sudo 29 | fi 30 | 31 | ${maybe_sudo} apt-get install --no-install-recommends $(cat <]$' 14 | Priority: 10 15 | - Regex: '^[<"](algorithm|array|atomic|bitset|cassert|ccomplex|cctype|cerrno|cfenv|cfloat|chrono|cinttypes|ciso646|climits|clocale|cmath|codecvt|complex|condition_variable|csetjmp|csignal|cstdalign|cstdarg|cstdbool|cstddef|cstdint|cstdio|cstdlib|cstring|ctgmath|ctime|cuchar|cwchar|cwctype|deque|exception|forward_list|fstream|functional|future|initializer_list|iomanip|ios|iosfwd|iostream|istream|iterator|limits|list|locale|map|memory|mutex|new|numeric|ostream|queue|random|ratio|regex|scoped_allocator|set|shared_mutex|sstream|stack|stdexcept|streambuf|string|strstream|system_error|thread|tuple|type_traits|typeindex|typeinfo|unordered_map|unordered_set|utility|valarray|vector)[">]$' 16 | Priority: 20 17 | - Regex: '^<' 18 | Priority: 30 19 | - Regex: '^"(drake|drake_external_examples)' 20 | Priority: 50 21 | - Regex: '^"' 22 | Priority: 40 23 | -------------------------------------------------------------------------------- /drake_cmake_installed/.github/ci_build_test: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # SPDX-License-Identifier: MIT-0 3 | 4 | set -euxo pipefail 5 | 6 | cmake --version 7 | 8 | mkdir build 9 | pushd build 10 | 11 | cmake -DCMAKE_PREFIX_PATH=$HOME/drake "$@" .. 12 | make 13 | ctest -V . 14 | 15 | popd 16 | 17 | chmod -R a+w build || true 18 | rm -rf build 19 | -------------------------------------------------------------------------------- /drake_cmake_installed/.github/ubuntu_setup: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # SPDX-License-Identifier: MIT-0 3 | 4 | set -euxo pipefail 5 | 6 | echo 'APT::Acquire::Retries "4";' > /etc/apt/apt.conf.d/80-acquire-retries 7 | echo 'APT::Get::Assume-Yes "true";' > /etc/apt/apt.conf.d/90-get-assume-yes 8 | 9 | export DEBIAN_FRONTEND='noninteractive' 10 | 11 | setup/install_prereqs "$@" 12 | -------------------------------------------------------------------------------- /drake_cmake_installed/.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT-0 2 | 3 | --- 4 | name: ci 5 | on: 6 | push: 7 | branches: 8 | - main 9 | pull_request: 10 | branches: 11 | - main 12 | schedule: 13 | - cron: '0 12 * * *' 14 | workflow_dispatch: 15 | inputs: 16 | linux_jammy_package_tar: 17 | description: 'Drake linux-jammy-*-packaging .tar.gz artifact URL' 18 | required: false 19 | mac_arm_sonoma_package_tar: 20 | description: 'Drake mac-arm-sonoma-*-packaging .tar.gz artifact URL' 21 | required: false 22 | concurrency: 23 | # Cancel previous CI runs when additional commits are added to a pull request. 24 | # This will not cancel CI runs associated with `schedule` or `push`. 25 | group: ${{ github.head_ref || github.run_id }} 26 | cancel-in-progress: true 27 | jobs: 28 | macos_sonoma_arm_cmake_installed: 29 | name: macos sonoma 14 arm 30 | runs-on: macos-14 31 | steps: 32 | - name: checkout 33 | uses: actions/checkout@v4 34 | # See issue https://github.com/actions/setup-python/issues/577. There is 35 | # some kind of environment conflict between the symlinks found in the 36 | # GitHub Actions runner and `brew upgrade python` where `brew` detects and 37 | # refuses to overwrite symlinks. The cause for our runs is not clear, 38 | # we do not use that action, but if that issue is closed this section 39 | # can be removed. 40 | - name: sanitize GHA / brew python environment 41 | run: | 42 | # Remove the symlinks that cause issues. 43 | find /usr/local/bin -lname '*/Library/Frameworks/Python.framework/*' -delete 44 | sudo rm -rf /Library/Frameworks/Python.framework/ 45 | - name: setup 46 | working-directory: drake_cmake_installed 47 | run: | 48 | args=() 49 | if [[ '${{ github.event.inputs.mac_arm_sonoma_package_tar }}' != '' ]]; then 50 | args+=(--package-url ${{ github.event.inputs.mac_arm_sonoma_package_tar }}) 51 | fi 52 | setup/install_prereqs "${args[@]}" 53 | shell: zsh -efuo pipefail {0} 54 | - name: cmake_installed build and test 55 | working-directory: drake_cmake_installed 56 | run: .github/ci_build_test 57 | shell: zsh -efuo pipefail {0} 58 | ubuntu_jammy_cmake_installed: 59 | name: ubuntu 22.04 jammy 60 | runs-on: ubuntu-latest 61 | container: ubuntu:jammy 62 | steps: 63 | - name: checkout 64 | uses: actions/checkout@v4 65 | - name: setup 66 | working-directory: drake_cmake_installed 67 | run: | 68 | args=() 69 | if [[ '${{ github.event.inputs.linux_jammy_package_tar }}' != '' ]]; then 70 | args+=(--package-url ${{ github.event.inputs.linux_jammy_package_tar }}) 71 | fi 72 | .github/ubuntu_setup "${args[@]}" 73 | shell: bash 74 | - name: cmake_installed build and test 75 | working-directory: drake_cmake_installed 76 | run: .github/ci_build_test 77 | shell: bash 78 | -------------------------------------------------------------------------------- /drake_cmake_installed/.gitignore: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT-0 2 | 3 | /.idea/ 4 | /build/ 5 | /cmake-build-*/ 6 | -------------------------------------------------------------------------------- /drake_cmake_installed/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT-0 2 | 3 | # Note that the minimum required version of CMake to consume a binary 4 | # installation of Drake is lower than the minimum required version 5 | # when building Drake from source (as seen in drake_cmake_external). 6 | # The maximum version below allows for the use of modern policies 7 | # with newer versions of CMake. 8 | cmake_minimum_required(VERSION 3.9...4.0) 9 | project(drake_cmake_installed) 10 | 11 | include(CTest) 12 | 13 | find_package(drake CONFIG REQUIRED) 14 | 15 | find_package(Python3 ${drake_PYTHON_VERSION} EXACT REQUIRED COMPONENTS Interpreter Development) 16 | 17 | execute_process(COMMAND ${Python3_EXECUTABLE}-config --exec-prefix 18 | OUTPUT_VARIABLE PYTHON_EXEC_PREFIX 19 | OUTPUT_STRIP_TRAILING_WHITESPACE 20 | ) 21 | list(APPEND CMAKE_PREFIX_PATH "${PYTHON_EXEC_PREFIX}") 22 | 23 | get_filename_component(DRAKE_PYTHONPATH 24 | "${drake_DIR}/../../python${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR}/site-packages" 25 | REALPATH 26 | ) 27 | 28 | set(CMAKE_CXX_EXTENSIONS OFF) 29 | set(CMAKE_CXX_STANDARD 20) 30 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 31 | set(CMAKE_POSITION_INDEPENDENT_CODE ON) 32 | 33 | add_subdirectory(src) 34 | add_subdirectory(third_party) 35 | -------------------------------------------------------------------------------- /drake_cmake_installed/CPPLINT.cfg: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT-0 2 | 3 | set noparent 4 | 5 | filter=-build/c++11 6 | filter=-build/header_guard 7 | filter=-build/include_subdir 8 | -------------------------------------------------------------------------------- /drake_cmake_installed/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2017-2025 by the drake-external-examples developers. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so. 9 | 10 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 11 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 12 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 13 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 14 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 15 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 16 | SOFTWARE. 17 | -------------------------------------------------------------------------------- /drake_cmake_installed/README.md: -------------------------------------------------------------------------------- 1 | # CMake Project with an Installed Drake 2 | 3 | This uses the CMake `find_package(drake)` 4 | mechanism to find an installed instance of Drake. 5 | 6 | # Instructions 7 | 8 | ## Download and Install Prerequisites 9 | 10 | First, run the `install_prereqs` script to download the 11 | Drake source to `$HOME/drake/`. This also run's Drake's 12 | setup script to install the required packages depending 13 | on your operating system: 14 | 15 | ```bash 16 | setup/install_prereqs 17 | ``` 18 | 19 | See [below](#alternative-versions) for alternative versions of 20 | Drake to download. 21 | 22 | ## Build Everything 23 | 24 | Then run the following to build using CMake from the current directory 25 | (`drake-external-examples/drake_cmake_installed`): 26 | 27 | ```bash 28 | mkdir build && cd build 29 | cmake -DCMAKE_PREFIX_PATH=$HOME/drake .. 30 | make 31 | ``` 32 | 33 | You can also optionally run the tests by calling `make test`. 34 | 35 | ## Alternative Versions 36 | 37 | By default, `install_prereqs` script gets the latest version 38 | of Drake (usually last night's build). Ignore this if that 39 | version is desired. Otherwise, the following are alternative 40 | options for which version of Drake to download. 41 | 42 | To use any of these options, instead of running `install_prereqs`, 43 | run the code for whichever option you prefer below. Each option 44 | downloads Drake to the `$HOME` directory. 45 | 46 | 1. A specific version (date-stamped) 47 | 48 | Replace `jammy` (for Ubuntu 22.04) with `noble` or `mac-arm64` 49 | to download the version needed for your operating system. 50 | 51 | ```bash 52 | curl -O https://drake-packages.csail.mit.edu/drake/nightly/drake-0.0.20250131-jammy.tar.gz 53 | tar -xvzf drake-0.0.20250131-jammy.tar.gz -C $HOME 54 | $HOME/drake/share/drake/setup/install_prereqs 55 | ``` 56 | 57 | See [Installation via Direct Download](https://drake.mit.edu/from_binary.html) 58 | for more information. 59 | 60 | 2. Manual installation 61 | 62 | ```bash 63 | git clone https://github.com/RobotLocomotion/drake.git 64 | cd drake 65 | setup/install_prereqs 66 | (mkdir build && cd build && cmake -DCMAKE_INSTALL_PREFIX=$HOME/drake .. && make) 67 | ``` 68 | 69 | 3. Manual installation w/ licensed Gurobi 70 | Install & setup gurobi (http://drake.mit.edu/bazel.html?highlight=gurobi#install-on-ubuntu) 71 | 72 | ```bash 73 | git clone https://github.com/RobotLocomotion/drake.git 74 | cd drake 75 | setup/install_prereqs 76 | (mkdir build && cd build && cmake -DCMAKE_INSTALL_PREFIX=$HOME/drake -DWITH_GUROBI=ON .. && make) 77 | ``` 78 | 79 | Finally, for the code in this example, ensure you have `python3-all-dev` 80 | installed if on Ubuntu. 81 | 82 | # Examples 83 | 84 | Drake-specific examples: 85 | 86 | * [Simple Continuous Time System](src/simple_continuous_time_system/README.md) 87 | * [Particle System](src/particle) 88 | * [Find Resources](src/find_resource/README.md) 89 | 90 | # Developer Testing 91 | 92 | If you are a Drake Developer making build or API changes that may affect the 93 | downstream interface, please test this locally on your system. 94 | 95 | These build instructions are adapted from those above, but will use an existing 96 | source tree of Drake (but *not* installing it to `$HOME/drake`), 97 | build this project, and then run all available tests: 98 | 99 | ```bash 100 | # Build development version of Drake, ensuring no old artifacts are present. 101 | cd drake # Where you are developing. 102 | rm -rf build && mkdir build && cd build 103 | cmake .. # Configure Gurobi, Mosek, etc, if needed. 104 | # Build locally. 105 | make 106 | # Record the build's install directory. 107 | drake_install=${PWD}/install 108 | 109 | # Build this project using a development version of Drake. 110 | cd .. 111 | # Clone this repository if you have not already. 112 | git clone https://github.com/RobotLocomotion/drake-external-examples.git 113 | cd drake-external-examples/drake_cmake_installed 114 | # Follow "Install Prerequisites" in the instructions linked above if you 115 | # have not already. 116 | mkdir build && cd build 117 | cmake -DCMAKE_PREFIX_PATH=${drake_install} .. 118 | make 119 | ctest 120 | ``` 121 | -------------------------------------------------------------------------------- /drake_cmake_installed/setup/install_prereqs: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # SPDX-License-Identifier: MIT-0 4 | 5 | set -euxo pipefail 6 | 7 | package_url= 8 | 9 | while [ "${1:-}" != "" ]; do 10 | case "$1" in 11 | --package-url) 12 | shift 13 | if [[ $# -eq 0 ]]; then 14 | echo 'No argument specified for --package-url' >&2 15 | exit 1 16 | fi 17 | package_url="$1" 18 | ;; 19 | *) 20 | echo 'Invalid command line argument' >&2 21 | exit 1 22 | esac 23 | shift 24 | done 25 | 26 | maybe_sudo= 27 | 28 | case "$OSTYPE" in 29 | darwin*) 30 | # Mac specific installations 31 | if [[ "${EUID}" -eq 0 ]]; then 32 | echo 'This script must NOT be run as root' >&2 33 | exit 1 34 | fi 35 | 36 | # Download the drake source 37 | curl -o drake.tar.gz "${package_url:-https://drake-packages.csail.mit.edu/drake/nightly/drake-latest-mac-arm64.tar.gz}" 38 | trap 'rm -f drake.tar.gz' EXIT 39 | tar -xf drake.tar.gz -C $HOME 40 | ;; 41 | 42 | linux*) 43 | # Ubuntu specific installations 44 | if [[ "${EUID}" -ne 0 ]]; then 45 | maybe_sudo=sudo 46 | fi 47 | 48 | ${maybe_sudo} apt-get update 49 | ${maybe_sudo} apt-get install --no-install-recommends lsb-release 50 | 51 | if [[ "$(lsb_release -sc)" != 'jammy' ]]; then 52 | echo 'This script requires Ubuntu 22.04 (Jammy)' >&2 53 | exit 3 54 | fi 55 | 56 | ${maybe_sudo} apt-get install --no-install-recommends $(cat < 8 | #include 9 | 10 | #include 11 | 12 | namespace drake_external_examples { 13 | namespace { 14 | 15 | int main() { 16 | drake::FindResourceOrThrow("drake/examples/pendulum/Pendulum.urdf"); 17 | 18 | try { 19 | drake::FindResourceOrThrow("nobody_home.urdf"); 20 | std::cerr << "Should have thrown" << std::endl; 21 | return 1; 22 | } catch (const std::runtime_error&) { 23 | } 24 | 25 | return 0; 26 | } 27 | 28 | } // namespace 29 | } // namespace drake_external_examples 30 | 31 | int main() { return drake_external_examples::main(); } 32 | -------------------------------------------------------------------------------- /drake_cmake_installed/src/find_resource/find_resource_example.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT-0 2 | 3 | """Test the Drake find resource API.""" 4 | 5 | from pydrake.common import FindResourceOrThrow 6 | 7 | FindResourceOrThrow('drake/examples/pendulum/Pendulum.urdf') 8 | -------------------------------------------------------------------------------- /drake_cmake_installed/src/import_all_test.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT-0 2 | 3 | """ 4 | Provides an example of importing all modules available in pydrake. 5 | """ 6 | 7 | import pydrake.all 8 | -------------------------------------------------------------------------------- /drake_cmake_installed/src/particle/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT-0 2 | 3 | add_library(particle particle.cc particle.h) 4 | target_link_libraries(particle drake::drake) 5 | 6 | add_executable(particle_test particle_test.cc) 7 | target_link_libraries(particle_test particle drake::drake gtest) 8 | add_test(NAME cc_particle_test COMMAND particle_test) 9 | set_tests_properties(cc_particle_test PROPERTIES LABELS small TIMEOUT 60) 10 | 11 | add_test(NAME python_particle_test 12 | COMMAND Python3::Interpreter -B -m unittest particle_test 13 | ) 14 | set_tests_properties(python_particle_test PROPERTIES 15 | ENVIRONMENT "PYTHONPATH=${DRAKE_PYTHONPATH}" 16 | LABELS small 17 | REQUIRED_FILES "${CMAKE_CURRENT_SOURCE_DIR}/particle_test.py" 18 | TIMEOUT 60 19 | WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" 20 | ) 21 | -------------------------------------------------------------------------------- /drake_cmake_installed/src/particle/particle.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT-0 2 | 3 | #include "particle.h" 4 | 5 | #include 6 | #include 7 | 8 | namespace drake_external_examples { 9 | namespace particles { 10 | 11 | template 12 | Particle::Particle() { 13 | // A 1D input vector for acceleration. 14 | this->DeclareInputPort(drake::systems::kUseDefaultName, 15 | drake::systems::kVectorValued, 1); 16 | // Adding one generalized position and one generalized velocity. 17 | this->DeclareContinuousState(1, 1, 0); 18 | // A 2D output vector for position and velocity. 19 | this->DeclareVectorOutputPort(drake::systems::kUseDefaultName, 20 | drake::systems::BasicVector(2), 21 | &Particle::CopyStateOut); 22 | } 23 | 24 | template 25 | void Particle::CopyStateOut(const drake::systems::Context& context, 26 | drake::systems::BasicVector* output) const { 27 | // Get current state from context. 28 | const drake::systems::VectorBase& continuous_state_vector = 29 | context.get_continuous_state_vector(); 30 | // Write system output. 31 | output->set_value(continuous_state_vector.CopyToVector()); 32 | } 33 | 34 | template 35 | void Particle::DoCalcTimeDerivatives( 36 | const drake::systems::Context& context, 37 | drake::systems::ContinuousState* derivatives) const { 38 | // Get current state from context. 39 | const drake::systems::VectorBase& continuous_state_vector = 40 | context.get_continuous_state_vector(); 41 | // Obtain the structure we need to write into. 42 | drake::systems::VectorBase& derivatives_vector = 43 | derivatives->get_mutable_vector(); 44 | // Get current input acceleration value. 45 | const drake::systems::BasicVector* input_vector = 46 | this->EvalVectorInput(context, 0); 47 | // Set the derivatives. The first one is 48 | // velocity and the second one is acceleration. 49 | derivatives_vector.SetAtIndex(0, continuous_state_vector.GetAtIndex(1)); 50 | derivatives_vector.SetAtIndex(1, input_vector->GetAtIndex(0)); 51 | } 52 | 53 | template class Particle; 54 | 55 | } // namespace particles 56 | } // namespace drake_external_examples 57 | -------------------------------------------------------------------------------- /drake_cmake_installed/src/particle/particle.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT-0 2 | 3 | #pragma once 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | namespace drake_external_examples { 12 | namespace particles { 13 | 14 | /// A linear 1DOF particle system. 15 | /// 16 | /// With very simple dynamics @f$ \ddot x = a @f$, this system can be 17 | /// described in terms of its: 18 | /// 19 | /// - Inputs: 20 | /// - linear acceleration (input index 0), in @f$ m/s^2 @f$ units. 21 | /// - States/Outputs: 22 | /// - linear position (state/output index 0), in @f$ m @f$ units. 23 | /// - linear velocity (state/output index 1), in @f$ m/s @f$ units. 24 | /// 25 | /// @tparam_double_only 26 | /// 27 | template 28 | class Particle final : public drake::systems::LeafSystem { 29 | public: 30 | DRAKE_NO_COPY_NO_MOVE_NO_ASSIGN(Particle); 31 | 32 | /// A constructor that initializes the system. 33 | Particle(); 34 | 35 | protected: 36 | void CopyStateOut(const drake::systems::Context& context, 37 | drake::systems::BasicVector* output) const; 38 | 39 | void DoCalcTimeDerivatives( 40 | const drake::systems::Context& context, 41 | drake::systems::ContinuousState* derivatives) const override; 42 | }; 43 | 44 | } // namespace particles 45 | } // namespace drake_external_examples 46 | -------------------------------------------------------------------------------- /drake_cmake_installed/src/particle/particle.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT-0 2 | 3 | from pydrake.systems.framework import BasicVector 4 | from pydrake.systems.framework import LeafSystem 5 | from pydrake.systems.framework import PortDataType 6 | 7 | 8 | class Particle(LeafSystem): 9 | """ 10 | A linear 1DOF particle system. 11 | 12 | With very simple dynamics xdotdot = a, this system can be described in 13 | terms of its: 14 | 15 | Inputs: 16 | linear acceleration (input index 0), in m/s^2 units. 17 | 18 | States/Outputs: 19 | linear position (state/output index 0), in m units. 20 | linear velocity (state/output index 1), in m/s units. 21 | """ 22 | def __init__(self): 23 | LeafSystem.__init__(self) 24 | # A 1D input vector for acceleration. 25 | self.DeclareInputPort('acceleration', PortDataType.kVectorValued, 1) 26 | # Adding one generalized position and one generalized velocity. 27 | self.DeclareContinuousState(1, 1, 0) 28 | # A 2D output vector for position and velocity. 29 | self.DeclareVectorOutputPort('postion_and_velocity', BasicVector(2), 30 | self.CopyStateOut) 31 | 32 | def CopyStateOut(self, context, output): 33 | # Get current state from context. 34 | continuous_state_vector = context.get_continuous_state_vector() 35 | # Write system output. 36 | output.SetFromVector(continuous_state_vector.CopyToVector()) 37 | 38 | def DoCalcTimeDerivatives(self, context, derivatives): 39 | # Get current state from context. 40 | continuous_state_vector = x = context.get_continuous_state_vector() 41 | # Obtain the structure we need to write into. 42 | derivatives_vector = derivatives.get_mutable_vector() 43 | # Get current input acceleration value. 44 | input_vector = self.EvalVectorInput(context, 0) 45 | # Set the derivatives. The first one is velocity and the second one is 46 | # acceleration. 47 | derivatives_vector.SetAtIndex(0, continuous_state_vector.GetAtIndex(1)) 48 | derivatives_vector.SetAtIndex(1, input_vector.GetAtIndex(0)) 49 | -------------------------------------------------------------------------------- /drake_cmake_installed/src/particle/particle_test.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT-0 2 | 3 | #include "particle.h" // IWYU pragma: associated 4 | 5 | #include 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | namespace drake_external_examples { 16 | namespace particles { 17 | namespace { 18 | 19 | /// 20 | /// A test fixture class for Particle systems. 21 | /// 22 | /// @tparam T must be a valid Eigen ScalarType. 23 | /// 24 | template 25 | class ParticleTest : public ::testing::Test { 26 | protected: 27 | /// Arrange a Particle as the Device Under Test. 28 | void SetUp() override { 29 | this->dut_ = std::make_unique>(); 30 | this->context_ = this->dut_->CreateDefaultContext(); 31 | this->output_ = this->dut_->AllocateOutput(); 32 | this->derivatives_ = this->dut_->AllocateTimeDerivatives(); 33 | } 34 | 35 | /// System (aka Device Under Test) being tested. 36 | std::unique_ptr> dut_; 37 | /// Context for the given @p dut_. 38 | std::unique_ptr> context_; 39 | /// Outputs of the given @p dut_. 40 | std::unique_ptr> output_; 41 | /// Derivatives of the given @p dut_. 42 | std::unique_ptr> derivatives_; 43 | }; 44 | 45 | TYPED_TEST_SUITE_P(ParticleTest); 46 | 47 | /// Makes sure a Particle output is consistent with its 48 | /// state (position and velocity). 49 | TYPED_TEST_P(ParticleTest, OutputTest) { 50 | // Initialize state. 51 | drake::systems::VectorBase& continuous_state_vector = 52 | this->context_->get_mutable_continuous_state_vector(); 53 | continuous_state_vector.SetAtIndex( 54 | 0, static_cast(10.0)); // x0 = 10 m. 55 | continuous_state_vector.SetAtIndex( 56 | 1, static_cast(1.0)); // x1 = 1 m/s. 57 | // Compute outputs. 58 | this->dut_->CalcOutput(*this->context_, this->output_.get()); 59 | drake::systems::BasicVector* output_vector = 60 | this->output_->GetMutableVectorData(0); 61 | // Check results. 62 | EXPECT_EQ(output_vector->GetAtIndex(0), 63 | static_cast(10.0)); // y0 == x0 64 | EXPECT_EQ(output_vector->GetAtIndex(1), 65 | static_cast(1.0)); // y1 == x1 66 | } 67 | 68 | /// Makes sure a Particle system state derivatives are 69 | /// consistent with its state and input (velocity and acceleration). 70 | TYPED_TEST_P(ParticleTest, DerivativesTest) { 71 | // Set input. 72 | const drake::systems::InputPort& input_port = 73 | this->dut_->get_input_port(0); 74 | drake::VectorX u0(input_port.size()); 75 | u0 << 1.0; // m/s^2 76 | input_port.FixValue(this->context_.get(), u0); 77 | // Set state. 78 | drake::systems::VectorBase& continuous_state_vector = 79 | this->context_->get_mutable_continuous_state_vector(); 80 | continuous_state_vector.SetAtIndex( 81 | 0, static_cast(0.0)); // x0 = 0 m 82 | continuous_state_vector.SetAtIndex( 83 | 1, static_cast(2.0)); // x1 = 2 m/s 84 | // Compute derivatives. 85 | this->dut_->CalcTimeDerivatives(*this->context_, this->derivatives_.get()); 86 | const drake::systems::VectorBase& derivatives_vector = 87 | this->derivatives_->get_vector(); 88 | // Check results. 89 | EXPECT_EQ(derivatives_vector.GetAtIndex(0), 90 | static_cast(2.0)); // x0dot == x1 91 | EXPECT_EQ(derivatives_vector.GetAtIndex(1), 92 | static_cast(1.0)); // x1dot == u0 93 | } 94 | 95 | REGISTER_TYPED_TEST_SUITE_P(ParticleTest, OutputTest, DerivativesTest); 96 | 97 | INSTANTIATE_TYPED_TEST_SUITE_P(WithDoubles, ParticleTest, double); 98 | 99 | } // namespace 100 | } // namespace particles 101 | } // namespace drake_external_examples 102 | 103 | int main(int argc, char** argv) { 104 | ::testing::InitGoogleTest(&argc, argv); 105 | return RUN_ALL_TESTS(); 106 | } 107 | -------------------------------------------------------------------------------- /drake_cmake_installed/src/particle/particle_test.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT-0 2 | 3 | import unittest 4 | 5 | from particle import Particle 6 | 7 | 8 | class TestParticle(unittest.TestCase): 9 | """A test case for Particle systems.""" 10 | def setUp(self): 11 | # System (aka 'device under test') being tested. 12 | self.dut = Particle() 13 | # Context for the given dut. 14 | self.context = self.dut.CreateDefaultContext() 15 | # Outputs of the given dut. 16 | self.output = self.dut.AllocateOutput() 17 | # Derivatives of the given dut. 18 | self.derivatives = self.dut.AllocateTimeDerivatives() 19 | 20 | def test_output(self): 21 | """ 22 | Makes sure a Particle output is consistent with its state (position and 23 | velocity). 24 | """ 25 | # Initialize state. 26 | continuous_state_vector = \ 27 | self.context.get_mutable_continuous_state_vector() 28 | continuous_state_vector.SetAtIndex(0, 10.0) # x0 = 10 m. 29 | continuous_state_vector.SetAtIndex(1, 1.0) # x1 = 1 m/s. 30 | # Compute outputs. 31 | self.dut.CalcOutput(self.context, self.output) 32 | output_vector = self.output.get_vector_data(0) 33 | # Check results. 34 | self.assertEqual(output_vector.GetAtIndex(0), 10.0) # y0 == x0 35 | self.assertEqual(output_vector.GetAtIndex(1), 1.0) # y1 == x1 36 | 37 | def test_derivatives(self): 38 | """ 39 | Makes sure a Particle system state derivatives are consistent with its 40 | state and input (velocity and acceleration). 41 | """ 42 | # Set input. 43 | input_port = self.dut.get_input_port(0) 44 | input_port.FixValue(self.context, 1.0) # u0 = 1 m/s^2 45 | # Set state. 46 | continuous_state_vector = \ 47 | self.context.get_mutable_continuous_state_vector() 48 | continuous_state_vector.SetAtIndex(0, 0.0) # x0 = 0 m 49 | continuous_state_vector.SetAtIndex(1, 2.0) # x1 = 2 m/s 50 | # Compute derivatives. 51 | self.dut.CalcTimeDerivatives(self.context, self.derivatives) 52 | derivatives_vector = self.derivatives.get_vector() 53 | # Check results. 54 | self.assertEqual(derivatives_vector.GetAtIndex(0), 2.0) # x0dot == x1 55 | self.assertEqual(derivatives_vector.GetAtIndex(1), 1.0) # x1dot == u0 56 | 57 | 58 | if __name__ == '__main__': 59 | unittest.main() 60 | -------------------------------------------------------------------------------- /drake_cmake_installed/src/simple_bindings/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT-0 2 | 3 | find_package(pybind11 CONFIG REQUIRED) 4 | 5 | pybind11_add_module(simple_bindings MODULE simple_bindings.cc) 6 | target_link_libraries(simple_bindings PUBLIC drake::drake) 7 | # N.B. `pybind11_add_module` normally sets the default visibility to "hidden" 8 | # to avoid warnings. However, we need the default visibility to be public so 9 | # template instantions that are bound in Python (e.g. `drake::Value<>`) 10 | # maintain the same RTTI across translation units. 11 | # Additionally, in Drake we avoid mixing hidden and public symbols, so we 12 | # can confidently re-enable this setting for Drake's symbols. 13 | # For more information, see: 14 | # https://github.com/pybind/pybind11/issues/2479 15 | set_target_properties(simple_bindings PROPERTIES CXX_VISIBILITY_PRESET default) 16 | 17 | add_test(NAME simple_bindings_test COMMAND 18 | "${Python3_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/simple_bindings_test.py") 19 | set_tests_properties(simple_bindings_test PROPERTIES 20 | # Using `pybind11/tests/test_cmake_build/installed_target` as an example. 21 | ENVIRONMENT "PYTHONPATH=$:${DRAKE_PYTHONPATH}") 22 | -------------------------------------------------------------------------------- /drake_cmake_installed/src/simple_bindings/simple_bindings.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT-0 2 | 3 | /** 4 | * @file 5 | * Provides an example of creating a simple Drake C++ system and binding it in 6 | * pybind11, to be used with pydrake. 7 | */ 8 | 9 | #include 10 | 11 | #include 12 | 13 | namespace py = pybind11; 14 | 15 | using drake::systems::BasicVector; 16 | using drake::systems::Context; 17 | using drake::systems::LeafSystem; 18 | using drake::systems::kVectorValued; 19 | 20 | namespace drake_external_examples { 21 | namespace { 22 | 23 | /// Adds a constant to an input. 24 | template 25 | class SimpleAdder : public LeafSystem { 26 | public: 27 | explicit SimpleAdder(T add) 28 | : add_(add) { 29 | this->DeclareInputPort("in", kVectorValued, 1); 30 | this->DeclareVectorOutputPort( 31 | "out", BasicVector(1), &SimpleAdder::CalcOutput); 32 | } 33 | 34 | private: 35 | void CalcOutput(const Context& context, BasicVector* output) const { 36 | auto u = this->get_input_port(0).Eval(context); 37 | auto&& y = output->get_mutable_value(); 38 | y.array() = u.array() + add_; 39 | } 40 | 41 | const T add_{}; 42 | }; 43 | 44 | PYBIND11_MODULE(simple_bindings, m) { 45 | m.doc() = "Example module interfacing with pydrake and Drake C++"; 46 | 47 | py::module::import("pydrake.systems.framework"); 48 | 49 | using T = double; 50 | 51 | py::class_, LeafSystem>(m, "SimpleAdder") 52 | .def(py::init(), py::arg("add")); 53 | } 54 | 55 | } // namespace 56 | } // namespace drake_external_examples 57 | -------------------------------------------------------------------------------- /drake_cmake_installed/src/simple_bindings/simple_bindings_test.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT-0 2 | 3 | """ 4 | Provides an example of using pybind11-bound Drake C++ system with pydrake. 5 | """ 6 | 7 | from __future__ import print_function 8 | 9 | from simple_bindings import SimpleAdder 10 | 11 | import numpy as np 12 | 13 | from pydrake.systems.analysis import Simulator 14 | from pydrake.systems.framework import ( 15 | DiagramBuilder, 16 | ) 17 | from pydrake.systems.primitives import ( 18 | ConstantVectorSource, 19 | VectorLogSink, 20 | ) 21 | 22 | 23 | def main(): 24 | builder = DiagramBuilder() 25 | source = builder.AddSystem(ConstantVectorSource([10.])) 26 | adder = builder.AddSystem(SimpleAdder(100.)) 27 | builder.Connect(source.get_output_port(0), adder.get_input_port(0)) 28 | logger = builder.AddSystem(VectorLogSink(1)) 29 | builder.Connect(adder.get_output_port(0), logger.get_input_port(0)) 30 | diagram = builder.Build() 31 | 32 | simulator = Simulator(diagram) 33 | simulator.AdvanceTo(1) 34 | 35 | x = logger.FindLog(simulator.get_context()).data() 36 | print("Output values: {}".format(x)) 37 | assert np.allclose(x, 110.) 38 | 39 | 40 | if __name__ == "__main__": 41 | main() 42 | -------------------------------------------------------------------------------- /drake_cmake_installed/src/simple_continuous_time_system/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT-0 2 | 3 | add_executable(simple_continuous_time_system simple_continuous_time_system.cc) 4 | target_link_libraries(simple_continuous_time_system drake::drake) 5 | add_test(NAME simple_continuous_time_system 6 | COMMAND simple_continuous_time_system 7 | ) 8 | -------------------------------------------------------------------------------- /drake_cmake_installed/src/simple_continuous_time_system/README.md: -------------------------------------------------------------------------------- 1 | # Simple Continuous Time System 2 | 3 | This is the hello world for the `drake::system` classes. 4 | 5 | ## How do I build it? 6 | 7 | Follow the instructions in the [README](../../README.md) for this project. 8 | 9 | ## How do I run it? 10 | 11 | ``` 12 | # Switch to the build directory 13 | cd build/src/simple_continuous_time_system 14 | # Run the tests 15 | ./simple_continuous_time_system 16 | ``` 17 | 18 | Note that there is no interaction nor output from this program. It is merely intended to exercise the code. -------------------------------------------------------------------------------- /drake_cmake_installed/src/simple_continuous_time_system/simple_continuous_time_system.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT-0 2 | 3 | // Simple Continuous Time System Example 4 | // 5 | // This is meant to be a sort of "hello world" example for the drake::system 6 | // classes. It defines a very simple continuous time system and simulates it 7 | // from a given initial condition. 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | namespace drake_external_examples { 19 | namespace systems { 20 | 21 | // Simple Continuous Time System 22 | // xdot = -x + x³ 23 | // y = x 24 | class SimpleContinuousTimeSystem : public drake::systems::LeafSystem { 25 | public: 26 | SimpleContinuousTimeSystem() { 27 | DeclareVectorOutputPort("y", drake::systems::BasicVector(1), 28 | &SimpleContinuousTimeSystem::CopyStateOut); 29 | DeclareContinuousState(1); // One state variable. 30 | } 31 | 32 | private: 33 | // xdot = -x + x³ 34 | void DoCalcTimeDerivatives( 35 | const drake::systems::Context& context, 36 | drake::systems::ContinuousState* derivatives) const override { 37 | const double x = context.get_continuous_state()[0]; 38 | const double xdot = -x + std::pow(x, 3.0); 39 | (*derivatives)[0] = xdot; 40 | } 41 | 42 | // y = x 43 | void CopyStateOut(const drake::systems::Context& context, 44 | drake::systems::BasicVector* output) const { 45 | const double x = context.get_continuous_state()[0]; 46 | (*output)[0] = x; 47 | } 48 | }; 49 | 50 | } // namespace systems 51 | } // namespace drake_external_examples 52 | 53 | int main() { 54 | // Create the simple system. 55 | drake_external_examples::systems::SimpleContinuousTimeSystem system; 56 | 57 | // Create the simulator. 58 | drake::systems::Simulator simulator(system); 59 | 60 | // Set the initial conditions x(0). 61 | drake::systems::ContinuousState& state = 62 | simulator.get_mutable_context().get_mutable_continuous_state(); 63 | state[0] = 0.9; 64 | 65 | // Simulate for 10 seconds. 66 | simulator.AdvanceTo(10); 67 | 68 | // Make sure the simulation converges to the stable fixed point at x = 0. 69 | DRAKE_DEMAND(state[0] < 1.0e-4); 70 | 71 | return 0; 72 | } 73 | -------------------------------------------------------------------------------- /drake_cmake_installed/third_party/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT-0 2 | 3 | find_package(Threads) 4 | 5 | add_library(gtest STATIC googletest/gtest-all.cc googletest/gtest/gtest.h) 6 | target_include_directories(gtest PUBLIC googletest) 7 | target_link_libraries(gtest Threads::Threads) 8 | -------------------------------------------------------------------------------- /drake_cmake_installed/third_party/googletest/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2008, Google Inc. 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | * Neither the name of Google Inc. nor the names of its 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /drake_cmake_installed_apt/.clang-format: -------------------------------------------------------------------------------- 1 | # -*- mode: yaml -*- 2 | # vi: set ft=yaml : 3 | # SPDX-License-Identifier: MIT-0 4 | 5 | --- 6 | BasedOnStyle: Google 7 | --- 8 | Language: Cpp 9 | DerivePointerAlignment: false 10 | PointerAlignment: Left 11 | 12 | IncludeCategories: 13 | - Regex: '^[<"](aio|arpa/inet|assert|complex|cpio|ctype|curses|dirent|dlfcn|errno|fcntl|fenv|float|fmtmsg|fnmatch|ftw|glob|grp|iconv|inttypes|iso646|langinfo|libgen|limits|locale|math|monetary|mqueue|ndbm|netdb|net/if|netinet/in|netinet/tcp|nl_types|poll|pthread|pwd|regex|sched|search|semaphore|setjmp|signal|spawn|stdalign|stdarg|stdatomic|stdbool|stddef|stdint|stdio|stdlib|stdnoreturn|string|strings|stropts|sys/ipc|syslog|sys/mman|sys/msg|sys/resource|sys/select|sys/sem|sys/shm|sys/socket|sys/stat|sys/statvfs|sys/time|sys/times|sys/types|sys/uio|sys/un|sys/utsname|sys/wait|tar|term|termios|tgmath|threads|time|trace|uchar|ulimit|uncntrl|unistd|utime|utmpx|wchar|wctype|wordexp)\.h[">]$' 14 | Priority: 10 15 | - Regex: '^[<"](algorithm|array|atomic|bitset|cassert|ccomplex|cctype|cerrno|cfenv|cfloat|chrono|cinttypes|ciso646|climits|clocale|cmath|codecvt|complex|condition_variable|csetjmp|csignal|cstdalign|cstdarg|cstdbool|cstddef|cstdint|cstdio|cstdlib|cstring|ctgmath|ctime|cuchar|cwchar|cwctype|deque|exception|forward_list|fstream|functional|future|initializer_list|iomanip|ios|iosfwd|iostream|istream|iterator|limits|list|locale|map|memory|mutex|new|numeric|ostream|queue|random|ratio|regex|scoped_allocator|set|shared_mutex|sstream|stack|stdexcept|streambuf|string|strstream|system_error|thread|tuple|type_traits|typeindex|typeinfo|unordered_map|unordered_set|utility|valarray|vector)[">]$' 16 | Priority: 20 17 | - Regex: '^<' 18 | Priority: 30 19 | - Regex: '^"(drake|drake_external_examples)' 20 | Priority: 50 21 | - Regex: '^"' 22 | Priority: 40 23 | -------------------------------------------------------------------------------- /drake_cmake_installed_apt/.github/ci_build_test: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # SPDX-License-Identifier: MIT-0 3 | 4 | set -euxo pipefail 5 | 6 | cmake --version 7 | 8 | mkdir build 9 | pushd build 10 | 11 | cmake .. 12 | make 13 | ctest -V . 14 | 15 | popd 16 | 17 | chmod -R a+w build || true 18 | rm -rf build 19 | -------------------------------------------------------------------------------- /drake_cmake_installed_apt/.github/ubuntu_apt_setup: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # SPDX-License-Identifier: MIT-0 3 | 4 | set -euxo pipefail 5 | 6 | package_url= 7 | 8 | while [ "${1:-}" != "" ]; do 9 | case "$1" in 10 | --package-url) 11 | shift 12 | if [[ $# -eq 0 ]]; then 13 | echo 'No argument specified for --package-url' >&2 14 | exit 1 15 | fi 16 | package_url="$1" 17 | ;; 18 | *) 19 | echo 'Invalid command line argument' >&2 20 | exit 1 21 | esac 22 | shift 23 | done 24 | 25 | export DEBIAN_FRONTEND=noninteractive 26 | 27 | apt-get -qq update || (sleep 30; apt-get -qq update) 28 | apt-get -o Acquire::Retries=4 -o Dpkg::Use-Pty=0 -qy --no-install-recommends \ 29 | install build-essential ca-certificates cmake gnupg lsb-release wget 30 | 31 | if [[ ! -z "${package_url}" ]]; then 32 | # Install a custom Drake package if specified. 33 | wget -O drake.deb ${package_url} 34 | trap 'rm -f drake.deb' EXIT 35 | 36 | apt-get -o Acquire::Retries=4 -o Dpkg::Use-Pty=0 -qy --no-install-recommends \ 37 | install ./drake.deb 38 | else 39 | # Otherwise, install the latest released version. 40 | readonly codename="$(lsb_release -cs)" 41 | 42 | wget -qO- --retry-connrefused https://drake-apt.csail.mit.edu/drake.asc \ 43 | | gpg --dearmor - > /etc/apt/trusted.gpg.d/drake.gpg 44 | echo "deb [arch=amd64] https://drake-apt.csail.mit.edu/${codename} ${codename} main" \ 45 | > /etc/apt/sources.list.d/drake.list 46 | 47 | apt-get -qq update || (sleep 30; apt-get -qq update) 48 | apt-get -o Acquire::Retries=4 -o Dpkg::Use-Pty=0 -qy --no-install-recommends \ 49 | install drake-dev 50 | fi 51 | -------------------------------------------------------------------------------- /drake_cmake_installed_apt/.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT-0 2 | 3 | --- 4 | name: ci 5 | on: 6 | push: 7 | branches: 8 | - main 9 | pull_request: 10 | branches: 11 | - main 12 | schedule: 13 | - cron: '0 12 * * *' 14 | workflow_dispatch: 15 | inputs: 16 | linux_jammy_package_deb: 17 | description: 'Drake linux-jammy-*-packaging .deb artifact URL' 18 | required: false 19 | concurrency: 20 | # Cancel previous CI runs when additional commits are added to a pull request. 21 | # This will not cancel CI runs associated with `schedule` or `push`. 22 | group: ${{ github.head_ref || github.run_id }} 23 | cancel-in-progress: true 24 | jobs: 25 | ubuntu_jammy_cmake_installed_apt: 26 | name: ubuntu 22.04 jammy 27 | runs-on: ubuntu-latest 28 | container: ubuntu:jammy 29 | steps: 30 | - name: checkout 31 | uses: actions/checkout@v4 32 | - name: setup 33 | working-directory: drake_cmake_installed_apt 34 | run: | 35 | args=() 36 | if [[ '${{ github.event.inputs.linux_jammy_package_deb }}' != '' ]]; then 37 | args+=(--package-url ${{ github.event.inputs.linux_jammy_package_deb }}) 38 | fi 39 | .github/ubuntu_apt_setup "${args[@]}" 40 | shell: bash 41 | - name: cmake_installed_apt build and test 42 | working-directory: drake_cmake_installed_apt 43 | run: .github/ci_build_test 44 | shell: bash 45 | -------------------------------------------------------------------------------- /drake_cmake_installed_apt/.gitignore: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT-0 2 | 3 | /.idea/ 4 | /build/ 5 | /cmake-build-*/ 6 | -------------------------------------------------------------------------------- /drake_cmake_installed_apt/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT-0 2 | 3 | # Note that the minimum required version of CMake to consume a binary 4 | # installation of Drake is lower than the minimum required version 5 | # when building Drake from source (as seen in drake_cmake_external). 6 | # The maximum version below allows for the use of modern policies 7 | # with newer versions of CMake. 8 | cmake_minimum_required(VERSION 3.9...4.0) 9 | project(drake_cmake_installed_apt) 10 | 11 | include(CTest) 12 | 13 | set(CMAKE_CXX_EXTENSIONS OFF) 14 | set(CMAKE_CXX_STANDARD 20) 15 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 16 | set(CMAKE_POSITION_INDEPENDENT_CODE ON) 17 | 18 | find_package(Threads MODULE REQUIRED) 19 | 20 | add_library(gtest STATIC 21 | third_party/googletest/1.10/googletest/include/gtest/gtest.h 22 | third_party/googletest/1.10/googletest/src/gtest-all.cc 23 | ) 24 | target_include_directories(gtest PUBLIC 25 | third_party/googletest/1.10/googletest/include 26 | ) 27 | target_link_libraries(gtest Threads::Threads) 28 | 29 | find_package(drake CONFIG REQUIRED PATHS /opt/drake) 30 | find_package(Python3 ${drake_PYTHON_VERSION} EXACT REQUIRED COMPONENTS Interpreter Development) 31 | 32 | get_filename_component(DRAKE_PYTHONPATH "${drake_DIR}" DIRECTORY) 33 | get_filename_component(DRAKE_PYTHONPATH "${DRAKE_PYTHONPATH}" DIRECTORY) 34 | set(DRAKE_PYTHONPATH 35 | "${DRAKE_PYTHONPATH}/python${drake_PYTHON_VERSION}/site-packages" 36 | ) 37 | 38 | add_subdirectory(src) 39 | 40 | -------------------------------------------------------------------------------- /drake_cmake_installed_apt/CPPLINT.cfg: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT-0 2 | 3 | set noparent 4 | 5 | filter=-build/c++11 6 | filter=-build/header_guard 7 | filter=-build/include_subdir 8 | -------------------------------------------------------------------------------- /drake_cmake_installed_apt/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2017-2025 by the drake-external-examples developers. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so. 9 | 10 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 11 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 12 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 13 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 14 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 15 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 16 | SOFTWARE. 17 | -------------------------------------------------------------------------------- /drake_cmake_installed_apt/README.md: -------------------------------------------------------------------------------- 1 | # CMake Project with Drake Installed Using APT 2 | 3 | This example uses the [`cmake`](https://cmake.org/) build system with an 4 | instance of Drake installed using the 5 | [APT](https://manpages.ubuntu.com/manpages/jammy/man8/apt.8.html) package 6 | manager. 7 | 8 | ## Instructions 9 | 10 | Install the `drake-dev` APT package by following the instructions found at: 11 | 12 | 13 | 14 | For this example, also install the `build-essential` and `cmake` APT packages: 15 | 16 | ```bash 17 | sudo apt-get update 18 | sudo apt-get --no-install-recommends install build-essential cmake 19 | ``` 20 | 21 | To build the `drake_cmake_installed_apt` example: 22 | 23 | ```bash 24 | mkdir build 25 | cd build 26 | cmake .. 27 | make 28 | ``` 29 | 30 | To run the `drake_cmake_installed_apt` tests: 31 | 32 | ```bash 33 | cd build 34 | ctest . 35 | ``` 36 | -------------------------------------------------------------------------------- /drake_cmake_installed_apt/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT-0 2 | 3 | add_library(particle particle.cc particle.h) 4 | target_link_libraries(particle drake::drake) 5 | 6 | add_executable(particle_test particle_test.cc) 7 | target_link_libraries(particle_test particle drake::drake gtest) 8 | add_test(NAME cc_particle_test COMMAND particle_test) 9 | set_tests_properties(cc_particle_test PROPERTIES LABELS small TIMEOUT 60) 10 | 11 | add_test(NAME python_particle_test 12 | COMMAND Python3::Interpreter -B -m unittest particle_test 13 | ) 14 | set_tests_properties(python_particle_test PROPERTIES 15 | ENVIRONMENT "PYTHONPATH=${DRAKE_PYTHONPATH}" 16 | LABELS small 17 | REQUIRED_FILES "${CMAKE_CURRENT_SOURCE_DIR}/particle_test.py" 18 | TIMEOUT 60 19 | WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" 20 | ) 21 | -------------------------------------------------------------------------------- /drake_cmake_installed_apt/src/particle.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT-0 2 | 3 | #include "particle.h" 4 | 5 | #include 6 | #include 7 | 8 | namespace drake_external_examples { 9 | namespace particles { 10 | 11 | template 12 | Particle::Particle() { 13 | // A 1D input vector for acceleration. 14 | this->DeclareInputPort(drake::systems::kUseDefaultName, 15 | drake::systems::kVectorValued, 1); 16 | // Adding one generalized position and one generalized velocity. 17 | this->DeclareContinuousState(1, 1, 0); 18 | // A 2D output vector for position and velocity. 19 | this->DeclareVectorOutputPort(drake::systems::kUseDefaultName, 20 | drake::systems::BasicVector(2), 21 | &Particle::CopyStateOut); 22 | } 23 | 24 | template 25 | void Particle::CopyStateOut(const drake::systems::Context& context, 26 | drake::systems::BasicVector* output) const { 27 | // Get current state from context. 28 | const drake::systems::VectorBase& continuous_state_vector = 29 | context.get_continuous_state_vector(); 30 | // Write system output. 31 | output->set_value(continuous_state_vector.CopyToVector()); 32 | } 33 | 34 | template 35 | void Particle::DoCalcTimeDerivatives( 36 | const drake::systems::Context& context, 37 | drake::systems::ContinuousState* derivatives) const { 38 | // Get current state from context. 39 | const drake::systems::VectorBase& continuous_state_vector = 40 | context.get_continuous_state_vector(); 41 | // Obtain the structure we need to write into. 42 | drake::systems::VectorBase& derivatives_vector = 43 | derivatives->get_mutable_vector(); 44 | // Get current input acceleration value. 45 | const drake::systems::BasicVector* input_vector = 46 | this->EvalVectorInput(context, 0); 47 | // Set the derivatives. The first one is 48 | // velocity and the second one is acceleration. 49 | derivatives_vector.SetAtIndex(0, continuous_state_vector.GetAtIndex(1)); 50 | derivatives_vector.SetAtIndex(1, input_vector->GetAtIndex(0)); 51 | } 52 | 53 | template class Particle; 54 | 55 | } // namespace particles 56 | } // namespace drake_external_examples 57 | -------------------------------------------------------------------------------- /drake_cmake_installed_apt/src/particle.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT-0 2 | 3 | #pragma once 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | namespace drake_external_examples { 12 | namespace particles { 13 | 14 | /// A linear 1DOF particle system. 15 | /// 16 | /// With very simple dynamics @f$ \ddot x = a @f$, this system can be 17 | /// described in terms of its: 18 | /// 19 | /// - Inputs: 20 | /// - linear acceleration (input index 0), in @f$ m/s^2 @f$ units. 21 | /// - States/Outputs: 22 | /// - linear position (state/output index 0), in @f$ m @f$ units. 23 | /// - linear velocity (state/output index 1), in @f$ m/s @f$ units. 24 | /// 25 | /// @tparam_double_only 26 | /// 27 | template 28 | class Particle final : public drake::systems::LeafSystem { 29 | public: 30 | DRAKE_NO_COPY_NO_MOVE_NO_ASSIGN(Particle); 31 | 32 | /// A constructor that initializes the system. 33 | Particle(); 34 | 35 | protected: 36 | void CopyStateOut(const drake::systems::Context& context, 37 | drake::systems::BasicVector* output) const; 38 | 39 | void DoCalcTimeDerivatives( 40 | const drake::systems::Context& context, 41 | drake::systems::ContinuousState* derivatives) const override; 42 | }; 43 | 44 | } // namespace particles 45 | } // namespace drake_external_examples 46 | -------------------------------------------------------------------------------- /drake_cmake_installed_apt/src/particle.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT-0 2 | 3 | from pydrake.systems.framework import BasicVector 4 | from pydrake.systems.framework import LeafSystem 5 | from pydrake.systems.framework import PortDataType 6 | 7 | 8 | class Particle(LeafSystem): 9 | """ 10 | A linear 1DOF particle system. 11 | 12 | With very simple dynamics xdotdot = a, this system can be described in 13 | terms of its: 14 | 15 | Inputs: 16 | linear acceleration (input index 0), in m/s^2 units. 17 | 18 | States/Outputs: 19 | linear position (state/output index 0), in m units. 20 | linear velocity (state/output index 1), in m/s units. 21 | """ 22 | def __init__(self): 23 | LeafSystem.__init__(self) 24 | # A 1D input vector for acceleration. 25 | self.DeclareInputPort('acceleration', PortDataType.kVectorValued, 1) 26 | # Adding one generalized position and one generalized velocity. 27 | self.DeclareContinuousState(1, 1, 0) 28 | # A 2D output vector for position and velocity. 29 | self.DeclareVectorOutputPort('postion_and_velocity', BasicVector(2), 30 | self.CopyStateOut) 31 | 32 | def CopyStateOut(self, context, output): 33 | # Get current state from context. 34 | continuous_state_vector = context.get_continuous_state_vector() 35 | # Write system output. 36 | output.SetFromVector(continuous_state_vector.CopyToVector()) 37 | 38 | def DoCalcTimeDerivatives(self, context, derivatives): 39 | # Get current state from context. 40 | continuous_state_vector = x = context.get_continuous_state_vector() 41 | # Obtain the structure we need to write into. 42 | derivatives_vector = derivatives.get_mutable_vector() 43 | # Get current input acceleration value. 44 | input_vector = self.EvalVectorInput(context, 0) 45 | # Set the derivatives. The first one is velocity and the second one is 46 | # acceleration. 47 | derivatives_vector.SetAtIndex(0, continuous_state_vector.GetAtIndex(1)) 48 | derivatives_vector.SetAtIndex(1, input_vector.GetAtIndex(0)) 49 | -------------------------------------------------------------------------------- /drake_cmake_installed_apt/src/particle_test.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT-0 2 | 3 | #include "particle.h" // IWYU pragma: associated 4 | 5 | #include 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | namespace drake_external_examples { 16 | namespace particles { 17 | namespace { 18 | 19 | /// 20 | /// A test fixture class for Particle systems. 21 | /// 22 | /// @tparam T must be a valid Eigen ScalarType. 23 | /// 24 | template 25 | class ParticleTest : public ::testing::Test { 26 | protected: 27 | /// Arrange a Particle as the Device Under Test. 28 | void SetUp() override { 29 | this->dut_ = std::make_unique>(); 30 | this->context_ = this->dut_->CreateDefaultContext(); 31 | this->output_ = this->dut_->AllocateOutput(); 32 | this->derivatives_ = this->dut_->AllocateTimeDerivatives(); 33 | } 34 | 35 | /// System (aka Device Under Test) being tested. 36 | std::unique_ptr> dut_; 37 | /// Context for the given @p dut_. 38 | std::unique_ptr> context_; 39 | /// Outputs of the given @p dut_. 40 | std::unique_ptr> output_; 41 | /// Derivatives of the given @p dut_. 42 | std::unique_ptr> derivatives_; 43 | }; 44 | 45 | TYPED_TEST_SUITE_P(ParticleTest); 46 | 47 | /// Makes sure a Particle output is consistent with its 48 | /// state (position and velocity). 49 | TYPED_TEST_P(ParticleTest, OutputTest) { 50 | // Initialize state. 51 | drake::systems::VectorBase& continuous_state_vector = 52 | this->context_->get_mutable_continuous_state_vector(); 53 | continuous_state_vector.SetAtIndex( 54 | 0, static_cast(10.0)); // x0 = 10 m. 55 | continuous_state_vector.SetAtIndex( 56 | 1, static_cast(1.0)); // x1 = 1 m/s. 57 | // Compute outputs. 58 | this->dut_->CalcOutput(*this->context_, this->output_.get()); 59 | drake::systems::BasicVector* output_vector = 60 | this->output_->GetMutableVectorData(0); 61 | // Check results. 62 | EXPECT_EQ(output_vector->GetAtIndex(0), 63 | static_cast(10.0)); // y0 == x0 64 | EXPECT_EQ(output_vector->GetAtIndex(1), 65 | static_cast(1.0)); // y1 == x1 66 | } 67 | 68 | /// Makes sure a Particle system state derivatives are 69 | /// consistent with its state and input (velocity and acceleration). 70 | TYPED_TEST_P(ParticleTest, DerivativesTest) { 71 | // Set input. 72 | const drake::systems::InputPort& input_port = 73 | this->dut_->get_input_port(0); 74 | drake::VectorX u0(input_port.size()); 75 | u0 << 1.0; // m/s^2 76 | input_port.FixValue(this->context_.get(), u0); 77 | // Set state. 78 | drake::systems::VectorBase& continuous_state_vector = 79 | this->context_->get_mutable_continuous_state_vector(); 80 | continuous_state_vector.SetAtIndex( 81 | 0, static_cast(0.0)); // x0 = 0 m 82 | continuous_state_vector.SetAtIndex( 83 | 1, static_cast(2.0)); // x1 = 2 m/s 84 | // Compute derivatives. 85 | this->dut_->CalcTimeDerivatives(*this->context_, this->derivatives_.get()); 86 | const drake::systems::VectorBase& derivatives_vector = 87 | this->derivatives_->get_vector(); 88 | // Check results. 89 | EXPECT_EQ(derivatives_vector.GetAtIndex(0), 90 | static_cast(2.0)); // x0dot == x1 91 | EXPECT_EQ(derivatives_vector.GetAtIndex(1), 92 | static_cast(1.0)); // x1dot == u0 93 | } 94 | 95 | REGISTER_TYPED_TEST_SUITE_P(ParticleTest, OutputTest, DerivativesTest); 96 | 97 | INSTANTIATE_TYPED_TEST_SUITE_P(WithDoubles, ParticleTest, double); 98 | 99 | } // namespace 100 | } // namespace particles 101 | } // namespace drake_external_examples 102 | 103 | int main(int argc, char** argv) { 104 | ::testing::InitGoogleTest(&argc, argv); 105 | return RUN_ALL_TESTS(); 106 | } 107 | -------------------------------------------------------------------------------- /drake_cmake_installed_apt/src/particle_test.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT-0 2 | 3 | import unittest 4 | 5 | from particle import Particle 6 | 7 | 8 | class TestParticle(unittest.TestCase): 9 | """A test case for Particle systems.""" 10 | def setUp(self): 11 | # System (aka 'device under test') being tested. 12 | self.dut = Particle() 13 | # Context for the given dut. 14 | self.context = self.dut.CreateDefaultContext() 15 | # Outputs of the given dut. 16 | self.output = self.dut.AllocateOutput() 17 | # Derivatives of the given dut. 18 | self.derivatives = self.dut.AllocateTimeDerivatives() 19 | 20 | def test_output(self): 21 | """ 22 | Makes sure a Particle output is consistent with its state (position and 23 | velocity). 24 | """ 25 | # Initialize state. 26 | continuous_state_vector = \ 27 | self.context.get_mutable_continuous_state_vector() 28 | continuous_state_vector.SetAtIndex(0, 10.0) # x0 = 10 m. 29 | continuous_state_vector.SetAtIndex(1, 1.0) # x1 = 1 m/s. 30 | # Compute outputs. 31 | self.dut.CalcOutput(self.context, self.output) 32 | output_vector = self.output.get_vector_data(0) 33 | # Check results. 34 | self.assertEqual(output_vector.GetAtIndex(0), 10.0) # y0 == x0 35 | self.assertEqual(output_vector.GetAtIndex(1), 1.0) # y1 == x1 36 | 37 | def test_derivatives(self): 38 | """ 39 | Makes sure a Particle system state derivatives are consistent with its 40 | state and input (velocity and acceleration). 41 | """ 42 | # Set input. 43 | input_port = self.dut.get_input_port(0) 44 | input_port.FixValue(self.context, 1.0) # u0 = 1 m/s^2 45 | # Set state. 46 | continuous_state_vector = \ 47 | self.context.get_mutable_continuous_state_vector() 48 | continuous_state_vector.SetAtIndex(0, 0.0) # x0 = 0 m 49 | continuous_state_vector.SetAtIndex(1, 2.0) # x1 = 2 m/s 50 | # Compute derivatives. 51 | self.dut.CalcTimeDerivatives(self.context, self.derivatives) 52 | derivatives_vector = self.derivatives.get_vector() 53 | # Check results. 54 | self.assertEqual(derivatives_vector.GetAtIndex(0), 2.0) # x0dot == x1 55 | self.assertEqual(derivatives_vector.GetAtIndex(1), 1.0) # x1dot == u0 56 | 57 | 58 | if __name__ == '__main__': 59 | unittest.main() 60 | -------------------------------------------------------------------------------- /drake_cmake_installed_apt/third_party/cmake/3.12/Copyright.txt: -------------------------------------------------------------------------------- 1 | CMake - Cross Platform Makefile Generator 2 | Copyright 2000-2018 Kitware, Inc. and Contributors 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | * Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | * Neither the name of Kitware, Inc. nor the names of Contributors 17 | may be used to endorse or promote products derived from this 18 | software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | ------------------------------------------------------------------------------ 33 | 34 | The following individuals and institutions are among the Contributors: 35 | 36 | * Aaron C. Meadows 37 | * Adriaan de Groot 38 | * Aleksey Avdeev 39 | * Alexander Neundorf 40 | * Alexander Smorkalov 41 | * Alexey Sokolov 42 | * Alex Turbov 43 | * Andreas Pakulat 44 | * Andreas Schneider 45 | * André Rigland Brodtkorb 46 | * Axel Huebl, Helmholtz-Zentrum Dresden - Rossendorf 47 | * Benjamin Eikel 48 | * Bjoern Ricks 49 | * Brad Hards 50 | * Christopher Harvey 51 | * Christoph Grüninger 52 | * Clement Creusot 53 | * Daniel Blezek 54 | * Daniel Pfeifer 55 | * Enrico Scholz 56 | * Eran Ifrah 57 | * Esben Mose Hansen, Ange Optimization ApS 58 | * Geoffrey Viola 59 | * Google Inc 60 | * Gregor Jasny 61 | * Helio Chissini de Castro 62 | * Ilya Lavrenov 63 | * Insight Software Consortium 64 | * Jan Woetzel 65 | * Kelly Thompson 66 | * Konstantin Podsvirov 67 | * Mario Bensi 68 | * Mathieu Malaterre 69 | * Matthaeus G. Chajdas 70 | * Matthias Kretz 71 | * Matthias Maennich 72 | * Michael Stürmer 73 | * Miguel A. Figueroa-Villanueva 74 | * Mike Jackson 75 | * Mike McQuaid 76 | * Nicolas Bock 77 | * Nicolas Despres 78 | * Nikita Krupen'ko 79 | * NVIDIA Corporation 80 | * OpenGamma Ltd. 81 | * Patrick Stotko 82 | * Per Øyvind Karlsen 83 | * Peter Collingbourne 84 | * Petr Gotthard 85 | * Philip Lowman 86 | * Philippe Proulx 87 | * Raffi Enficiaud, Max Planck Society 88 | * Raumfeld 89 | * Roger Leigh 90 | * Rolf Eike Beer 91 | * Roman Donchenko 92 | * Roman Kharitonov 93 | * Ruslan Baratov 94 | * Sebastian Holtermann 95 | * Stephen Kelly 96 | * Sylvain Joubert 97 | * Thomas Sondergaard 98 | * Tobias Hunger 99 | * Todd Gamblin 100 | * Tristan Carel 101 | * University of Dundee 102 | * Vadim Zhukov 103 | * Will Dicharry 104 | 105 | See version control history for details of individual contributions. 106 | 107 | The above copyright and license notice applies to distributions of 108 | CMake in source and binary form. Third-party software packages supplied 109 | with CMake under compatible licenses provide their own copyright notices 110 | documented in corresponding subdirectories or source files. 111 | 112 | ------------------------------------------------------------------------------ 113 | 114 | CMake was initially developed by Kitware with the following sponsorship: 115 | 116 | * National Library of Medicine at the National Institutes of Health 117 | as part of the Insight Segmentation and Registration Toolkit (ITK). 118 | 119 | * US National Labs (Los Alamos, Livermore, Sandia) ASC Parallel 120 | Visualization Initiative. 121 | 122 | * National Alliance for Medical Image Computing (NAMIC) is funded by the 123 | National Institutes of Health through the NIH Roadmap for Medical Research, 124 | Grant U54 EB005149. 125 | 126 | * Kitware, Inc. 127 | -------------------------------------------------------------------------------- /drake_cmake_installed_apt/third_party/googletest/1.10/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2008, Google Inc. 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are 6 | met: 7 | 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above 11 | copyright notice, this list of conditions and the following disclaimer 12 | in the documentation and/or other materials provided with the 13 | distribution. 14 | * Neither the name of Google Inc. nor the names of its 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | -------------------------------------------------------------------------------- /drake_pip/.github/ci_build_test: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # SPDX-License-Identifier: MIT-0 3 | 4 | set -euxo pipefail 5 | 6 | source env/bin/activate 7 | 8 | cd src 9 | python3 particle_test.py 10 | 11 | cd .. 12 | deactivate 13 | rm -rf env src/__pycache__ 14 | -------------------------------------------------------------------------------- /drake_pip/.github/ubuntu_setup: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # SPDX-License-Identifier: MIT-0 3 | 4 | set -euxo pipefail 5 | 6 | echo 'APT::Acquire::Retries "4";' > /etc/apt/apt.conf.d/80-acquire-retries 7 | echo 'APT::Get::Assume-Yes "true";' > /etc/apt/apt.conf.d/90-get-assume-yes 8 | 9 | export DEBIAN_FRONTEND='noninteractive' 10 | 11 | setup/install_prereqs "$@" 12 | -------------------------------------------------------------------------------- /drake_pip/.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT-0 2 | 3 | --- 4 | name: ci 5 | on: 6 | push: 7 | branches: 8 | - main 9 | pull_request: 10 | branches: 11 | - main 12 | schedule: 13 | - cron: '0 12 * * *' 14 | workflow_dispatch: 15 | inputs: 16 | linux_jammy_wheel: 17 | description: 'Drake linux-jammy-*-wheel-*-release Python 3.10 artifact URL' 18 | required: false 19 | mac_arm_sonoma_wheel: 20 | description: 'Drake mac-arm-sonoma-*-wheel-*-release Python 3.13 artifact URL' 21 | required: false 22 | concurrency: 23 | # Cancel previous CI runs when additional commits are added to a pull request. 24 | # This will not cancel CI runs associated with `schedule` or `push`. 25 | group: ${{ github.head_ref || github.run_id }} 26 | cancel-in-progress: true 27 | jobs: 28 | macos_sonoma_arm_pip: 29 | name: macos sonoma 14 arm 30 | runs-on: macos-14 31 | env: 32 | PYTHON_VERSION: '3.13' 33 | steps: 34 | - name: checkout 35 | uses: actions/checkout@v4 36 | # See issue https://github.com/actions/setup-python/issues/577. There is 37 | # some kind of environment conflict between the symlinks found in the 38 | # GitHub Actions runner and `brew upgrade python` where `brew` detects and 39 | # refuses to overwrite symlinks. The cause for our runs is not clear, 40 | # we do not use that action, but if that issue is closed this section 41 | # can be removed. 42 | - name: sanitize GHA / brew python environment 43 | run: | 44 | # Remove the symlinks that cause issues. 45 | find /usr/local/bin -lname '*/Library/Frameworks/Python.framework/*' -delete 46 | sudo rm -rf /Library/Frameworks/Python.framework/ 47 | - name: python setup 48 | uses: actions/setup-python@v5 49 | with: 50 | python-version: ${{ env.PYTHON_VERSION }} 51 | - name: venv setup and install 52 | working-directory: drake_pip 53 | run: | 54 | args=(--python-version $PYTHON_VERSION) 55 | if [[ '${{ github.event.inputs.mac_arm_sonoma_wheel }}' != '' ]]; then 56 | args+=(--wheel-url ${{ github.event.inputs.mac_arm_sonoma_wheel }}) 57 | fi 58 | setup/setup_env "${args[@]}" 59 | shell: zsh -eufo pipefail {0} 60 | - name: pip build and test 61 | working-directory: drake_pip 62 | run: .github/ci_build_test 63 | shell: zsh -efuo pipefail {0} 64 | ubuntu_jammy_pip: 65 | name: ubuntu 22.04 jammy 66 | runs-on: ubuntu-latest 67 | container: ubuntu:jammy 68 | steps: 69 | - name: checkout 70 | uses: actions/checkout@v4 71 | - name: pip setup 72 | working-directory: drake_pip 73 | run: | 74 | args=() 75 | if [[ '${{ github.event.inputs.linux_jammy_wheel }}' != '' ]]; then 76 | args+=(--wheel-url ${{ github.event.inputs.linux_jammy_wheel }}) 77 | fi 78 | .github/ubuntu_setup "${args[@]}" 79 | shell: bash 80 | - name: pip build and test 81 | working-directory: drake_pip 82 | run: .github/ci_build_test 83 | shell: bash 84 | -------------------------------------------------------------------------------- /drake_pip/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2017-2025 by the drake-external-examples developers. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so. 9 | 10 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 11 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 12 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 13 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 14 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 15 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 16 | SOFTWARE. 17 | -------------------------------------------------------------------------------- /drake_pip/README.md: -------------------------------------------------------------------------------- 1 | # Python Project with Drake Installed from Pip 2 | 3 | This installs Drake using [`pip`](https://pypi.org/project/pip/), 4 | the Python package manager. 5 | 6 | # Instructions 7 | 8 | Follow the setup instructions for [Ubuntu](#ubuntu-setup) 9 | or [Mac OS](#mac-setup). 10 | 11 | See [Installation via Pip](https://drake.mit.edu/pip.html#stable-releases) 12 | for more information on installation. 13 | 14 | ## Ubuntu Setup 15 | 16 | If on Ubuntu, first install the required packages: 17 | 18 | ```bash 19 | setup/install_prereqs 20 | ``` 21 | 22 | This script will also run `setup/setup_env`, 23 | which creates the virtual environment for this project and installs Drake. 24 | 25 | To start programming, simply activate the environment by calling: 26 | 27 | ```bash 28 | source env/bin/activate 29 | ``` 30 | 31 | ## Mac Setup 32 | 33 | If on Mac OS X, simply ensure the correct version of Python 34 | is installed from Homebrew by referring to the 35 | [Supported Configurations](https://drake.mit.edu/installation.html#supported-configurations). 36 | 37 | Then, run the following script to create the virtual environment 38 | for this project and install Drake: 39 | 40 | ```bash 41 | setup/setup_env 42 | ``` 43 | 44 | *Note*: If you have multiple versions of Python installed, 45 | you can specify the correct version as an optional argument 46 | to the script. For example, to use `python3.13`, call: 47 | 48 | ```bash 49 | setup/setup_env --python-version 3.13 50 | ``` 51 | 52 | Refer to the 53 | [Drake installation documentation](https://drake.mit.edu/installation.html) 54 | for the versions of Python officially supported on each OS 55 | when installing via PyPI. 56 | 57 | To start programming, simply activate the environment by calling: 58 | 59 | ```bash 60 | source env/bin/activate 61 | ``` 62 | 63 | # Examples 64 | 65 | To run the particle example tests in this directory, 66 | navigate to `src` and call the test file to execute the unit tests: 67 | 68 | ```bash 69 | cd src 70 | python3 particle_test.py 71 | ``` 72 | 73 | For more information on what's available for Drake in Python, 74 | see [Using Drake from Python](https://drake.mit.edu/python_bindings.html) 75 | and the Python API [pydrake](https://drake.mit.edu/pydrake/index.html). 76 | -------------------------------------------------------------------------------- /drake_pip/requirements.txt: -------------------------------------------------------------------------------- 1 | # Currently, this only includes a recent version of Drake. 2 | # Feel free to add more packages for your own project below! 3 | # Note: When specifying a compatible version of Drake with ~=, 4 | # use 'drake~=x.y' instead of 'drake~=x.y.z'. See 5 | # https://packaging.python.org/en/latest/specifications/version-specifiers/#compatible-release 6 | # for more details. 7 | drake~=1.40 8 | -------------------------------------------------------------------------------- /drake_pip/setup/install_prereqs: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # SPDX-License-Identifier: MIT-0 3 | 4 | set -euxo pipefail 5 | 6 | maybe_sudo= 7 | if [[ "${EUID}" -ne 0 ]]; then 8 | maybe_sudo=sudo 9 | fi 10 | 11 | # Ubuntu-specific installations 12 | # See https://github.com/RobotLocomotion/drake/blob/master/tools/wheel/content/INSTALLATION 13 | # for a complete list of the required libraries to be installed. 14 | ${maybe_sudo} apt-get update 15 | ${maybe_sudo} apt-get install --no-install-recommends $(cat <&2 15 | exit 1 16 | fi 17 | wheel_url="$1" 18 | ;; 19 | --python-version) 20 | shift 21 | if [[ $# -eq 0 ]]; then 22 | echo 'No argument specified for --python-version' >&2 23 | exit 1 24 | fi 25 | python_version="$1" 26 | ;; 27 | *) 28 | echo 'Invalid command line argument' >&2 29 | exit 1 30 | esac 31 | shift 32 | done 33 | 34 | echo "Creating virtual environment with python${python_version}" 35 | "python${python_version}" -m venv env 36 | # Install from requirements.txt, which currently only includes drake. 37 | "env/bin/pip$python_version" install -r requirements.txt 38 | 39 | # Use custom wheels if specified. 40 | if [[ ! -z "${wheel_url}" ]]; then 41 | "env/bin/pip$python_version" install "${wheel_url}" 42 | fi 43 | -------------------------------------------------------------------------------- /drake_pip/src/particle.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT-0 2 | 3 | from pydrake.systems.framework import BasicVector 4 | from pydrake.systems.framework import LeafSystem 5 | from pydrake.systems.framework import PortDataType 6 | 7 | 8 | class Particle(LeafSystem): 9 | """ 10 | A linear 1DOF particle system. 11 | 12 | With very simple dynamics xdotdot = a, this system can be described in 13 | terms of its: 14 | 15 | Inputs: 16 | linear acceleration (input index 0), in m/s^2 units. 17 | 18 | States/Outputs: 19 | linear position (state/output index 0), in m units. 20 | linear velocity (state/output index 1), in m/s units. 21 | """ 22 | def __init__(self): 23 | LeafSystem.__init__(self) 24 | # A 1D input vector for acceleration. 25 | self.DeclareInputPort('acceleration', PortDataType.kVectorValued, 1) 26 | # Adding one generalized position and one generalized velocity. 27 | self.DeclareContinuousState(1, 1, 0) 28 | # A 2D output vector for position and velocity. 29 | self.DeclareVectorOutputPort('postion_and_velocity', BasicVector(2), 30 | self.CopyStateOut) 31 | 32 | def CopyStateOut(self, context, output): 33 | # Get current state from context. 34 | continuous_state_vector = context.get_continuous_state_vector() 35 | # Write system output. 36 | output.SetFromVector(continuous_state_vector.CopyToVector()) 37 | 38 | def DoCalcTimeDerivatives(self, context, derivatives): 39 | # Get current state from context. 40 | continuous_state_vector = x = context.get_continuous_state_vector() 41 | # Obtain the structure we need to write into. 42 | derivatives_vector = derivatives.get_mutable_vector() 43 | # Get current input acceleration value. 44 | input_vector = self.EvalVectorInput(context, 0) 45 | # Set the derivatives. The first one is velocity and the second one is 46 | # acceleration. 47 | derivatives_vector.SetAtIndex(0, continuous_state_vector.GetAtIndex(1)) 48 | derivatives_vector.SetAtIndex(1, input_vector.GetAtIndex(0)) 49 | -------------------------------------------------------------------------------- /drake_pip/src/particle_test.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT-0 2 | 3 | import unittest 4 | 5 | from particle import Particle 6 | 7 | 8 | class TestParticle(unittest.TestCase): 9 | """A test case for Particle systems.""" 10 | def setUp(self): 11 | # System (aka 'device under test') being tested. 12 | self.dut = Particle() 13 | # Context for the given dut. 14 | self.context = self.dut.CreateDefaultContext() 15 | # Outputs of the given dut. 16 | self.output = self.dut.AllocateOutput() 17 | # Derivatives of the given dut. 18 | self.derivatives = self.dut.AllocateTimeDerivatives() 19 | 20 | def test_output(self): 21 | """ 22 | Makes sure a Particle output is consistent with its state (position and 23 | velocity). 24 | """ 25 | # Initialize state. 26 | continuous_state_vector = \ 27 | self.context.get_mutable_continuous_state_vector() 28 | continuous_state_vector.SetAtIndex(0, 10.0) # x0 = 10 m. 29 | continuous_state_vector.SetAtIndex(1, 1.0) # x1 = 1 m/s. 30 | # Compute outputs. 31 | self.dut.CalcOutput(self.context, self.output) 32 | output_vector = self.output.get_vector_data(0) 33 | # Check results. 34 | self.assertEqual(output_vector.GetAtIndex(0), 10.0) # y0 == x0 35 | self.assertEqual(output_vector.GetAtIndex(1), 1.0) # y1 == x1 36 | 37 | def test_derivatives(self): 38 | """ 39 | Makes sure a Particle system state derivatives are consistent with its 40 | state and input (velocity and acceleration). 41 | """ 42 | # Set input. 43 | input_port = self.dut.get_input_port(0) 44 | input_port.FixValue(self.context, 1.0) # u0 = 1 m/s^2 45 | # Set state. 46 | continuous_state_vector = \ 47 | self.context.get_mutable_continuous_state_vector() 48 | continuous_state_vector.SetAtIndex(0, 0.0) # x0 = 0 m 49 | continuous_state_vector.SetAtIndex(1, 2.0) # x1 = 2 m/s 50 | # Compute derivatives. 51 | self.dut.CalcTimeDerivatives(self.context, self.derivatives) 52 | derivatives_vector = self.derivatives.get_vector() 53 | # Check results. 54 | self.assertEqual(derivatives_vector.GetAtIndex(0), 2.0) # x0dot == x1 55 | self.assertEqual(derivatives_vector.GetAtIndex(1), 1.0) # x1dot == u0 56 | 57 | 58 | if __name__ == '__main__': 59 | unittest.main() 60 | -------------------------------------------------------------------------------- /drake_poetry/.github/ci_build_test: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # SPDX-License-Identifier: MIT-0 3 | 4 | set -euxo pipefail 5 | 6 | poetry --version 7 | 8 | cd src 9 | poetry run python particle_test.py 10 | 11 | cd .. 12 | rm -rf src/__pycache__ 13 | -------------------------------------------------------------------------------- /drake_poetry/.github/setup: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # SPDX-License-Identifier: MIT-0 3 | 4 | set -euxo pipefail 5 | 6 | case "$OSTYPE" in 7 | darwin*) 8 | # Mac-specific installations 9 | brew install pipx 10 | ;; 11 | 12 | linux*) 13 | if [[ "${EUID:-}" -ne 0 ]]; then 14 | echo 'This script must be run as root' >&2 15 | exit 2 16 | fi 17 | 18 | # Ubuntu-specific installations 19 | echo 'APT::Acquire::Retries "4";' > /etc/apt/apt.conf.d/80-acquire-retries 20 | echo 'APT::Get::Assume-Yes "true";' > /etc/apt/apt.conf.d/90-get-assume-yes 21 | 22 | export DEBIAN_FRONTEND='noninteractive' 23 | 24 | apt-get update 25 | apt-get install --no-install-recommends pipx python3 26 | ;; 27 | esac 28 | 29 | pipx install poetry 30 | pipx ensurepath 31 | -------------------------------------------------------------------------------- /drake_poetry/.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT-0 2 | 3 | --- 4 | name: ci 5 | on: 6 | push: 7 | branches: 8 | - main 9 | pull_request: 10 | branches: 11 | - main 12 | schedule: 13 | - cron: '0 12 * * *' 14 | workflow_dispatch: 15 | inputs: 16 | linux_jammy_wheel: 17 | description: 'Drake linux-jammy-*-wheel-*-release Python 3.10 artifact URL' 18 | required: false 19 | mac_arm_sonoma_wheel: 20 | description: 'Drake mac-arm-sonoma-*-wheel-*-release Python 3.13 artifact URL' 21 | required: false 22 | concurrency: 23 | # Cancel previous CI runs when additional commits are added to a pull request. 24 | # This will not cancel CI runs associated with `schedule` or `push`. 25 | group: ${{ github.head_ref || github.run_id }} 26 | cancel-in-progress: true 27 | jobs: 28 | macos_sonoma_arm_poetry: 29 | name: macos sonoma 14 arm 30 | runs-on: macos-14 31 | env: 32 | PYTHON_VERSION: '3.13' 33 | steps: 34 | - name: checkout 35 | uses: actions/checkout@v4 36 | # See issue https://github.com/actions/setup-python/issues/577. There is 37 | # some kind of environment conflict between the symlinks found in the 38 | # GitHub Actions runner and `brew upgrade python` where `brew` detects and 39 | # refuses to overwrite symlinks. The cause for our runs is not clear, 40 | # we do not use that action, but if that issue is closed this section 41 | # can be removed. 42 | - name: sanitize GHA / brew python environment 43 | run: | 44 | # Remove the symlinks that cause issues. 45 | find /usr/local/bin -lname '*/Library/Frameworks/Python.framework/*' -delete 46 | sudo rm -rf /Library/Frameworks/Python.framework/ 47 | - name: python setup 48 | uses: actions/setup-python@v5 49 | with: 50 | python-version: ${{ env.PYTHON_VERSION }} 51 | - name: poetry setup 52 | working-directory: drake_poetry 53 | run: | 54 | .github/setup 55 | args=(--python-version $PYTHON_VERSION) 56 | if [[ '${{ github.event.inputs.mac_arm_sonoma_wheel }}' != '' ]]; then 57 | args+=(--wheel-url ${{ github.event.inputs.mac_arm_sonoma_wheel }}) 58 | fi 59 | setup/install_prereqs "${args[@]}" 60 | shell: zsh -efuo pipefail {0} 61 | - name: poetry test 62 | working-directory: drake_poetry 63 | run: .github/ci_build_test 64 | shell: zsh -efuo pipefail {0} 65 | ubuntu_jammy_poetry: 66 | name: ubuntu 22.04 jammy 67 | runs-on: ubuntu-latest 68 | container: ubuntu:jammy 69 | steps: 70 | - name: checkout 71 | uses: actions/checkout@v4 72 | # setup and test must occur in one step 73 | # because when poetry is installed, the update to PATH 74 | # does not persist between steps on GHA 75 | - name: poetry setup and test 76 | working-directory: drake_poetry 77 | run: | 78 | .github/setup 79 | source $HOME/.profile 80 | args=() 81 | if [[ '${{ github.event.inputs.linux_jammy_wheel }}' != '' ]]; then 82 | args+=(--wheel-url ${{ github.event.inputs.linux_jammy_wheel }}) 83 | fi 84 | setup/install_prereqs "${args[@]}" 85 | .github/ci_build_test 86 | shell: bash 87 | -------------------------------------------------------------------------------- /drake_poetry/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2017-2025 by the drake-external-examples developers. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so. 9 | 10 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 11 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 12 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 13 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 14 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 15 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 16 | SOFTWARE. 17 | -------------------------------------------------------------------------------- /drake_poetry/README.md: -------------------------------------------------------------------------------- 1 | # Python Project with Drake Installed from Poetry 2 | 3 | This installs Drake using [`poetry`](https://python-poetry.org/), 4 | the Python package manager. For an introduction to `poetry`, 5 | see [Basic usage](https://python-poetry.org/docs/basic-usage/). 6 | 7 | # Instructions 8 | 9 | The `pyproject.toml` file found in this directory contains all 10 | that is needed to start a Poetry project using Drake. 11 | 12 | First, follow the [Installation Instructions](https://python-poetry.org/docs/#installation) 13 | to install Poetry using your preferred method. 14 | 15 | Run the installation script to perform the following: 16 | 17 | * install the required system packages for Drake (Ubuntu only) 18 | * set up your Poetry environment and install Drake 19 | - The `poetry.lock` file listing all dependencies and their versions is not 20 | included with this example in order to reduce confusion and keep the version 21 | of Drake up to date. It will be created once the environment is set up, 22 | and it is encouraged to include this file in your own project's version 23 | control in order to manage your project's dependencies. 24 | 25 | ```bash 26 | setup/install_prereqs 27 | ``` 28 | 29 | *Note*: If you have multiple versions of Python installed, 30 | you can specify the correct version as an optional argument 31 | to the script. For example, to use `python3.13`, call: 32 | 33 | ```bash 34 | setup/setup_env --python-version 3.13 35 | ``` 36 | 37 | Refer to the 38 | [Drake installation documentation](https://drake.mit.edu/installation.html) 39 | for the versions of Python officially supported on each OS 40 | when installing via PyPI. 41 | 42 | # Examples 43 | 44 | To run the particle example tests in this directory, 45 | navigate to `src` and call the test file to execute the unit tests: 46 | 47 | ```bash 48 | cd src 49 | poetry run python particle_test.py 50 | ``` 51 | 52 | For more information on what's available for Drake in Python, 53 | see [Using Drake from Python](https://drake.mit.edu/python_bindings.html) 54 | and the Python API [pydrake](https://drake.mit.edu/pydrake/index.html). 55 | -------------------------------------------------------------------------------- /drake_poetry/pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = ["poetry-core"] 3 | build-backend = "poetry.core.masonry.api" 4 | 5 | [project] 6 | name = "drake-external-examples" 7 | version = "0.0.0.dev0" 8 | description = "External examples for Drake" 9 | authors = [{ name = "RobotLocomotion <@>" }] 10 | readme = "README.md" 11 | requires-python = ">=3.10" 12 | dynamic = ["dependencies"] 13 | 14 | [tool.poetry] 15 | package-mode = false 16 | 17 | [tool.poetry.dependencies] 18 | drake = "~=1.40" 19 | -------------------------------------------------------------------------------- /drake_poetry/setup/install_prereqs: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # SPDX-License-Identifier: MIT-0 3 | 4 | set -euxo pipefail 5 | 6 | wheel_url= 7 | python_version='3' 8 | 9 | while [ "${1:-}" != "" ]; do 10 | case "$1" in 11 | --wheel-url) 12 | shift 13 | if [[ $# -eq 0 ]]; then 14 | echo 'No argument specified for --wheel-url' >&2 15 | exit 1 16 | fi 17 | wheel_url="$1" 18 | ;; 19 | --python-version) 20 | shift 21 | if [[ $# -eq 0 ]]; then 22 | echo 'No argument specified for --python-version' >&2 23 | exit 1 24 | fi 25 | python_version="$1" 26 | ;; 27 | *) 28 | echo 'Invalid command line argument' >&2 29 | exit 1 30 | esac 31 | shift 32 | done 33 | 34 | maybe_sudo= 35 | if [[ "${EUID}" -ne 0 ]]; then 36 | maybe_sudo=sudo 37 | fi 38 | 39 | if [[ "$OSTYPE" == "linux"* ]]; then 40 | # Ubuntu-specific installations 41 | # See https://github.com/RobotLocomotion/drake/blob/master/tools/wheel/content/INSTALLATION 42 | # for a complete list of the required libraries to be installed. 43 | ${maybe_sudo} apt-get update 44 | ${maybe_sudo} apt-get install --no-install-recommends $(cat <