DMC4000

The DMC4000 model supports stepper motors controlled by DMC-40x0 series motion controllers.

Whereas a basic low-level stepper driver supported by the gpiostepper model sends power to a stepper motor based on PWM signals from GPIO pins, the DMC40x0 motion controller has many motion control features. When using it, you do not need to configure a board component because it handles computation and signal creation on the motion controller itself.

The DMC-40x0 controller can drive a variety of motor types, but the built-in Viam implementation supports only stepper motors at this time. You can drive other types of motors with Viam and the DMC-40x0 controller by creating a modular resource to add support for it.

{
  "components": [
    {
      "name": "<your-motor-name>",
      "model": "DMC4000",
      "api": "rdk:component:motor",
      "attributes": {
        "amplifier_gain": <int>,
        "low_current": <int>,
        "ticks_per_rotation": <int>,
        "serial_path": <string>,
        "controller_axis": "<your-motion-controller-axis-label>",
        "home_rpm": <int>,
        "max_rpm": <float>,
        "max_acceleration_rpm_per_sec": <float>
      },
      "depends_on": []
    }
  ]
}

Example configuration for a stepper motor controlled by a DMC-40x0 motion controller:

{
  "components": [
    {
      "name": "my-dmc-motor",
      "model": "DMC4000",
      "api": "rdk:component:motor",
      "attributes": {
        "amplifier_gain": 3,
        "low_current": 1,
        "ticks_per_rotation": 200,
        "serial_path": "/dev/serial/by-path/usb-0:1.1:1.0",
        "controller_axis": "A",
        "home_rpm": 70,
        "max_rpm": 300
      },
      "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 DMC4000 motors:

NameTypeRequired?Description
amplifier_gainintRequiredSet the per phase current (when using stepper amp).
low_currentintRequiredReduce the hold current.
ticks_per_rotationintRequiredNumber of full steps in a rotation. 200 (equivalent to 1.8 degrees per step) is very common. If your data sheet specifies this in terms of degrees per step, divide 360 by that number to get ticks per rotation.
serial_pathstringOptionalThe 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".

If you do not provide a serial_path, the driver will attempt to auto-detect the path to your serial device.
controller_axisstringRequiredPhysical port label (A-H); select which “axis” the motor is wired to on the controller.
home_rpmintRequiredSet speed in revolutions per minute (RPM) that the motor will turn when executing a Home() command (using DoCommand()).
dir_flipboolOptionalFlip the direction of the signal sent if there is a DIR pin.
max_rpmfloatOptionalSet a limit on maximum revolutions per minute that the motor can be run at.
max_acceleration_rpm_per_secfloatOptionalSet the maximum revolutions per minute (RPM) per second acceleration limit.

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

Extended API

The DMC4000 model supports additional methods that are not part of the standard Viam motor API:

Home

Run the DMC homing routine.

Parameters:

  • None

Raises:

  • (error): An error, if one occurred.

For more information on do_command, see the Python SDK Docs.

my_motor = Motor.from_robot(robot=robot, name='my_motor')

# Home the motor
home_dict = {
  "command": "home"
}
await my_motor.do_command(home_dict)

Parameters:

  • ctx (Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.

Returns:

  • (error): An error, if one occurred.

For more information, see the Go SDK docs on Home and on DoCommand.

// Home the motor
resp, err := myMotorComponent.DoCommand(ctx, map[string]interface{}{"command": "home"})

Jog

Move the motor indefinitely at the specified RPM.

Parameters:

  • rpm (float64): The revolutions per minute at which the motor will turn indefinitely.

Raises:

  • (error): An error, if one occurred.

For more information on do_command, see the Python SDK Docs.

my_motor = Motor.from_robot(robot=robot, name='my_motor')

# Run the motor indefinitely at 70 rpm
jog_dict = {
  "command": "jog",
  "rpm": 70
}
await my_motor.do_command(jog_dict)

Parameters:

  • ctx (Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.
  • rpm (float64): The revolutions per minute at which the motor will turn indefinitely.

Returns:

  • (error): An error, if one occurred.

For more information, see the Go SDK Docs on Jog and on DoCommand.

// Run the motor indefinitely at 70 rpm
resp, err := myMotorComponent.DoCommand(ctx, map[string]interface{}{"command": "jog", "rpm": 70})

Raw

Send raw string commands to the controller.

Parameters:

  • raw_input (String): The raw string to send to the controller.

Raises:

  • (error): An error, if one occurred.

For more information on do_command, see the Python SDK Docs.

my_motor = Motor.from_robot(robot=robot, name='my_motor')

raw_dict = {
  "command": "raw",
  "raw_input": "home"
}
await my_motor.do_command(raw_dict)

Parameters:

  • ctx (Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.
  • raw_input (String): The raw string to send to the controller.

Returns:

  • (error): An error, if one occurred.

For more information, see the Go SDK Docs on Raw and on DoCommand.

resp, err := myMotorComponent.DoCommand(ctx, map[string]interface{}{"command": "jog", "raw_input": "home"})