-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobserve_attribute.py
More file actions
40 lines (32 loc) · 1.12 KB
/
observe_attribute.py
File metadata and controls
40 lines (32 loc) · 1.12 KB
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
'''
Author: Cahit Yusuf Tas / cyusuftas@gmail.com
'''
from dronekit import connect, VehicleMode
import time
#connection_string = '/dev/serial0' #raspberry pi
connection_string = '127.0.0.1:14552' #simulation
#connect to the vehicle
#vehicle = connect(connection_string, wait_ready = True, baud=921600)
vehicle = connect(connection_string, wait_ready = True)
#use decorator to observe changes in mode
@vehicle.on_attribute('mode')
def callback(self, attr_name, value):
print '%s Value: %s' % (attr_name, value)
#use decorator to observe changes in any parameter
@vehicle.parameters.on_attribute('*')
def parameter_callback(self, attr_name, value):
print '%s Value: %s' % (attr_name, value)
mode_changed = False
vehicle.mode = VehicleMode('STABILIZE')
time_start = time.time()
while True:
time_now = time.time()
if 3 < time_now - time_start < 5 and not mode_changed:
vehicle.mode = VehicleMode('GUIDED')
mode_changed = True
if time_now - time_start > 15: #observe changes in 15 seconds then quit
print 'exiting'
break
time.sleep(0.1)
#close vehicle
vehicle.close()