#id shorttrack_startup_adjustments_example.py # Fullmo MovingCap CODE - micropython example. # original file name: shorttrack_startup_adjustments_example.py # This demonstrates how to adjust controller parameters that are not stored permanently # and need to be set each time the drive is powered up. # # This is a general example that can be used / adapted as follows # - Open the Kickdrive Object Editor module, create a list of parameters you want to adjust, # write the objects to a drive and test. # - If ok, select the relevant parameters in the table (or all), # and use the "Export" button from the Object Editor toolbar # - From the severa different files created (.xdc, .csv, .cdcf, .txt) choose the .txt and use its contents # to define the PARAMETER_ADJUSTMENTS variable below. # - Upload the resulting script to the MovingCap drive, choose "Autostart = ON" and press "Store Permanently" # --> The adjustments will now be applied each time the drive is powered up. # import mcdrive as mc PARAMETER_ADJUSTMENTS = """ 050.3302h.02h,unsigned8,0 # velInp bank1 mode 050.3302h.03h,unsigned8,1 # velLoNoise bank2 mode 050.3304h.03h,unsigned32,500 # velLoNoise bank2 filterFreq 050.3305h.03h,unsigned32,500 # velLoNoise bank2 milliQ """ def WriteObjectsFromKickdriveList(kickdriveTxtExportString): """ This function takes a Kickdrive Object Editor text list and sets the parameters Parameters: kickdriveTxtExportString (str): A string containing KickDrive export data. EEach line represents a CANopen object as comma seperated list format "ID,Type,Value". IDs contain NodeId, index and subindex in format 050.3401h.03h (for example) Values are in decimal format. Everything after '#' is a comment / ignored. Returns: None. The function prints a message for each object written to the drive. """ # Create a list of parameters params = [line.split(',') for line in kickdriveTxtExportString.split('\n') if line.strip()] # Iterate through each parameter for param in params: # Skip lines without an ID if len(param) < 2: continue id = param[0].split('.') index = int(id[1].rstrip('h'), 16) subindex = int(id[2].rstrip('h'), 16) value = int(param[2].split('#')[0]) mc.WriteObject(index, subindex, value) print ("Writing object " + hex(index) + "," + hex(subindex) + " = " + str(value)) WriteObjectsFromKickdriveList(PARAMETER_ADJUSTMENTS)