示例#1
0
文件: accelcal.py 项目: uav360/FWLoad
def accel_calibrate_run(conn):
    '''run accelcal'''
    logger.info("STARTING ACCEL CALIBRATION")
    wait_gyros(conn)
    time.sleep(2)
    if ETE == 0:
        logger.debug("re-running gyro cal")
        conn.discard_messages()
        conn.ref.send('gyrocal\n')
        conn.test.send('gyrocal\n')
        conn.ref.expect('Calibrated')
        conn.test.expect('Calibrated')
        wait_gyros(conn)
        rotate.set_rotation(conn, 'level', wait=False)

    logger.info("Turning safety off")
    util.safety_off(conn.refmav)
    logger.info("Turning on testjig mode")
    conn.test.send("factory_test start\n")

    # use zero trims on reference board
    util.param_set(conn.ref, 'AHRS_TRIM_X', 0)
    util.param_set(conn.ref, 'AHRS_TRIM_Y', 0)

    level_attitude = None
    conn.test.send("accelcal\n")
    for rotation in ['level', 'left', 'right', 'up', 'down', 'back']:
        try:
            conn.test.expect("Place vehicle")
            conn.test.expect("and press any key")
        except Exception as ex:
            util.show_tail(conn.testlog)
            util.failure("Failed to get place vehicle message for %s" %
                         rotation)
        attitude = rotate.set_rotation(conn, rotation)
        if rotation == 'level':
            level_attitude = attitude
        conn.test.send("\n")
    i = conn.test.expect(["Calibration successful", "Calibration FAILED"])
    if i != 0:
        logger.error(conn.test.before)
        logger.error("Calibration FAILED")
        util.show_tail(conn.testlog)
        util.failure("Accel calibration failed")
    #logger.info(conn.test.before)
    logger.info("Calibration successful")

    rotate.write_calibration()

    if ETE == 0:
        rotate.set_rotation(conn, 'level', wait=False)

    # get AHRS_TRIM_{X,Y} right
    adjust_ahrs_trim(conn, level_attitude)

    # rotate while integrating gyros to test all gyros are working
    rotate.gyro_integrate(conn)

    # finish in level position
    rotate.set_rotation(conn, 'level')
示例#2
0
def accel_calibrate_reference():
    """run accelcal on reference board"""
    logger.info("STARTING REFERENCE ACCEL CALIBRATION")

    conn = connection.Connection(ref_only=True)

    logger.info("Turning safety off")
    rotate.set_rotation(conn, "level", wait=False)
    util.safety_off(conn.refmav)

    conn.ref.send("accelcal\n")
    for rotation in ["level", "left", "right", "up", "down", "back"]:
        try:
            conn.ref.expect("Place vehicle")
            conn.ref.expect("and press any key")
        except Exception as ex:
            util.failure("Failed to get place vehicle message for %s" % rotation)
        logger.debug("Rotating %s" % rotation)
        attitude = rotate.set_rotation(conn, rotation, wait=False)
        time.sleep(13)
        conn.ref.send("\n")
    i = conn.ref.expect(["Calibration successful", "Calibration FAILED"])
    if i != 0:
        util.failure("Accel calibration failed at %s" % time.ctime())
    logger.info("Calibration successful")
    rotate.set_rotation(conn, "level", wait=False)
    util.param_set(conn.ref, "AHRS_TRIM_X", 0)
    util.param_set(conn.ref, "AHRS_TRIM_Y", 0)
    util.discard_messages(conn.refmav)
    util.wait_heartbeat(conn.refmav)
示例#3
0
文件: accelcal.py 项目: uav360/FWLoad
def accel_calibrate_reference():
    '''run accelcal on reference board'''
    logger.info("STARTING REFERENCE ACCEL CALIBRATION")

    conn = connection.Connection(ref_only=True)

    logger.info("Turning safety off")
    rotate.set_rotation(conn, 'level', wait=False)
    util.safety_off(conn.refmav)

    conn.ref.send("accelcal\n")
    for rotation in ['level', 'left', 'right', 'up', 'down', 'back']:
        try:
            conn.ref.expect("Place vehicle")
            conn.ref.expect("and press any key")
        except Exception as ex:
            util.failure("Failed to get place vehicle message for %s" %
                         rotation)
        logger.debug("Rotating %s" % rotation)
        attitude = rotate.set_rotation(conn, rotation, wait=False)
        time.sleep(13)
        conn.ref.send("\n")
    i = conn.ref.expect(["Calibration successful", "Calibration FAILED"])
    if i != 0:
        util.failure("Accel calibration failed at %s" % time.ctime())
    logger.info("Calibration successful")
    rotate.set_rotation(conn, 'level', wait=False)
    util.param_set(conn.ref, 'AHRS_TRIM_X', 0)
    util.param_set(conn.ref, 'AHRS_TRIM_Y', 0)
    util.discard_messages(conn.refmav)
    util.wait_heartbeat(conn.refmav)
示例#4
0
文件: rotate.py 项目: normylin/FWLoad
def unjam_servos(conn):
    '''try to unjam servos with random movement'''
    logger.info("Starting unjamming")
    conn.discard_messages()

    rotations = ROTATIONS.keys()

    util.param_set(conn.ref, 'SR0_RAW_SENS', 10)

    last_change = time.time()
    while True:
        imu = conn.refmav.recv_match(type='RAW_IMU', blocking=False)
        if imu is not None:
            gyro = util.gyro_vector(imu)
            logger.info('Gyro: %s' % gyro)
            if abs(gyro.x) > 5 or abs(gyro.y) > 5:
                logger.info("Unjammed: ", gyro)
                break
        if time.time() > last_change+0.7:
            last_change = time.time()
            r1 = int(random.uniform(800, 2100))
            r2 = int(random.uniform(800, 2100))
            logger.debug("%s %s" % (r1, r2))
            util.set_servo(conn.refmav, YAW_CHANNEL, r1)
            util.set_servo(conn.refmav, PITCH_CHANNEL, r2)
