-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
53 changed files
with
2,390 additions
and
796 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
""" | ||
Dump all register values of the TMC2240 IC. | ||
The connection to a Landungsbrücke is established over USB. TMCL commands are used for communicating with the IC. | ||
""" | ||
import time | ||
import pytrinamic | ||
from pytrinamic.connections import ConnectionManager | ||
from pytrinamic.evalboards import TMC2240_eval | ||
|
||
pytrinamic.show_info() | ||
|
||
with ConnectionManager().connect() as my_interface: | ||
print(my_interface) | ||
|
||
eval_board = TMC2240_eval(my_interface) | ||
mc = eval_board.ics[0] | ||
|
||
|
||
print("GCONF: 0x{0:08X}".format(eval_board.read_register(mc.REG.GCONF))) | ||
print("GSTAT: 0x{0:08X}".format(eval_board.read_register(mc.REG.GSTAT))) | ||
print("IFCNT: 0x{0:08X}".format(eval_board.read_register(mc.REG.IFCNT))) | ||
print("SLAVECONF: 0x{0:08X}".format(eval_board.read_register(mc.REG.SLAVECONF))) | ||
print("IOIN: 0x{0:08X}".format(eval_board.read_register(mc.REG.IOIN))) | ||
print("DRV_CONF: 0x{0:08X}".format(eval_board.read_register(mc.REG.DRV_CONF))) | ||
print("GLOBAL_SCALE 0x{0:08X}".format(eval_board.read_register(mc.REG.GLOBAL_SCALER))) | ||
print("IHOLD_IRUN: 0x{0:08X}".format(eval_board.read_register(mc.REG.IHOLD_IRUN))) | ||
print("TPOWERDOWN: 0x{0:08X}".format(eval_board.read_register(mc.REG.TPOWERDOWN))) | ||
print("TSTEP: 0x{0:08X}".format(eval_board.read_register(mc.REG.TSTEP))) | ||
print("TPWMTHRS: 0x{0:08X}".format(eval_board.read_register(mc.REG.TPWMTHRS))) | ||
print("TCOOLTHRS: 0x{0:08X}".format(eval_board.read_register(mc.REG.TCOOLTHRS))) | ||
print("THIGH: 0x{0:08X}".format(eval_board.read_register(mc.REG.THIGH))) | ||
print("DIRECT_MODE: 0x{0:08X}".format(eval_board.read_register(mc.REG.DIRECT_MODE))) | ||
print("ENCMODE: 0x{0:08X}".format(eval_board.read_register(mc.REG.ENCMODE))) | ||
print("X_ENC: 0x{0:08X}".format(eval_board.read_register(mc.REG.X_ENC))) | ||
print("ENC_CONST: 0x{0:08X}".format(eval_board.read_register(mc.REG.ENC_CONST))) | ||
print("ENC_STATUS: 0x{0:08X}".format(eval_board.read_register(mc.REG.ENC_STATUS))) | ||
print("ENC_LATCH: 0x{0:08X}".format(eval_board.read_register(mc.REG.ENC_LATCH))) | ||
print("ADC_VSUPPLY_AIN: 0x{0:08X}".format(eval_board.read_register(mc.REG.ADC_VSUPPLY_AIN))) | ||
print("ADC_TEMP: 0x{0:08X}".format(eval_board.read_register(mc.REG.ADC_TEMP))) | ||
print("OTW_OV_VTH: 0x{0:08X}".format(eval_board.read_register(mc.REG.OTW_OV_VTH))) | ||
print("MSLUT_0: 0x{0:08X}".format(eval_board.read_register(mc.REG.MSLUT_0))) | ||
print("MSLUT_1: 0x{0:08X}".format(eval_board.read_register(mc.REG.MSLUT_1))) | ||
print("MSLUT_2: 0x{0:08X}".format(eval_board.read_register(mc.REG.MSLUT_2))) | ||
print("MSLUT_3: 0x{0:08X}".format(eval_board.read_register(mc.REG.MSLUT_3))) | ||
print("MSLUT_4: 0x{0:08X}".format(eval_board.read_register(mc.REG.MSLUT_4))) | ||
print("MSLUT_5: 0x{0:08X}".format(eval_board.read_register(mc.REG.MSLUT_5))) | ||
print("MSLUT_6: 0x{0:08X}".format(eval_board.read_register(mc.REG.MSLUT_6))) | ||
print("MSLUT_7: 0x{0:08X}".format(eval_board.read_register(mc.REG.MSLUT_7))) | ||
print("MSLUTSEL: 0x{0:08X}".format(eval_board.read_register(mc.REG.MSLUTSEL))) | ||
print("MSLUTSTART: 0x{0:08X}".format(eval_board.read_register(mc.REG.MSLUTSTART))) | ||
print("MSCNT: 0x{0:08X}".format(eval_board.read_register(mc.REG.MSCNT))) | ||
print("MSCURACT: 0x{0:08X}".format(eval_board.read_register(mc.REG.MSCURACT))) | ||
print("CHOPCONF: 0x{0:08X}".format(eval_board.read_register(mc.REG.CHOPCONF))) | ||
print("COOLCONF: 0x{0:08X}".format(eval_board.read_register(mc.REG.COOLCONF))) | ||
print("DCCTRL: 0x{0:08X}".format(eval_board.read_register(mc.REG.DCCTRL))) | ||
print("DRV_STATUS: 0x{0:08X}".format(eval_board.read_register(mc.REG.DRV_STATUS))) | ||
print("PWMCONF: 0x{0:08X}".format(eval_board.read_register(mc.REG.PWMCONF))) | ||
print("PWM_SCALE: 0x{0:08X}".format(eval_board.read_register(mc.REG.PWM_SCALE))) | ||
print("PWM_AUTO: 0x{0:08X}".format(eval_board.read_register(mc.REG.PWM_AUTO))) | ||
print("SG4_THRS: 0x{0:08X}".format(eval_board.read_register(mc.REG.SG4_THRS))) | ||
print("SG4_RESULT: 0x{0:08X}".format(eval_board.read_register(mc.REG.SG4_RESULT))) | ||
print("SG4_IND: 0x{0:08X}".format(eval_board.read_register(mc.REG.SG4_IND))) | ||
|
||
|
||
print("\nReady.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
""" | ||
Move a motor back and forth using velocity and position mode of the TMC2240 | ||
""" | ||
import time | ||
import pytrinamic | ||
from pytrinamic.connections import ConnectionManager | ||
from pytrinamic.evalboards import TMC2240_eval | ||
|
||
pytrinamic.show_info() | ||
|
||
with ConnectionManager().connect() as my_interface: | ||
print(my_interface) | ||
|
||
# Create TMC2240-EVAL class which communicates over the Landungsbrücke via TMCL | ||
eval_board = TMC2240_eval(my_interface) | ||
mc = eval_board.ics[0] | ||
motor = eval_board.motors[0] | ||
|
||
print("Preparing parameter...") | ||
motor.set_axis_parameter(motor.AP.MaxAcceleration, 20000) | ||
motor.set_axis_parameter(motor.AP.MaxVelocity, 100000) | ||
motor.set_axis_parameter(motor.AP.MaxCurrent, 30) | ||
|
||
# Clear actual positions | ||
motor.actual_position = 0 | ||
|
||
print("Rotating...") | ||
motor.rotate(7*25600) | ||
time.sleep(5) | ||
|
||
print("Stopping...") | ||
motor.stop() | ||
time.sleep(1) | ||
|
||
print("Moving back to 0...") | ||
motor.move_to(0, 100000) | ||
|
||
# Wait until position 0 is reached | ||
while motor.actual_position != 0: | ||
print("Actual position: " + str(motor.actual_position)) | ||
time.sleep(0.2) | ||
|
||
print("Reached position 0") | ||
|
||
print("\nReady.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
""" | ||
Sets the StallGuard2 threshold such that the stall guard value (i.e SG value) is zero | ||
when the motor comes close to stall and also sets the stop on stall velocity to a value | ||
one less than the actual velocity of the motor | ||
""" | ||
import pytrinamic | ||
from pytrinamic.connections import ConnectionManager | ||
from pytrinamic.modules import TMCM1231 | ||
import time | ||
|
||
def stallguard2_init(motor, init_velocity): | ||
# Resetting SG2 threshold and stop on stall velocity to zero | ||
motor.stallguard2.set_threshold(0) | ||
motor.stallguard2.stop_velocity = 0 | ||
print("Initial StallGuard2 values:") | ||
print(motor.stallguard2) | ||
print("Rotating...") | ||
motor.rotate(init_velocity) | ||
sgthresh = 0 | ||
sgt = 0 | ||
load_samples = [] | ||
while (sgt == 0) and (sgthresh < 64): | ||
load_samples = [] | ||
motor.stallguard2.set_threshold(sgthresh) | ||
time.sleep(0.2) | ||
sgthresh += 1 | ||
for i in range(50): | ||
load_samples.append(motor.stallguard2.get_load_value()) | ||
if not any(load_samples): | ||
sgt = 0 | ||
else: | ||
sgt = max(load_samples) | ||
while 1: | ||
load_samples = [] | ||
for i in range(50): | ||
load_samples.append(motor.stallguard2.get_load_value()) | ||
if 0 in load_samples: | ||
motor.drive_settings.max_current = motor.drive_settings.max_current - 1 | ||
else: | ||
break | ||
|
||
motor.stallguard2.stop_velocity = motor.get_actual_velocity() - 1 | ||
print("Configured StallGuard2 parameters:") | ||
print(motor.stallguard2) | ||
|
||
def main(): | ||
pytrinamic.show_info() | ||
|
||
# This example is using PCAN, if you want to use another connection please change the next line. | ||
connection_manager = ConnectionManager("--interface pcan_tmcl") | ||
with connection_manager.connect() as my_interface: | ||
module = TMCM1231(my_interface) | ||
motor = module.motors[0] | ||
|
||
print("Preparing parameters") | ||
# preparing drive settings | ||
motor.drive_settings.max_current = 20 | ||
motor.drive_settings.standby_current = 8 | ||
motor.drive_settings.boost_current = 0 | ||
motor.drive_settings.microstep_resolution = motor.ENUM.microstep_resolution_256_microsteps | ||
print(motor.drive_settings) | ||
print(motor.linear_ramp) | ||
|
||
time.sleep(1.0) | ||
|
||
# clear position counter | ||
motor.actual_position = 0 | ||
|
||
# set up StallGuard2 | ||
print("Configuring StallGuard2 parameters...") | ||
stallguard2_init(motor, init_velocity = 10000) | ||
print("Apply load and try to stall the motor...") | ||
while not (motor.actual_velocity == 0): | ||
pass | ||
print("Motor stopped by StallGuard2!") | ||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import pytrinamic | ||
from pytrinamic.connections import ConnectionManager | ||
from pytrinamic.modules import TMCM1231 | ||
import time | ||
|
||
pytrinamic.show_info() | ||
|
||
# This example is using PCAN, if you want to use another connection please change the next line. | ||
connectionManager = ConnectionManager("--interface pcan_tmcl") | ||
with connectionManager.connect() as myInterface: | ||
module = TMCM1231(myInterface) | ||
motor = module.motors[0] | ||
|
||
# Please be sure not to use a too high current setting for your motor. | ||
|
||
print("Preparing parameters") | ||
# preparing drive settings | ||
motor.drive_settings.max_current = 128 | ||
motor.drive_settings.standby_current = 0 | ||
motor.drive_settings.boost_current = 0 | ||
motor.drive_settings.microstep_resolution = motor.ENUM.microstep_resolution_256_microsteps | ||
print(motor.drive_settings) | ||
|
||
|
||
# preparing linear ramp settings | ||
motor.max_acceleration = 51200 | ||
motor.max_velocity = 51200 | ||
|
||
# reset actual position | ||
motor.actual_position = 0 | ||
|
||
print(motor.linear_ramp) | ||
|
||
# start rotating motor in different directions | ||
print("Rotating") | ||
motor.rotate(51200) | ||
time.sleep(5) | ||
|
||
# stop rotating motor | ||
print("Stopping") | ||
motor.stop() | ||
|
||
# read actual position | ||
print("ActualPostion = {}".format(motor.actual_position)) | ||
time.sleep(2) | ||
|
||
# doubling moved distance | ||
print("Doubling moved distance") | ||
motor.move_by(motor.actual_position) | ||
|
||
# wait till position_reached | ||
while not(motor.get_position_reached()): | ||
print("target position motor: " + str(motor.target_position) + " actual position motor: " + str(motor.actual_position)) | ||
|
||
time.sleep(0.2) | ||
print("Furthest point reached") | ||
print("ActualPostion motor = {}".format(motor.actual_position)) | ||
|
||
# short delay and move back to start | ||
time.sleep(2) | ||
print("Moving back to 0") | ||
motor.move_to(0) | ||
|
||
# wait until position 0 is reached | ||
while not(motor.get_position_reached()): | ||
print("target position motor: " + str(motor.target_position) + " actual position motor: " + str(motor.actual_position)) | ||
|
||
print("Reached Position 0") |
Oops, something went wrong.