Skip to content

Add missing arm get_geometries method in examples #401

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

Merged
merged 1 commit into from
Aug 23, 2023
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
10 changes: 9 additions & 1 deletion docs/examples/my_cool_arm.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

import asyncio
import json
from typing import Any, Dict, Optional, Tuple
from typing import Any, Dict, List, Optional, Tuple

from viam.components.arm import Arm, JointPositions, KinematicsFileFormat, Pose
from viam.operations import run_with_operation
from viam.proto.common import Capsule, Geometry, Sphere


class MyCoolArm(Arm):
Expand All @@ -26,6 +27,10 @@ def __init__(self, name: str):
# Starting joint positions
self.joint_positions = JointPositions(values=[0, 0, 0, 0, 0, 0])
self.is_stopped = True
self.geometries = [
Geometry(center=Pose(x=1, y=2, z=3, o_x=2, o_y=3, o_z=4, theta=20), sphere=Sphere(radius_mm=2)),
Geometry(center=Pose(x=1, y=2, z=3, o_x=2, o_y=3, o_z=4, theta=20), capsule=Capsule(radius_mm=3, length_mm=8)),
]

# Minimal working kinematics model
self.kinematics = json.dumps(
Expand Down Expand Up @@ -92,5 +97,8 @@ async def stop(self, extra: Optional[Dict[str, Any]] = None, **kwargs):
async def is_moving(self) -> bool:
return not self.is_stopped

async def get_geometries(self) -> List[Geometry]:
return self.geometries

async def get_kinematics(self, extra: Optional[Dict[str, Any]] = None, **kwargs) -> Tuple[KinematicsFileFormat.ValueType, bytes]:
return KinematicsFileFormat.KINEMATICS_FILE_FORMAT_SVA, self.kinematics
12 changes: 10 additions & 2 deletions examples/complex_module/src/arm/my_arm.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import asyncio
import os
from typing import Any, ClassVar, Dict, Mapping, Optional, Tuple
from typing import Any, ClassVar, Dict, List, Mapping, Optional, Tuple

from typing_extensions import Self

from viam.components.arm import Arm, JointPositions, KinematicsFileFormat, Pose
from viam.operations import run_with_operation
from viam.proto.app.robot import ComponentConfig
from viam.proto.common import ResourceName
from viam.proto.common import Capsule, Geometry, ResourceName, Sphere
from viam.resource.base import ResourceBase
from viam.resource.types import Model, ModelFamily

Expand All @@ -30,6 +31,10 @@ def __init__(self, name: str):
# Starting joint positions
self.joint_positions = JointPositions(values=[0, 0, 0, 0, 0, 0])
self.is_stopped = True
self.geometries = [
Geometry(center=Pose(x=1, y=2, z=3, o_x=2, o_y=3, o_z=4, theta=20), sphere=Sphere(radius_mm=2)),
Geometry(center=Pose(x=1, y=2, z=3, o_x=2, o_y=3, o_z=4, theta=20), capsule=Capsule(radius_mm=3, length_mm=8)),
]
super().__init__(name)

@classmethod
Expand Down Expand Up @@ -90,6 +95,9 @@ async def stop(self, extra: Optional[Dict[str, Any]] = None, **kwargs):
async def is_moving(self) -> bool:
return not self.is_stopped

async def get_geometries(self) -> List[Geometry]:
return self.geometries

async def get_kinematics(self, extra: Optional[Dict[str, Any]] = None, **kwargs) -> Tuple[KinematicsFileFormat.ValueType, bytes]:
dirname = os.path.dirname(__file__)
filepath = os.path.join(dirname, "./my_arm_kinematics.json")
Expand Down