Configure a roboclaw motor

The roboclaw model of the motor component supports standard brushed DC motors driven by Basicmicro’s RoboClaw motor controller.

To configure a roboclaw motor as a component of your robot:

Navigate to the Config tab of your robot’s page in the Viam app. Click on the Components subtab and click Create component. Select the motor type, then select the roboclaw model. Enter a name for your motor and click Create.

A roboclaw motor config.

Edit and fill in the attributes as applicable.

{
  "components": [
    {
      "name": "<your-roboclaw-motor-name>",
      "type": "motor",
      "model": "roboclaw",
      "attributes": {
        "serial_path": "<your-serial-path>",
        "motor_channel": <int>,
        "serial_baud_rate": <int>
      },
      "depends_on": []
    }
  ]
}

Example configuration for a roboclaw DC brushed motor:

{
  "components": [
    {
      "name": "your-roboclaw-motor",
      "type": "motor",
      "model": "roboclaw",
      "attributes": {
        "serial_path": "/dev/ttyUSB0",
        "motor_channel": 1,
        "serial_baud_rate": 38400
      },
      "depends_on": []
    }
  ]
}

The following attributes are available for roboclaw motors:

NameTypeInclusionDescription
serial_pathstringRequiredThe full filesystem path to the serial device, starting with /dev/. With your serial device connected, you can run sudo dmesg | grep tty to show relevant device connection log messages, and then match the returned device name, such as ttyAMA0 , to its device file, such as /dev/ttyAMA0. On a Raspberry Pi, you can also run ls /dev/serial/by-path to list USB serial devices. If you omit this attribute, Viam will attempt to automatically detect the path.
Example: "/dev/serial/by-path/usb-0:1.1:1.0"
serial_baud_rateintOptionalRate to send data over the serial line. This must match the baudrate you have set up using basicmicro’s setup program. You cannot have multiple roboclaw motors with different baud rates.
Default: 38400
motor_channelintRequiredChannel the motor is connected to on the controller. Must be 1 or 2.
addressintOptionalSerial address of the controller.
Default: 128
ticks_per_rotationintOptionalNumber of full steps in a rotation. Update this if you connect encoders to your controller through its EN1 and EN2 pins.
Default: 0

Refer to your motor and motor driver data sheets for specifics.

Test the motor

Once your motor is configured and connected, go to the Control tab and click on the motor’s drop-down panel. Use the buttons to try turning your motor forwards or backwards at different power levels and check whether it moves as expected.

Motor control panel.

If the motor does not appear on the Control tab, or if you notice unexpected behavior, check your robot’s Logs tab for errors, and review the configuration.



Have questions, or want to meet other people working on robots? Join our Community Discord.