示例#5
0
文件: rotate.py 项目: tridge/FWLoad
def unjam_servos(conn):
    '''try to unjam servos with random movement'''
    logger.info("Starting unjamming")
    conn.discard_messages()

    rotations = ROTATIONS.keys()

    util.param_set(conn.ref, 'SR0_RAW_SENS', 10)

    last_change = time.time()
    while True:
        imu = conn.refmav.recv_match(type='RAW_IMU', blocking=False)
        if imu is not None:
            gyro = util.gyro_vector(imu)
            logger.info('Gyro: %s' % gyro)
            if abs(gyro.x) > 5 or abs(gyro.y) > 5:
                logger.info("Unjammed: ", gyro)
                break
        if time.time() > last_change+0.7:
            last_change = time.time()
            r1 = int(random.uniform(800, 2100))
            r2 = int(random.uniform(800, 2100))
            logger.debug("%s %s" % (r1, r2))
            util.set_servo(conn.refmav, YAW_CHANNEL, r1)
            util.set_servo(conn.refmav, PITCH_CHANNEL, r2)
示例#6
0
def accel_calibrate_run(conn):
    '''run accelcal'''
    logger.info("STARTING ACCEL CALIBRATION")
    wait_gyros(conn)
    time.sleep(2)
    if ETE == 0:
        logger.debug("re-running gyro cal")
        conn.discard_messages()
        conn.ref.send('gyrocal\n')
        conn.test.send('gyrocal\n')
        conn.ref.expect('Calibrated')
        conn.test.expect('Calibrated')
        wait_gyros(conn)
        rotate.set_rotation(conn, 'level', wait=False)

    logger.info("Turning safety off")
    util.safety_off(conn.refmav)
    logger.info("Turning on testjig mode")
    conn.test.send("factory_test start\n")

    # use zero trims on reference board
    util.param_set(conn.ref, 'AHRS_TRIM_X', 0)
    util.param_set(conn.ref, 'AHRS_TRIM_Y', 0)

    level_attitude = None
    conn.test.send("accelcal\n")
    for rotation in ['level', 'left', 'right', 'up', 'down', 'back']:
        try:
            conn.test.expect("Place vehicle")
            conn.test.expect("and press any key")
        except Exception as ex:
            util.show_tail(conn.testlog)
            util.failure("Failed to get place vehicle message for %s" % rotation)
        attitude = rotate.set_rotation(conn, rotation)
        if rotation == 'level':
            level_attitude = attitude
        conn.test.send("\n")
    i = conn.test.expect(["Calibration successful","Calibration FAILED"])
    if i != 0:
        logger.error(conn.test.before)
        logger.error("Calibration FAILED")
        util.show_tail(conn.testlog)
        util.failure("Accel calibration failed")
    #logger.info(conn.test.before)
    logger.info("Calibration successful")
    
    rotate.write_calibration()

    if ETE == 0:
        rotate.set_rotation(conn, 'level', wait=False)

    # get AHRS_TRIM_{X,Y} right
    adjust_ahrs_trim(conn, level_attitude)

    # rotate while integrating gyros to test all gyros are working
    rotate.gyro_integrate(conn)

    # finish in level position
    rotate.set_rotation(conn, 'level')
示例#7
0
def accel_calibrate_run(conn):
    """run accelcal"""
    logger.info("STARTING ACCEL CALIBRATION")

    wait_gyros(conn)
    time.sleep(2)

    logger.debug("re-running gyro cal")
    conn.discard_messages()
    conn.ref.send("gyrocal\n")
    conn.test.send("gyrocal\n")
    conn.ref.expect("Calibrated")
    conn.test.expect("Calibrated")
    wait_gyros(conn)

    logger.info("Turning safety off")
    rotate.set_rotation(conn, "level", wait=False)
    util.safety_off(conn.refmav)

    # use zero trims on reference board
    util.param_set(conn.ref, "AHRS_TRIM_X", 0)
    util.param_set(conn.ref, "AHRS_TRIM_Y", 0)

    level_attitude = None
    conn.test.send("accelcal\n")
    for rotation in ["level", "left", "right", "up", "down", "back"]:
        try:
            conn.test.expect("Place vehicle")
            conn.test.expect("and press any key")
        except Exception as ex:
            util.show_tail(conn.testlog)
            util.failure("Failed to get place vehicle message for %s" % rotation)
        attitude = rotate.set_rotation(conn, rotation)
        if rotation == "level":
            level_attitude = attitude
        conn.test.send("\n")
    i = conn.test.expect(["Calibration successful", "Calibration FAILED"])
    if i != 0:
        logger.error(conn.test.before)
        logger.error("Calibration FAILED")
        util.show_tail(conn.testlog)
        util.failure("Accel calibration failed")
    # logger.info(conn.test.before)
    logger.info("Calibration successful")
    rotate.write_calibration()
    rotate.set_rotation(conn, "level", wait=False)

    # rotate while integrating gyros to test all gyros are working
    rotate.gyro_integrate(conn)

    # get AHRS_TRIM_{X,Y} right
    adjust_ahrs_trim(conn, level_attitude)

    # finish in level position
    rotate.set_rotation(conn, "level", quick=True)
