Skip to content

Commit 9ec4ab4

Browse files
authored
DOCS-1873: Add remaining component methods and imports (#543)
1 parent 044a245 commit 9ec4ab4

File tree

14 files changed

+290
-0
lines changed

14 files changed

+290
-0
lines changed

src/viam/components/arm/arm.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ class Arm(ComponentBase):
1414
This acts as an abstract base class for any drivers representing specific
1515
arm implementations. This cannot be used on its own. If the ``__init__()`` function is
1616
overridden, it must call the ``super().__init__()`` function.
17+
18+
::
19+
20+
from viam.components.arm import Arm
21+
# To use move_to_position:
22+
from viam.proto.common import Pose
23+
# To use move_to_joint_positions:
24+
from viam.proto.component.arm import JointPositions
1725
"""
1826

1927
SUBTYPE: Final = Subtype(RESOURCE_NAMESPACE_RDK, RESOURCE_TYPE_COMPONENT, "arm") # pyright: ignore [reportIncompatibleVariableOverride]

src/viam/components/base/base.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ class Base(ComponentBase):
1515
This acts as an abstract base class for any drivers representing specific
1616
base implementations. This cannot be used on its own. If the ``__init__()`` function is
1717
overridden, it must call the ``super().__init__()`` function.
18+
19+
::
20+
21+
from viam.components.base import Base
1822
"""
1923

2024
SUBTYPE: Final = Subtype( # pyright: ignore [reportIncompatibleVariableOverride]

src/viam/components/board/board.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ class Board(ComponentBase):
1717
This acts as an abstract base class for any drivers representing specific
1818
board implementations. This cannot be used on its own. If the ``__init__()`` function is
1919
overridden, it must call the ``super().__init__()`` function.
20+
21+
::
22+
23+
from viam.components.board import Board
2024
"""
2125

2226
SUBTYPE: Final = Subtype( # pyright: ignore [reportIncompatibleVariableOverride]

src/viam/components/camera/camera.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ class Camera(ComponentBase):
2525
This acts as an abstract base class for any drivers representing specific
2626
camera implementations. This cannot be used on its own. If the ``__init__()`` function is
2727
overridden, it must call the ``super().__init__()`` function.
28+
29+
::
30+
31+
from viam.components.camera import Camera
2832
"""
2933

3034
SUBTYPE: Final = Subtype( # pyright: ignore [reportIncompatibleVariableOverride]

src/viam/components/encoder/encoder.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ class Properties:
2020
This acts as an abstract base class for any drivers representing specific
2121
encoder implementations. This cannot be used on its own. If the ``__init__()`` function is
2222
overridden, it must call the ``super().__init__()`` function.
23+
24+
::
25+
26+
from viam.components.encoder import Encoder
2327
"""
2428

2529
SUBTYPE: Final = Subtype( # pyright: ignore [reportIncompatibleVariableOverride]

src/viam/components/gantry/gantry.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ class Gantry(ComponentBase):
1313
This acts as an abstract base class for any drivers representing specific
1414
gantry implementations. This cannot be used on its own. If the ``__init__()`` function is
1515
overridden, it must call the ``super().__init__()`` function.
16+
17+
::
18+
19+
from viam.components.gantry import Gantry
1620
"""
1721

1822
SUBTYPE: Final = Subtype( # pyright: ignore [reportIncompatibleVariableOverride]

src/viam/components/generic/generic.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ class Generic(ComponentBase):
1515
To create a Generic component (an arbitrary component that can process commands), this ``Generic`` component should be subclassed
1616
and the ``do_command`` function implemented.
1717
18+
::
19+
20+
from viam.components.generic import Generic
21+
1822
Example::
1923
2024
class ComplexComponent(Generic):

src/viam/components/gripper/gripper.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ class Gripper(ComponentBase):
1212
This acts as an abstract base class for any drivers representing specific
1313
gripper implementations. This cannot be used on its own. If the ``__init__()`` function is
1414
overridden, it must call the ``super().__init__()`` function.
15+
16+
::
17+
18+
from viam.components.gripper import Gripper
1519
"""
1620

1721
SUBTYPE: Final = Subtype( # pyright: ignore [reportIncompatibleVariableOverride]

src/viam/components/input/input.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ class Controller(ComponentBase):
135135
Controller is a logical "container" more than an actual device
136136
Could be a single gamepad, or a collection of digitalInterrupts
137137
and analogReaders, a keyboard, etc.
138+
139+
::
140+
141+
from viam.components.input import Control, Controller, EventType
138142
"""
139143

140144
SUBTYPE: Final = Subtype( # pyright: ignore [reportIncompatibleVariableOverride]

src/viam/components/motor/motor.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ class Motor(ComponentBase):
1313
This acts as an abstract base class for any drivers representing specific
1414
motor implementations. This cannot be used on its own. If the ``__init__()`` function is
1515
overridden, it must call the ``super().__init__()`` function.
16+
17+
::
18+
19+
from viam.components.motor import Motor
1620
"""
1721

1822
@dataclass
@@ -36,6 +40,13 @@ async def set_power(
3640
Sets the "percentage" of power the motor should employ between -1 and 1.
3741
When ``power`` is negative, the rotation will be in the backward direction.
3842
43+
::
44+
45+
my_motor = Motor.from_robot(robot=robot, name="my_motor")
46+
47+
# Set the power to 40% forwards.
48+
await my_motor.set_power(power=0.4)
49+
3950
Args:
4051
power (float): Power between -1 and 1
4152
(negative implies backwards).
@@ -57,6 +68,13 @@ async def go_for(
5768
When ``rpm`` or ``revolutions`` is a negative value, the rotation will be in the backward direction.
5869
Note: if both ``rpm`` and ``revolutions`` are negative, the motor will spin in the forward direction.
5970
71+
::
72+
73+
my_motor = Motor.from_robot(robot=robot, name="my_motor")
74+
75+
# Turn the motor 7.2 revolutions at 60 RPM.
76+
await my_motor.go_for(rpm=60, revolutions=7.2)
77+
6078
Args:
6179
rpm (float): Speed at which the motor should move in rotations per minute
6280
(negative implies backwards).
@@ -81,6 +99,13 @@ async def go_to(
8199
Regardless of the directionality of the ``rpm`` this function will move
82100
the motor towards the specified position.
83101
102+
::
103+
104+
my_motor = Motor.from_robot(robot=robot, name="my_motor")
105+
106+
# Turn the motor to 8.3 revolutions from home at 75 RPM.
107+
await my_motor.go_to(rpm=75, revolutions=8.3)
108+
84109
Args:
85110
rpm (float): Speed at which the motor should rotate (absolute value).
86111
position_revolutions (float): Target position relative to home/zero, in revolutions.
@@ -99,6 +124,13 @@ async def reset_zero_position(
99124
"""
100125
Set the current position (modified by ``offset``) to be the new zero (home) position.
101126
127+
::
128+
129+
my_motor = Motor.from_robot(robot=robot, name="my_motor")
130+
131+
# Set the current position as the new home position with no offset.
132+
await my_motor.reset_zero_position(offset=0.0)
133+
102134
Args:
103135
offset (float): The offset from the current position to new home/zero position.
104136
"""
@@ -117,6 +149,13 @@ async def get_position(
117149
The value returned is the number of revolutions relative to its zero position.
118150
This method will raise an exception if position reporting is not supported by the motor.
119151
152+
::
153+
154+
my_motor = Motor.from_robot(robot=robot, name="my_motor")
155+
156+
# Get the current position of the motor.
157+
position = await my_motor.get_position()
158+
120159
Returns:
121160
float: Number of revolutions the motor is away from zero/home.
122161
"""
@@ -134,6 +173,17 @@ async def get_properties(
134173
Report a dictionary mapping optional properties to
135174
whether it is supported by this motor.
136175
176+
::
177+
178+
my_motor = Motor.from_robot(robot=robot, name="my_motor")
179+
180+
# Report a dictionary mapping optional properties to whether it is supported by
181+
# this motor.
182+
properties = await my_motor.get_properties()
183+
184+
# Print out the properties.
185+
print(f'Properties: {properties}')
186+
137187
Returns:
138188
Properties: Map of feature names to supported status.
139189
"""
@@ -149,6 +199,13 @@ async def stop(
149199
):
150200
"""
151201
Stop the motor immediately, without any gradual step down.
202+
203+
::
204+
205+
my_motor = Motor.from_robot(robot=robot, name="my_motor")
206+
207+
# Stop the motor.
208+
await my_motor.stop()
152209
"""
153210
...
154211

@@ -163,6 +220,15 @@ async def is_powered(
163220
"""
164221
Returns whether or not the motor is currently running.
165222
223+
::
224+
225+
my_motor = Motor.from_robot(robot=robot, name="my_motor")
226+
227+
# Check whether the motor is currently running.
228+
powered = await my_motor.is_powered()
229+
230+
print('Powered: ', powered)
231+
166232
Returns:
167233
bool: Indicates whether the motor is currently powered.
168234
float: The current power percentage of the motor
@@ -174,6 +240,14 @@ async def is_moving(self) -> bool:
174240
"""
175241
Get if the motor is currently moving.
176242
243+
::
244+
245+
my_motor = Motor.from_robot(robot=robot, name="my_motor")
246+
247+
# Check whether the motor is currently moving.
248+
moving = await my_motor.is_moving()
249+
print('Moving: ', moving)
250+
177251
Returns:
178252
bool: Whether the motor is moving.
179253
"""

0 commit comments

Comments
 (0)