1'''
2Drone - Drone_simple_rotate_roll.py with synchronous mode.
3
4- Ensure the drones center of gravity is properly balanced.
5- Verify that all mounted payloads are securely fastened.
6- Confirm that all screws on the drone are tightened.
7- Check that the drone battery is fully charged** (approximately 12.5V).
8- Make sure the USB drive has sufficient storage** to record the flight data.
9- Insert the USB drive into the flight control computer.
10
11For other examples please check:
12 https://github.com/WPC-Systems-Ltd/WPC_Python_driver_release/tree/main/examples
13See README.md file to get detailed usage of this example.
14
15Copyright (c) 2022-2025 WPC Systems Ltd. All rights reserved.
16'''
17
18## WPC
19from wpcsys import pywpc
20
21## Python
22import time
23
24
25def main():
26 ## Get Python driver version
27 print(f'{pywpc.PKG_FULL_NAME} - Version {pywpc.__version__}')
28
29 ## Parameters setting
30 baudrate = 921600
31 timeout = 3 ## [sec]
32 rotate_angle = 10 ## [degree]
33 velocity = 1 ## [degree/s]
34
35 ## Create device handle
36 dev = pywpc.Drone()
37
38 ## Connect to device
39 try:
40 dev.connect("COM5", baudrate) ## Depend on your device
41 # dev.connect("/dev/ttyTHS1", baudrate) ## Depend on your device
42 except Exception as err:
43 pywpc.printGenericError(err)
44 ## Release device handle
45 dev.close()
46 return
47
48 try:
49 ## Get firmware model & version
50 firmware_version = dev.Drone_getFirmwareVersion(timeout)
51 print(f"Firmware version: {firmware_version}")
52
53 ## Get serial number
54 serial_number = dev.Drone_getSerialNumber(timeout)
55 print(f"Serial number: {serial_number}")
56
57 ## Read task control mode
58 control_mode = dev.Drone_readTaskControlMode(timeout)
59 if control_mode == 0:
60 print("Please switch the remote controller to mission computer mode.")
61 print("Terminate example code. Goodbye!")
62 return
63
64 ## Set drone flight mode to attitude mode
65 err = dev.Drone_setAttiudeMode(timeout)
66 print(f"Drone_setAttiudeMode, status: {err}")
67
68 ## Get drone flight mode
69 flight_mode = Drone_getFlightMode(timeout)
70 print(f"Drone_getFlightMode, flight_mode: {flight_mode}")
71
72 ## Activate drone
73 err = dev.Drone_activate(timeout)
74 print(f"Drone_activate, status: {err}")
75
76 ## Start drone take-off
77 err = dev.Drone_startTakeOff(timeout)
78 print(f"Drone_startTakeOff, status: {err}")
79
80 ## Read drone take-off status
81 takeoff_status = 0
82 print("Taking off...")
83 while takeoff_status == 0:
84 takeoff_status = dev.Drone_getTakeOffStatus(timeout)
85 if takeoff_status == 1:
86 print("Completed the takeoff procedure")
87
88 ## Wait
89 print("Wait a while")
90 time.sleep(5) ## delay [sec]
91
92 ## Roll rotate with vehicle frame
93 err = dev.Drone_moveVehicleAbsRoll(rotate_angle, velocity, timeout)
94 print(f"Drone_moveVehicleAbsRoll, status: {err}")
95
96 ## Read inposition
97 inposition = 0
98 while inposition == 0:
99 posi_list = dev.Drone_readInposition(timeout)
100 roll_ready = posi_list[0]
101 inposition = int(bool(roll_ready))
102 if inposition == 1:
103 print("Reached roll!")
104
105 except Exception as err:
106 pywpc.printGenericError(err)
107
108 finally:
109 ## Wait
110 print("Wait a while")
111 time.sleep(5) ## delay [sec]
112
113 ## Start landing
114 err = dev.Drone_startLanding(timeout)
115 print(f"Drone_startLanding, status: {err}")
116
117 ## Read landing status
118 landing_status = 0
119 print("Landing....")
120 while landing_status == 0:
121 landing_status = dev.Drone_getLandingStatus(timeout)
122 if landing_status == 1:
123 print("Landing successful!")
124
125 ## Disactivate drone
126 err = dev.Drone_deactivate(timeout)
127 print(f"Drone_deactivate, status: {err}")
128
129 ## Disconnect device
130 dev.disconnect()
131
132 ## Release device handle
133 dev.close()
134
135if __name__ == '__main__':
136 main()