Skip to content

Commit be0de8a

Browse files
authored
RSDK-398, RSDK-861: Some documentation fixes (#187)
1 parent 4a60c5b commit be0de8a

File tree

26 files changed

+166
-234
lines changed

26 files changed

+166
-234
lines changed

src/viam/components/arm/arm.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ class Arm(ComponentBase):
1313
Arm represents a physical robot arm that exists in three-dimensional space.
1414
1515
This acts as an abstract base class for any drivers representing specific
16-
arm implementations. This cannot be used on its own. If the `__init__()` function is
17-
overridden, it must call the `super().__init__()` function.
16+
arm implementations. This cannot be used on its own. If the ``__init__()`` function is
17+
overridden, it must call the ``super().__init__()`` function.
1818
"""
1919

2020
@abc.abstractmethod
@@ -43,14 +43,14 @@ async def move_to_position(
4343
**kwargs,
4444
):
4545
"""
46-
Move the end of the arm to the Pose specified in `pose`.
47-
When obstacles are specified in `world_state`, the motion plan of the arm will avoid them.
46+
Move the end of the arm to the Pose specified in ``pose``.
47+
When obstacles are specified in ``world_state``, the motion plan of the arm will avoid them.
4848
4949
Args:
5050
5151
pose (Pose): The destination Pose for the arm.
5252
53-
world_state (WorldState): The obstacles for the arm to avoid on its way to `pose`.
53+
world_state (WorldState): The obstacles for the arm to avoid on its way to ``pose``.
5454
"""
5555
...
5656

@@ -64,11 +64,11 @@ async def move_to_joint_positions(
6464
**kwargs,
6565
):
6666
"""
67-
Move each joint on the arm to the corresponding angle specified in `positions`.
67+
Move each joint on the arm to the corresponding angle specified in ``positions``.
6868
6969
Args:
7070
71-
positions (JointPositions): The destination `JointPositions` for the arm.
71+
positions (JointPositions): The destination ``JointPositions`` for the arm.
7272
"""
7373
...
7474

src/viam/components/arm/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class ArmClient(Arm):
2323
"""
2424
gRPC client for an Arm component.
2525
26-
Used to communicate with an existing `Arm` implementation over gRPC.
26+
Used to communicate with an existing ``Arm`` implementation over gRPC.
2727
"""
2828

2929
def __init__(self, name: str, channel: Channel):

src/viam/components/base/base.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ class Base(ComponentBase):
1212
Base represents a physical base of a robot.
1313
1414
This acts as an abstract base class for any drivers representing specific
15-
base implementations. This cannot be used on its own. If the `__init__()` function is
16-
overridden, it must call the `super().__init__()` function.
15+
base implementations. This cannot be used on its own. If the ``__init__()`` function is
16+
overridden, it must call the ``super().__init__()`` function.
1717
"""
1818

1919
@abc.abstractmethod
@@ -27,9 +27,9 @@ async def move_straight(
2727
**kwargs,
2828
):
2929
"""
30-
Move the base in a straight line the given `distance`, expressed in millimeters,
31-
at the given `velocity`, expressed in millimeters per second.
32-
When `distance` or `velocity` is 0, the base will stop.
30+
Move the base in a straight line the given ``distance``, expressed in millimeters,
31+
at the given ``velocity``, expressed in millimeters per second.
32+
When ``distance`` or ``velocity`` is 0, the base will stop.
3333
This method blocks until completed or cancelled.
3434
3535
Args:
@@ -51,9 +51,9 @@ async def spin(
5151
**kwargs,
5252
):
5353
"""
54-
Spin the base in place `angle` degrees, at the given angular `velocity`,
54+
Spin the base in place ``angle`` degrees, at the given angular ``velocity``,
5555
expressed in degrees per second.
56-
When `velocity` is 0, the base will stop.
56+
When ``velocity`` is 0, the base will stop.
5757
This method blocks until completed or cancelled.
5858
5959
Args:
@@ -75,10 +75,10 @@ async def set_power(
7575
**kwargs,
7676
):
7777
"""Set the linear and angular velocity of the Base
78-
When `linear` is 0, the the base will spin.
79-
When `angular` is 0, the the base will move in a straight line.
80-
When both `linear` and `angular` are 0, the base will stop.
81-
When `linear` and `angular` are both nonzero, the base will move in an arc,
78+
When ``linear`` is 0, the the base will spin.
79+
When ``angular`` is 0, the the base will move in a straight line.
80+
When both ``linear`` and ``angular`` are 0, the base will stop.
81+
When ``linear`` and ``angular`` are both nonzero, the base will move in an arc,
8282
with a tighter radius if angular power is greater than linear power.
8383
8484
Args:

src/viam/components/board/board.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ class Board(ComponentBase):
1616
components such as analog readers, and digital interrupts.
1717
1818
This acts as an abstract base class for any drivers representing specific
19-
board implementations. This cannot be used on its own. If the `__init__()` function is
20-
overridden, it must call the `super().__init__()` function.
19+
board implementations. This cannot be used on its own. If the ``__init__()`` function is
20+
overridden, it must call the ``super().__init__()`` function.
2121
"""
2222

2323
@dataclass
@@ -70,14 +70,14 @@ async def tick(self, high: bool, nanos: int):
7070
high (bool): If the signal of the interrupt is high.
7171
nanos (int): Nanoseconds from an arbitrary point in time,
7272
but always increasing and always needs to be accurate.
73-
Using `time.time_ns()` would be acceptable.
73+
Using ``time.time_ns()`` would be acceptable.
7474
"""
7575
...
7676

7777
@abc.abstractmethod
7878
async def add_callback(self, queue: Queue):
7979
"""
80-
Add a callback to be sent the low/high value on `tick()`.
80+
Add a callback to be sent the low/high value on ``tick()``.
8181
8282
Args:
8383
queue (Queue): The receiving queue.
@@ -88,7 +88,7 @@ async def add_callback(self, queue: Queue):
8888
async def add_post_processor(self, processor: PostProcessor):
8989
"""
9090
Add a post processor that should be used to modify what
91-
is returned by `self.value()`
91+
is returned by ``self.value()``
9292
9393
Args:
9494
processor (PostProcessor): The post processor to add.
@@ -133,7 +133,7 @@ async def get_pwm(self, *, extra: Optional[Dict[str, Any]] = None, timeout: Opti
133133
@abc.abstractmethod
134134
async def set_pwm(self, duty_cycle: float, *, extra: Optional[Dict[str, Any]] = None, timeout: Optional[float] = None, **kwargs):
135135
"""
136-
Set the pin to the given `duty_cycle`.
136+
Set the pin to the given ``duty_cycle``.
137137
138138
Args:
139139
duty_cycle (float): The duty cycle.
@@ -160,8 +160,8 @@ async def set_pwm_frequency(
160160
**kwargs,
161161
):
162162
"""
163-
Set the pin to the given PWM `frequency` (in Hz).
164-
When `frequency` is 0, it will use the board's default PWM frequency.
163+
Set the pin to the given PWM ``frequency`` (in Hz).
164+
When ``frequency`` is 0, it will use the board's default PWM frequency.
165165
166166
Args:
167167
frequency (int): The frequency, in Hz.
@@ -171,7 +171,7 @@ async def set_pwm_frequency(
171171
@abc.abstractmethod
172172
async def analog_reader_by_name(self, name: str) -> AnalogReader:
173173
"""
174-
Get an AnalogReader by `name`.
174+
Get an AnalogReader by ``name``.
175175
176176
Args:
177177
name (str): Name of the analog reader to be retrieved.
@@ -184,7 +184,7 @@ async def analog_reader_by_name(self, name: str) -> AnalogReader:
184184
@abc.abstractmethod
185185
async def digital_interrupt_by_name(self, name: str) -> DigitalInterrupt:
186186
"""
187-
Get a DigitalInterrupt by `name`.
187+
Get a DigitalInterrupt by ``name``.
188188
189189
Args:
190190
name (str): Name of the digital interrupt.
@@ -197,7 +197,7 @@ async def digital_interrupt_by_name(self, name: str) -> DigitalInterrupt:
197197
@abc.abstractmethod
198198
async def gpio_pin_by_name(self, name: str) -> GPIOPin:
199199
"""
200-
Get a GPIO Pin by `name`.
200+
Get a GPIO Pin by ``name``.
201201
202202
Args:
203203
name (str): Name of the GPIO pin.

src/viam/components/camera/camera.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ class Camera(ComponentBase):
1414
Camera represents any physical hardware that can capture frames.
1515
1616
This acts as an abstract base class for any drivers representing specific
17-
camera implementations. This cannot be used on its own. If the `__init__()` function is
18-
overridden, it must call the `super().__init__()` function.
17+
camera implementations. This cannot be used on its own. If the ``__init__()`` function is
18+
overridden, it must call the ``super().__init__()`` function.
1919
"""
2020

2121
class Properties(NamedTuple):
2222
"""The camera's supported features and settings"""
2323

2424
supports_pcd: bool
25-
"""Whether the camera has a valid implementation of `get_point_cloud`"""
25+
"""Whether the camera has a valid implementation of ``get_point_cloud``"""
2626

2727
intrinsic_parameters: IntrinsicParameters
2828
"""The properties of the camera"""

src/viam/components/component_base.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def get_resource_name(cls, name: str) -> ResourceName:
4343

4444
@classmethod
4545
def from_robot(cls, robot: "RobotClient", name: str) -> Self:
46-
"""Get the component named `name` from the provided robot.
46+
"""Get the component named ``name`` from the provided robot.
4747
4848
Args:
4949
robot (RobotClient): The robot
@@ -56,10 +56,11 @@ def from_robot(cls, robot: "RobotClient", name: str) -> Self:
5656
return cast(cls, component)
5757

5858
def get_operation(self, kwargs: Mapping[str, Any]) -> Operation:
59-
"""Get the `Operation` associated with the currently running function.
59+
"""Get the ``Operation`` associated with the currently running function.
6060
61-
When writing custom components, you should get the `Operation` by calling this function and check to see if it's cancelled.
62-
If the `Operation` is cancelled, then you can perform any necessary (terminating long running tasks, cleaning up connections, etc.).
61+
When writing custom components, you should get the ``Operation`` by calling this function and check to see if it's cancelled.
62+
If the ``Operation`` is cancelled, then you can perform any necessary (terminating long running tasks, cleaning up connections, etc.
63+
).
6364
6465
Args:
6566
kwargs (Mapping[str, Any]): The kwargs object containing the operation

src/viam/components/gantry/gantry.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ class Gantry(ComponentBase):
1212
Gantry represents a physical Gantry and can be used for controlling gantries of N axes.
1313
1414
This acts as an abstract base class for any drivers representing specific
15-
gantry implementations. This cannot be used on its own. If the `__init__()` function is
16-
overridden, it must call the `super().__init__()` function.
15+
gantry implementations. This cannot be used on its own. If the ``__init__()`` function is
16+
overridden, it must call the ``super().__init__()`` function.
1717
"""
1818

1919
@abc.abstractmethod
@@ -43,7 +43,7 @@ async def move_to_position(
4343
positions (List[float]): List of positions for the axes to move to,
4444
in millimeters.
4545
world_state (Optional[WorldState]): Object describing
46-
obstacles for the gantry to avoid on its way to `positions`.
46+
obstacles for the gantry to avoid on its way to ``positions``.
4747
"""
4848
...
4949

src/viam/components/generic/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ async def do_command(self, command: Dict[str, Any], *, timeout: Optional[float]
2929

3030

3131
async def do_command(channel: Channel, name: str, command: Dict[str, Any], *, timeout: Optional[float] = None) -> Dict[str, Any]:
32-
"""Convenience method to allow component clients to execute `do_command` functions
32+
"""Convenience method to allow component clients to execute ``do_command`` functions
3333
3434
Args:
3535
channel (Channel): A gRPC channel

src/viam/components/generic/generic.py

Lines changed: 47 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -6,54 +6,51 @@ class Generic(ComponentBase):
66
Generic component, which represents any type of component that can executes arbitrary commands
77
88
This acts as an abstract base class for any drivers representing generic components.
9-
This cannot be used on its own. If the `__init__()` function is overridden, it must call the `super().__init__()` function.
10-
11-
To create a Generic component (an arbitrary component that can process commands), this `Generic` component should be subclassed
12-
and the `do_command` function implemented.
13-
14-
Example:
15-
16-
```python
17-
class ComplexComponent(Generic):
18-
19-
async def do_command(self, command: Dict[str, Any]) -> Dict[str, Any]:
20-
result = {key: False for key in command.keys()}
21-
for (name, args) in command.items():
22-
if name == 'on':
23-
self.on(*args)
24-
result[name] = True
25-
if name == 'set_frequency':
26-
self.set_frequency(*args)
27-
result[name] = True
28-
if name == 'get_frequency':
29-
result[name] = self.frequency
30-
if name == 'complex_command':
31-
self.complex_command(*args)
32-
result[name] = True
33-
return result
34-
35-
def set_frequency(self, frequency: int):
36-
self.frequency = frequency
37-
38-
def on(self, frequency: int, duration: int):
39-
self.frequency = frequency
40-
self.power = 1
41-
task = threading.Timer(duration, self.off)
42-
task.start()
43-
44-
def off(self):
45-
self.power = 0
46-
47-
def complex_command(self, arg1, arg2, arg3):
48-
...
49-
```
50-
51-
To execute commands, simply call the `do_command` function with the appropriate parameters
52-
53-
```python
54-
await component.do_command({'on': [300, 10]})
55-
component.power # 1
56-
await asyncio.sleep(10)
57-
component.power # 0
58-
```
9+
This cannot be used on its own. If the ``__init__()`` function is overridden, it must call the ``super().__init__()`` function.
10+
11+
To create a Generic component (an arbitrary component that can process commands), this ``Generic`` component should be subclassed
12+
and the ``do_command`` function implemented.
13+
14+
Example::
15+
16+
class ComplexComponent(Generic):
17+
18+
async def do_command(self, command: Dict[str, Any]) -> Dict[str, Any]:
19+
result = {key: False for key in command.keys()}
20+
for (name, args) in command.items():
21+
if name == 'on':
22+
self.on(*args)
23+
result[name] = True
24+
if name == 'set_frequency':
25+
self.set_frequency(*args)
26+
result[name] = True
27+
if name == 'get_frequency':
28+
result[name] = self.frequency
29+
if name == 'complex_command':
30+
self.complex_command(*args)
31+
result[name] = True
32+
return result
33+
34+
def set_frequency(self, frequency: int):
35+
self.frequency = frequency
36+
37+
def on(self, frequency: int, duration: int):
38+
self.frequency = frequency
39+
self.power = 1
40+
task = threading.Timer(duration, self.off)
41+
task.start()
42+
43+
def off(self):
44+
self.power = 0
45+
46+
def complex_command(self, arg1, arg2, arg3):
47+
...
48+
49+
To execute commands, simply call the ``do_command`` function with the appropriate parameters.
50+
::
51+
52+
await component.do_command({'on': [300, 10]})
53+
component.power # 1
54+
await asyncio.sleep(10)
55+
component.power # 0
5956
"""

src/viam/components/generic/service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ async def DoCommand(self, stream: Stream[DoCommandRequest, DoCommandResponse]) -
3333
timeout = stream.deadline.time_remaining() if stream.deadline else None
3434
result = await component.do_command(struct_to_dict(request.command), timeout=timeout)
3535
except NotImplementedError:
36-
raise GRPCError(Status.UNIMPLEMENTED, f"`DO` command is unimplemented for component named: {name}")
36+
raise GRPCError(Status.UNIMPLEMENTED, f"``DO`` command is unimplemented for component named: {name}")
3737
response = DoCommandResponse(result=dict_to_struct(result))
3838
await stream.send_message(response)

0 commit comments

Comments
 (0)