From 449f4f5c1e2b5a37c572cab962c007f1e7e8d080 Mon Sep 17 00:00:00 2001 From: AndresG Date: Wed, 26 Feb 2025 14:15:59 +0100 Subject: [PATCH] Update parameter measurements for modular parts, use V4 Github Actions (#591) * added an example to analyze part parameters and their effect on the modular robot * updated brick and core v2 parameters * updated active hinge frame mass * fix GitHub Actions: Update artifacts to v4 * artifacts now save with platform dependant names to avoid conflicts * switched runner to latest Mac version hoping to reduce queue time --- .github/workflows/main.yml | 25 +++- .../2c_custom_parts/README.md | 6 + .../2c_custom_parts/main.py | 123 ++++++++++++++++++ .../2c_custom_parts/requirements.txt | 0 modular_robot/pyproject.toml | 1 + .../modular_robot/body/v2/_active_hinge_v2.py | 2 +- .../modular_robot/body/v2/_brick_v2.py | 2 +- .../modular_robot/body/v2/_core_v2.py | 4 +- project.yml | 1 + simulators/mujoco_simulator/pyproject.toml | 1 + standards/pyproject.toml | 1 + 11 files changed, 155 insertions(+), 11 deletions(-) create mode 100644 examples/2_modular_robot_basics/2c_custom_parts/README.md create mode 100644 examples/2_modular_robot_basics/2c_custom_parts/main.py create mode 100644 examples/2_modular_robot_basics/2c_custom_parts/requirements.txt diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index cce311570..0abfa4727 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -144,9 +144,14 @@ jobs: python-version: 3.11 - name: Build wheels run: pip wheel --no-deps ./${{ matrix.package }} -w ./dist/${{ matrix.package }} - - uses: actions/upload-artifact@v3 + - name: Generate artifact name + shell: bash + run: | + SAFE_PACKAGE=$(echo "${{ matrix.package }}" | sed 's/\//-/g') + echo "ARTIFACT_NAME=dist-${SAFE_PACKAGE}-${{ github.run_id }}" >> $GITHUB_ENV + - uses: actions/upload-artifact@v4 with: - name: dist + name: ${{ env.ARTIFACT_NAME }} path: ./dist/**/*.whl build_wheels_platform_dependent: @@ -154,7 +159,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [windows-2022, ubuntu-22.04, macos-12] + os: [windows-2022, ubuntu-22.04, macos-latest] package: ${{ fromJson(needs.read-project-info.outputs.platform_dependent_packages) }} steps: - uses: actions/checkout@v4 @@ -170,9 +175,14 @@ jobs: CIBW_ARCHS_WINDOWS: AMD64 CIBW_ARCHS_MACOS: universal2 CIBW_ARCHS_LINUX: x86_64 - - uses: actions/upload-artifact@v3 + - name: Generate artifact name + shell: bash + run: | + SAFE_PACKAGE=$(echo "${{ matrix.package }}" | sed 's/\//-/g') + echo "ARTIFACT_NAME=dist-${SAFE_PACKAGE}-${{ matrix.os }}-${{ github.run_id }}" >> $GITHUB_ENV + - uses: actions/upload-artifact@v4 with: - name: dist + name: ${{ env.ARTIFACT_NAME }} path: ./dist/**/*.whl publish: @@ -188,10 +198,11 @@ jobs: id-token: write steps: - name: Download dist artifact - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: - name: dist + pattern: dist-* path: dist + merge-multiple: true - name: Generate name for package # Prepend 'revolve2-', replace '/' with '-' and remove '/simulators' run: echo "PACKAGE_URL=https://pypi.org/p/revolve2-$(echo ${{ matrix.package }} | sed 's/_/-/g' | sed 's/simulators\///g')" >> $GITHUB_ENV diff --git a/examples/2_modular_robot_basics/2c_custom_parts/README.md b/examples/2_modular_robot_basics/2c_custom_parts/README.md new file mode 100644 index 000000000..2cedbc851 --- /dev/null +++ b/examples/2_modular_robot_basics/2c_custom_parts/README.md @@ -0,0 +1,6 @@ +This example shows you how to create vustom versions of the modular robot elements. + +You learn: +- Where are parts defined and what parameters can be changed. +- How to implement custom versions of the parts to analyze the effect of different parameters. +- Using the test_robot function to test robots with manual/dummy brains. diff --git a/examples/2_modular_robot_basics/2c_custom_parts/main.py b/examples/2_modular_robot_basics/2c_custom_parts/main.py new file mode 100644 index 000000000..eb19eb809 --- /dev/null +++ b/examples/2_modular_robot_basics/2c_custom_parts/main.py @@ -0,0 +1,123 @@ +"""Main script for the example.""" + +from pyrr import Vector3 + +from revolve2.experimentation.logging import setup_logging +from revolve2.modular_robot import ModularRobot +from revolve2.modular_robot.body import RightAngles +from revolve2.modular_robot.body.v2 import ActiveHingeV2, BodyV2, BrickV2, CoreV2 +from revolve2.modular_robot.brain.dummy import BrainDummy +from revolve2.modular_robot_simulation import test_robot +from revolve2.simulators.mujoco_simulator import LocalSimulator +from revolve2.standards import terrains +from revolve2.standards.simulation_parameters import make_standard_batch_parameters + +""" Below we create a custom version of the ActiveHingeV2. + By pressing shift+right click on the ActiveHingeV2 class in the IDE you can see where it is defined. + Changing the parameters there will change it for all instances of ActiveHingeV2, which is not what we want. + Therefore we create a custom version of the ActiveHingeV2 and change the parameters there.""" + + +class CustomActiveHingeV2(ActiveHingeV2): + """Custom ActiveHinge for parameter testing.""" + + def __init__(self, rotation: float | RightAngles): + """Initialize with custom parameters. + + :param rotation: The Modules rotation. + + """ + super().__init__(rotation=rotation) + # Modify parameters here to experiment + self._frame_bounding_box = Vector3([0.036, 0.104, 0.033]) # Double size + self._servo1_bounding_box = Vector3([0.1025, 0.1024, 0.040]) # Double size + self._servo2_bounding_box = Vector3([0.004, 0.104, 0.104]) # Double size + + +class CustomBrickV2(BrickV2): + """Custom Brick for parameter testing.""" + + def __init__(self, rotation: float | RightAngles): + """Initialize with custom parameters. + + :param rotation: The Modules rotation. + + """ + super().__init__(rotation=rotation) + # Modify parameters here to experiment + self._mass = 0.100 # Double mass + self._bounding_box = Vector3([0.130, 0.130, 0.130]) # Double size + + +class CustomCoreV2(CoreV2): + """Custom Core for parameter testing.""" + + def __init__(self, rotation: float | RightAngles): + """Initialize with custom parameters. + + :param rotation: The Modules rotation. + + """ + super().__init__(rotation=rotation) + # Modify parameters here to experiment + self._mass = 0.200 # Double mass + self._bounding_box = Vector3([0.130, 0.130, 0.130]) # Double size + + +def make_visualization_body() -> BodyV2: + """ + Create a body with all components for visualization. + + :returns: The created body. + """ + body = BodyV2() + + # Attach components in different configurations to visualize all parts + hinge_left = CustomActiveHingeV2(RightAngles.DEG_0) + body.core_v2.front_face.bottom = hinge_left + hinge_left.attachment = CustomBrickV2(RightAngles.DEG_0) + + # Add a chain of components to see how they connect + hinge = CustomActiveHingeV2(RightAngles.DEG_0) + body.core_v2.back_face.bottom = hinge + hinge.attachment = CustomBrickV2(RightAngles.DEG_0) + + return body + + +def main() -> None: + """Run the visualization.""" + setup_logging() + + body = make_visualization_body() + + # Create dummy brain (no movement) for better visualization + brain = BrainDummy() + robot = ModularRobot(body, brain) + + # Set up simulator with custom viewer for better visualization + simulator = LocalSimulator( + viewer_type="custom", + headless=False, + ) + + # Configure sim params + batch_parameters = make_standard_batch_parameters() + batch_parameters.simulation_time = ( + 10 # Short sim time since we just want to view it + ) + batch_parameters.simulation_timestep = ( + 0.005 # Smaller timestep for smoother visualization + ) + + # Test the robot using the test_robot utility + test_robot( + robot=robot, + terrain=terrains.flat(), + simulator=simulator, + batch_parameters=batch_parameters, + ) + + +if __name__ == "__main__": + main() diff --git a/examples/2_modular_robot_basics/2c_custom_parts/requirements.txt b/examples/2_modular_robot_basics/2c_custom_parts/requirements.txt new file mode 100644 index 000000000..e69de29bb diff --git a/modular_robot/pyproject.toml b/modular_robot/pyproject.toml index bd78aa0b1..4c8a5b2fc 100644 --- a/modular_robot/pyproject.toml +++ b/modular_robot/pyproject.toml @@ -10,6 +10,7 @@ readme = "../README.md" authors = [ "Aart Stuurman ", "Oliver Weissl ", + "Andres Garcia " ] repository = "https://github.com/ci-group/revolve2" classifiers = [ diff --git a/modular_robot/revolve2/modular_robot/body/v2/_active_hinge_v2.py b/modular_robot/revolve2/modular_robot/body/v2/_active_hinge_v2.py index 307119369..243a31470 100644 --- a/modular_robot/revolve2/modular_robot/body/v2/_active_hinge_v2.py +++ b/modular_robot/revolve2/modular_robot/body/v2/_active_hinge_v2.py @@ -27,7 +27,7 @@ def __init__(self, rotation: float | RightAngles): frame_offset=0.04495, servo1_bounding_box=Vector3([0.05125, 0.0512, 0.020]), servo2_bounding_box=Vector3([0.002, 0.052, 0.052]), - frame_mass=0.01632, + frame_mass=0.01144, servo1_mass=0.058, servo2_mass=0.025, servo_offset=0.0239, diff --git a/modular_robot/revolve2/modular_robot/body/v2/_brick_v2.py b/modular_robot/revolve2/modular_robot/body/v2/_brick_v2.py index c8588ee7c..97ba8efcb 100644 --- a/modular_robot/revolve2/modular_robot/body/v2/_brick_v2.py +++ b/modular_robot/revolve2/modular_robot/body/v2/_brick_v2.py @@ -17,7 +17,7 @@ def __init__(self, rotation: float | RightAngles): super().__init__( rotation=rotation, bounding_box=Vector3([w, h, d]), - mass=0.06043, + mass=0.05864, child_offset=d / 2.0, sensors=[], ) diff --git a/modular_robot/revolve2/modular_robot/body/v2/_core_v2.py b/modular_robot/revolve2/modular_robot/body/v2/_core_v2.py index 5a0940913..5ce12ded6 100644 --- a/modular_robot/revolve2/modular_robot/body/v2/_core_v2.py +++ b/modular_robot/revolve2/modular_robot/body/v2/_core_v2.py @@ -10,8 +10,8 @@ class CoreV2(Core): """The core module of a modular robot.""" - _BATTERY_MASS = 0.39712 # in kg - _FRAME_MASS = 1.0644 # in kg + _BATTERY_MASS = 0.39201 # in kg + _FRAME_MASS = 0.9783 # in kg _horizontal_offset = 0.029 # The horizontal offset for attachment positions (in m). _vertical_offset = 0.032 # The vertical offset for attachment positions (in m). diff --git a/project.yml b/project.yml index f79ddd3cf..7d97b554d 100644 --- a/project.yml +++ b/project.yml @@ -14,6 +14,7 @@ examples: - 1_simulator_basics/1b_custom_terrain - 2_modular_robot_basics/2a_custom_brain - 2_modular_robot_basics/2b_brain_with_feedback + - 2_modular_robot_basics/2c_custom_parts - 3_experiment_foundations/3a_experiment_setup - 3_experiment_foundations/3b_evaluate_single_robot - 3_experiment_foundations/3c_evaluate_multiple_isolated_robots diff --git a/simulators/mujoco_simulator/pyproject.toml b/simulators/mujoco_simulator/pyproject.toml index f29b30dbc..b82285dfd 100644 --- a/simulators/mujoco_simulator/pyproject.toml +++ b/simulators/mujoco_simulator/pyproject.toml @@ -11,6 +11,7 @@ authors = [ "Aart Stuurman ", "Oliver Weissl ", "Kevin Godin-Dubois ", + "Andres Garcia " ] repository = "https://github.com/ci-group/revolve2" classifiers = [ diff --git a/standards/pyproject.toml b/standards/pyproject.toml index 7b137e0c5..227ea90e6 100644 --- a/standards/pyproject.toml +++ b/standards/pyproject.toml @@ -15,6 +15,7 @@ readme = "../README.md" authors = [ "Aart Stuurman ", "Oliver Weissl ", + "Andres Garcia " ] repository = "https://github.com/ci-group/revolve2" classifiers = [