Example #1
0
    def get_address(self, parameter='address'):
        '''
        Reads the address of the motor and returns it
        '''

        values = self.read(self.address, self.PARAMETER[parameter])
        address = translations.hextodec(values)
        if self.verbose: print 'The address of the motor is ' + str(address)

        return address
Example #2
0
    def get_address(self, parameter = 'address'):
        '''
        Reads the address of the motor and returns it
        '''

        values = self.read(self.address, self.PARAMETER[parameter])
        address = translations.hextodec(values)
        if self.verbose: print 'The address of the motor is ' + str(address)

        return address
Example #3
0
    def get_errorstatus(self, parameter='errorstatus'):
        '''
        Returns bits which express what the status of the motor is.
        If this returns a non-zero value, you may not be able to change any motor settings depending on the error.
        Depending on the value returned, this may be state of the motor:

        :param Bit0: Overload
        :param Bit1: Follow Error
        :param Bit2: Function Error
        :param Bit3: Regenerative overload
        :param Bit4: In position
        :param Bit5: Accelerating
        :param Bit6: Decelerating
        :param Bit7: Position limits error
        :param Bit11: Motor current too high
        :param Bit12: Supply undervoltage
        :param Bit16: SII Read error

        The mode must be set to 1 before reading any errorbits, otherwise returns 0.

        More details on the errordict is given in the 'Translations' module in the 'Library' section at the 'checkforerrors' definition.
        '''

        errordict = {
            'Bit 0': 2**0,
            'Bit 1': 2**1,
            'Bit 2': 2**2,
            'Bit 3': 2**3,
            'Bit 4': 2**4,
            'Bit 5': 2**5,
            'Bit 6': 2**6,
            'Bit 7': 2**7,
            'Bit 8': 2**8,
            'Bit 9': 2**9,
            'Bit 10': 2**10,
            'Bit 11': 2**11,
            'Bit 12': 2**12,
            'Bit 13': 2**13,
            'Bit 14': 2**14,
            'Bit 15': 2**15,
            'Bit 16': 2**16,
        }

        BITS = 16
        hexa = self.read(self.address, self.PARAMETER[parameter])
        error = translations.hextodec(hexa)

        if error != 0:
            bina = translations.dectobin(error, BITS)
            translations.checkforerrors(errordict, bina)

        else:
            if self.verbose:
                print 'If the mode is set to 1, there is an error in Bit 0'
Example #4
0
    def get_errorstatus(self, parameter = 'errorstatus'):
        '''
        Returns bits which express what the status of the motor is.
        If this returns a non-zero value, you may not be able to change any motor settings depending on the error.
        Depending on the value returned, this may be state of the motor:

        :param Bit0: Overload
        :param Bit1: Follow Error
        :param Bit2: Function Error
        :param Bit3: Regenerative overload
        :param Bit4: In position
        :param Bit5: Accelerating
        :param Bit6: Decelerating
        :param Bit7: Position limits error
        :param Bit11: Motor current too high
        :param Bit12: Supply undervoltage
        :param Bit16: SII Read error

        The mode must be set to 1 before reading any errorbits, otherwise returns 0.

        More details on the errordict is given in the 'Translations' module in the 'Library' section at the 'checkforerrors' definition.
        '''

        errordict = {'Bit 0' : 2**0,
                     'Bit 1' : 2**1,
                     'Bit 2' : 2**2,
                     'Bit 3' : 2**3,
                     'Bit 4' : 2**4,
                     'Bit 5' : 2**5,
                     'Bit 6' : 2**6,
                     'Bit 7' : 2**7,
                     'Bit 8' : 2**8,
                     'Bit 9' : 2**9,
                     'Bit 10' : 2**10,
                     'Bit 11' : 2**11,
                     'Bit 12' : 2**12,
                     'Bit 13' : 2**13,
                     'Bit 14' : 2**14,
                     'Bit 15' : 2**15,
                     'Bit 16' : 2**16,
                     }

        BITS = 16
        hexa = self.read(self.address, self.PARAMETER[parameter])
        error = translations.hextodec(hexa)

        if error != 0:
            bina = translations.dectobin(error,BITS)
            translations.checkforerrors(errordict, bina)

        else:
            if self.verbose: print 'If the mode is set to 1, there is an error in Bit 0'
Example #5
0
    def get_setvelocity(self, parameter = 'velocity'):
        '''
        reads the velocity that is currently set and returns it in rpm
        '''

        values = self.read(self.address, self.PARAMETER[parameter])

        pulses = translations.hextodec(values)
        rpm = constants.READ_SRPM/constants.RSPPS*pulses
        rpm = translations.rounding(rpm)
        if self.verbose: print 'The velocity is set at ' + str(rpm) + ' rpm'

        return rpm
Example #6
0
    def get_setvelocity(self, parameter='velocity'):
        '''
        reads the velocity that is currently set and returns it in rpm
        '''

        values = self.read(self.address, self.PARAMETER[parameter])

        pulses = translations.hextodec(values)
        rpm = constants.READ_SRPM / constants.RSPPS * pulses
        rpm = translations.rounding(rpm)
        if self.verbose: print 'The velocity is set at ' + str(rpm) + ' rpm'

        return rpm
Example #7
0
    def get_temperature(self, parameter = 'temperature'):
        '''
        Reads the temperature in degrees Celcius and returns it, will give 0 if mode is set to 0
        '''

        values = self.read(self.address, self.PARAMETER[parameter])
        temp = translations.hextodec(values)

        if self.verbose:
            if temp == 0:
                print 'Please turn the motor on before attempting to measure the temperature.'
            else:
                print 'The Temperature of the motor is ' + str(temp) +' degrees Celcius'

        return temp
