Example #1
0
    def arm_and_takeoff(aTargetAltitude):
        """
        Arms vehicle and fly to aTargetAltitude.
        """

        # print "Basic pre-arm checks"
        # Don't let the user try to fly autopilot is booting
        if vehicle.mode.name == "INITIALISING":
            # print "Waiting for vehicle to initialise"
            time.sleep(1)
        while vehicle.gps_0.fix_type < 2:
            # print "Waiting for GPS...:", vehicle.gps_0.fix_type
            time.sleep(1)

        # print "Arming motors"
        # Copter should arm in GUIDED mode
        vehicle.mode = VehicleMode("GUIDED")
        vehicle.flush()

        i = 60
        while not api.exit and vehicle.mode.name != 'GUIDED' and i > 0:
            # print " Waiting for guided %s seconds..." % (i,)
            time.sleep(1)
            i = i - 1

        vehicle.armed = True
        vehicle.flush()

        i = 60
        while not api.exit and not vehicle.armed and vehicle.mode.name == 'GUIDED' and i > 0:
            # print " Waiting for arming %s seconds..." % (i,)
            time.sleep(1)
            i = i - 1

        # Failure will result in arming but immediately landing
        assert vehicle.armed
        assert_equals(vehicle.mode.name, 'GUIDED')

        # print "Taking off!"
        vehicle.commands.takeoff(
            aTargetAltitude)  # Take off to target altitude
        vehicle.flush()

        # Wait until the vehicle reaches a safe height before
        # processing the goto (otherwise the command after
        # Vehicle.commands.takeoff will execute immediately).
        while not api.exit:
            # print " Altitude: ", vehicle.location.alt
            # Test for altitude just below target, in case of undershoot.
            if vehicle.location.alt >= aTargetAltitude * 0.95:
                # print "Reached target altitude"
                break

            assert_equals(vehicle.mode.name, 'GUIDED')
            time.sleep(1)
    def arm_and_takeoff(aTargetAltitude):
        """
        Arms vehicle and fly to aTargetAltitude.
        """

        # print "Basic pre-arm checks"
        # Don't let the user try to fly autopilot is booting
        if vehicle.mode.name == "INITIALISING":
            # print "Waiting for vehicle to initialise"
            time.sleep(1)
        while vehicle.gps_0.fix_type < 2:
            # print "Waiting for GPS...:", vehicle.gps_0.fix_type
            time.sleep(1)
            
        # print "Arming motors"
        # Copter should arm in GUIDED mode
        vehicle.mode    = VehicleMode("GUIDED")
        vehicle.flush()

        i = 60
        while not api.exit and vehicle.mode.name != 'GUIDED' and i > 0:
            # print " Waiting for guided %s seconds..." % (i,)
            time.sleep(1)
            i = i - 1

        vehicle.armed   = True
        vehicle.flush()

        i = 60
        while not api.exit and not vehicle.armed and vehicle.mode.name == 'GUIDED' and i > 0:
            # print " Waiting for arming %s seconds..." % (i,)
            time.sleep(1)
            i = i - 1

        # Failure will result in arming but immediately landing
        assert vehicle.armed
        assert_equals(vehicle.mode.name, 'GUIDED')

        # print "Taking off!"
        vehicle.commands.takeoff(aTargetAltitude) # Take off to target altitude
        vehicle.flush()

        # Wait until the vehicle reaches a safe height before
        # processing the goto (otherwise the command after
        # Vehicle.commands.takeoff will execute immediately).
        while not api.exit:
            # print " Altitude: ", vehicle.location.alt
            # Test for altitude just below target, in case of undershoot.
            if vehicle.location.alt >= aTargetAltitude * 0.95: 
                # print "Reached target altitude"
                break

            assert_equals(vehicle.mode.name, 'GUIDED')
            time.sleep(1)
