viam.components.board.client

Module Contents

Classes

AnalogReaderClient

AnalogReader represents an analog pin reader that resides on a Board.

DigitalInterruptClient

DigitalInterrupt represents a configured interrupt on the Board that

GPIOPinClient

Abstract representation of an individual GPIO pin on a board

BoardClient

gRPC client for the Board component.

class viam.components.board.client.AnalogReaderClient(name: str, board: BoardClient)[source]

Bases: viam.components.board.Board.AnalogReader

AnalogReader represents an analog pin reader that resides on a Board.

async read(*, extra: Optional[Dict[str, Any]] = None, timeout: Optional[float] = None) int[source]

Read the current value.

Returns:

The current value.

Return type:

int

classmethod from_robot(robot: viam.robot.client.RobotClient, name: str) typing_extensions.Self

Get the component named name from the provided robot.

Parameters:
  • robot (RobotClient) – The robot

  • name (str) – The name of the component

Returns:

The component, if it exists on the robot

Return type:

Self

abstract async do_command(command: Mapping[str, ValueTypes], *, timeout: Optional[float] = None, **kwargs) Mapping[str, ValueTypes]

Send/Receive arbitrary commands to the Resource

Parameters:

command (Mapping[str, ValueTypes]) – The command to execute

Raises:

NotImplementedError – Raised if the Resource does not support arbitrary commands

Returns:

Result of the executed command

Return type:

Mapping[str, ValueTypes]

classmethod get_resource_name(name: str) viam.proto.common.ResourceName

Get the ResourceName for this Resource with the given name

Parameters:

name (str) – The name of the Resource

get_operation(kwargs: Mapping[str, Any]) viam.operations.Operation

Get the Operation associated with the currently running function.

When writing custom resources, you should get the Operation by calling this function and check to see if it’s cancelled. If the Operation is cancelled, then you can perform any necessary (terminating long running tasks, cleaning up connections, etc. ).

Parameters:

kwargs (Mapping[str, Any]) – The kwargs object containing the operation

Returns:

The operation associated with this function

Return type:

viam.operations.Operation

class viam.components.board.client.DigitalInterruptClient(name: str, board: BoardClient)[source]

Bases: viam.components.board.Board.DigitalInterrupt

DigitalInterrupt represents a configured interrupt on the Board that when interrupted, calls the added callbacks. Post processors can be added to modify what Value it ultimately returns.

async value(*, extra: Optional[Dict[str, Any]] = None, timeout: Optional[float] = None) int[source]

Get the current value of the interrupt, which is based on the type of interrupt.

Returns:

The current value.

Return type:

int

abstract async tick(high: bool, nanos: int)[source]

This method is to be called either manually if the interrupt is a proxy to some real hardware interrupt or for tests.

Parameters:
  • high (bool) – If the signal of the interrupt is high.

  • nanos (int) – Nanoseconds from an arbitrary point in time, but always increasing and always needs to be accurate. Using time.time_ns() would be acceptable.

abstract async add_callback(queue: multiprocessing.Queue)[source]

Add a callback to be sent the low/high value on tick().

Parameters:

queue (Queue) – The receiving queue.

abstract async add_post_processor(processor: viam.components.board.board.PostProcessor)[source]

Add a post processor that should be used to modify what is returned by self.value()

Parameters:

processor (PostProcessor) – The post processor to add.

classmethod from_robot(robot: viam.robot.client.RobotClient, name: str) typing_extensions.Self

Get the component named name from the provided robot.

Parameters:
  • robot (RobotClient) – The robot

  • name (str) – The name of the component

Returns:

The component, if it exists on the robot

Return type:

Self

abstract async do_command(command: Mapping[str, ValueTypes], *, timeout: Optional[float] = None, **kwargs) Mapping[str, ValueTypes]

Send/Receive arbitrary commands to the Resource

Parameters:

command (Mapping[str, ValueTypes]) – The command to execute

Raises:

NotImplementedError – Raised if the Resource does not support arbitrary commands

Returns:

Result of the executed command

Return type:

Mapping[str, ValueTypes]

classmethod get_resource_name(name: str) viam.proto.common.ResourceName

Get the ResourceName for this Resource with the given name

Parameters:

name (str) – The name of the Resource

get_operation(kwargs: Mapping[str, Any]) viam.operations.Operation

Get the Operation associated with the currently running function.

When writing custom resources, you should get the Operation by calling this function and check to see if it’s cancelled. If the Operation is cancelled, then you can perform any necessary (terminating long running tasks, cleaning up connections, etc. ).

Parameters:

kwargs (Mapping[str, Any]) – The kwargs object containing the operation

Returns:

The operation associated with this function

Return type:

viam.operations.Operation

class viam.components.board.client.GPIOPinClient(name: str, board: BoardClient)[source]

Bases: viam.components.board.Board.GPIOPin

Abstract representation of an individual GPIO pin on a board

async get(*, extra: Optional[Dict[str, Any]] = None, timeout: Optional[float] = None) bool[source]

Get the high/low state of the pin.

Returns:

Indicates if the state of the pin is high.

Return type:

bool

async set(high: bool, *, extra: Optional[Dict[str, Any]] = None, timeout: Optional[float] = None)[source]

Set the pin to either low or high.

Parameters:

high (bool) – When true, sets the pin to high. When false, sets the pin to low.

async get_pwm(*, extra: Optional[Dict[str, Any]] = None, timeout: Optional[float] = None) float[source]

Get the pin’s given duty cycle.

Returns:

The duty cycle.

Return type:

float

async set_pwm(duty_cycle: float, *, extra: Optional[Dict[str, Any]] = None, timeout: Optional[float] = None)[source]

