Configure a DMC4000-Controlled Motor
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.
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 DMC4000
model.
Enter a name or use the suggested name for your motor and click Create.
Edit and fill in the attributes as applicable.
{
"components": [
{
"name": "<your-motor-name>",
"model": "DMC4000",
"type": "motor",
"namespace": "rdk",
"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",
"type": "motor",
"namespace": "rdk",
"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
The following attributes are available for DMC4000
motors:
Name | Type | Required? | Description |
---|---|---|---|
amplifier_gain | int | Required | Set the per phase current (when using stepper amp). |
low_current | int | Required | Reduce the hold current. |
ticks_per_rotation | int | Required | Number 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_path | string | Optional | The full filesystem path to the serial device, starting with
If you do not provide a serial_path , the driver will attempt to auto-detect the path to your serial device. |
controller_axis | string | Required | Physical port label (A-H); select which “axis” the motor is wired to on the controller. |
home_rpm | int | Required | Set speed in revolutions per minute (RPM) that the motor will turn when executing a Home() command (using DoCommand()). |
dir_flip | bool | Optional | Flip the direction of the signal sent if there is a DIR pin. |
max_rpm | float | Optional | Set a limit on maximum revolutions per minute that the motor can be run at. |
max_acceleration_rpm_per_sec | float | Optional | Set 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"})
Test the motor
Once your motor is configured and connected, open the motor’s TEST panel on the CONFIGURE or CONTROL tabs. Use the buttons to try turning your motor forwards or backwards at different power levels and check whether it moves as expected.
If the motor does not appear on the TEST panel, or if you notice unexpected behavior, check your machine’s LOGS tab for errors, and review the configuration.
Next steps
For more configuration and development info, see:
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.
Was this page helpful?
Glad to hear it! If you have any other feedback please let us know:
We're sorry about that. To help us improve, please tell us what we can do better:
Thank you!