示例#8
0
文件: rotate.py 项目: normylin/FWLoad
def gyro_integrate(conn):
    '''test gyros by integrating while rotating to the given rotations'''
    conn.ref.send('set streamrate -1\n')
    conn.test.send('set streamrate -1\n')
    util.param_set(conn.ref, 'SR0_RAW_SENS', 20)
    util.param_set(conn.test, 'SR0_RAW_SENS', 20)

    logger.info("Starting gyro integration at %s" % time.ctime())
    wait_quiescent(conn.refmav)
    conn.discard_messages()

    util.set_servo(conn.refmav, YAW_CHANNEL, ROTATIONS['level'].chan1+200)
    util.set_servo(conn.refmav, PITCH_CHANNEL, ROTATIONS['level'].chan2+200)

    start_time = time.time()
    ref_tstart = None
    test_tstart = [None]*3
    ref_sum = Vector3()
    test_sum = [Vector3(), Vector3(), Vector3()]
    msgs = { 'RAW_IMU' : 0, 'SCALED_IMU2' : 1, 'SCALED_IMU3' : 2 }
    while time.time() < start_time+20:
        imu = conn.refmav.recv_match(type='RAW_IMU', blocking=False)
        if imu is not None:
            gyro = util.gyro_vector(imu)
            tnow = imu.time_usec*1.0e-6
            if ref_tstart is not None:
                deltat = tnow - ref_tstart
                ref_sum += gyro * deltat
            ref_tstart = tnow
            if time.time() - start_time > 2 and gyro.length() < GYRO_TOLERANCE:
                break
        imu = conn.testmav.recv_match(type=msgs.keys(), blocking=False)
        if imu is not None:
            idx = msgs[imu.get_type()]
            gyro = util.gyro_vector(imu)
            if imu.get_type().startswith("SCALED_IMU"):
                tnow = imu.time_boot_ms*1.0e-3
            else:
                tnow = imu.time_usec*1.0e-6
            if test_tstart[idx] is not None:
                deltat = tnow - test_tstart[idx]
                test_sum[idx] += gyro * deltat
            test_tstart[idx] = tnow
    logger.debug("Gyro ref  sums: %s" % ref_sum)
    logger.debug("Gyro test sum1: %s" % test_sum[0])
    logger.debug("Gyro test sum2: %s" % test_sum[1])
    logger.debug("Gyro test sum3: %s" % test_sum[2])
    for idx in range(3):
        err = test_sum[idx] - ref_sum
        if abs(err.x) > GYRO_SUM_TOLERANCE:
            util.failure("X gyro %u error: %.1f" % (idx, err.x))
        if abs(err.y) > GYRO_SUM_TOLERANCE:
            util.failure("Y gyro %u error: %.1f" % (idx, err.y))
        if abs(err.z) > GYRO_SUM_TOLERANCE:
            util.failure("Z gyro %u error: %.1f" % (idx, err.z))
示例#9
0
文件: rotate.py 项目: tridge/FWLoad
def gyro_integrate(conn):
    '''test gyros by integrating while rotating to the given rotations'''
    conn.ref.send('set streamrate -1\n')
    conn.test.send('set streamrate -1\n')
    util.param_set(conn.ref, 'SR0_RAW_SENS', 20)
    util.param_set(conn.test, 'SR0_RAW_SENS', 20)

    logger.info("Starting gyro integration")
    wait_quiescent(conn.refmav)
    conn.discard_messages()

    util.set_servo(conn.refmav, YAW_CHANNEL, ROTATIONS['level'].chan1+200)
    util.set_servo(conn.refmav, PITCH_CHANNEL, ROTATIONS['level'].chan2+200)

    start_time = time.time()
    ref_tstart = None
    test_tstart = [None]*3
    ref_sum = Vector3()
    test_sum = [Vector3(), Vector3(), Vector3()]
    msgs = { 'RAW_IMU' : 0, 'SCALED_IMU2' : 1, 'SCALED_IMU3' : 2 }
    while time.time() < start_time+20:
        imu = conn.refmav.recv_match(type='RAW_IMU', blocking=False)
        if imu is not None:
            gyro = util.gyro_vector(imu)
            tnow = imu.time_usec*1.0e-6
            if ref_tstart is not None:
                deltat = tnow - ref_tstart
                ref_sum += gyro * deltat
            ref_tstart = tnow
            if time.time() - start_time > 2 and gyro.length() < GYRO_TOLERANCE:
                break
        imu = conn.testmav.recv_match(type=msgs.keys(), blocking=False)
        if imu is not None:
            idx = msgs[imu.get_type()]
            gyro = util.gyro_vector(imu)
            if imu.get_type().startswith("SCALED_IMU"):
                tnow = imu.time_boot_ms*1.0e-3
            else:
                tnow = imu.time_usec*1.0e-6
            if test_tstart[idx] is not None:
                deltat = tnow - test_tstart[idx]
                test_sum[idx] += gyro * deltat
            test_tstart[idx] = tnow
    logger.debug("Gyro ref  sums: %s" % ref_sum)
    logger.debug("Gyro test sum1: %s" % test_sum[0])
    logger.debug("Gyro test sum2: %s" % test_sum[1])
    logger.debug("Gyro test sum3: %s" % test_sum[2])
    for idx in range(3):
        err = test_sum[idx] - ref_sum
        if abs(err.x) > GYRO_SUM_TOLERANCE:
            util.failure("X gyro %u error: %.1f" % (idx, err.x))
        if abs(err.y) > GYRO_SUM_TOLERANCE:
            util.failure("Y gyro %u error: %.1f" % (idx, err.y))
        if abs(err.z) > GYRO_SUM_TOLERANCE:
            util.failure("Z gyro %u error: %.1f" % (idx, err.z))
