Repository navigation
Expand file tree
/
Copy pathhello_robot.py
More file actions
61 lines (56 loc) · 2.54 KB
/
Copy pathhello_robot.py
File metadata and controls
61 lines (56 loc) · 2.54 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
import asyncio
import os
from hebbian_rua import StationClient
from hebbian_rua.client.contract.station_api import (
ArmMode,
PreviewRefused,
ProjectedPoseOutcome,
QuaternionOrientation,
UnavailableProjection,
)
from hebbian_rua.client.station_client import (
DEFAULT_SERVER,
JointSpeedRadiansPerSecond,
WorldPositionMeters,
)
async def main() -> None:
async with StationClient(
os.environ.get("HEBBIAN_STATION_URL", DEFAULT_SERVER)
) as station:
arm = station.arm("follower")
# 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("follower")
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.22, 0.0, 0.10])
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.5)
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
if __name__ == "__main__":
asyncio.run(main())