Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOCS-2949: Fix board and encoder example snippets #778

Merged
merged 4 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions src/viam/components/board/board.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ async def read(self, *, extra: Optional[Dict[str, Any]] = None, timeout: Optiona

::

my_board = Board.from_robot(robot=robot, name="my_board")
my_board = Board.from_robot(robot=machine, name="my_board")

# Get the Analog "my_example_analog_reader".
reader = await my_board.analog_reader_by_name(
Expand All @@ -89,7 +89,7 @@ async def write(self, value: int, *, extra: Optional[Dict[str, Any]] = None, tim

::

my_board = Board.from_robot(robot=robot, name="my_board")
my_board = Board.from_robot(robot=machine, name="my_board")

# Get the Analog "my_example_analog_writer".
writer = await my_board.analog_by_name(
Expand Down Expand Up @@ -127,7 +127,7 @@ async def value(self, *, extra: Optional[Dict[str, Any]] = None, timeout: Option

::

my_board = Board.from_robot(robot=robot, name="my_board")
my_board = Board.from_robot(robot=machine, name="my_board")

# Get the DigitalInterrupt "my_example_digital_interrupt".
interrupt = await my_board.digital_interrupt_by_name(
Expand Down Expand Up @@ -163,13 +163,13 @@ async def set(self, high: bool, *, extra: Optional[Dict[str, Any]] = None, timeo

::

my_board = Board.from_robot(robot=robot, name="my_board")
my_board = Board.from_robot(robot=machine, name="my_board")

# Get the GPIOPin with pin number 15.
pin = await my_board.gpio_pin_by_name(name="15")

# Set the pin to high.
await pin.set(high="true")
await pin.set(high=True)

Args:
high (bool): When true, sets the pin to high. When false, sets the pin to low.
Expand All @@ -185,7 +185,7 @@ async def get(self, *, extra: Optional[Dict[str, Any]] = None, timeout: Optional

::

my_board = Board.from_robot(robot=robot, name="my_board")
my_board = Board.from_robot(robot=machine, name="my_board")

# Get the GPIOPin with pin number 15.
pin = await my_board.gpio_pin_by_name(name="15")
Expand All @@ -207,7 +207,7 @@ async def get_pwm(self, *, extra: Optional[Dict[str, Any]] = None, timeout: Opti

::

my_board = Board.from_robot(robot=robot, name="my_board")
my_board = Board.from_robot(robot=machine, name="my_board")

# Get the GPIOPin with pin number 15.
pin = await my_board.gpio_pin_by_name(name="15")
Expand All @@ -229,14 +229,14 @@ async def set_pwm(self, duty_cycle: float, *, extra: Optional[Dict[str, Any]] =

::

my_board = Board.from_robot(robot=robot, name="my_board")
my_board = Board.from_robot(robot=machine, name="my_board")

# Get the GPIOPin with pin number 15.
pin = await my_board.gpio_pin_by_name(name="15")

# Set the duty cycle to .6, meaning that this pin will be in the high state for
# 60% of the duration of the PWM interval period.
await pin.set_pwm(cycle=.6)
await pin.set_pwm(duty_cycle=.6)

Args:
duty_cycle (float): The duty cycle.
Expand All @@ -252,7 +252,7 @@ async def get_pwm_frequency(self, *, extra: Optional[Dict[str, Any]] = None, tim

::

my_board = Board.from_robot(robot=robot, name="my_board")
my_board = Board.from_robot(robot=machine, name="my_board")

# Get the GPIOPin with pin number 15.
pin = await my_board.gpio_pin_by_name(name="15")
Expand Down Expand Up @@ -282,7 +282,7 @@ async def set_pwm_frequency(

::

my_board = Board.from_robot(robot=robot, name="my_board")
my_board = Board.from_robot(robot=machine, name="my_board")

# Get the GPIOPin with pin number 15.
pin = await my_board.gpio_pin_by_name(name="15")
Expand All @@ -304,7 +304,7 @@ async def analog_by_name(self, name: str) -> Analog:

::

my_board = Board.from_robot(robot=robot, name="my_board")
my_board = Board.from_robot(robot=machine, name="my_board")

# Get the Analog "my_example_analog_reader".
reader = await my_board.analog_by_name(name="my_example_analog_reader")
Expand All @@ -326,7 +326,7 @@ async def digital_interrupt_by_name(self, name: str) -> DigitalInterrupt:

::

my_board = Board.from_robot(robot=robot, name="my_board")
my_board = Board.from_robot(robot=machine, name="my_board")

# Get the DigitalInterrupt "my_example_digital_interrupt".
interrupt = await my_board.digital_interrupt_by_name(
Expand All @@ -349,7 +349,7 @@ async def gpio_pin_by_name(self, name: str) -> GPIOPin:

::

my_board = Board.from_robot(robot=robot, name="my_board")
my_board = Board.from_robot(robot=machine, name="my_board")

# Get the GPIOPin with pin number 15.
pin = await my_board.gpio_pin_by_name(name="15")
Expand All @@ -371,7 +371,7 @@ async def analog_names(self) -> List[str]:

::

my_board = Board.from_robot(robot=robot, name="my_board")
my_board = Board.from_robot(robot=machine, name="my_board")

# Get the name of every Analog configured on the board.
names = await my_board.analog_names()
Expand All @@ -390,7 +390,7 @@ async def digital_interrupt_names(self) -> List[str]:

::

my_board = Board.from_robot(robot=robot, name="my_board")
my_board = Board.from_robot(robot=machine, name="my_board")

# Get the name of every DigitalInterrupt configured on the board.
names = await my_board.digital_interrupt_names()
Expand All @@ -411,7 +411,7 @@ async def set_power_mode(

::

my_board = Board.from_robot(robot=robot, name="my_board")
my_board = Board.from_robot(robot=machine, name="my_board")

# Set the power mode of the board to OFFLINE_DEEP.
status = await my_board.set_power_mode(mode=PowerMode.POWER_MODE_OFFLINE_DEEP)
Expand All @@ -432,9 +432,9 @@ async def stream_ticks(self, interrupts: List[DigitalInterrupt], *, timeout: Opt
::


my_board = Board.from_robot(robot=robot, name="my_board")
di8 = await my_board.digital_interrupt_by_name(name="8"))
di11 = await my_board.digital_interrupt_by_name(name="11"))
my_board = Board.from_robot(robot=machine, name="my_board")
di8 = await my_board.digital_interrupt_by_name(name="8")
di11 = await my_board.digital_interrupt_by_name(name="11")

# Iterate over stream of ticks from pins 8 and 11.
async for tick in await my_board.stream_ticks([di8, di11]):
Expand Down
6 changes: 3 additions & 3 deletions src/viam/components/encoder/encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async def reset_position(

::

my_encoder = Encoder.from_robot(robot=robot, name='my_encoder')
my_encoder = Encoder.from_robot(robot=machine, name='my_encoder')

# Reset the zero position of the encoder.
await my_encoder.reset_position()
Expand Down Expand Up @@ -73,7 +73,7 @@ async def get_position(

::

my_encoder = Encoder.from_robot(robot=robot, name='my_encoder')
my_encoder = Encoder.from_robot(robot=machine, name='my_encoder')

# Get the position of the encoder in ticks
position = await my_encoder.get_position(PositionType.POSITION_TYPE_TICKS_COUNT)
Expand Down Expand Up @@ -105,7 +105,7 @@ async def get_properties(

::

my_encoder = Encoder.from_robot(robot=robot, name='my_encoder')
my_encoder = Encoder.from_robot(robot=machine, name='my_encoder')

# Get whether the encoder returns position in ticks or degrees.
properties = await my_encoder.get_properties()
Expand Down
Loading