Configure a TMC5072 motor
This model supports stepper motors controlled by the TMC5072 chip.
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 TMC5072 chip uses SPI bus to communicate with the board, does some processing on the chip itself, and provides convenient features including StallGuard2TM.
To configure a TMC5072
motor as a component of your robot, first configure the board to which the motor driver is wired.
Then, add the motor:
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 TMC5072
model.
Enter a name for your motor and click Create.
Edit and fill in the attributes as applicable.
{
"components": [
{
"name": "<your-board-name>",
"type": "board",
"model": "<your-board-model>",
"attributes": {},
"depends_on": [],
},
{
"name": "<your-motor-name>",
"type": "motor",
"model": "TMC5072",
"attributes": {
"board": "<your-board-name>",
"spi_bus": "<your-spi-bus-name>",
"chip_select": "<pin-number>",
"index": "<your-spi-bus-index>",
"ticks_per_rotation": <int>,
"max_acceleration_rpm_per_sec": <float>,
"sg_thresh": <int>,
"home_rpm": <float>,
"cal_factor": <float>,
"run_current": <int>,
"hold_current": <int>,
"hold_delay": <int>
},
"depends_on": []
}
]
}
{
"components": [
{
"name": "example-board",
"type": "board",
"model": "pi"
},
{
"name": "my-tmc-motor",
"type": "motor",
"model": "TMC5072",
"attributes": {
"board": "example-board",
"chip_select": "36",
"index": 0,
"max_acceleration": 10000,
"max_rpm": 450,
"spi_bus": "main",
"ticks_per_rotation": 200
}
}
]
}
The following attributes are available for TMC5072
motors:
Name | Type | Inclusion | Description |
---|---|---|---|
board | string | Required | name of the board to which the motor controller is wired. |
spi_bus | string | Required | The board SPI bus over which the TMC chip communicates with the board. |
chip_select | string | Required | The pin number of the GPIO pin on the board wired to the TMC controller. The board sets this high or low to let the TMC chip know whether to listen for commands over SPI. |
index | int | Required | The index of the part of the chip the motor is wired to. Either 1 or 2 , depending on whether the motor is wired to the “MOTOR1” terminals or the “MOTOR2” terminals, respectively. |
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. |
max_acceleration_rpm_per_sec | number | Required | Set a limit on maximum acceleration in revolutions per minute per second. |
sg_thresh | int | Optional | Stallguard threshold; sets sensitivity of virtual endstop detection when homing. |
home_rpm | number | Optional | Speed in revolutions per minute that the motor will turn when executing a Home() command (through DoCommand()). |
cal_factor | number | Optional | Calibration factor for velocity and acceleration. Compensates for clock source drift when doing time-based calculations. |
run_current | int | Optional | Set current when motor is turning, from 1-32 as a percentage of rsense voltage. Defaults to 15 if omitted or set to 0. |
hold_current | int | Optional | Set current when motor is holding a position, from 1-32 as a percentage of rsense voltage. Defaults to 8 if omitted or set to 0. |
hold_delay | int | Optional | How long to hold full power at a set position before ramping down to hold_current . 0=instant powerdown, 1-15=delay * 2^18 clocks, 6 is the default. |
Refer to your motor and motor driver data sheets for specifics.
Extended API
The TMC5072
model supports additional methods that are not part of the standard Viam motor API (passed through DoCommand()):
Home
Home the motor using TMC’s StallGuardTM (a builtin feature of this controller).
Parameters:
- None
Raises:
- (error): An error, if one occurred.
For more information on do_command
, see the Python SDK Docs.
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().
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.
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
.
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})
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.
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.
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!