https://github.com/dronekit/dronekit-python/blob/master/docs/examples/vehicle_state.rst
这个例子展示了如何获取/设置车辆属性和参数信息,如何观察车辆属性变化,以及如何获取原点位置。
指南主题:ref:`vehicle-information`提供了有关如何使用 API 的更详细说明。
文档
https://github.com/dronekit/dronekit-python/blob/master/docs/examples/simple_goto.rst
此示例演示如何在 GUIDED 模式下武装和启动直升机,向多个目标点行进,然后返回原点。它使用:py:func:`Vehicle.simple_takeoff() <dronekit.Vehicle.simple_takeoff>`、 :py:func:`Vehicle.simple_goto() <dronekit.Vehicle.simple_goto>`和:py:attr:`Vehicle。模式 <dronekit.Vehicle.mode>` .
当:ref:`Simulated Vehicle <vagrant-sitl-from-full-image>`启动时,目标位置以家庭位置为中心;您可以编辑纬度和经度,为自己的车辆使用更合适的位置。
代码
https://github.com/dronekit/dronekit-python/blob/master/examples/simple_goto/simple_goto.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | #!/usr/bin/env python # -*- coding: utf-8 -*- """ © Copyright 2015-2016, 3D Robotics. simple_goto.py: GUIDED mode "simple goto" example (Copter Only) Demonstrates how to arm and takeoff in Copter and how to navigate to points using Vehicle.simple_goto. Full documentation is provided at http://python.dronekit.io/examples/simple_goto.html """ from __future__ import print_function import time from dronekit import connect, VehicleMode, LocationGlobalRelative # Set up option parsing to get connection string import argparse parser = argparse.ArgumentParser(description = 'Commands vehicle using vehicle.simple_goto.' ) parser.add_argument( '--connect' , help = "Vehicle connection target string. If not specified, SITL automatically started and used." ) args = parser.parse_args() connection_string = args.connect sitl = None # Start SITL if no connection string specified if not connection_string: import dronekit_sitl sitl = dronekit_sitl.start_default() connection_string = sitl.connection_string() # Connect to the Vehicle print ( 'Connecting to vehicle on: %s' % connection_string) vehicle = connect(connection_string, wait_ready = True ) def arm_and_takeoff(aTargetAltitude): """ Arms vehicle and fly to aTargetAltitude. """ print ( "Basic pre-arm checks" ) # Don't try to arm until autopilot is ready while not vehicle.is_armable: print ( " Waiting for vehicle to initialise..." ) time.sleep( 1 ) print ( "Arming motors" ) # Copter should arm in GUIDED mode vehicle.mode = VehicleMode( "GUIDED" ) vehicle.armed = True # Confirm vehicle armed before attempting to take off while not vehicle.armed: print ( " Waiting for arming..." ) time.sleep( 1 ) print ( "Taking off!" ) vehicle.simple_takeoff(aTargetAltitude) # Take off to target altitude # Wait until the vehicle reaches a safe height before processing the goto # (otherwise the command after Vehicle.simple_takeoff will execute # immediately). while True : print ( " Altitude: " , vehicle.location.global_relative_frame.alt) # Break and return from function just below target altitude. if vehicle.location.global_relative_frame.alt > = aTargetAltitude * 0.95 : print ( "Reached target altitude" ) break time.sleep( 1 ) arm_and_takeoff( 10 ) print ( "Set default/target airspeed to 3" ) vehicle.airspeed = 3 print ( "Going towards first point for 30 seconds ..." ) point1 = LocationGlobalRelative( - 35.361354 , 149.165218 , 20 ) vehicle.simple_goto(point1) # sleep so we can see the change in map time.sleep( 30 ) print ( "Going towards second point for 30 seconds (groundspeed set to 10 m/s) ..." ) point2 = LocationGlobalRelative( - 35.363244 , 149.168801 , 20 ) vehicle.simple_goto(point2, groundspeed = 10 ) # sleep so we can see the change in map time.sleep( 30 ) print ( "Returning to Launch" ) vehicle.mode = VehicleMode( "RTL" ) # Close vehicle object before exiting script print ( "Close vehicle object" ) vehicle.close() # Shut down simulator if it was started. if sitl: sitl.stop() |
分类:
3_1飞机pix
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
2019-06-21 (4)给树莓派安装中文输入法Fcitx及Google拼音输入法
2019-06-21 (3)使用Android手机作为树莓派的屏幕
2019-06-21 (2)在树莓派安装运行在Python3上的OpenCV