Skip to content

Commit e6b63ec

Browse files
authored
DOCS-1870: Add methods for arm, board, and base (#541)
1 parent 9ec4ab4 commit e6b63ec

File tree

3 files changed

+304
-0
lines changed

3 files changed

+304
-0
lines changed

src/viam/components/arm/arm.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ async def get_end_position(
3737
"""
3838
Get the current position of the end of the arm expressed as a Pose.
3939
40+
::
41+
42+
my_arm = Arm.from_robot(robot=robot, name="my_arm")
43+
44+
# Get the end position of the arm as a Pose.
45+
pos = await my_arm.get_end_position()
46+
4047
Returns:
4148
Pose: The location and orientation of the arm described as a Pose.
4249
"""
@@ -54,6 +61,16 @@ async def move_to_position(
5461
"""
5562
Move the end of the arm to the Pose specified in ``pose``.
5663
64+
::
65+
66+
my_arm = Arm.from_robot(robot=robot, name="my_arm")
67+
68+
# Create a Pose for the arm.
69+
examplePose = Pose(x=5, y=5, z=5, o_x=5, o_y=5, o_z=5, theta=20)
70+
71+
# Move your arm to the Pose.
72+
await my_arm.move_to_position(pose=examplePose)
73+
5774
Args:
5875
pose (Pose): The destination Pose for the arm.
5976
"""
@@ -71,6 +88,21 @@ async def move_to_joint_positions(
7188
"""
7289
Move each joint on the arm to the corresponding angle specified in ``positions``.
7390
91+
::
92+
93+
my_arm = Arm.from_robot(robot=robot, name="my_arm")
94+
95+
# Declare a list of values with your desired rotational value for each joint on
96+
# the arm.
97+
degrees = [0.0, 45.0, 0.0, 0.0, 0.0]
98+
99+
# Declare a new JointPositions with these values.
100+
jointPos = arm.move_to_joint_positions(
101+
JointPositions(values=[0.0, 45.0, 0.0, 0.0, 0.0]))
102+
103+
# Move each joint of the arm to the position these values specify.
104+
await my_arm.move_to_joint_positions(positions=jointPos)
105+
74106
Args:
75107
positions (JointPositions): The destination ``JointPositions`` for the arm.
76108
"""
@@ -87,6 +119,13 @@ async def get_joint_positions(
87119
"""
88120
Get the JointPositions representing the current position of the arm.
89121
122+
::
123+
124+
my_arm = Arm.from_robot(robot=robot, name="my_arm")
125+
126+
# Get the current position of each joint on the arm as JointPositions.
127+
pos = await my_arm.get_joint_positions()
128+
90129
Returns:
91130
JointPositions: The current JointPositions for the arm.
92131
"""
@@ -102,6 +141,13 @@ async def stop(
102141
):
103142
"""
104143
Stop all motion of the arm. It is assumed that the arm stops immediately.
144+
145+
::
146+
147+
my_arm = Arm.from_robot(robot=robot, name="my_arm")
148+
149+
# Stop all motion of the arm. It is assumed that the arm stops immediately.
150+
await my_arm.stop()
105151
"""
106152
...
107153

@@ -110,6 +156,16 @@ async def is_moving(self) -> bool:
110156
"""
111157
Get if the arm is currently moving.
112158
159+
::
160+
161+
my_arm = Arm.from_robot(robot=robot, name="my_arm")
162+
163+
# Stop all motion of the arm. It is assumed that the arm stops immediately.
164+
await my_arm.stop()
165+
166+
# Print if the arm is currently moving.
167+
print(my_arm.is_moving())
168+
113169
Returns:
114170
bool: Whether the arm is moving.
115171
"""
@@ -122,6 +178,19 @@ async def get_kinematics(
122178
"""
123179
Get the kinematics information associated with the arm.
124180
181+
::
182+
183+
my_arm = Arm.from_robot(robot=robot, name="my_arm")
184+
185+
# Get the kinematics information associated with the arm.
186+
kinematics = await my_arm.get_kinematics()
187+
188+
# Get the format of the kinematics file.
189+
k_file = kinematics[0]
190+
191+
# Get the byte contents of the file.
192+
k_bytes = kinematics[1]
193+
125194
Returns:
126195
Tuple[KinematicsFileFormat.ValueType, bytes]:
127196
- KinematicsFileFormat.ValueType:

src/viam/components/base/base.py

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@ async def move_straight(
4747
When ``distance`` or ``velocity`` is 0, the base will stop.
4848
This method blocks until completed or cancelled.
4949
50+
::
51+
52+
my_base = Base.from_robot(robot=robot, name="my_base")
53+
54+
# Move the base 40 mm at a velocity of 90 mm/s, forward.
55+
await my_base.move_straight(distance=40, velocity=90)
56+
57+
# Move the base 40 mm at a velocity of -90 mm/s, backward.
58+
await my_base.move_straight(distance=40, velocity=-90)
59+
5060
Args:
5161
distance (int): The distance (in millimeters) to move.
5262
Negative implies backwards.
@@ -71,6 +81,13 @@ async def spin(
7181
When ``velocity`` is 0, the base will stop.
7282
This method blocks until completed or cancelled.
7383
84+
::
85+
86+
my_base = Base.from_robot(robot=robot, name="my_base")
87+
88+
# Spin the base 10 degrees at an angular velocity of 15 deg/sec.
89+
await my_base.spin(angle=10, velocity=15)
90+
7491
Args:
7592
angle (float): The angle (in degrees) to spin.
7693
velocity (float): The angular velocity (in degrees per second)
@@ -96,6 +113,34 @@ async def set_power(
96113
When ``linear`` and ``angular`` are both nonzero, the base will move in an arc,
97114
with a tighter radius if angular power is greater than linear power.
98115
116+
::
117+
118+
my_base = Base.from_robot(robot=robot, name="my_base")
119+
120+
# Make your wheeled base move forward. Set linear power to 75%.
121+
print("move forward")
122+
await my_base.set_power(
123+
linear=Vector3(x=0, y=-.75, z=0),
124+
angular=Vector3(x=0, y=0, z=0))
125+
126+
# Make your wheeled base move backward. Set linear power to -100%.
127+
print("move backward")
128+
await my_base.set_power(
129+
linear=Vector3(x=0, y=-1.0, z=0),
130+
angular=Vector3(x=0, y=0, z=0))
131+
132+
# Make your wheeled base spin left. Set angular power to 100%.
133+
print("spin left")
134+
await my_base.set_power(
135+
linear=Vector3(x=0, y=0, z=0),
136+
angular=Vector3(x=0, y=0, z=1))
137+
138+
# Make your wheeled base spin right. Set angular power to -75%.
139+
print("spin right")
140+
await my_base.set_power(
141+
linear=Vector3(x=0, y=0, z=0),
142+
angular=Vector3(x=0, y=0, z=-.75))
143+
99144
Args:
100145
linear (Vector3): The linear component. Only the Y component is used
101146
for wheeled base. Positive implies forwards.
@@ -117,6 +162,14 @@ async def set_velocity(
117162
"""
118163
Set the linear and angular velocities of the base.
119164
165+
::
166+
167+
my_base = Base.from_robot(robot=robot, name="my_base")
168+
169+
# Set the linear velocity to 50 mm/sec and the angular velocity to
170+
# 15 degree/sec.
171+
await my_base.set_velocity(
172+
linear=Vector3(x=0, y=50, z=0), angular=Vector3(x=0, y=0, z=15))
120173
121174
Args:
122175
linear (Vector3): Velocity in mm/sec
@@ -133,6 +186,16 @@ async def stop(
133186
):
134187
"""
135188
Stop the base.
189+
190+
::
191+
192+
my_base = Base.from_robot(robot=robot, name="my_base")
193+
194+
# Move the base forward 10 mm at a velocity of 50 mm/s.
195+
await my_base.move_straight(distance=10, velocity=50)
196+
197+
# Stop the base.
198+
await my_base.stop()
136199
"""
137200
...
138201

@@ -141,6 +204,14 @@ async def is_moving(self) -> bool:
141204
"""
142205
Get if the base is currently moving.
143206
207+
::
208+
209+
my_base = Base.from_robot(robot=robot, name="my_base")
210+
211+
# Check whether the base is currently moving.
212+
moving = await my_base.is_moving()
213+
print('Moving: ', moving)
214+
144215
Returns:
145216
bool: Whether the base is moving.
146217
"""
@@ -151,6 +222,22 @@ async def get_properties(self, *, timeout: Optional[float] = None, **kwargs) ->
151222
"""
152223
Get the base width and turning radius
153224
225+
::
226+
227+
my_base = Base.from_robot(robot=robot, name="my_base")
228+
229+
# Get the width and turning radius of the base
230+
properties = await my_base.get_properties()
231+
232+
# Get the width
233+
print(f"Width of base: {properties.width_meters}")
234+
235+
# Get the turning radius
236+
print(f"Turning radius of base: {properties.turning_radius_meters}")
237+
238+
# Get the wheel circumference
239+
print(f"Wheel circumference of base: {properties.wheel_circumference_meters}")
240+
154241
Returns:
155242
Properties: The properties of the base
156243
"""

0 commit comments

Comments
 (0)