Motor Component

The motor component provides an API for operating a motor or getting its current status.

If you have a device that converts electricity into rotary motion, such as a brushed DC motor, a brushless DC motor, or a stepper motor, configure it as a motor component.

If you have a hobby servo, configure it as a servo component instead.

Configuration

To use a motor, you need to add it to your machine’s configuration. Go to your machine’s CONFIGURE page, and add a model that supports your motor and its motor driver.

The following list shows the available motor models. For additional configuration information, click on the model name:

Model
Description
ModelDescription
gpioStandard brushed or brushless DC motor

API

The motor API supports the following methods:

Method NameDescriptionviam-micro-server Support
SetPowerSet the portion of max power to send to the motor (between -1 and 1).

SetRPMSpin 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.

GoForSpin the motor the specified number of revolutions at specified revolutions per minute.

GoToTurn the motor to a specified position (in terms of revolutions from home/zero) at a specified speed in revolutions per minute (RPM).

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

GetPositionReport the position of the motor based on its encoder.

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

IsPoweredReturn 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).

IsMovingReturn whether the motor is actively moving (or attempting to move) under its own power.

StopCut the power to the motor immediately, without any gradual step down.

ReconfigureReconfigure this resource.

DoCommandExecute model-specific commands that are not otherwise defined by the component API.
GetResourceNameGet the ResourceName for this motor with the given name.

CloseSafely shut down the resource and prevent further use.

Troubleshooting

If your motor is not working as expected, follow these steps:

  1. Check your machine logs on the LOGS tab to check for errors.
  2. Review your motor model’s documentation to ensure you have configured all required attributes.
  3. Check that all wires are securely attached to the correct pins.
  4. Click on the TEST panel on the CONFIGURE or CONTROL tab and test if you can use the motor there.

If none of these steps work, reach out to us on the Community Discord and we will be happy to help.

Next steps

For general configuration and development info, see: