viam.components.motor.client

Module Contents

Classes

MotorClient

gRPC client for the Motor component.

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

Bases: viam.components.motor.motor.Motor, viam.resource.rpc_client_base.ReconfigurableResourceRPCClientBase

gRPC client for the Motor component.

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

Sets the “percentage” of power the motor should employ between -1 and 1. When power is negative, the rotation will be in the backward direction.

Parameters:

power (float) – Power between -1 and 1 (negative implies backwards).

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

Spin the motor the specified number of revolutions at specified rpm. When rpm or revolutions is a negative value, the rotation will be in the backward direction. Note: if both rpm and revolutions are negative, the motor will spin in the forward direction.

Parameters:
  • rpm (float) – Speed at which the motor should move in rotations per minute (negative implies backwards).

  • revolutions (float) – Number of revolutions the motor should run for (negative implies backwards).

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

Spin the motor to the specified position (provided in revolutions from home/zero), at the specified speed, in revolutions per minute. Regardless of the directionality of the rpm this function will move the motor towards the specified position.

Parameters:
  • rpm (float) – Speed at which the motor should rotate (absolute value).

  • position_revolutions (float) – Target position relative to home/zero, in revolutions.

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

Set the current position (modified by offset) to be the new zero (home) position.

Parameters:

offset (float) – The offset from the current position to new home/zero position.

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

Report the position of the motor based on its encoder. The value returned is the number of revolutions relative to its zero position. This method will raise an exception if position reporting is not supported by the motor.

Returns:

Number of revolutions the motor is away from zero/home.

Return type:

float

async get_properties(*, extra: Optional[Dict[str, Any]] = None, timeout: Optional[float] = None) viam.components.motor.motor.Motor.Properties[source]

Report a dictionary mapping optional properties to whether it is supported by this motor.

Returns:

Map of feature names to supported status.

Return type:

Properties

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

Stop the motor immediately, without any gradual step down.

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

Returns whether or not the motor is currently running.

Returns:

Indicates whether the motor is currently powered. float: The current power percentage of the motor

Return type:

bool

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

Get if the motor is currently moving.

Returns:

Whether the motor is moving.

Return type:

bool

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]

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