Motor API | Component APIs

Motor API

The motor API allows you to give commands to your motor components for operating a motor or getting its current status.

The motor component supports the following methods:

Method Name Description viam-micro-server Support
SetPower Set the portion of max power to send to the motor (between -1 and 1).
SetRPM Spin the motor indefinitely at the specified speed, in revolutions per minute. If rpm is positive, the motor will spin forwards, and if rpm is negative, the motor will spin backwards.
GoFor Spin the motor the specified number of revolutions at specified revolutions per minute.
GoTo Turn the motor to a specified position (in terms of revolutions from home/zero) at a specified speed in revolutions per minute (RPM).
ResetZeroPosition Set the current position (modified by offset) to be the new zero (home) position.
GetPosition Report the position of the motor based on its encoder.
GetProperties Report a dictionary mapping optional properties to whether it is supported by this motor.
IsPowered Return whether or not the motor is currently running, and the portion of max power (between 0 and 1; if the motor is off the power will be 0).
IsMoving Return whether the motor is actively moving (or attempting to move) under its own power.
Stop Cut the power to the motor immediately, without any gradual step down.
GetGeometries Get all the geometries associated with the motor in its current configuration, in the frame of the motor.
Reconfigure Reconfigure this resource.
DoCommand Execute model-specific commands that are not otherwise defined by the component API.
GetResourceName Get the ResourceName for this motor.
Close Safely shut down the resource and prevent further use.

API

SetPower

Set the portion of max power to send to the motor (between -1 and 1). A value of 1 represents 100% power forwards, while a value of -1 represents 100% power backwards.

Power is expressed as a floating point between -1 and 1 that scales between -100% and 100% power. Supported by viam-micro-server.

Parameters:

Returns:

Example:


For more information, see the Python SDK Docs.

SetRPM

Spin the motor indefinitely at the specified speed, in revolutions per minute. If rpm is positive, the motor will spin forwards, and if rpm is negative, the motor will spin backwards.

Parameters:

Returns:

Example:


For more information, see the Python SDK Docs.

GoFor

Spin the motor the specified number of revolutions at specified revolutions per minute. When rpm or revolutions is a negative value, the motor spins in the backward direction. If both rpm and revolutions are negative, the motor spins in the forward direction.

Parameters:

Returns:

Example:


For more information, see the Python SDK Docs.

GoTo

Turn the motor to a specified position (in terms of revolutions from home/zero) at a specified speed in revolutions per minute (RPM). Regardless of the directionality of the rpm, the motor will move towards the specified target position. This blocks until the position has been reached.

Parameters:

Returns:

Example:


For more information, see the Python SDK Docs.

ResetZeroPosition

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

Parameters:

Returns:

Example:


For more information, see the Python SDK Docs.

GetPosition

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 raises an exception if position reporting is not supported by the motor. Supported by viam-micro-server.

Parameters:

Returns:

Example:


For more information, see the Python SDK Docs.

GetProperties

Report a dictionary mapping optional properties to whether it is supported by this motor. Supported by viam-micro-server.

Parameters:

Returns:

Example:


For more information, see the Python SDK Docs.

IsPowered

Return whether or not the motor is currently running, and the portion of max power (between 0 and 1; if the motor is off the power will be 0). Stepper motors will report true if they are being powered while holding a position, as well as when they are turning.

Parameters:

Returns:

Example:


For more information, see the Python SDK Docs.

IsMoving

Return whether the motor is actively moving (or attempting to move) under its own power. Supported by viam-micro-server.

Parameters:

Returns:

Example:


For more information, see the Python SDK Docs.

Stop

Cut the power to the motor immediately, without any gradual step down. Supported by viam-micro-server.

Parameters:

Returns:

Example:


For more information, see the Python SDK Docs.

GetGeometries

Get all the geometries associated with the motor in its current configuration, in the frame of the motor. The motion and navigation services use the relative position of inherent geometries to configured geometries representing obstacles for collision detection and obstacle avoidance while motion planning.

Parameters:

Returns:

Example:


For more information, see the Python SDK Docs.

Reconfigure

Reconfigure this resource. Reconfigure must reconfigure the resource atomically and in place.

Parameters:

Returns:

For more information, see the Go SDK Docs.

DoCommand

Execute model-specific commands that are not otherwise defined by the component API. Most models do not implement DoCommand. Any available model-specific commands should be covered in the model’s documentation. If you are implementing your own motor and want to add features that have no corresponding built-in API method, you can implement them with DoCommand.

Parameters:

Returns:

Raises:

Example:


For more information, see the Python SDK Docs.

GetResourceName

Get the ResourceName for this motor.

Parameters:

Returns:

Example:


For more information, see the Python SDK Docs.

Close

Safely shut down the resource and prevent further use.

Parameters:

Returns:

Example:


For more information, see the Python SDK Docs.