Example #3
0
def test_110(local_connect):
    api = local_connect()
    v = api.get_vehicles()[0]

    # Change the vehicle into STABILIZE mode
    v.mode = VehicleMode("STABILIZE")

    # NOTE wait crudely for ACK on mode update
    time.sleep(3)

    # Define example callback for mode
    def armed_callback(attribute):
        armed_callback.called += 1

    armed_callback.called = 0

    # When the same (event, callback) pair is passed to add_attribute_observer,
    # only one instance of the observer callback should be added.
    v.add_attribute_observer('armed', armed_callback)
    v.add_attribute_observer('armed', armed_callback)
    v.add_attribute_observer('armed', armed_callback)
    v.add_attribute_observer('armed', armed_callback)
    v.add_attribute_observer('armed', armed_callback)

    # Disarm and see update.
    v.armed = False
    v.flush()
    # Wait for ACK.
    time.sleep(3)

    # Ensure the callback was called.
    assert armed_callback.called > 0, "Callback should have been called."

    # Rmove all observers. The first call should remove all listeners
    # we've added; the second call should be ignored and not throw.
    # NOTE: We test if armed_callback were treating adding each additional callback
    # and remove_attribute_observer were removing them one at a time; in this
    # case, there would be three callbacks still attached.
    v.remove_attribute_observer('armed', armed_callback)
    v.remove_attribute_observer('armed', armed_callback)
    callcount = armed_callback.called

    # Re-arm and see update.
    v.armed = True
    v.flush()
    # Wait for ack
    time.sleep(3)

    # Ensure the callback was called zero times.
    assert_equals(armed_callback.called, callcount,
                  "Callback should not have been called once removed.")
Example #4
0
def test_110(local_connect):
    api = local_connect()
    v = api.get_vehicles()[0]
    
    # Change the vehicle into STABILIZE mode
    v.mode = VehicleMode("STABILIZE")

    # NOTE wait crudely for ACK on mode update
    time.sleep(3)

    # Define example callback for mode
    def armed_callback(attribute):
        armed_callback.called += 1
    armed_callback.called = 0

    # When the same (event, callback) pair is passed to add_attribute_observer,
    # only one instance of the observer callback should be added.
    v.add_attribute_observer('armed', armed_callback)
    v.add_attribute_observer('armed', armed_callback)
    v.add_attribute_observer('armed', armed_callback)
    v.add_attribute_observer('armed', armed_callback)
    v.add_attribute_observer('armed', armed_callback)

    # Disarm and see update.
    v.armed = False
    v.flush()
    # Wait for ACK.
    time.sleep(3)

    # Ensure the callback was called.
    assert armed_callback.called > 0, "Callback should have been called."

    # Rmove all observers. The first call should remove all listeners
    # we've added; the second call should be ignored and not throw.
    # NOTE: We test if armed_callback were treating adding each additional callback
    # and remove_attribute_observer were removing them one at a time; in this
    # case, there would be three callbacks still attached.
    v.remove_attribute_observer('armed', armed_callback)
    v.remove_attribute_observer('armed', armed_callback)
    callcount = armed_callback.called

    # Re-arm and see update.
    v.armed = True
    v.flush()
    # Wait for ack
    time.sleep(3)

    # Ensure the callback was called zero times.
    assert_equals(armed_callback.called, callcount, "Callback should not have been called once removed.")
Example #5
0
def test_115(local_connect):
    api = local_connect()
    v = api.get_vehicles()[0]

    # Dummy callback
    def mavlink_callback(*args):
        mavlink_callback.count += 1
    mavlink_callback.count = 0

    # Set the callback.
    v.set_mavlink_callback(mavlink_callback)

    # Change the vehicle into STABILIZE mode
    v.mode = VehicleMode("STABILIZE")
    # NOTE wait crudely for ACK on mode update
    time.sleep(3)

    # Expect the callback to have been called
    assert mavlink_callback.count > 0

    # Unset the callback.
    v.unset_mavlink_callback()
    savecount = mavlink_callback.count

    # Disarm. A callback of None should not throw errors
    v.armed = False
    v.flush()
    # NOTE wait crudely for ACK on mode update
    time.sleep(3)

    # Expect the callback to have been called
    assert_equals(savecount, mavlink_callback.count)

    # Re-arm should not throw errors.
    v.armed = True
    v.flush()
    # NOTE wait crudely for ACK on mode update
    time.sleep(3)
Example #6
0
def test_timeout(local_connect):
    v = local_connect().get_vehicles()[0]

    value = v.parameters['THR_MIN']
    assert_equals(type(value), float)

    start = current_milli_time()
    v.parameters['THR_MIN'] = value + 10
    end = current_milli_time()

    newvalue = v.parameters['THR_MIN']
    assert_equals(type(newvalue), float)
    assert_equals(newvalue, value + 10)
def test_parameters(local_connect):
    v = local_connect().get_vehicles()[0]

    # Simple parameter checks
    assert_equals(type(v.parameters["THR_MIN"]), float)
Example #8
0
def test_parameter(local_connect):
    v = local_connect().get_vehicles()[0]

    # Perform a simple parameter check
    assert_equals(type(v.parameters['THR_MIN']), float)