Skip to content

Commit

Permalink
Adds vehicle_goto test.
Browse files Browse the repository at this point in the history
  • Loading branch information
tcr3dr committed Jul 14, 2015
1 parent 38e8438 commit f89d34b
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 4 deletions.
24 changes: 20 additions & 4 deletions tests/sitl/__main__.py
Expand Up @@ -100,20 +100,36 @@ def lets_run_a_test(name):
sys.stdout.flush()
sys.stderr.flush()

timeout = 300
# APPVEYOR = SLOW
timeout = 15*60 if sys.platform == 'win32' else 5*60

This comment has been minimized.

Copy link
@mrpollo

mrpollo Jul 14, 2015

Member

timeout = 900 if sys.platform == 'win32' else 300 IMO I don't think there's any gain from having the static multiplier here, better add the real numbers and add a comment eg: # 15 seconds if windows else 5

try:
p = Popen([sys.executable, '-m', 'MAVProxy.mavproxy', '--logfile=' + tempfile.mkstemp()[1], '--master=tcp:127.0.0.1:5760'], cwd=testpath, env=newenv, stdin=PIPE, stdout=PIPE, stderr=PIPE)
p = Popen([sys.executable, '-m', 'MAVProxy.mavproxy', '--logfile=' + tempfile.mkstemp()[1], '--master=tcp:127.0.0.1:5760'], cwd=testpath, env=newenv, stdin=PIPE, stdout=PIPE)#, stderr=PIPE)
bg.append(p)

while p.poll() == None:
line = p.stdout.readline()
sys.stdout.write(line)
sys.stdout.flush()
if 'parameters' in line:
break

# TODO this sleep is only for us to waiting until
# all parameters to be received; would prefer to
# move this to testlib.py and happen asap
time.sleep(20)
time.sleep(3)
p.stdin.write('module load droneapi.module.api\n')
p.stdin.write('param set ARMING_CHECK 0\n')
p.stdin.write('api start testlib.py\n')
p.stdin.flush()

while True:
nextline = p.stdout.readline()
if nextline == '' and p.poll() != None:
break
sys.stdout.write(nextline)
sys.stdout.flush()

wait_timeout(p, timeout)
# wait_timeout(p, timeout)

This comment has been minimized.

Copy link
@mrpollo

mrpollo Jul 14, 2015

Member

remove this?

except RuntimeError:
kill(p.pid)
p.returncode = 143
Expand Down
81 changes: 81 additions & 0 deletions tests/sitl/test_goto.py
@@ -0,0 +1,81 @@
"""
simple_goto.py: GUIDED mode "simple goto" example (Copter Only)
The example demonstrates how to arm and takeoff in Copter and how to navigate to
points using Vehicle.commands.goto.
Full documentation is provided at http://python.dronekit.io/examples/simple_goto.html
"""

import time
from droneapi.lib import VehicleMode, Location
from pymavlink import mavutil
from testlib import assert_equals

def test_goto(local_connect):
api = local_connect()
vehicle = api.get_vehicles()[0]

def arm_and_takeoff(aTargetAltitude):

This comment has been minimized.

Copy link
@mrpollo

mrpollo Jul 14, 2015

Member

would arm_and_takeoff be more helpful in testlib or any other shared lib? we seem to be using it a lot in the docs, maybe its the case that in our tests we will too

This comment has been minimized.

Copy link
@hamishwillee

hamishwillee Jul 15, 2015

Contributor

@mrpollo I have tried to standardise on this arm_and_takeoff in all my examples - previously there was an ad-hoc mess of different pre-arm checks (including disabling the checks altogether).

In 99% of cases I think this sort of approach is what people will want to do, so it makes sense to make it easily accessible in a shared libary - part of Vehicle.commands?

We would need to make the system robust so that it would timeout if arming failed, and cope with the case of being called if the vehicle is already airborne (and what to do if not at the correct height). Note also that this method is (deliberately) synchronous, which means that you can't send other commands to the vehicle (e.g. set ROI) while this is executing.

This comment has been minimized.

Copy link
@mrpollo

mrpollo Jul 15, 2015

Member

@tcr3dr what do you think?

This comment has been minimized.

Copy link
@tcr3dr

tcr3dr Jul 16, 2015

Author Contributor

Worth discussing! Moving to a #209 issue.

"""
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.armed = True
vehicle.flush()

while not vehicle.armed and not api.exit and vehicle.mode.name != 'LAND':
print " Waiting for arming..."
time.sleep(1)

# Failure will result in arming but immediately landing
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
if vehicle.location.alt>=aTargetAltitude*0.95: #Just below target, in case of undershoot.

This comment has been minimized.

Copy link
@mrpollo

mrpollo Jul 14, 2015

Member

add white-space for readability?

print "Reached target altitude"
break;

assert_equals(vehicle.mode.name, 'GUIDED')
time.sleep(1)

arm_and_takeoff(10)

print "Going to first point..."
point1 = Location(-35.361354, 149.165218, 20, is_relative=True)
vehicle.commands.goto(point1)
vehicle.flush()

# sleep so we can see the change in map
time.sleep(3)

print "Going to second point..."
point2 = Location(-35.363244, 149.168801, 20, is_relative=True)
vehicle.commands.goto(point2)
vehicle.flush()

# sleep so we can see the change in map
time.sleep(3)

print "Returning to Launch"
vehicle.mode = VehicleMode("RTL")
vehicle.flush()

0 comments on commit f89d34b

Please sign in to comment.