Beispiel #1
0
def accel_calibrate():
    '''run full accel calibration'''

    logger.info("Starting accel cal at %s" % time.ctime())

    conn = connection.Connection()
    logger.info("FW version: %s" % conn.fw_version)
    logger.info("PX4 version: %s" % conn.px4_version)
    logger.info("NuttX version: %s" % conn.nuttx_version)
    logger.info("STM32 serial: %s" % conn.stm32_serial)

    # lock the two telemetry ports to prevent the COMMAND_ACK messages in accel cal
    # from looping back between the two telemetry ports
    logger.info("Locking telemetry ports")
    util.lock_serial_port(conn.testmav,
                          mavutil.mavlink.SERIAL_CONTROL_DEV_TELEM1)
    util.lock_serial_port(conn.testmav,
                          mavutil.mavlink.SERIAL_CONTROL_DEV_TELEM2)

    try:
        accel_calibrate_run(conn)
        test_sensors.check_accel_cal(conn)
        test_sensors.check_gyro_cal(conn)
    except Exception as ex:
        conn.close()
        util.show_error('Accel calibration complete???', ex)

    try:
        # we run the sensor checks from here to avoid re-opening the links
        test_sensors.check_all_sensors(conn)
    except Exception as ex:
        conn.close()
        util.show_error('Test sensors failed', ex)

    try:
        logger.info("Loading factory parameters")
        conn.test.send('param load %s\n' % FACTORY_PARM)
        conn.test.expect('Loaded \d+ parameters from')
        logger.info("Parameters loaded OK")
    except Exception as ex:
        conn.close()
        util.show_error('Parameter load failed', ex)

    logger.info("Resetting AHRS_ORIENTATION to 0")
    util.param_set(conn.test, 'AHRS_ORIENTATION', 0)
    time.sleep(1)

    if ETE == 0:
        rotate.center_servos(conn)
    conn.close()
Beispiel #2
0
def accel_calibrate():
    '''run full accel calibration'''

    logger.info("Starting accel cal at %s" % time.ctime())

    conn = connection.Connection()
    logger.info("FW version: %s" % conn.fw_version)
    logger.info("PX4 version: %s" % conn.px4_version)
    logger.info("NuttX version: %s" % conn.nuttx_version)
    logger.info("STM32 serial: %s" % conn.stm32_serial)

    # lock the two telemetry ports to prevent the COMMAND_ACK messages in accel cal
    # from looping back between the two telemetry ports
    logger.info("Locking telemetry ports")
    util.lock_serial_port(conn.testmav, mavutil.mavlink.SERIAL_CONTROL_DEV_TELEM1)
    util.lock_serial_port(conn.testmav, mavutil.mavlink.SERIAL_CONTROL_DEV_TELEM2)

    try:
        accel_calibrate_run(conn)
        test_sensors.check_accel_cal(conn)
        test_sensors.check_gyro_cal(conn)
    except Exception as ex:
        conn.close()
        util.show_error('Accel calibration complete???',  ex)

    try:
        # we run the sensor checks from here to avoid re-opening the links
        test_sensors.check_all_sensors(conn)
    except Exception as ex:
        conn.close()
        util.show_error('Test sensors failed', ex)

    try:
        logger.info("Loading factory parameters")
        conn.test.send('param load %s\n' % FACTORY_PARM)
        conn.test.expect('Loaded \d+ parameters from')
        logger.info("Parameters loaded OK")
    except Exception as ex:
        conn.close()
        util.show_error('Parameter load failed', ex)

    logger.info("Resetting AHRS_ORIENTATION to 0")
    util.param_set(conn.test, 'AHRS_ORIENTATION', 0)
    time.sleep(1)

    if ETE == 0:
            rotate.center_servos(conn)
    conn.close()
