Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

script updates #18

Merged
merged 2 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 30 additions & 3 deletions .github/workflows/update_stompy_s3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
release:
types: [created]
schedule:
- cron: "30 2 * * *"
- cron: "30 10 * * *"
workflow_dispatch:

permissions:
Expand All @@ -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
Expand All @@ -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 }}
111 changes: 111 additions & 0 deletions sim/scripts/run_onshape_to_urdf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# mypy: disable-error-code="import-not-found"
"""Updates the Stompy model."""

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

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: Union[str, Path], override_central_node: Union[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))
33 changes: 33 additions & 0 deletions sim/scripts/update_stompy_arm_s3.py
Original file line number Diff line number Diff line change
@@ -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()
84 changes: 14 additions & 70 deletions sim/scripts/update_stompy_s3.py
Original file line number Diff line number Diff line change
@@ -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()
33 changes: 33 additions & 0 deletions sim/scripts/update_stompy_torso_s3.py
Original file line number Diff line number Diff line change
@@ -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()
Loading