def decodeRegisters(cls, MSLUT, MSLUTSEL, MSLUTSTART): obj = cls() obj._reg_MSLUT = MSLUT obj._reg_MSLUTSEL = MSLUTSEL obj._reg_MSLUTSTART = MSLUTSTART ranges = [ (TMC_helpers.field_get(MSLUTSEL, 0x0000FF00, 8), TMC_helpers.field_get(MSLUTSEL, 0x00000003, 0)), (TMC_helpers.field_get(MSLUTSEL, 0x00FF0000, 16), TMC_helpers.field_get(MSLUTSEL, 0x0000000C, 2)), (TMC_helpers.field_get(MSLUTSEL, 0xFF000000, 24), TMC_helpers.field_get(MSLUTSEL, 0x00000030, 4)), (255, TMC_helpers.field_get(MSLUTSEL, 0x000000C0, 6)), ] if not(ranges[0][0] <= ranges[1][0] <= ranges[2][0] <= ranges[3][0]): raise ValueError("Condition X1 <= X2 <= X3 <= X4 not satisfied") startSin = TMC_helpers.field_get(MSLUTSTART, 0x000000FF, 0) startCos = TMC_helpers.field_get(MSLUTSTART, 0x00FF0000, 16) # Generate the first quarter sine wave sineValues = [ (0, startSin) ] for i in range(1, 257): for j in range(0, 4): if i < ranges[j][0]: offset = ranges[j][1] - 1 break bitValue = ((MSLUT[math.floor((i)/32) & 7] >> ((i) % 32) ) & 1) deltaValue = bitValue + offset newValue = sineValues[i-1][1] + deltaValue sineValues += [(i, newValue)] # Generate the second quarter sine wave for i in range(257, 512): newValue = sineValues[511-i][1] sineValues += [(i, newValue)] # Generate the remaining sine wave offset = 2*sineValues[0][1] - 1 for i in range(512, 1024): newValue = -sineValues[i-512][1] + offset sineValues += [(i, newValue)] # Generate the cosine wave cosOffset = startCos - sineValues[256][1] obj._waveform = [] for i in range(0, 1024): tmp = sineValues[i] obj._waveform += [(tmp[0], tmp[1], sineValues[(i+256) % 1024][1] + cosOffset)] # The table is now initialized obj._initialized = True return obj
def readRegister(self, registerAddress, command, channel, moduleID=None, signed=False): value = self.send(command, registerAddress, channel, 0, moduleID).value return TMC_helpers.toSigned32(value) if signed else value
def parameter(self, pCommand, pType, pAxis, pValue, moduleID=None, signed=False): value = self.send(pCommand, pType, pAxis, pValue, moduleID).value return TMC_helpers.toSigned32(value) if signed else value
def readRegister(self, registerAddress, signed=False): datagram = struct.pack(DATAGRAM_FORMAT, registerAddress, 0) reply = self.__connection.send_datagram(datagram, DATAGRAM_LENGTH, self.__channel) values = struct.unpack(DATAGRAM_FORMAT, reply) value = values[1] return TMC_helpers.toSigned32(value) if signed else value
def set_pullup(self, idx, pullup): self.set_pullups( TMC_helpers.field_set(self.get_pullups(), (1 << idx), idx, pullup))
def get_direction(self, idx): return TMC_helpers.field_get(self.get_directions(), (1 << idx), idx)
def set_direction(self, idx, direction): self.set_directions( TMC_helpers.field_set(self.get_directions(), (1 << idx), idx, direction))
def writeRegisterField(self, field, value): return self.writeRegister( field[0], TMC_helpers.field_set(self.readRegister(field[0]), field[1], field[2], value))
def actualVelocity(self): return TMC_helpers.toSigned32(self.axisParameter(self.APs.ActualVelocity))
def get_gpio(self, idx): return TMC_helpers.field_get(self.get_gpios(), (1 << idx), idx)
def targetPosition(self): return TMC_helpers.toSigned32(self.axisParameter(self.AP.TargetPosition))
def actualVolume(self): reg_value = self.axisParameter(self.APs.ActualVolume) return TMC_helpers.toSigned32(reg_value)
def globalParameter(self, commandType, bank, moduleID=None, signed=False): value = self.send(TMCL_Command.GGP, commandType, bank, 0, moduleID).value return TMC_helpers.toSigned32(value) if signed else value
def axisParameter(self, commandType, axis, moduleID=None, signed=False): value = self.send(TMCL_Command.GAP, commandType, axis, 0, moduleID).value return TMC_helpers.toSigned32(value) if signed else value
def globalParameter(self, commandType, axis): return TMC_helpers.toSigned32(self.send(self.moduleAddress, TMCL_Command.GGP, commandType, axis, 0).value)
def get_pullup(self, idx): return TMC_helpers.field_get(self.get_pullups(), (1 << idx), idx)
def set_gpio(self, idx, gpio): self.set_gpios( TMC_helpers.field_set(self.get_gpios(), (1 << idx), idx, gpio))
def targetTorque(self): return TMC_helpers.toSigned32(self.axisParameter(self.AP.TargetTorque))
def actualPosition(self): return TMC_helpers.toSigned32(self.axisParameter(self.APs.ActualPosition))
def actualTorque(self): return TMC_helpers.toSigned32(self.axisParameter(self.AP.ActualTorque))
def writeRegisterField(self, registerAddress, value, mask, shift): return self.writeRegister( registerAddress, TMC_helpers.field_set(self.readRegister(registerAddress), mask, shift, value))
def readRegisterField(self, registerAddress, mask, shift): return TMC_helpers.field_get(self.readRegister(registerAddress), mask, shift)
def readRegisterField(self, field): return TMC_helpers.field_get(self.readRegister(field[0]), field[1], field[2])
def actualVelocity(self): return TMC_helpers.toSigned32( self.readRegister(self.tmc4671_reg.PID_VELOCITY_ACTUAL))