return module.make_iface(ids[0],param) # otherwise print('Available IDs:') n = 0 for i in ids: n+=1 print('[{0}] {1}'.format(n, i)) n = input('Select iface (1-{0}):'.format(len(ids))) return module.make_iface(ids[n-1],param) #------------------------------------------------------------------------------ # MAIN #------------------------------------------------------------------------------ if __name__ == '__main__': iface = get_iface('ixxat') io_service = canio2.IOService(iface) NODE_ID = 1 node = CANopenNode(NODE_ID, io_service) waiter = canio2.TriggersWaiter(io_service) print 'Resetting node...' if node.reset(5000) == False: print 'Boot Timeout' sys.exit(1) print 'Node state after reset: ' + str(node.state) node.state = CANopenNode.STATES.OPERATIONAL print 'Node state : ' + str(node.state) print('* Drive Initialization.') print('\tClear Faults.')
def main(): parser = OptionParser() parser.add_option('-m', '--mode', action='store', dest='mode', type='choice', choices=['homing', 'test', 'srv'], default='homing', help='Modes: homing = do homing, test = do test; service = move one axis' ) parser.add_option('-d', action='store', type='int', dest='distance', default = 0, help='This is a relative distance in mm for service mode and amplitude for test mode.' ) parser.add_option('-a', action='store', type='int', dest='service_axis', default=-1, help='This is a target axis [0-3] for service mode. Both table axes will be used if this option is not supplied.' ) parser.add_option('-n', action='store', type='int', dest='test_cycles', default=1, help='This is a number of test iterations for test mode.' ) #parser.add_option('-l', action='store', type='string', dest='log', default=LogFile, # help='Log file.' ) (options, args) = parser.parse_args() #LogFile = options.log iface = get_iface('ixxat') io_service = canio2.IOService(iface) pmd = canio2.PMD(NODE_ID, io_service) waiter = canio2.TriggersWaiter(io_service) axes = [] print '*** Axes Initialization ***' if options.mode == 'srv' and options.service_axis >=0 and options.service_axis<=3: axes = [pmd.axis(options.service_axis),] else: for n in AXES_IDS: ax = pmd.axis(n) axes.append(ax) init_axes('nic',axes) global PMDCycleTime PMDCycleTime = pmd.sample_time print 'PMDCycleTime', PMDCycleTime print '*** Axes Initialization Done ***' try: if options.mode == 'homing' or options.mode == 'test': print '*** HOMING ***' stop_axes(pmd,axes) unlock_axes(axes) print '\tHoming. Step1. Moving Up...' for ax in axes: waiter.add(ax.event_trigger) move_rel(pmd, axes, SAFE_SPEED_RPM, HOMING_INIT_UP_MOVE_MM) wait(waiter, 4) #TODO wait time calc for ax in axes: st = ax.event_status print '\tAxis', ax.number, 'status reg:', bin(st) if (st & PMD.STATUS_BITS.MOTION_ERR) > 0: raise MotionErr() print '\tHoming. Step1. Completed.' time.sleep(1) print '\tHoming. Step2. Moving Down to Negative Limit...' for ax in axes: waiter.add(ax.event_trigger) move_rel(pmd, axes, SAFE_SPEED_RPM, -1000) # -1000 mm wait(waiter, 2) for ax in axes: st = ax.event_status print '\tAxis', ax.number, 'status reg:', bin(st) if (st & PMD.STATUS_BITS.MOTION_ERR) > 0: raise MotionErr() if (st & PMD.STATUS_BITS.NEGATIVE_LIMIT) == 0: raise NoLimitErr() ax.actual_position = 0 print '\tHoming. Step2. Completed.' elif options.mode == 'srv': print '*** SERVICE ***' print '\tMoving', options.distance, 'mm from current position' stop_axes(pmd,axes) unlock_axes(axes) for ax in axes: waiter.add(ax.event_trigger) v = SAFE_SPEED_RPM move_rel(pmd, axes, v, options.distance) wait(waiter, 1+abs(options.distance)/rpm_to_mms(v)) # show status reg at the end for ax in axes: st = ax.event_status print '\tAxis', ax.number, 'status reg:', bin(st) if (st & PMD.STATUS_BITS.MOTION_ERR) > 0: raise MotionErr() print '\tMoving done.' if options.mode =='test': time.sleep(1) # do delay after homing print '*** TABLE TEST (', options.test_cycles, 'times ) ***' v = TEST_V down = 20 up = options.distance + 20 waiter.reset(); t0 = time.clock() for i in range(options.test_cycles): print '\tITERATION', i+1 print '\tMoving UP...' for ax in axes: waiter.add(ax.event_trigger) move_abs(pmd, axes, v, up) wait_ex(waiter, 10+abs(options.distance)/rpm_to_mms(v),axes) #TODO wait time # show status reg at the end for ax in axes: st = ax.event_status print '\tAxis', ax.number, 'status reg:', bin(st) if (st & PMD.STATUS_BITS.MOTION_ERR) > 0: raise MotionErr() print '\tMoving UP Done.' print '\tMoving DOWN...' for ax in axes: waiter.add(ax.event_trigger) move_abs(pmd, axes, v, down) wait_ex(waiter, 10+abs(options.distance)/rpm_to_mms(v), axes) #TODO wait time # show status reg at the end for ax in axes: st = ax.event_status print '\tAxis', ax.number, 'status reg:', bin(st) if (st & PMD.STATUS_BITS.MOTION_ERR) > 0: raise MotionErr() print '\tMoving DOWN Done.' t1 = time.clock() print 'Test duration', t1-t0 except TimeoutEx: print 'Error: Timeout' except MotionErr: print 'Error: Motion Error' except NoLimitErr: print 'Error: Can\'t find limit' except KeyboardInterrupt: print 'Keyboard Interrupt' finally: print '\tFinally...' stop_axes(pmd, axes) time.sleep(1) lock_axes(axes) disable_axes(pmd, axes) time.sleep(0.1) #to handle unreceived CAN messages, cause there is a problem...