Ejemplo n.º 1
0
 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
Ejemplo n.º 2
0
 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
Ejemplo n.º 3
0
 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
Ejemplo n.º 4
0
    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
Ejemplo n.º 5
0
 def set_pullup(self, idx, pullup):
     self.set_pullups(
         TMC_helpers.field_set(self.get_pullups(), (1 << idx), idx, pullup))
Ejemplo n.º 6
0
 def get_direction(self, idx):
     return TMC_helpers.field_get(self.get_directions(), (1 << idx), idx)
Ejemplo n.º 7
0
 def set_direction(self, idx, direction):
     self.set_directions(
         TMC_helpers.field_set(self.get_directions(), (1 << idx), idx,
                               direction))
Ejemplo n.º 8
0
 def writeRegisterField(self, field, value):
     return self.writeRegister(
         field[0],
         TMC_helpers.field_set(self.readRegister(field[0]), field[1],
                               field[2], value))
Ejemplo n.º 9
0
 def actualVelocity(self):
     return TMC_helpers.toSigned32(self.axisParameter(self.APs.ActualVelocity))    
Ejemplo n.º 10
0
 def get_gpio(self, idx):
     return TMC_helpers.field_get(self.get_gpios(), (1 << idx), idx)
Ejemplo n.º 11
0
 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)
Ejemplo n.º 13
0
 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
Ejemplo n.º 14
0
 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
Ejemplo n.º 15
0
 def globalParameter(self, commandType, axis):
     return TMC_helpers.toSigned32(self.send(self.moduleAddress, TMCL_Command.GGP, commandType, axis, 0).value)
Ejemplo n.º 16
0
 def get_pullup(self, idx):
     return TMC_helpers.field_get(self.get_pullups(), (1 << idx), idx)
Ejemplo n.º 17
0
 def set_gpio(self, idx, gpio):
     self.set_gpios(
         TMC_helpers.field_set(self.get_gpios(), (1 << idx), idx, gpio))
Ejemplo n.º 18
0
 def targetTorque(self):
     return TMC_helpers.toSigned32(self.axisParameter(self.AP.TargetTorque))
Ejemplo n.º 19
0
 def actualPosition(self):
     return TMC_helpers.toSigned32(self.axisParameter(self.APs.ActualPosition))    
Ejemplo n.º 20
0
 def actualTorque(self):
     return TMC_helpers.toSigned32(self.axisParameter(self.AP.ActualTorque))
Ejemplo n.º 21
0
 def writeRegisterField(self, registerAddress, value, mask, shift):
     return self.writeRegister(
         registerAddress,
         TMC_helpers.field_set(self.readRegister(registerAddress), mask,
                               shift, value))
Ejemplo n.º 22
0
 def readRegisterField(self, registerAddress, mask, shift):
     return TMC_helpers.field_get(self.readRegister(registerAddress), mask,
                                  shift)
Ejemplo n.º 23
0
 def readRegisterField(self, field):
     return TMC_helpers.field_get(self.readRegister(field[0]), field[1],
                                  field[2])
Ejemplo n.º 24
0
 def actualVelocity(self):
     return TMC_helpers.toSigned32(
         self.readRegister(self.tmc4671_reg.PID_VELOCITY_ACTUAL))