Example #1
0
# StallGuard
THRESHOLD_SG = 3

# CoolStep
CURRENT_MIN = 0  # 0: CURRENT_MAX / 2, 1: CURRENT_MAX / 4
CURRENT_DOWN_STEP = 2  # 0 : Slow, 3: Instant
CURRENT_UP_STEP = 2  # 0 : Slow, 3: Instant
HYSTERESIS_WIDTH = 4
HYSTERESIS_START = 9
THRESHOLD_COOLSTEP = 0

################################################################################

pytrinamic.show_info()
connectionManager = ConnectionManager()
myInterface = connectionManager.connect()

shields = TmcEvalShield(myInterface, TMC5160_shield).shields

# Initialize all attached shields
for shield in shields:
    print("Rotating motor.")
    shield.set_axis_parameter(shield.AP.MaxCurrent, 0, CURRENT_MAX)
    shield.set_axis_parameter(shield.AP.MaxAcceleration, 0, ACCELERATION)
    shield.rotate(0, VELOCITY)

    # StallGuard settings
    shield.set_axis_parameter(shield.AP.SG2Threshold, 0, THRESHOLD_SG)

    # CoolStep settings
Example #2
0
"""
Turn a motor using hall sensors
"""

import pytrinamic
from pytrinamic.connections.connection_manager import ConnectionManager
from pytrinamic.referencedesigns import TMC4671_LEV_REF
import time

pytrinamic.show_info()

# please select your CAN adapter
# my_interface = ConnectionManager("--interface pcan_tmcl").connect()
my_interface = ConnectionManager("--interface kvaser_tmcl").connect()

with my_interface:
    module = TMC4671_LEV_REF(my_interface)
    motor = module.motors[0]

    # Define motor configuration for the TMC4671-LEV-REF.
    #
    # The configuration is based on our standard BLDC motor (QBL4208-61-04-013-1024-AT).
    # If you use a different motor be sure you have the right configuration setup otherwise the script may not work.

    # drive configuration
    motor.drive_settings.motor_type = motor.ENUM.MOTOR_TYPE_THREE_PHASE_BLDC
    motor.drive_settings.pole_pairs = 4
    motor.drive_settings.max_current = 2000
    motor.drive_settings.commutation_mode = motor.ENUM.COMM_MODE_DIGITAL_HALL
    motor.drive_settings.target_reached_distance = 5
    motor.drive_settings.target_reached_velocity = 500
consoleHandler = logging.StreamHandler()
consoleHandler.setLevel(verbosity)
formatter = logging.Formatter(
    "[%(asctime)s] [%(name)s] [%(levelname)s] %(message)s")
consoleHandler.setFormatter(formatter)
logger.addHandler(consoleHandler)

pytrinamic.show_info()

logger.debug(f"Target velocity: {args.velocity[0]}")
logger.debug(f"Maximum acceleration: {args.acceleration[0]}")
logger.debug(f"Maximum current: {args.current[0]}")
logger.debug(f"StallGuard velocity threshold: {args.threshold[0]}")

myInterface = ConnectionManager().connect()

shields = TmcEvalShield(myInterface, TMC5160_shield).shields

# Initialize all attached shields
for shield in shields:
    logger.info(f"Initializing motor at shield {shield}.")

    logger.info("Rotating motor.")
    shield.set_axis_parameter(shield.AP.MaxCurrent, 0, args.current[0])
    shield.set_axis_parameter(shield.AP.MaxAcceleration, 0,
                              args.acceleration[0])
    shield.rotate(0, args.velocity[0])

    StallGuard(shield, sys.argv, logger).calibrate_zero()
Example #4
0
# ################################ Preparation ##################################
pytrinamic.show_info()

if len(sys.argv) < 2:
    print("Usage:\n\tFirmwareUpdate.py HexFilePath [connection options]")
    exit(1)

print("Opening hex file (" + sys.argv[1] + ")")

try:
    f = open(sys.argv[1], "rt")
except FileNotFoundError:
    print("Error: Hex file not found")
    exit(1)

connectionManager = ConnectionManager(sys.argv)

# ############################## Hex file parsing ###############################
print("Parsing hex file")

data = []
extendedAddress = 0
segmentAddress = 0
for lineNumber, line in enumerate(f, 1):
    # ## Parse a hex file line
    # Check for RECORD MARK
    if line[0] != ':':
        continue

    # CHECKSUM validation
    # All Bytes summed together modulo 256 have to be 0