示例#10
0
文件: accelcal.py 项目: uav360/FWLoad
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()
示例#11
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()
示例#12
0
def accel_calibrate_run(conn):
    '''run accelcal'''
    logger.info("STARTING ACCEL CALIBRATION")

    wait_gyros(conn)

    logger.debug("running ref gyro cal")
    conn.ref.send('gyrocal\n')
    conn.ref.expect('Calibrated')
    wait_gyros(conn)

    logger.info("Turning safety off")
    rotate.set_rotation(conn, 'level', wait=False)
    util.safety_off(conn.refmav)

    # use zero trims on reference board
    util.param_set(conn.ref, 'AHRS_TRIM_X', 0)
    util.param_set(conn.ref, 'AHRS_TRIM_Y', 0)

    level_attitude = None
    conn.test.send("accelcal\n")
    for rotation in ['level', 'left', 'right', 'up', 'down', 'back']:
        try:
            conn.test.expect("Place vehicle")
            conn.test.expect("and press any key")
        except Exception as ex:
            util.show_tail(conn.testlog)
            util.failure("Failed to get place vehicle message for %s" % rotation)
        attitude = rotate.set_rotation(conn, rotation)
        if rotation == 'level':
            level_attitude = attitude
        conn.test.send("\n")
    i = conn.test.expect(["Calibration successful","Calibration FAILED"])
    if i != 0:
        logger.error(conn.test.before)
        logger.error("Calibration FAILED")
        util.show_tail(conn.testlog)
        util.failure("Accel calibration failed at %s" % time.ctime())
    #logger.info(conn.test.before)
    logger.info("Calibration successful")
    rotate.write_calibration()
    rotate.set_rotation(conn, 'level', wait=False)
    adjust_ahrs_trim(conn, level_attitude)
示例#13
0
def wait_gyros_healthy(conn):
    '''wait for gyros to be healthy'''
    util.wait_heartbeat(conn.testmav)

    # we must have AHRS_ORIENTATION 0 for the accelcal
    # we will fix for AHRS_ORIENTATION=12 later
    util.param_set(conn.test, 'AHRS_ORIENTATION', 0)
    util.param_set(conn.ref, 'AHRS_ORIENTATION', 0)

    # setup right reference board parameters, in case someone has reset them
    util.param_set(conn.ref, 'THR_FAILSAFE', 0)
    util.param_set(conn.ref, 'RCMAP_ROLL', 5)
    util.param_set(conn.ref, 'RCMAP_PITCH', 6)

    # give time for 1Hz loop to set orientation
    time.sleep(2)

    logger.info("Waiting for gyro health")
    start_time = time.time()
    ref_gyros_healthy = False
    test_gyros_healthy = False
    conn.discard_messages()
    while time.time() < start_time + 20 and (not ref_gyros_healthy or not test_gyros_healthy):
        ref_sys_status = conn.refmav.recv_match(type='SYS_STATUS', blocking=True, timeout=1)
        if ref_sys_status:
            ref_gyros_healthy = (ref_sys_status.onboard_control_sensors_health & mavutil.mavlink.MAV_SYS_STATUS_SENSOR_3D_GYRO) != 0
        test_sys_status = conn.testmav.recv_match(type='SYS_STATUS', blocking=True, timeout=1)
        if test_sys_status:
            test_gyros_healthy = (test_sys_status.onboard_control_sensors_health & mavutil.mavlink.MAV_SYS_STATUS_SENSOR_3D_GYRO) != 0
    if not ref_gyros_healthy:
        logger.error("Failed to get healthy reference gyros")
        return False
    if not test_gyros_healthy:
        logger.error("Failed to get healthy test gyros")
        return False
    logger.info("Gyros are healthy")
    return True
示例#14
0
def gyro_integrate(conn):
    '''test gyros by integrating while rotating to the given rotations'''
    conn.ref.send('set streamrate -1\n')
    conn.test.send('set streamrate -1\n')
    util.param_set(conn.ref, 'SR0_RAW_SENS', 20)
    util.param_set(conn.test, 'SR0_RAW_SENS', 20)

    logger.info("Starting gyro integration")
    wait_quiescent(conn.refmav)
    conn.discard_messages()
    if ETE == 0:
        util.set_servo(conn.refmav, YAW_CHANNEL, ROTATIONS['level'].chan1+200)
        util.set_servo(conn.refmav, PITCH_CHANNEL, ROTATIONS['level'].chan2+200)
    if ETE == 1:
        ete = PixETE()
        ete.position(45, 180)
        time.sleep(1)
        ete.rollspeed(4000)
        ete.position(45, 0)
    logger.info("Starting gyro motion")    
    start_time = time.time()
    ref_tstart = None
    test_tstart = [None]*3
    ref_sum = Vector3()
    test_sum = [Vector3(), Vector3(), Vector3()]
    msgs = { 'RAW_IMU' : 0, 'SCALED_IMU2' : 1, 'SCALED_IMU3' : 2 }
    while time.time() < start_time+20:
        imu = conn.refmav.recv_match(type='RAW_IMU', blocking=False)
        if imu is not None:
            #gyro = util.gyro_vector(imu)
            gyro = Vector3(degrees(imu.xgyro*-0.001), degrees(imu.ygyro*0.001), degrees(imu.zgyro*-0.001))  #phil change.... when running this check from back to top, I found that the reference IMU X and Z were reversed.... this hack makes this pass, but I suspect something else is wrong, this should be reverted when that is found.
            tnow = imu.time_usec*1.0e-6
            if ref_tstart is not None:
                deltat = tnow - ref_tstart
                ref_sum += gyro * deltat
            ref_tstart = tnow
            if time.time() - start_time > 2 and gyro.length() < GYRO_TOLERANCE:
                break
        imu = conn.testmav.recv_match(type=msgs.keys(), blocking=False)
        if imu is not None:
            idx = msgs[imu.get_type()]
            gyro = util.gyro_vector(imu)
            if imu.get_type().startswith("SCALED_IMU"):
                tnow = imu.time_boot_ms*1.0e-3
            else:
                tnow = imu.time_usec*1.0e-6
            if test_tstart[idx] is not None:
                deltat = tnow - test_tstart[idx]
                test_sum[idx] += gyro * deltat
            test_tstart[idx] = tnow
    logger.debug("Gyro ref  sums: %s" % ref_sum)
    logger.debug("Gyro test sum1: %s" % test_sum[0])
    logger.debug("Gyro test sum2: %s" % test_sum[1])
    logger.debug("Gyro test sum3: %s" % test_sum[2])
    ete.yawspeed(5000)
    ete.rollspeed(5000)
    ete.position(0, 0)
    wait_quiescent(conn.refmav)
    for idx in range(3):
        err = test_sum[idx] - ref_sum
        if abs(err.x) > GYRO_SUM_TOLERANCE:
            util.failure("X gyro %u error: %.1f" % (idx, err.x))
        if abs(err.y) > GYRO_SUM_TOLERANCE:
            util.failure("Y gyro %u error: %.1f" % (idx, err.y))
        if abs(err.z) > GYRO_SUM_TOLERANCE:
            util.failure("Z gyro %u error: %.1f" % (idx, err.z))
    logger.debug("Gyro test finished")