Example #8
0
    def get_acceleration(self, parameter = 'acceleration'):
        '''
        Reads acceleration and returns the value in rpm/s
        '''

        values = self.read(self.address, self.PARAMETER[parameter])


        pulses = translations.hextodec(values)
        acc = constants.READ_ACC/constants.READ_PPSS*pulses
        acc = translations.rounding(acc)

        if self.verbose: print 'The acceleration is set at ' + str(acc) + ' rpm/s'

        return acc
Example #9
0
    def get_acceleration(self, parameter='acceleration'):
        '''
        Reads acceleration and returns the value in rpm/s
        '''

        values = self.read(self.address, self.PARAMETER[parameter])

        pulses = translations.hextodec(values)
        acc = constants.READ_ACC / constants.READ_PPSS * pulses
        acc = translations.rounding(acc)

        if self.verbose:
            print 'The acceleration is set at ' + str(acc) + ' rpm/s'

        return acc
Example #10
0
    def get_temperature(self, parameter='temperature'):
        '''
        Reads the temperature in degrees Celcius and returns it, will give 0 if mode is set to 0
        '''

        values = self.read(self.address, self.PARAMETER[parameter])
        temp = translations.hextodec(values)

        if self.verbose:
            if temp == 0:
                print 'Please turn the motor on before attempting to measure the temperature.'
            else:
                print 'The Temperature of the motor is ' + str(
                    temp) + ' degrees Celcius'

        return temp
Example #11
0
    def __findMotor(self, start=0, end=10, found=False):
        '''
        Scans to see if a motor is connected and to which address.
        
        Writes the same message to different addresses, if it receives a reply it returns True.
        
        It also saves the address every time a motor is found in a list and each address can be summoned with
        a definition found below.        
        '''

        BYTESIZE = 19
        ADDRESREGISTER = 156
        #         MOTOR_TYPE=153
        #         SERIAL_NBR = 154
        data = []
        self.addr = dict()
        if self.port.isOpen() == False:
            self.port.open()
        try:
            for j in range(start, end):

                address = translations.createcommand_read(
                    j, ADDRESREGISTER
                )  #ADDRESREGISTER)# SERIAL_NBR) #MOTOR_TYPE)#)
                self.port.write(address.decode('hex'))
                for k in range(BYTESIZE):
                    byte = self.port.read()
                    data.append(k)
                    data[k] = byte.encode('hex')
                try:
                    values = [data[9], data[11]]
                    decim = translations.hextodec(values)
                    if decim == 1:
                        found = True
                        if 'motor' in self.addr:
                            self.addr.append(j)
                        else:
                            self.addr['motor'] = j
                    print 'Motor found on address ' + str(
                        j) + ' decim: %s' % decim, ' values: %s' % values
                except:
                    print 'No motor on address ' + str(j)
        finally:
            self.port.close()
            return found
Example #12
0
    def __findMotor(self, start =0, end=10, found = False):
        '''
        Scans to see if a motor is connected and to which address.
        
        Writes the same message to different addresses, if it receives a reply it returns True.
        
        It also saves the address every time a motor is found in a list and each address can be summoned with
        a definition found below.        
        '''
        
        BYTESIZE = 19
        ADDRESREGISTER = 156
#         MOTOR_TYPE=153
#         SERIAL_NBR = 154
        data = []
        self.addr = dict()
        if self.port.isOpen()==False:
            self.port.open()
        try: 
            for j in range(start,end):
            
                address = translations.createcommand_read(j, ADDRESREGISTER) #ADDRESREGISTER)# SERIAL_NBR) #MOTOR_TYPE)#)
                self.port.write(address.decode('hex'))
                for k in range(BYTESIZE):
                    byte = self.port.read()     
                    data.append(k)
                    data[k] = byte.encode('hex')
                try:
                    values = [data[9],data[11]]
                    decim = translations.hextodec(values)
                    if decim == 1:
                        found = True
                        if 'motor' in self.addr:
                            self.addr.append(j)
                        else:
                            self.addr['motor'] = j
                    print 'Motor found on address ' + str(j)+ ' decim: %s'%decim, ' values: %s'%values
                except:
                    print 'No motor on address ' + str(j)
        finally:
            self.port.close()
            return found
Example #13
0
    def get_actualvelocity(self, parameter = 'actualvelocity'):
        '''
        reads the actual velocity that the motor is running and returns it in rpm, will return 0 if mode is set to 0
        '''

        values = self.read(self.address, self.PARAMETER[parameter])

        pulses = translations.hextodec(values)
        rpm = constants.READ_ARPM/constants.RAPPS*pulses

        rpm = translations.rounding(rpm)

        if self.verbose:
            if rpm == 0:
                print 'The motor is running at ' + str(rpm) + ' rpm, make sure the motor is on'

            else:
                print 'The motor is running at ' + str(rpm) + ' rpm'

        return rpm
Example #14
0
    def get_actualvelocity(self, parameter='actualvelocity'):
        '''
        reads the actual velocity that the motor is running and returns it in rpm, will return 0 if mode is set to 0
        '''

        values = self.read(self.address, self.PARAMETER[parameter])

        pulses = translations.hextodec(values)
        rpm = constants.READ_ARPM / constants.RAPPS * pulses

        rpm = translations.rounding(rpm)

        if self.verbose:
            if rpm == 0:
                print 'The motor is running at ' + str(
                    rpm) + ' rpm, make sure the motor is on'

            else:
                print 'The motor is running at ' + str(rpm) + ' rpm'

        return rpm