Repository navigation
Expand file tree
/
Copy pathhello_robot.py
More file actions
83 lines (75 loc) · 3.17 KB
/
Copy pathhello_robot.py
File metadata and controls
83 lines (75 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
from typing import Annotated
from cyclopts import App, Parameter
from hebbian_rua import StationClient
from hebbian_rua.client.contract.station_api import (
ArmMode,
PreviewRefused,
ProjectedPoseOutcome,
QuaternionOrientation,
UnavailableProjection,
)
from hebbian_rua.client.environment import load_environment
from hebbian_rua.client.station_client import (
JointSpeedRadiansPerSecond,
WorldPositionMeters,
)
command_line = App(
help=(
"Preview and move an SO-101 arm. Use a real arm whenever available. "
"Reserve simulation for testing without hardware."
),
version_flags=(),
)
@command_line.default
async def main(
*,
requested_arm: Annotated[
str | None,
Parameter(name="--arm", help="Arm name. Defaults to the station's sole arm."),
] = None,
) -> int | None:
load_environment()
async with StationClient() as station:
try:
arm_name = await station.resolve_arm_name(requested_arm)
except ValueError as error:
command_line.error_console.print(str(error), markup=False)
return 2
arm = station.arm(arm_name)
# Holding the lease keeps the viewer and other programs off the arm while we run.
# Only the lease can move the arm; enable, stop and reads are on `arm`.
async with station.holding_lease("hello robot") as lease:
moving_arm = lease.arm(arm_name)
if (await arm.state()).mode != ArmMode.holding:
enabled = await arm.enable() # the arm holds its current pose
if not enabled.completed:
raise SystemExit(f"Could not enable the arm: {enabled}")
target = WorldPositionMeters([0.18, 0.0, 0.16])
preview = await arm.preview_pose(
target
) # let the solver choose an orientation
if isinstance(preview, PreviewRefused):
raise SystemExit(f"Preview refused: {preview.reason}: {preview.detail}")
match preview.outcome:
case ProjectedPoseOutcome(pose=pose, within_tolerance=True):
orientation = QuaternionOrientation(quaternion=pose.quaternion)
case ProjectedPoseOutcome(reason=reason):
raise SystemExit(
f"Preview only found an approximate pose: {reason}"
)
case UnavailableProjection(reason=reason):
raise SystemExit(f"Preview is unavailable: {reason}")
speed = JointSpeedRadiansPerSecond(0.25)
result = await moving_arm.move_to_pose(
target, orientation, max_joint_speed=speed
)
print(result.outcome, result.detail) # "completed", or why not
if not result.completed:
raise SystemExit("Move did not complete")
if result.was_limited:
raise SystemExit("The planned move was limited before the target")
print((await moving_arm.set_gripper(1.0)).outcome) # 0 is closed, 1 is open
print((await arm.state()).tool) # where the tool actually is
return None
if __name__ == "__main__":
command_line()