示例#15
0
def adjust_ahrs_trim(conn, level_attitude):
    """
    force the AHRS trim to zero, which removes the effect of the jig not being quite
    level. This is only incorrect if the accels are not aligned on the board, which
    we check in check_accel_cal later

    As a side effect this function set AHRS_ORIENTATION for the test board to 12
    """

    # start with board right way up
    rotate.set_rotation(conn, "level")

    # we need to work out what the error in attitude of the 3 IMUs on the test jig is
    # to do that we start with it level, and measure the roll/pitch as compared to the reference
    conn.discard_messages()
    ref_imu = conn.refmav.recv_match(type="RAW_IMU", blocking=True, timeout=3)
    test_imu1 = conn.testmav.recv_match(type="RAW_IMU", blocking=True, timeout=3)
    test_imu2 = conn.testmav.recv_match(type="SCALED_IMU2", blocking=True, timeout=3)
    test_imu3 = conn.testmav.recv_match(type="SCALED_IMU3", blocking=True, timeout=3)
    if ref_imu is None:
        util.failure("Lost comms to reference board in ahrs trim")
    if test_imu1 is None or test_imu2 is None or test_imu3 is None:
        util.failure("Lost comms to test board in ahrs trim")

    (ref_roll, ref_pitch) = util.attitude_estimate(ref_imu)
    (test_roll1, test_pitch1) = util.attitude_estimate(test_imu1)
    (test_roll2, test_pitch2) = util.attitude_estimate(test_imu2)
    (test_roll3, test_pitch3) = util.attitude_estimate(test_imu3)

    # get the roll and pitch errors
    roll_error1 = test_roll1 - ref_roll
    roll_error2 = test_roll2 - ref_roll
    roll_error3 = test_roll3 - ref_roll
    pitch_error1 = test_pitch1 - ref_pitch
    pitch_error2 = test_pitch2 - ref_pitch
    pitch_error3 = test_pitch3 - ref_pitch

    conn.discard_messages()
    ref_imu = conn.refmav.recv_match(type="RAW_IMU", blocking=True, timeout=3)
    test_imu1 = conn.testmav.recv_match(type="RAW_IMU", blocking=True, timeout=3)
    test_imu2 = conn.testmav.recv_match(type="SCALED_IMU2", blocking=True, timeout=3)
    test_imu3 = conn.testmav.recv_match(type="SCALED_IMU3", blocking=True, timeout=3)
    if ref_imu is None:
        util.failure("Lost comms to reference board in ahrs trim")
    if test_imu1 is None or test_imu2 is None or test_imu3 is None:
        util.failure("Lost comms to test board in ahrs trim")

    logger.debug(
        "Tilt Ref=(%.1f %.1f) Test1=(%.1f %.1f) Test2=(%.1f %.1f) Test3=(%.1f %.1f)"
        % (ref_roll, ref_pitch, test_roll1, test_pitch1, test_roll2, test_pitch2, test_roll3, test_pitch3)
    )

    if abs(ref_roll) > ROTATION_TOLERANCE or abs(ref_pitch) > ROTATION_TOLERANCE:
        util.failure("Reference board rotation error")

    logger.debug(
        "Tilt offsets: Roll(%.1f %.1f %.1f) Pitch(%.1f %.1f %.1f) "
        % (roll_error1, roll_error2, roll_error3, pitch_error1, pitch_error2, pitch_error3)
    )

    if abs(roll_error1) > TILT_TOLERANCE1 or abs(roll_error2) > TILT_TOLERANCE1 or abs(roll_error3) > TILT_TOLERANCE3:
        util.failure("Test board roll error")

    if (
        abs(pitch_error1) > TILT_TOLERANCE1
        or abs(pitch_error2) > TILT_TOLERANCE1
        or abs(pitch_error3) > TILT_TOLERANCE3
    ):
        util.failure("Test board pitch error")

    # flip upside down for the trim calculation
    rotate.set_rotation(conn, "back")

    # set orientation upside down for trim measurement
    util.param_set(conn.test, "AHRS_ORIENTATION", 12)

    # sleep an extra four seconds - we need to be very sure the board is still for trim
    time.sleep(4)
    conn.discard_messages()

    # average over 30 samples for trim
    num_samples = 30
    test_roll = [0] * 3
    test_pitch = [0] * 3
    msgs = ["RAW_IMU", "SCALED_IMU2", "SCALED_IMU3"]

    for i in range(num_samples):
        for j in range(3):
            test_imu = conn.testmav.recv_match(type=msgs[j], blocking=True, timeout=3)
            if test_imu is None:
                util.failure("Lost comms to test board in ahrs trim")
            (roll, pitch) = util.attitude_estimate(test_imu)
            test_roll[j] += roll
            test_pitch[j] += pitch

    for j in range(3):
        test_roll[j] /= num_samples
        test_pitch[j] /= num_samples

    logger.debug(
        "Average Trim tilt Test1=(%.1f %.1f) Test2=(%.1f %.1f) Test3=(%.1f %.1f)"
        % (test_roll[0], test_pitch[0], test_roll[1], test_pitch[1], test_roll[2], test_pitch[2])
    )

    # setting a positive trim value reduces the attitude that is
    # read. So setting a trim of 0.1 when level results in a attitude
    # reading of -5.8 degrees

    # this approach assumes the mpu6000 on the FMU (IMU3) is level
    # with respect to the board, and that any attitude error is due to
    # the isolation board mount. We use the average of the error from
    # IMU1 and IMU2
    trim_x = radians((test_roll[0] + test_roll[1]) * 0.5 - test_roll[2])
    trim_y = radians((test_pitch[0] + test_pitch[1]) * 0.5 - test_pitch[2])

    util.param_set(conn.test, "AHRS_TRIM_X", trim_x)
    time.sleep(0.2)
    util.param_set(conn.test, "AHRS_TRIM_Y", trim_y)
    time.sleep(0.2)
    logger.debug("Set trims AHRS_TRIM_X=%.4f AHRS_TRIM_Y=%.4f" % (trim_x, trim_y))