Beispiel #3
0
def factory_install(device_barcode):
    '''main factory installer'''
    start_time = time.time()

    script_dir = os.path.dirname(os.path.abspath(__file__))

    ete.command_bytes('test_work')

    if not args.test:
        colour_text.clear_screen()

    # start a new log directory on each run
    logger.new_log_dir()
    logger.reopen_logfile()

    logdir = logger.get_log_dir()
    logger.info("Logging to %s" % logdir)
    #logger.info("Device barcode %s" % device_barcode)

    colour_text.print_blue('''
==================================================
| Starting installation. Barcode is %s
==================================================
''' % device_barcode)

    logger.info(time.ctime())
    
    if args.erase:
        if not jtag.erase_firmwares():
            colour_text.print_fail('''
======================================
| FAILED: JTAG firmware erase failed
======================================
''')
            logger.critical("JTAG firmware erase failed")
            ete.command_bytes('test_fail')
            ete.command_bytes('reset')
            ete.accel(10000)
            ete.yawspeed(5000)
            ete.rollspeed(10000)
            return False
    
    if not args.nofw and not jtag.load_all_firmwares(retries=3):
        colour_text.print_fail('''
======================================
| FAILED: JTAG firmware install failed
======================================
''')
        logger.critical("JTAG firmware install failed")
        ete.command_bytes('test_fail')
        ete.command_bytes('reset')
        ete.accel(100000)
        ete.yawspeed(5000)
        ete.rollspeed(10000)
        try:
            conn = connection.Connection(ref_only=True)
            rotate.center_servos(conn)
        except Exception as ex:
            print("Failed to center servos: %s" % ex)
            pass
        return False

    if args.erase:
        if not connection.erase_parameters():
            colour_text.print_fail('''
==========================================
| FAILED: Failed to erase parameters
==========================================
''')
            logger.critical("Failed to erase parameters")
            ete.command_bytes('test_fail')
            ete.position(0, 0)
            ete.command_bytes('reset')
            ete.accel(100000)
            ete.yawspeed(5000)
            ete.rollspeed(10000)
            return False

    if not accelcal.accel_calibrate_retries(retries=4):
        colour_text.print_fail('''
==========================================
| FAILED: Accelerometer calibration failed
==========================================
''')
        logger.critical("Accelerometer calibration failed")
        ete.command_bytes('test_fail')
        ete.position(0, 0)
        ete.command_bytes('reset')
        ete.accel(100000)
        ete.yawspeed(5000)
        ete.rollspeed(10000)
        return False

    # all OK
    logger.info("Writting OTP region in STM32")
    #Add OTP HERE
    script_dir = os.path.dirname(os.path.abspath(__file__))
    if args.otp_show:
        p1 = Popen(['python', script_dir + '/otp_program.py', '--port', FMU_DEBUG,'--only-display',"abc"], stdin=PIPE, stdout=PIPE, stderr=PIPE)
        output, err = p1.communicate()
        logger.info(output)
    time.sleep(1)
    #conn = connection.Connection(ref_only=False)
    #otp_program_mod.Display_OTP(conn)


    

    def getMacAddress(): 
        if sys.platform == 'win32': 
            for line in os.popen("ipconfig /all"): 
                if line.lstrip().startswith('Physical Address'): 
                    mac = line.split(':')[1].strip().replace('-',':') 
                    break 
        else: 
            for line in os.popen("/sbin/ifconfig"): 
                if line.find('Ether') > -1: 
                    mac = line.split()[4] 
                    break 
        return mac 

    print("Manufacturer info : Hex Technology, \xA9 ProfiCNC 2016")
    print "MAC Address:",getMacAddress() #.join(['{:02x}'.format((uuid.getnode() >> i) & 0xff) for i in range(0,8*6,8)][::-1])

    colour_text.print_blue('''Barcode is %s''' % device_barcode)
    print("date of testing :" + time.strftime("%x"))
    print("time of testing :" + time.strftime("%X"))
    accel_data0 = "%f,%f,%f,%f,%f,%f" % (test_sensors.offset[0][0] ,test_sensors.offset[0][1] ,test_sensors.offset[0][2],test_sensors.scale_factor[0][0],test_sensors.scale_factor[0][1],test_sensors.scale_factor[0][2])
    accel_data2 = "%f,%f,%f,%f,%f,%f" % (test_sensors.offset[2][0] ,test_sensors.offset[2][1] ,test_sensors.offset[2][2],test_sensors.scale_factor[2][0],test_sensors.scale_factor[2][1],test_sensors.scale_factor[2][2])
    print "Accel :", accel_data0
    print "Accel :", accel_data2
    if True:#args.otp_write:
	#Manufacturing Info
        p2 = Popen(['python', script_dir + '/otp_program.py', '--port', FMU_DEBUG,'Hex Technology, \xA9 ProfiCNC 2016',getMacAddress(),device_barcode,time.strftime("%x"),time.strftime("%X"),'--',str(accel_data0),str(accel_data2)], stdin=PIPE, stdout=PIPE, stderr=PIPE)
        output, err = p2.communicate()
        logger.info(output)
	logger.info(err)
	time.sleep(1)
        #Display
        #p3 = Popen(['python', script_dir + '/otp_program.py', '--port', FMU_DEBUG,'--only-display',"abc"], stdin=PIPE, stdout=PIPE, stderr=PIPE)
        #output, err = p3.communicate()
        #logger.info(output)

    colour_text.print_green('''
================================================
| Device: %s
| PASSED: Factory install complete (%u seconds)
================================================
''' %  (device_barcode, (time.time() - start_time)))
    logger.info("Factory install complete (%u seconds)" % (time.time() - start_time))
    ete.command_bytes('test_pass')
    ete.position(0, 0)
    ete.command_bytes('reset')
    ete.accel(100000)
    ete.yawspeed(5000)
    ete.rollspeed(10000)
    return True