Set the pin to the given duty_cycle.

Parameters:

duty_cycle (float) – The duty cycle.

async get_pwm_frequency(*, extra: Optional[Dict[str, Any]] = None, timeout: Optional[float] = None) int[source]

Get the PWM frequency of the pin.

Returns:

The PWM frequency.

Return type:

int

async set_pwm_frequency(frequency: int, *, extra: Optional[Dict[str, Any]] = None, timeout: Optional[float] = None)[source]

Set the pin to the given PWM frequency (in Hz). When frequency is 0, it will use the board’s default PWM frequency.

Parameters:

frequency (int) – The frequency, in Hz.

classmethod from_robot(robot: viam.robot.client.RobotClient, name: str) typing_extensions.Self

Get the component named name from the provided robot.

Parameters:
  • robot (RobotClient) – The robot

  • name (str) – The name of the component

Returns:

The component, if it exists on the robot

Return type:

Self

abstract async do_command(command: Mapping[str, ValueTypes], *, timeout: Optional[float] = None, **kwargs) Mapping[str, ValueTypes]

Send/Receive arbitrary commands to the Resource

Parameters:

command (Mapping[str, ValueTypes]) – The command to execute

Raises:

NotImplementedError – Raised if the Resource does not support arbitrary commands

Returns:

Result of the executed command

Return type:

Mapping[str, ValueTypes]

classmethod get_resource_name(name: str) viam.proto.common.ResourceName

Get the ResourceName for this Resource with the given name

Parameters:

name (str) – The name of the Resource

get_operation(kwargs: Mapping[str, Any]) viam.operations.Operation

Get the Operation associated with the currently running function.

When writing custom resources, you should get the Operation by calling this function and check to see if it’s cancelled. If the Operation is cancelled, then you can perform any necessary (terminating long running tasks, cleaning up connections, etc. ).

Parameters:

kwargs (Mapping[str, Any]) – The kwargs object containing the operation

Returns:

The operation associated with this function

Return type:

viam.operations.Operation

class viam.components.board.client.BoardClient(name: str, channel: grpclib.client.Channel)[source]

Bases: viam.components.board.Board, viam.resource.rpc_client_base.ReconfigurableResourceRPCClientBase

gRPC client for the Board component.

async analog_reader_by_name(name: str) viam.components.board.Board.AnalogReader[source]

Get an AnalogReader by name.

Parameters:

name (str) – Name of the analog reader to be retrieved.

Returns:

The analog reader.

Return type:

AnalogReader

async digital_interrupt_by_name(name: str) viam.components.board.Board.DigitalInterrupt[source]

Get a DigitalInterrupt by name.

Parameters:

name (str) – Name of the digital interrupt.

Returns:

the digital interrupt.

Return type:

DigitalInterrupt

async gpio_pin_by_name(name: str) viam.components.board.Board.GPIOPin[source]

Get a GPIO Pin by name.

Parameters:

name (str) – Name of the GPIO pin.

Returns:

the pin.

Return type:

GPIOPin

async analog_reader_names() List[str][source]

Get the names of all known analog readers.

Returns:

The names of the analog readers..

Return type:

List[str]

async digital_interrupt_names() List[str][source]

Get the names of all known digital interrupts.

Returns:

The names of the digital interrupts.

Return type:

List[str]

async status(*, extra: Optional[Dict[str, Any]] = None, timeout: Optional[float] = None) viam.proto.common.BoardStatus[source]

Return the current status of the board.

Returns:

the status.

Return type:

viam.proto.common.BoardStatus

async model_attributes() viam.components.board.Board.Attributes[source]

Get the attributes related to the model of this board.

Returns:

The attributes.

Return type:

Attributes

async do_command(command: Mapping[str, viam.utils.ValueTypes], *, timeout: Optional[float] = None) Mapping[str, viam.utils.ValueTypes][source]

Send/Receive arbitrary commands to the Resource

Parameters:

command (Mapping[str, ValueTypes]) – The command to execute

Raises:

NotImplementedError – Raised if the Resource does not support arbitrary commands

Returns:

Result of the executed command

Return type:

Mapping[str, ValueTypes]

async set_power_mode(mode: viam.proto.component.board.PowerMode.ValueType, duration: Optional[datetime.timedelta] = None, *, timeout: Optional[float] = None)[source]

Set the board to the indicated power mode.

Parameters:

mode – the desired power mode

async get_geometries(*, extra: Optional[Dict[str, Any]] = None, timeout: Optional[float] = None) List[viam.proto.common.Geometry][source]

Get all geometries associated with the Component, in their current configuration, in the frame of the Component.

Returns:

The geometries associated with the Component.

Return type:

List[Geometry]

classmethod from_robot(robot: viam.robot.client.RobotClient, name: str) typing_extensions.Self

Get the component named name from the provided robot.

Parameters:
  • robot (RobotClient) – The robot

  • name (str) – The name of the component

Returns:

The component, if it exists on the robot

Return type:

Self

classmethod get_resource_name(name: str) viam.proto.common.ResourceName

Get the ResourceName for this Resource with the given name

Parameters:

name (str) – The name of the Resource

get_operation(kwargs: Mapping[str, Any]) viam.operations.Operation

Get the Operation associated with the currently running function.

When writing custom resources, you should get the Operation by calling this function and check to see if it’s cancelled. If the Operation is cancelled, then you can perform any necessary (terminating long running tasks, cleaning up connections, etc. ).

Parameters:

kwargs (Mapping[str, Any]) – The kwargs object containing the operation

Returns:

The operation associated with this function

Return type:

viam.operations.Operation