示例#16
0
文件: accelcal.py 项目: uav360/FWLoad
def adjust_ahrs_trim(conn, level_attitude):
    '''
    force the AHRS trim to zero, which removes the effect of the jig not being quite
    level. This is only incorrect if the accels are not aligned on the board, which
    we check in check_accel_cal later

    As a side effect this function set AHRS_ORIENTATION for the test board to 12
    '''

    # start with board right way up
    if ETE == 0:
        rotate.set_rotation(conn, 'level')

    # we need to work out what the error in attitude of the 3 IMUs on the test jig is
    # to do that we start with it level, and measure the roll/pitch as compared to the reference
    conn.discard_messages()
    ref_imu = conn.refmav.recv_match(type='RAW_IMU', blocking=True, timeout=3)
    test_imu1 = conn.testmav.recv_match(type='RAW_IMU',
                                        blocking=True,
                                        timeout=3)
    test_imu2 = conn.testmav.recv_match(type='SCALED_IMU2',
                                        blocking=True,
                                        timeout=3)
    test_imu3 = conn.testmav.recv_match(type='SCALED_IMU3',
                                        blocking=True,
                                        timeout=3)
    if ref_imu is None:
        util.failure("Lost comms to reference board in ahrs trim")
    if test_imu1 is None or test_imu2 is None or test_imu3 is None:
        util.failure("Lost comms to test board in ahrs trim")

    (ref_roll, ref_pitch) = util.attitude_estimate(ref_imu)
    (test_roll1, test_pitch1) = util.attitude_estimate(test_imu1)
    (test_roll2, test_pitch2) = util.attitude_estimate(test_imu2)
    (test_roll3, test_pitch3) = util.attitude_estimate(test_imu3)

    # get the roll and pitch errors
    roll_error1 = (test_roll1 - ref_roll)
    roll_error2 = (test_roll2 - ref_roll)
    roll_error3 = (test_roll3 - ref_roll)
    pitch_error1 = (test_pitch1 - ref_pitch)
    pitch_error2 = (test_pitch2 - ref_pitch)
    pitch_error3 = (test_pitch3 - ref_pitch)

    conn.discard_messages()
    ref_imu = conn.refmav.recv_match(type='RAW_IMU', blocking=True, timeout=3)
    test_imu1 = conn.testmav.recv_match(type='RAW_IMU',
                                        blocking=True,
                                        timeout=3)
    test_imu2 = conn.testmav.recv_match(type='SCALED_IMU2',
                                        blocking=True,
                                        timeout=3)
    test_imu3 = conn.testmav.recv_match(type='SCALED_IMU3',
                                        blocking=True,
                                        timeout=3)
    if ref_imu is None:
        util.failure("Lost comms to reference board in ahrs trim")
    if test_imu1 is None or test_imu2 is None or test_imu3 is None:
        util.failure("Lost comms to test board in ahrs trim")

    logger.debug(
        "Tilt Ref=(%.1f %.1f) Test1=(%.1f %.1f) Test2=(%.1f %.1f) Test3=(%.1f %.1f)"
        % (ref_roll, ref_pitch, test_roll1, test_pitch1, test_roll2,
           test_pitch2, test_roll3, test_pitch3))

    if (abs(ref_roll) > ROTATION_TOLERANCE
            or abs(ref_pitch) > ROTATION_TOLERANCE):
        util.failure("Reference board rotation error")

    logger.debug("Tilt offsets: Roll(%.1f %.1f %.1f) Pitch(%.1f %.1f %.1f) " %
                 (roll_error1, roll_error2, roll_error3, pitch_error1,
                  pitch_error2, pitch_error3))

    if (abs(roll_error1) > TILT_TOLERANCE1
            or abs(roll_error2) > TILT_TOLERANCE1
            or abs(roll_error3) > TILT_TOLERANCE3):
        util.failure("Test board roll error")

    if (abs(pitch_error1) > TILT_TOLERANCE1
            or abs(pitch_error2) > TILT_TOLERANCE1
            or abs(pitch_error3) > TILT_TOLERANCE3):
        util.failure("Test board pitch error")

    # flip upside down for the trim calculation
    if ETE == 0:
        rotate.set_rotation(conn, 'back')

    # set orientation upside down for trim measurement
    util.param_set(conn.test, 'AHRS_ORIENTATION', 12)
    util.param_set(conn.ref, 'AHRS_ORIENTATION', 12)

    # sleep an extra four seconds - we need to be very sure the board is still for trim
    time.sleep(4)
    conn.discard_messages()

    # average over 30 samples for trim
    num_samples = 30
    test_roll = [0] * 3
    test_pitch = [0] * 3
    msgs = ['RAW_IMU', 'SCALED_IMU2', 'SCALED_IMU3']

    for i in range(num_samples):
        for j in range(3):
            test_imu = conn.testmav.recv_match(type=msgs[j],
                                               blocking=True,
                                               timeout=3)
            if test_imu is None:
                util.failure("Lost comms to test board in ahrs trim")
            (roll, pitch) = util.attitude_estimate(test_imu)
            test_roll[j] += roll
            test_pitch[j] += pitch

    for j in range(3):
        test_roll[j] /= num_samples
        test_pitch[j] /= num_samples

    logger.debug(
        "Average Trim tilt Test1=(%.1f %.1f) Test2=(%.1f %.1f) Test3=(%.1f %.1f)"
        % (test_roll[0], test_pitch[0], test_roll[1], test_pitch[1],
           test_roll[2], test_pitch[2]))

    # setting a positive trim value reduces the attitude that is
    # read. So setting a trim of 0.1 when level results in a attitude
    # reading of -5.8 degrees

    # this approach assumes the mpu6000 on the FMU (IMU3) is level
    # with respect to the board, and that any attitude error is due to
    # the isolation board mount. We use the average of the error from
    # IMU1 and IMU2
    trim_x = radians((test_roll[0] + test_roll[1]) * 0.5 - test_roll[2])
    trim_y = radians((test_pitch[0] + test_pitch[1]) * 0.5 - test_pitch[2])

    util.param_set(conn.test, 'AHRS_TRIM_X', trim_x)
    time.sleep(0.2)
    util.param_set(conn.test, 'AHRS_TRIM_Y', trim_y)
    time.sleep(0.2)
    logger.debug("Set trims AHRS_TRIM_X=%.4f AHRS_TRIM_Y=%.4f" %
                 (trim_x, trim_y))
    util.param_set(conn.ref, 'AHRS_ORIENTATION', 0)