Beispiel #4
0
def factory_install(device_barcode):
    '''main factory installer'''
    start_time = time.time()

    if not args.test:
        colour_text.clear_screen()

    # start a new log directory on each run
    logger.new_log_dir()
    logger.reopen_logfile()

    logdir = logger.get_log_dir()
    logger.info("Logging to %s" % logdir)
    logger.info("Device barcode %s" % device_barcode)

    colour_text.print_blue('''
==================================================
| Starting installation. Barcode is %s
==================================================
''' % device_barcode)

    logger.info(time.ctime())
    
    if args.erase:
        if not jtag.erase_firmwares():
            colour_text.print_fail('''
======================================
| FAILED: JTAG firmware erase failed
======================================
''')
            logger.critical("JTAG firmware erase failed")
            return False
    
    if not args.nofw and not jtag.load_all_firmwares(retries=3):
        colour_text.print_fail('''
======================================
| FAILED: JTAG firmware install failed
======================================
''')
        logger.critical("JTAG firmware install failed")
        try:
            conn = connection.Connection(ref_only=True)
            rotate.center_servos(conn)
        except Exception as ex:
            print("Failed to center servos: %s" % ex)
            pass
        return False

    if args.erase:
        if not connection.erase_parameters():
            colour_text.print_fail('''
==========================================
| FAILED: Failed to erase parameters
==========================================
''')
            logger.critical("Failed to erase parameters")
            return False

    if not accelcal.accel_calibrate_retries(retries=4):
        colour_text.print_fail('''
==========================================
| FAILED: Accelerometer calibration failed
==========================================
''')
        logger.critical("Accelerometer calibration failed")
        return False

    # all OK
    colour_text.print_green('''
================================================
| Device: %s
| PASSED: Factory install complete (%u seconds)
================================================
''' %  (device_barcode, (time.time() - start_time)))
    logger.info("Factory install complete (%u seconds)" % (time.time() - start_time))
    return True
