DroneKit示例分析1---状态的获取与设置
来源:互联网 发布:小提琴音准软件 编辑:程序博客网 时间:2024/06/07 17:50
- 能获取大部分无人机的状态信息,但只有以下几个可以设置
Vehicle.home_location,Vehicle.gimbal Vehicle.airspeed, Vehicle.groundspeed, Vehicle.mode Vehicle.armed
- 以下代码涵盖了大部分的无人机状态获取(通过MavLink)
# vehicle is an instance of the Vehicle classprint "Autopilot Firmware version: %s" % vehicle.versionprint "Autopilot capabilities (supports ftp): %s" % vehicle.capabilities.ftpprint "Global Location: %s" % vehicle.location.global_frameprint "Global Location (relative altitude): %s" % vehicle.location.global_relative_frameprint "Local Location: %s" % vehicle.location.local_frame #NEDprint "Attitude: %s" % vehicle.attitudeprint "Velocity: %s" % vehicle.velocityprint "GPS: %s" % vehicle.gps_0print "Groundspeed: %s" % vehicle.groundspeedprint "Airspeed: %s" % vehicle.airspeedprint "Gimbal status: %s" % vehicle.gimbalprint "Battery: %s" % vehicle.batteryprint "EKF OK?: %s" % vehicle.ekf_okprint "Last Heartbeat: %s" % vehicle.last_heartbeatprint "Rangefinder: %s" % vehicle.rangefinderprint "Rangefinder distance: %s" % vehicle.rangefinder.distanceprint "Rangefinder voltage: %s" % vehicle.rangefinder.voltageprint "Heading: %s" % vehicle.headingprint "Is Armable?: %s" % vehicle.is_armableprint "System status: %s" % vehicle.system_status.stateprint "Mode: %s" % vehicle.mode.name # settableprint "Armed: %s" % vehicle.armed # settable
- 以下四个属性可以直接设置
Vehicle.modeVehicle.armedVehicle.airspeedVehicle.groundspeed#disarm the vehiclevehicle.armed = False#set the default groundspeed to be used in movement commandsvehicle.groundspeed = 3.2
- 我们无法确保这些属性值一定能成功修改,所以要加循环
vehicle.mode = VehicleMode("GUIDED")vehicle.armed = Truewhile not vehicle.mode.name=='GUIDED' and not vehicle.armed and not api.exit: print " Getting ready to take off ..." time.sleep(1)
- 云台的设置比较特殊
#Point the gimbal straight downvehicle.gimbal.rotate(-90, 0, 0)time.sleep(10)#Set the camera to track the current home position.vehicle.gimbal.target_location(vehicle.home_location)time.sleep(10)
- 监听属性值的改变,有两个方法,
Vehicle.add_attribute_listener()
和Vehicle.on_attribute()
#Callback to print the location in global frames. 'value' is the updated value,self指所连接的无人机 def location_callback(self, attr_name, value): print "Location (Global): ", value # Add a callback `location_callback` for the `global_frame` attribute.有两种方法可以添加 vehicle.add_attribute_listener('location.global_frame', location_callback) #第二种方法 vehicle.location.add_attribute_listener('global_frame', location_callback) # Wait 2s so callback can be notified before the observer is removed time.sleep(2) # Remove observer - specifying the attribute and previously registered callback function vehicle.remove_message_listener('location.global_frame', location_callback)
#如果我们只需要相对明显的状态变化,可以用这个,round(x,1)返回x的四舍五入值---保留一位小数。last_rangefinder_distance=0@vehicle.on_attribute('rangefinder') def rangefinder_callback(self,attr_name): #attr_name not used here. global last_rangefinder_distance if last_rangefinder_distance == round(self.rangefinder.distance, 1): return last_rangefinder_distance = round(self.rangefinder.distance, 1) print " Rangefinder (metres): %s" % last_rangefinder_distance
0 0
- DroneKit示例分析1---状态的获取与设置
- DroneKit教程(四):属性和参数的读取与设置
- CListCtrl中CheckBox状态的获取与设置
- ExtJS设置与获取radio控件的选取状态
- ExtJS设置与获取radio控件的选取状态
- DroneKit教程(二):控制Pixhawk示例
- fragment状态的保存与获取
- 获得进程,服务,应用的状态以及获取各种开关的状态,设置开关状态
- AppSettings的设置与获取
- SpringMVC addFlashAttribute的分析与使用示例
- SpringMVC addFlashAttribute的分析与使用示例
- TCP协议的原理分析与示例
- 获取(设置)键盘状态
- 设置和获取单选框状态的一种蠢方法
- Lex示例与分析
- Android 飞行模式的设置(打开/关闭飞行模式,获取飞行状态状态)
- Android 飞行模式的设置(打开/关闭飞行模式,获取飞行状态状态)
- Linux fork 后 wait 获取子进程结束的状态示例
- 计算机网络基础
- 图论10—二维矩阵排序及索引
- 419. Battleships in a Board
- mac下安装和使用brew
- 小游戏 fifteen puzzle
- DroneKit示例分析1---状态的获取与设置
- c/c++中&& ||的区别
- iOS-菜鸟到大师-1-iOS介绍及hello world
- ESP8266下载电路的搭建
- Java流式输入输出-面向字节
- 自制Minecraft的初次尝试【01】
- Wireshark lua插件
- 分析system_call中断处理过程
- tomcat 管理站点提示