示例#17
0
文件: accelcal.py 项目: uav360/FWLoad
def wait_gyros_healthy(conn):
    '''wait for gyros to be healthy'''
    util.wait_heartbeat(conn.testmav)

    # we must have AHRS_ORIENTATION 0 for the accelcal
    # we will fix for AHRS_ORIENTATION=12 later
    util.param_set(conn.test, 'AHRS_ORIENTATION', 0)
    util.param_set(conn.ref, 'AHRS_ORIENTATION', 0)

    # disable mag to prevent it causing affects on the gyro drift
    util.param_set(conn.ref, 'MAG_ENABLE', 0)

    # setup right reference board parameters, in case someone has reset them
    util.param_set(conn.ref, 'THR_FAILSAFE', 0)
    util.param_set(conn.ref, 'RCMAP_ROLL', 5)
    util.param_set(conn.ref, 'RCMAP_PITCH', 6)

    # give time for 1Hz loop to set orientation
    time.sleep(2)

    logger.info("Waiting for gyro health")
    start_time = time.time()
    ref_gyros_healthy = False
    test_gyros_healthy = False
    conn.discard_messages()
    while time.time() < start_time + 20 and (not ref_gyros_healthy
                                             or not test_gyros_healthy):
        ref_sys_status = conn.refmav.recv_match(type='SYS_STATUS',
                                                blocking=True,
                                                timeout=1)
        if ref_sys_status:
            ref_gyros_healthy = (
                ref_sys_status.onboard_control_sensors_health
                & mavutil.mavlink.MAV_SYS_STATUS_SENSOR_3D_GYRO) != 0
        test_sys_status = conn.testmav.recv_match(type='SYS_STATUS',
                                                  blocking=True,
                                                  timeout=1)
        if test_sys_status:
            test_gyros_healthy = (
                test_sys_status.onboard_control_sensors_health
                & mavutil.mavlink.MAV_SYS_STATUS_SENSOR_3D_GYRO) != 0
    if not ref_gyros_healthy:
        logger.error("Failed to get healthy reference gyros")
        return False
    if not test_gyros_healthy:
        logger.error("Failed to get healthy test gyros")
        return False
    logger.info("Gyros are healthy")
    return True