Beispiel #5
0
def factory_install(device_barcode):
    '''main factory installer'''
    start_time = time.time()

    script_dir = os.path.dirname(os.path.abspath(__file__))

    ete.command_bytes('test_work')

    if not args.test:
        colour_text.clear_screen()

    # start a new log directory on each run
    logger.new_log_dir()
    logger.reopen_logfile()

    logdir = logger.get_log_dir()
    logger.info("Logging to %s" % logdir)
    #logger.info("Device barcode %s" % device_barcode)

    colour_text.print_blue('''
==================================================
| Starting installation. Barcode is %s
==================================================
''' % device_barcode)

    logger.info(time.ctime())

    if args.erase:
        if not jtag.erase_firmwares():
            colour_text.print_fail('''
======================================
| FAILED: JTAG firmware erase failed
======================================
''')
            logger.critical("JTAG firmware erase failed")
            ete.command_bytes('test_fail')
            ete.command_bytes('reset')
            ete.accel(10000)
            ete.yawspeed(5000)
            ete.rollspeed(10000)
            return False

    if not args.nofw and not jtag.load_all_firmwares(retries=3):
        colour_text.print_fail('''
======================================
| FAILED: JTAG firmware install failed
======================================
''')
        logger.critical("JTAG firmware install failed")
        ete.command_bytes('test_fail')
        ete.command_bytes('reset')
        ete.accel(100000)
        ete.yawspeed(5000)
        ete.rollspeed(10000)
        try:
            conn = connection.Connection(ref_only=True)
            rotate.center_servos(conn)
        except Exception as ex:
            print("Failed to center servos: %s" % ex)
            pass
        return False

    if args.erase:
        if not connection.erase_parameters():
            colour_text.print_fail('''
==========================================
| FAILED: Failed to erase parameters
==========================================
''')
            logger.critical("Failed to erase parameters")
            ete.command_bytes('test_fail')
            ete.position(0, 0)
            ete.command_bytes('reset')
            ete.accel(100000)
            ete.yawspeed(5000)
            ete.rollspeed(10000)
            return False

    if not accelcal.accel_calibrate_retries(retries=4):
        colour_text.print_fail('''
==========================================
| FAILED: Accelerometer calibration failed
==========================================
''')
        logger.critical("Accelerometer calibration failed")
        ete.command_bytes('test_fail')
        ete.position(0, 0)
        ete.command_bytes('reset')
        ete.accel(100000)
        ete.yawspeed(5000)
        ete.rollspeed(10000)
        return False

    # all OK
    logger.info("Writting OTP region in STM32")
    #Add OTP HERE
    script_dir = os.path.dirname(os.path.abspath(__file__))
    if args.otp_show:
        p1 = Popen([
            'python', script_dir + '/otp_program.py', '--port', FMU_DEBUG,
            '--only-display', "abc"
        ],
                   stdin=PIPE,
                   stdout=PIPE,
                   stderr=PIPE)
        output, err = p1.communicate()
        logger.info(output)
    time.sleep(1)

    #conn = connection.Connection(ref_only=False)
    #otp_program_mod.Display_OTP(conn)

    def getMacAddress():
        if sys.platform == 'win32':
            for line in os.popen("ipconfig /all"):
                if line.lstrip().startswith('Physical Address'):
                    mac = line.split(':')[1].strip().replace('-', ':')
                    break
        else:
            for line in os.popen("/sbin/ifconfig"):
                if line.find('Ether') > -1:
                    mac = line.split()[4]
                    break
        return mac

    print("Manufacturer info : Hex Technology, \xA9 ProfiCNC 2016")
    print "MAC Address:", getMacAddress(
    )  #.join(['{:02x}'.format((uuid.getnode() >> i) & 0xff) for i in range(0,8*6,8)][::-1])

    colour_text.print_blue('''Barcode is %s''' % device_barcode)
    print("date of testing :" + time.strftime("%x"))
    print("time of testing :" + time.strftime("%X"))
    accel_data0 = "%f,%f,%f,%f,%f,%f" % (
        test_sensors.offset[0][0], test_sensors.offset[0][1],
        test_sensors.offset[0][2], test_sensors.scale_factor[0][0],
        test_sensors.scale_factor[0][1], test_sensors.scale_factor[0][2])
    accel_data2 = "%f,%f,%f,%f,%f,%f" % (
        test_sensors.offset[2][0], test_sensors.offset[2][1],
        test_sensors.offset[2][2], test_sensors.scale_factor[2][0],
        test_sensors.scale_factor[2][1], test_sensors.scale_factor[2][2])
    print "Accel :", accel_data0
    print "Accel :", accel_data2
    if True:  #args.otp_write:
        #Manufacturing Info
        p2 = Popen([
            'python', script_dir + '/otp_program.py', '--port', FMU_DEBUG,
            'Hex Technology, \xA9 ProfiCNC 2016',
            getMacAddress(), device_barcode,
            time.strftime("%x"),
            time.strftime("%X"), '--',
            str(accel_data0),
            str(accel_data2)
        ],
                   stdin=PIPE,
                   stdout=PIPE,
                   stderr=PIPE)
        output, err = p2.communicate()
        logger.info(output)
        logger.info(err)
        time.sleep(1)
        #Display
        #p3 = Popen(['python', script_dir + '/otp_program.py', '--port', FMU_DEBUG,'--only-display',"abc"], stdin=PIPE, stdout=PIPE, stderr=PIPE)
        #output, err = p3.communicate()
        #logger.info(output)

    colour_text.print_green('''
================================================
| Device: %s
| PASSED: Factory install complete (%u seconds)
================================================
''' % (device_barcode, (time.time() - start_time)))
    logger.info("Factory install complete (%u seconds)" %
                (time.time() - start_time))
    ete.command_bytes('test_pass')
    ete.position(0, 0)
    ete.command_bytes('reset')
    ete.accel(100000)
    ete.yawspeed(5000)
    ete.rollspeed(10000)
    return True