How to use the canopen.profiles.p402.State402 function in canopen

To help you get started, we’ve selected a few canopen examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github christiansandberg / canopen / canopen / profiles / p402.py View on Github external
def _next_state(self, target_state):
        if target_state == 'OPERATION ENABLED':
            return State402.next_state_for_enabling(self.state)
        else:
            return target_state
github christiansandberg / canopen / canopen / profiles / p402.py View on Github external
def homing(self, timeout=30, set_new_home=True):
        """Function to execute the configured Homing Method on the node
        :param int timeout: Timeout value (default: 30)
        :param bool set_new_home: Defines if the node should set the home offset
        object (0x607C) to the current position after the homing procedure (default: true)
        :return: If the homing was complete with success
        :rtype: bool
        """
        previus_op_mode = self.op_mode
        self.state = 'SWITCHED ON'
        self.op_mode = 'HOMING'
        # The homing process will initialize at operation enabled
        self.state = 'OPERATION ENABLED'
        homingstatus = 'IN PROGRESS'
        self.controlword = State402.CW_OPERATION_ENABLED | Homing.CW_START
        t = time.time() + timeout
        try:
            while homingstatus not in ('TARGET REACHED', 'ATTAINED'):
                for key, value in Homing.STATES.items():
                    # check if the value after applying the bitmask (value[0])
                    # corresponds with the value[1] to determine the current status
                    bitmaskvalue = self.statusword & value[0]
                    if bitmaskvalue == value[1]:
                        homingstatus = key
                if homingstatus in ('INTERRUPTED', 'ERROR VELOCITY IS NOT ZERO', 'ERROR VELOCITY IS ZERO'):
                    raise  RuntimeError ('Unable to home. Reason: {0}'.format(homingstatus))
                time.sleep(0.001)
                if time.time() > t:
                    raise RuntimeError('Unable to home, timeout reached')
            if set_new_home:
                actual_position = self.sdo[0x6063].raw
github christiansandberg / canopen / canopen / profiles / p402.py View on Github external
def is_faulted(self):
        return self.statusword & State402.SW_MASK['FAULT'][0] == State402.SW_MASK['FAULT'][1]
github christiansandberg / canopen / canopen / profiles / p402.py View on Github external
def _change_state(self, target_state):
        try:
            self.controlword = State402.TRANSITIONTABLE[(self.state, target_state)]
        except KeyError:
            raise ValueError(
                'Illegal state transition from {f} to {t}'.format(f=self.state, t=target_state))
        timeout = time.time() + 0.4 # 400 ms
        while self.state != target_state:
            if time.time() > timeout:
                return False
            time.sleep(0.01) # 10 ms
        return True
github christiansandberg / canopen / canopen / profiles / p402.py View on Github external
def reset_from_fault(self):
        """Reset node from fault and set it to Operation Enable state
        """
        if self.state == 'FAULT':
            # Resets the Fault Reset bit (rising edge 0 -> 1)
            self.controlword = State402.CW_DISABLE_VOLTAGE
            timeout = time.time() + 0.4  # 400 ms
            
            while self.is_faulted():
                if time.time() > timeout:
                    break
                time.sleep(0.01)  # 10 ms
            self.state = 'OPERATION ENABLED'
github christiansandberg / canopen / canopen / profiles / p402.py View on Github external
def next_state_for_enabling(_from):
        """Returns the next state needed for reach the state Operation Enabled
        :param string target: Target state
        :return string: Next target to chagne
        """
        for cond, next_state in State402.NEXTSTATE2ENABLE.items():
            if _from in cond:
                return next_state