Configure a RoboClaw-Controlled 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 machine:

Navigate to the CONFIGURE tab of your machine’s page in the Viam app. Click the + icon next to your machine part in the left-hand menu and select Component. Select the motor type, then select the roboclaw model. Enter a name or use the suggested 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>",
      "model": "roboclaw",
      "type": "motor",
      "namespace": "rdk",
      "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",
      "model": "roboclaw",
      "type": "motor",
      "namespace": "rdk",
      "attributes": {
        "serial_path": "/dev/serial/by-path/usb-0:1.1:1.0",
        "motor_channel": 1,
        "serial_baud_rate": 38400
      },
      "depends_on": []
    }
  ]
}

The "serial_path" filepath used in this example is specific to serial devices connected to Linux systems. The "serial_path" filepath on a macOS system might resemble "/dev/ttyUSB0" or "/dev/ttyS0".

The following attributes are available for roboclaw motors:

NameTypeInclusionDescription
serial_pathstringRequiredThe full filesystem path to the serial device, starting with /dev/. To find your serial device path, first connect the serial device to your machine, then:
  • On Linux, run ls /dev/serial/by-path/* to show connected serial devices, or look for your device in the output of sudo dmesg | grep tty. Example: "/dev/serial/by-path/usb-0:1.1:1.0".
  • On macOS, run ls /dev/tty* | grep -i usb to show connected USB serial devices, ls /dev/tty* to browse all devices, or look for your device in the output of sudo dmesg | grep tty. Example: "/dev/ttyS0".
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 dropdown 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 machine’s LOGS tab for errors, and review the configuration.

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

If you notice any issues with the documentation, feel free to file an issue or edit this file.