-
Notifications
You must be signed in to change notification settings - Fork 0
/
new_cross_maneuver.py
58 lines (48 loc) · 1.72 KB
/
new_cross_maneuver.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
from dronekit import connect, VehicleMode
from pymavlink import mavutil
import time
def arm_and_takeoff(vehicle, target_altitude):
print("Arming and Taking Off...")
vehicle.mode = VehicleMode("GUIDED")
vehicle.armed = True
while not vehicle.armed:
time.sleep(1)
vehicle.simple_takeoff(target_altitude)
while True:
if vehicle.location.global_relative_frame.alt >= target_altitude * 0.95:
print("Reached target altitude")
break
time.sleep(1)
def send_local_ned_velocity(vehicle, vx, vy, vz, duration):
msg = vehicle.message_factory.set_position_target_local_ned_encode(
0,
0, 0,
mavutil.mavlink.MAV_FRAME_BODY_OFFSET_NED,
0b0000111111000111,
0, 0, 0,
vx, vy, vz,
0, 0, 0,
0, 0
)
vehicle.send_mavlink(msg)
vehicle.flush()
time.sleep(duration)
def cross_maneuver(vehicle):
print("Performing Cross Maneuver...")
duration = 12
send_local_ned_velocity(vehicle, 1, 0, 0, duration) # Forward for 5 seconds
send_local_ned_velocity(vehicle, -1, 0, 0, (duration/2)) # Backward for 2 seconds
send_local_ned_velocity(vehicle, 0, -1, 0, (duration/2)) # Left for 3 seconds
send_local_ned_velocity(vehicle, 0, 1, 0, duration) # Right for 6 seconds
send_local_ned_velocity(vehicle, 0, -1, 0, (duration/2)) # Left for 3 seconds
print("Cross Maneuver Complete!")
def main():
vehicle = connect('udp:127.0.0.1:14550', wait_ready=True)
arm_and_takeoff(vehicle, 10) # 10 meters altitude
cross_maneuver(vehicle)
print("Returning to Launch")
vehicle.mode = VehicleMode("RTL")
time.sleep(10)
vehicle.close()
if __name__ == "__main__":
main()