Configure a DMC4000 motor

This 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 custom motor model.

Configuration

Assign your motor a name (to identify the motor), type (motor) and model (DMC4000), and fill in the attributes that apply to your particular hardware. Refer to your motor and motor driver data sheets for specifics.

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

Screenshot of a DMC4000 motor config with the attributes configured per the Raw JSON on the next tab in this doc.
{
  "components": [
    {
      "name": <motor_name>,
      "type": "motor",
      "model": "DMC4000",
      "attributes": {
        "amplifier_gain": <int>,
        "low_current": <int>,
        "ticks_per_rotation": <int>,
        "serial_path": <string>,
        "controller_axis": <string>,
        "home_rpm": <int>,
        "max_rpm": <float>,
        "max_acceleration_rpm_per_sec": <float>
      },
      "depends_on": []
    }
  ]
}
{
  "components": [
    {
      "name": "my-dmc-motor",
      "type": "motor",
      "model": "DMC4000",
      "attributes": {
        "amplifier_gain": 3,
        "low_current": 1,
        "ticks_per_rotation": 200,
        "serial_path": "/dev/serial/by-path/<device_ID>",
        "controller_axis": "A",
        "home_rpm": 70,
        "max_rpm": 300
      },
      "depends_on": []
    }
  ]
}

Required Attributes

NameTypeDescription
amplifier_gainintSet the per phase current (when using stepper amp); see https://www.galil.com/download/comref/com4103/index.html#amplifier_gain.html.
low_currentintReduce the hold current; see https://www.galil.com/download/comref/com4103/index.html#low_current_stepper_mode.html.
ticks_per_rotationintNumber 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_pathstringPath to /dev/ttyXXXX file. You can find the XXXX by running dmesg on the computer plugged into the DMC-40x0. If you leave this empty, Viam will attempt to automatically detect the path.
controller_axisstringPhysical port label (A-H); select which “axis” the motor is wired to on the controller.
home_rpmintegerSpeed in revolutions per minute that the motor will turn when executing a Home() command (using DoCommand()).

Optional Attributes

NameTypeDescription
dir_flipboolFlip the direction of the signal sent if there is a DIR pin.
max_rpmfloat64Set a limit on maximum revolutions per minute that the motor can be run at.
max_acceleration_rpm_per_secfloat64Set a maximum RPM per second acceleration limit.

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.

Example usage:

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

# Home the motor
home_dict = {
  "command": "home"
}
await myMotor.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.

Example usage:

myMotor, err := motor.FromRobot(robot, "motor1")

// Home the motor
resp, err := myMotor.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.

Example usage:

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

# Run the motor indefinitely at 70 rpm
jog_dict = {
  "command": "jog",
  "rpm": 70
}
await myMotor.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.

Example usage:

myMotor, err := motor.FromRobot(robot, "motor1")

// Run the motor indefinitely at 70 rpm
resp, err := myMotor.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.

Example usage:

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

raw_dict = {
  "command": "raw",
  "raw_input": "home"
}
await myMotor.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.

Example usage:

myMotor, err := motor.FromRobot(robot, "motor1")

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