示例#18
0
def adjust_ahrs_trim(conn, level_attitude):
    '''
    force the AHRS trim to zero, which removes the effect of the jig not being quite
    level. This is only incorrect if the accels are not aligned on the board, which
    we check in check_accel_cal later
    '''
    util.param_set(conn.test, 'AHRS_TRIM_X', 0)
    util.param_set(conn.test, 'AHRS_TRIM_Y', 0)

    # get the board level
    rotate.set_rotation(conn, 'level')

    # be really sure it has stopped moving. This next measurement is critical
    time.sleep(2)

    # we need to work out what the error in attitude of the 3 IMUs on the test jig is
    # to do that we start with it level, and measure the roll/pitch as compared to the reference
    # then we rotate it to pitch 90 and measure the yaw error

    # check all accels are in range
    conn.discard_messages()
    ref_imu = conn.refmav.recv_match(type='RAW_IMU', blocking=True, timeout=3)
    test_imu1 = conn.testmav.recv_match(type='RAW_IMU', blocking=True, timeout=3)
    test_imu2 = conn.testmav.recv_match(type='SCALED_IMU2', blocking=True, timeout=3)
    test_imu3 = conn.testmav.recv_match(type='SCALED_IMU3', blocking=True, timeout=3)
    if ref_imu is None:
        util.failure("Lost comms to reference board in ahrs trim")
    if test_imu1 is None or test_imu2 is None or test_imu3 is None:
        util.failure("Lost comms to test board in ahrs trim")
    ref_accel = Vector3(ref_imu.xacc, ref_imu.yacc, ref_imu.zacc)*9.81*0.001

    (ref_roll, ref_pitch) = util.attitude_estimate(ref_imu)
    (test_roll1, test_pitch1) = util.attitude_estimate(test_imu1)
    (test_roll2, test_pitch2) = util.attitude_estimate(test_imu2)
    (test_roll3, test_pitch3) = util.attitude_estimate(test_imu3)

    # get the roll and pitch errors
    roll_error1 = (test_roll1 - ref_roll)
    roll_error2 = (test_roll2 - ref_roll)
    roll_error3 = (test_roll3 - ref_roll)
    pitch_error1 = (test_pitch1 - ref_pitch)
    pitch_error2 = (test_pitch2 - ref_pitch)
    pitch_error3 = (test_pitch3 - ref_pitch)

    # rotate to up position while integrating gyros to test
    # all gyros are working
    rotate.gyro_integrate(conn)

    # finish rotation to pitch 90 to measure the yaw error
    rotate.set_rotation(conn, 'up')

    conn.discard_messages()
    ref_imu = conn.refmav.recv_match(type='RAW_IMU', blocking=True, timeout=3)
    test_imu1 = conn.testmav.recv_match(type='RAW_IMU', blocking=True, timeout=3)
    test_imu2 = conn.testmav.recv_match(type='SCALED_IMU2', blocking=True, timeout=3)
    test_imu3 = conn.testmav.recv_match(type='SCALED_IMU3', blocking=True, timeout=3)
    if ref_imu is None:
        util.failure("Lost comms to reference board in ahrs trim")
    if test_imu1 is None or test_imu2 is None or test_imu3 is None:
        util.failure("Lost comms to test board in ahrs trim")
    ref_accel = Vector3(ref_imu.xacc, ref_imu.yacc, ref_imu.zacc)*9.81*0.001

    # start rotating back to level ready for the end of the test
    rotate.set_rotation(conn, 'level', wait=False)

    # when pointing straight up the roll_esimtate() actually estimates yaw error in body frame
    ref_yaw = util.roll_estimate(ref_imu)
    test_yaw1 = util.roll_estimate(test_imu1)
    test_yaw2 = util.roll_estimate(test_imu2)
    test_yaw3 = util.roll_estimate(test_imu3)
    yaw_error1 = test_yaw1 - ref_yaw
    yaw_error2 = test_yaw2 - ref_yaw
    yaw_error3 = test_yaw3 - ref_yaw

    logger.debug("Tilt Ref=(%.1f %.1f %.1f) Test1=(%.1f %.1f %.1f) Test2=(%.1f %.1f %.1f) Test3=(%.1f %.1f %.1f)" % (
        ref_roll, ref_pitch, ref_yaw,
        test_roll1, test_pitch1, test_yaw1,
        test_roll2, test_pitch2, test_yaw2,
        test_roll3, test_pitch3, test_yaw3))

    if (abs(ref_roll) > ROTATION_TOLERANCE or
        abs(ref_pitch) > ROTATION_TOLERANCE or
        abs(ref_yaw) > ROTATION_TOLERANCE):
        util.failure("Reference board rotation error")

    logger.debug("Tilt offsets: Roll(%.1f %.1f %.1f) Pitch(%.1f %.1f %.1f) Yaw(%.1f %.1f %.1f) " % (
        roll_error1, roll_error2, roll_error3,
        pitch_error1, pitch_error2, pitch_error3,
        yaw_error1, yaw_error2, yaw_error3))

    if (abs(roll_error1) > TILT_TOLERANCE1 or
        abs(roll_error2) > TILT_TOLERANCE1 or
        abs(roll_error3) > TILT_TOLERANCE3):
        util.failure("Test board roll error")

    if (abs(pitch_error1) > TILT_TOLERANCE1 or
        abs(pitch_error2) > TILT_TOLERANCE1 or
        abs(pitch_error3) > TILT_TOLERANCE3):
        util.failure("Test board pitch error")

    if (abs(yaw_error1) > TILT_TOLERANCE1 or
        abs(yaw_error2) > TILT_TOLERANCE1 or
        abs(yaw_error3) > TILT_TOLERANCE3):
        util.failure("Test board yaw error")

    # setting a positive trim value reduces the attitude that is
    # read. So setting a trim of 0.1 when level results in a attitude
    # reading of -5.8 degrees

    # this assumes the reference board always reads correct attitude
    # and that there is no attitude discrepance between test and
    # reference boards    
    trim_x = radians((roll_error1+roll_error2)/2)
    trim_y = radians((pitch_error1+pitch_error2)/2)
    logger.debug("OLD Set trims AHRS_TRIM_X=%.4f AHRS_TRIM_Y=%.4f" % (trim_x, trim_y))

    # this new approach assumes the mpu6000 on the FMU (IMU3) is level
    # with respect to the board, and that any attitude error is due to
    # the isolation board mount. We use the average of the error from
    # IMU1 and IMU2
    trim_x = radians((test_roll1+test_roll2)*0.5 - test_roll3)
    trim_y = radians((test_pitch1+test_pitch2)*0.5 - test_pitch3)

    util.param_set(conn.test, 'AHRS_TRIM_X', trim_x)
    time.sleep(0.2)
    util.param_set(conn.test, 'AHRS_TRIM_Y', trim_y)
    time.sleep(0.2)
    logger.debug("Set trims AHRS_TRIM_X=%.4f AHRS_TRIM_Y=%.4f" % (trim_x, trim_y))