From 56d505b0a7c0534af271f6cec9788bfc5f6a48e3 Mon Sep 17 00:00:00 2001 From: wuallenwu Date: Tue, 2 Jul 2024 18:37:35 -0700 Subject: [PATCH 1/2] script updates --- .github/workflows/update_stompy_s3.yml | 33 +++++++- sim/scripts/run_onshape_to_urdf.py | 108 +++++++++++++++++++++++++ sim/scripts/update_stompy_arm_s3.py | 33 ++++++++ sim/scripts/update_stompy_s3.py | 84 ++++--------------- sim/scripts/update_stompy_torso_s3.py | 33 ++++++++ 5 files changed, 218 insertions(+), 73 deletions(-) create mode 100644 sim/scripts/run_onshape_to_urdf.py create mode 100644 sim/scripts/update_stompy_arm_s3.py create mode 100644 sim/scripts/update_stompy_torso_s3.py diff --git a/.github/workflows/update_stompy_s3.yml b/.github/workflows/update_stompy_s3.yml index ce62aa42..a1087b94 100644 --- a/.github/workflows/update_stompy_s3.yml +++ b/.github/workflows/update_stompy_s3.yml @@ -4,7 +4,7 @@ on: release: types: [created] schedule: - - cron: "30 2 * * *" + - cron: "30 10 * * *" workflow_dispatch: permissions: @@ -30,16 +30,31 @@ jobs: with: python-version: "3.11" + - name: Restore cache + id: restore-cache + uses: actions/cache/restore@v3 + with: + path: | + ${{ env.pythonLocation }} + .mypy_cache/ + key: python-requirements-${{ env.pythonLocation }}-${{ github.event.pull_request.base.sha || github.sha }} + restore-keys: | + python-requirements-${{ env.pythonLocation }} + python-requirements- + - name: Install dependencies run: | - pip install 'kscale-onshape-library @ git+https://github.com/kscalelabs/onshape.git@master' # Bleeding edge + pip install -e '.[dev]' - name: Build package env: ONSHAPE_ACCESS_KEY: ${{ secrets.ONSHAPE_ACCESS_KEY }} ONSHAPE_SECRET_KEY: ${{ secrets.ONSHAPE_SECRET_KEY }} ONSHAPE_API: ${{ secrets.ONSHAPE_API }} - run: python -m sim.scripts.update_stompy_s3 + run: | + python -m ksim.scripts.update_stompy_s3 + python -m ksim.scripts.update_stompy_arm_s3 + python -m ksim.scripts.update_stompy_torso_s3 - name: Configure AWS credentials uses: aws-actions/configure-aws-credentials@v1 @@ -55,3 +70,15 @@ jobs: for file in stompy/*.tar.gz; do aws s3 cp "$file" s3://${AWS_S3_BUCKET}/$(basename "$file") done + for file in stompy_arm/*.tar.gz; do + aws s3 cp "$file" s3://${AWS_S3_BUCKET}/arm_$(basename "$file") + done + + - name: Save cache + uses: actions/cache/save@v3 + if: github.ref == 'refs/heads/master' + with: + path: | + ${{ env.pythonLocation }} + .mypy_cache/ + key: ${{ steps.restore-cache.outputs.cache-primary-key }} diff --git a/sim/scripts/run_onshape_to_urdf.py b/sim/scripts/run_onshape_to_urdf.py new file mode 100644 index 00000000..09f49946 --- /dev/null +++ b/sim/scripts/run_onshape_to_urdf.py @@ -0,0 +1,108 @@ +# mypy: disable-error-code="import-not-found" +"""Updates the Stompy model.""" + +import tarfile +from pathlib import Path + +from kol.logging import configure_logging as configure_kol_logging +from kol.onshape.converter import Converter + +SUFFIX_TO_JOINT_EFFORT = { + "dof_x4_h": 1.5, + "dof_x4": 1.5, + "dof_x6": 3, + "dof_x8": 6, + "dof_x10": 12, + "knee_revolute": 13.9, + "ankle_revolute": 6, +} + +UPDATE_NAMES = { + "dof_2_upper_left_arm_1_rmd_x8_90_mock_1_dof_x8": "left shoulder pitch", + "upper_left_arm_1_rmd_x8_90_mock_1_dof_x8": "shoulder pitch", + "dof_1_upper_left_arm_1_rmd_x8_90_mock_1_dof_x8": "right shoulder pitch", + "dof_2_upper_left_arm_1_rmd_x8_90_mock_2_dof_x8": "left shoulder yaw", + "upper_left_arm_1_rmd_x8_90_mock_2_dof_x8": "shoulder yaw", + "dof_1_upper_left_arm_1_rmd_x8_90_mock_2_dof_x8": "right shoulder yaw", + "torso_1_rmd_x8_90_mock_1_dof_x8": "torso roll", + "dof_2_upper_left_arm_1_rmd_x4_24_mock_1_dof_x4": "left shoulder roll", + "upper_left_arm_1_rmd_x4_24_mock_1_dof_x4": "shoulder roll", + "dof_1_full_arm_7_dof_1_upper_left_arm_1_rmd_x4_24_mock_1_dof_x4": "right shoulder roll", + "dof_2_upper_left_arm_1_rmd_x4_24_mock_2_dof_x4": "left elbow pitch", + "upper_left_arm_1_rmd_x4_24_mock_2_dof_x4": "elbow pitch", + "dof_1_upper_left_arm_1_rmd_x4_24_mock_2_dof_x4": "right elbow pitch", + "dof_2_lower_arm_3_dof_1_rmd_x4_24_mock_1_dof_x4": "left wrist roll", + "lower_arm_3_dof_1_rmd_x4_24_mock_1_dof_x4": "wrist roll", + "dof_1_lower_arm_3_dof_1_rmd_x4_24_mock_1_dof_x4": "right wrist roll", + "dof_2_lower_arm_3_dof_1_rmd_x4_24_mock_2_dof_x4": "left wrist pitch", + "lower_arm_3_dof_1_rmd_x4_24_mock_2_dof_x4": "wrist pitch", + "dof_1_lower_arm_3_dof_1_rmd_x4_24_mock_2_dof_x4": "right wrist pitch", + "dof_2_lower_arm_3_dof_1_rmd_x4_24_mock_3_dof_x4": "left wrist yaw", + "lower_arm_3_dof_1_rmd_x4_24_mock_3_dof_x4": "wrist yaw", + "dof_1_lower_arm_3_dof_1_rmd_x4_24_mock_3_dof_x4": "right wrist yaw", + "dof_1_lower_arm_3_dof_1_hand_1_slider_1": "right hand right finger", + "dof_1_lower_arm_3_dof_1_hand_1_slider_2": "right hand left finger", + "dof_2_lower_arm_3_dof_1_hand_1_slider_1": "left hand right finger", + "dof_2_lower_arm_3_dof_1_hand_1_slider_2": "left hand left finger", + "dof_2_lower_arm_1_dof_1_rmd_x4_24_mock_1_dof_x4": "left wrist roll", + "lower_arm_1_dof_1_rmd_x4_24_mock_1_dof_x4": "wrist roll", + "dof_1_lower_arm_1_dof_1_rmd_x4_24_mock_1_dof_x4": "right wrist roll", + "dof_2_lower_arm_1_dof_1_rmd_x4_24_mock_2_dof_x4": "left wrist pitch", + "lower_arm_1_dof_1_rmd_x4_24_mock_2_dof_x4": "wrist pitch", + "dof_1_lower_arm_1_dof_1_rmd_x4_24_mock_2_dof_x4": "right wrist pitch", + "dof_2_lower_arm_1_dof_1_rmd_x4_24_mock_3_dof_x4": "left wrist yaw", + "lower_arm_1_dof_1_rmd_x4_24_mock_3_dof_x4": "wrist yaw", + "dof_1_lower_arm_1_dof_1_rmd_x4_24_mock_3_dof_x4": "right wrist yaw", + "dof_1_lower_arm_1_dof_1_hand_1_slider_1": "right hand right finger", + "dof_1_lower_arm_1_dof_1_hand_1_slider_2": "right hand left finger", + "dof_2_lower_arm_1_dof_1_hand_1_slider_1": "left hand right finger", + "dof_2_lower_arm_1_dof_1_hand_1_slider_2": "left hand left finger", + "lower_limbs_1_leg_assembly_2_rmd_x12_150_mock_1_dof_x12": "left hip pitch", + "lower_limbs_1_leg_assembly_1_rmd_x12_150_mock_1_dof_x12": "right hip pitch", + "lower_limbs_1_leg_assembly_2_rmd_x8_90_mock_1_dof_x8": "left hip yaw", + "lower_limbs_1_leg_assembly_1_rmd_x8_90_mock_1_dof_x8": "right hip yaw", + "lower_limbs_1_leg_assembly_2_rmd_x8_90_mock_2_dof_x8": "left hip roll", + "lower_limbs_1_leg_assembly_1_rmd_x8_90_mock_2_dof_x8": "right hip roll", + "lower_limbs_1_leg_assembly_2_rmd_x8_90_mock_3_dof_x8": "left knee pitch", + "lower_limbs_1_leg_assembly_1_rmd_x8_90_mock_3_dof_x8": "right knee pitch", + "lower_limbs_1_leg_assembly_2_rmd_x4_24_mock_1_dof_x4": "left ankle pitch", + "lower_limbs_1_leg_assembly_1_rmd_x4_24_mock_1_dof_x4": "right ankle pitch", + "lower_limbs_1_left_foot_1_rmd_x4_24_mock_1_dof_x4": "right ankle roll", + "lower_limbs_1_right_foot_1_rmd_x4_24_mock_1_dof_x4": "left ankle roll", + "full_arm_5_dof_1_upper_left_arm_1_rmd_x4_24_mock_1_dof_x4": "right shoulder roll", + "full_arm_5_dof_2_upper_left_arm_1_rmd_x4_24_mock_1_dof_x4": "left shoulder roll", +} + +OVERRIDE = [ + "hand_1_rmd_x4_24_mock_1_dof_x4", + "joint_lower_arm_3_dof_1_hand_1_rmd_x4_24_mock_1_dof_x4", +] + + +def run_onshape_to_urdf(model_url: str, output_dir: str | Path, override_central_node: str | None = None) -> None: + configure_kol_logging() + + output_dir = Path(output_dir) + + # Gets the latest STL URDF and MJCF. + converter = Converter( + document_url=model_url, + output_dir=output_dir / "latest_robot", + suffix_to_joint_effort=list(SUFFIX_TO_JOINT_EFFORT.items()), + disable_mimics=True, + mesh_ext="stl", + override_central_node=override_central_node, + remove_inertia=True, + merge_fixed_joints=True, + simplify_meshes=True, + override_joint_names=UPDATE_NAMES, + override_nonfixed=OVERRIDE, + ) + converter.save_mjcf() + latest_stl_urdf_path = converter.output_dir + + # Manually builds the tarball. + with tarfile.open(output_dir / "latest_meshes.tar.gz", "w:gz") as tar: + for suffix in (".urdf", ".stl", ".mjcf"): + for file in latest_stl_urdf_path.rglob(f"**/*{suffix}"): + tar.add(file, arcname=file.relative_to(latest_stl_urdf_path)) diff --git a/sim/scripts/update_stompy_arm_s3.py b/sim/scripts/update_stompy_arm_s3.py new file mode 100644 index 00000000..206a7e86 --- /dev/null +++ b/sim/scripts/update_stompy_arm_s3.py @@ -0,0 +1,33 @@ +# mypy: disable-error-code="import-not-found" +"""Updates the Stompy model.""" + +from sim.scripts.run_onshape_to_urdf import run_onshape_to_urdf + +STOMPY_ARM_7DOF = ( + "https://cad.onshape.com/documents/afaee604f6ca311526a6aec8/" + "w/29af84cb974c2d825b71de39/e/949e5b6cd071fee000e2c296" +) + +STOMPY_ARM_5DOF = ( + "https://cad.onshape.com/documents/afaee604f6ca311526a6aec8/" + "w/29af84cb974c2d825b71de39/e/4fef6bce7179a665e62b03ba" +) + + +def main() -> None: + run_onshape_to_urdf( + model_url=STOMPY_ARM_7DOF, + output_dir="stompy_arm_7dof", + override_central_node="upper_left_arm_1_arm_part_1_1", + ) + + run_onshape_to_urdf( + model_url=STOMPY_ARM_5DOF, + output_dir="stompy_arm_5dof", + override_central_node="upper_left_arm_1_arm_part_1_1", + ) + + +if __name__ == "__main__": + # python -m ksim.scripts.update_stompy_arm_s3 + main() diff --git a/sim/scripts/update_stompy_s3.py b/sim/scripts/update_stompy_s3.py index b214010d..e232e01b 100644 --- a/sim/scripts/update_stompy_s3.py +++ b/sim/scripts/update_stompy_s3.py @@ -1,87 +1,31 @@ # mypy: disable-error-code="import-not-found" """Updates the Stompy model.""" -import tarfile -from pathlib import Path +from sim.scripts.run_onshape_to_urdf import run_onshape_to_urdf -STOMPY_MODEL = ( +STOMPY_MODEL_7DOF = ( "https://cad.onshape.com/documents/71f793a23ab7562fb9dec82d/" - "w/6160a4f44eb6113d3fa116cd/e/1a95e260677a2d2d5a3b1eb3" + "w/e879bcf272425973f9b3d8ad/e/1a95e260677a2d2d5a3b1eb3" ) -SUFFIX_TO_JOINT_EFFORT = { - "dof_x4_h": 1.5, - "dof_x4": 1.5, - "dof_x6": 3, - "dof_x8": 6, - "dof_x10": 12, - "knee_revolute": 13.9, - "ankle_revolute": 6, -} +STOMPY_MODEL_5DOF = ( + "https://cad.onshape.com/documents/71f793a23ab7562fb9dec82d/" + "w/e879bcf272425973f9b3d8ad/e/e07509571989528061c06a08" +) def main() -> None: - try: - from kol.logging import configure_logging - from kol.onshape.converter import Converter - except ImportError: - raise ImportError("Please install the `kscale-onshape-library` package to run this script.") - - configure_logging() - - output_dir = Path("stompy") - - # Gets the latest STL URDF. - converter = Converter( - document_url=STOMPY_MODEL, - output_dir=output_dir / "latest_stl_urdf", - suffix_to_joint_effort=list(SUFFIX_TO_JOINT_EFFORT.items()), - disable_mimics=True, - mesh_ext="stl", + run_onshape_to_urdf( + model_url=STOMPY_MODEL_7DOF, + output_dir="stompy_7dof", ) - converter.save_urdf() - latest_stl_urdf_path = converter.output_dir - # Manually builds the tarball. - with tarfile.open(output_dir / "latest_stl_urdf.tar.gz", "w:gz") as tar: - for suffix in (".urdf", ".stl"): - for file in latest_stl_urdf_path.rglob(f"**/*{suffix}"): - tar.add(file, arcname=file.relative_to(latest_stl_urdf_path)) - - # Gets the latest OBJ URDF. - converter = Converter( - document_url=STOMPY_MODEL, - output_dir=output_dir / "latest_obj_urdf", - suffix_to_joint_effort=list(SUFFIX_TO_JOINT_EFFORT.items()), - disable_mimics=True, - mesh_ext="obj", + run_onshape_to_urdf( + model_url=STOMPY_MODEL_5DOF, + output_dir="stompy_5dof", ) - converter.save_urdf() - latest_obj_urdf_path = converter.output_dir - - # Manually builds the tarball. - with tarfile.open(output_dir / "latest_obj_urdf.tar.gz", "w:gz") as tar: - for suffix in (".urdf", ".obj"): - for file in latest_obj_urdf_path.rglob(f"**/*{suffix}"): - tar.add(file, arcname=file.relative_to(latest_obj_urdf_path)) - - # Gets the latest MJCF. - converter = Converter( - document_url=STOMPY_MODEL, - output_dir=output_dir / "latest_mjcf", - suffix_to_joint_effort=list(SUFFIX_TO_JOINT_EFFORT.items()), - disable_mimics=True, - ) - converter.save_mjcf() - latest_mjcf_path = converter.output_dir - - # Manually builds the tarball. - with tarfile.open(output_dir / "latest_mjcf.tar.gz", "w:gz") as tar: - for suffix in (".xml", ".stl"): - for file in latest_mjcf_path.rglob(f"**/*{suffix}"): - tar.add(file, arcname=file.relative_to(latest_mjcf_path)) if __name__ == "__main__": - # python -m sim.scripts.update_stompy + # python -m ksim.scripts.update_stompy_s3 main() diff --git a/sim/scripts/update_stompy_torso_s3.py b/sim/scripts/update_stompy_torso_s3.py new file mode 100644 index 00000000..44140510 --- /dev/null +++ b/sim/scripts/update_stompy_torso_s3.py @@ -0,0 +1,33 @@ +# mypy: disable-error-code="import-not-found" +"""Updates the Stompy model.""" + +from sim.scripts.run_onshape_to_urdf import run_onshape_to_urdf + +STOMPY_TORSO_7DOF = ( + "https://cad.onshape.com/documents/77f178833017912bdc0eaaa8/w/" + "958f1684049f1413f6dd7831/e/348cad65143f892a40e33206" +) + +STOMPY_TORSO_5DOF = ( + "https://cad.onshape.com/documents/77f178833017912bdc0eaaa8/" + "w/958f1684049f1413f6dd7831/e/363614f1fc7c150003de244c" +) + + +def main() -> None: + run_onshape_to_urdf( + model_url=STOMPY_TORSO_7DOF, + output_dir="stompy_torso_7dof", + override_central_node="torso_1_hip_mount_1", + ) + + run_onshape_to_urdf( + model_url=STOMPY_TORSO_5DOF, + output_dir="stompy_torso_5dof", + override_central_node="torso_1_hip_mount_1", + ) + + +if __name__ == "__main__": + # python -m ksim.scripts.update_stompy_arm_s3 + main() From b5d97c121bb3151567bcf9ba37e0401cb10d2ae2 Mon Sep 17 00:00:00 2001 From: wuallenwu Date: Tue, 2 Jul 2024 18:52:39 -0700 Subject: [PATCH 2/2] lint --- sim/scripts/run_onshape_to_urdf.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sim/scripts/run_onshape_to_urdf.py b/sim/scripts/run_onshape_to_urdf.py index 09f49946..b3570dc0 100644 --- a/sim/scripts/run_onshape_to_urdf.py +++ b/sim/scripts/run_onshape_to_urdf.py @@ -3,6 +3,7 @@ import tarfile from pathlib import Path +from typing import Union from kol.logging import configure_logging as configure_kol_logging from kol.onshape.converter import Converter @@ -79,7 +80,9 @@ ] -def run_onshape_to_urdf(model_url: str, output_dir: str | Path, override_central_node: str | None = None) -> None: +def run_onshape_to_urdf( + model_url: str, output_dir: Union[str, Path], override_central_node: Union[str, None] = None +) -> None: configure_kol_logging() output_dir = Path(output_dir)