Vehicle.mode
Vehicle.armed
Vehicle.airspeed
Vehicle.groundspeed#disarm the vehicle
vehicle.armed = False
#set the default groundspeed to be used in movement commands
vehicle.groundspeed = 3.2
我们无法确保这些属性值一定能成功修改,所以要加循环
vehicle.mode = VehicleMode("GUIDED")
vehicle.armed = True
whilenot vehicle.mode.name=='GUIDED'andnot vehicle.armed andnot api.exit:
print" Getting ready to take off ..."time.sleep(1)
云台的设置比较特殊
#Point the gimbal straight down
vehicle.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)
#Callback to print the location in global frames. 'value' is the updated value,self指所连接的无人机deflocation_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')defrangefinder_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