Drone simple rotate roll

  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    except Exception as err:
 42        pywpc.printGenericError(err)
 43        ## Release device handle
 44        dev.close()
 45        return
 46
 47    try:
 48        ## Get firmware model & version
 49        firmware_version = dev.Drone_getFirmwareVersion(timeout)
 50        print(f"Firmware version: {firmware_version}")
 51
 52        ## Get serial number
 53        serial_number = dev.Drone_getSerialNumber(timeout)
 54        print(f"Serial number: {serial_number}")
 55
 56        ## Read task control mode
 57        control_mode = dev.Drone_readTaskControlMode(timeout)
 58        if control_mode == 0:
 59            print("Please switch the remote controller to mission computer mode.")
 60            print("Terminate example code. Goodbye!")
 61            return
 62
 63        ## Set drone flight mode to attitude mode
 64        err = dev.Drone_setAttiudeMode(timeout)
 65        print(f"Drone_setAttiudeMode, status: {err}")
 66
 67        ## Activate drone
 68        err = dev.Drone_activate(timeout)
 69        print(f"Drone_activate, status: {err}")
 70
 71        ## Start drone take-off
 72        err = dev.Drone_startTakeOff(timeout)
 73        print(f"Drone_startTakeOff, status: {err}")
 74
 75        ## Read drone take-off status
 76        takeoff_status = 0
 77        print("Taking off...")
 78        while takeoff_status == 0:
 79            takeoff_status = dev.Drone_getTakeOffStatus(timeout)
 80            if takeoff_status == 1:
 81                print("Completed the takeoff procedure")
 82
 83        ## Wait
 84        print("Wait a while")
 85        time.sleep(5)  ## delay [sec]
 86
 87        ## Roll rotate with vehicle frame
 88        err = dev.Drone_moveVehicleAbsRoll(rotate_angle, velocity, timeout)
 89        print(f"Drone_moveVehicleAbsRoll, status: {err}")
 90
 91        ## Read inposition
 92        inposition = 0
 93        while inposition == 0:
 94            posi_list = dev.Drone_readInposition(timeout)
 95            roll_ready = posi_list[0]
 96            inposition = int(bool(roll_ready))
 97            if inposition == 1:
 98                print("Reached roll!")
 99
100    except Exception as err:
101        pywpc.printGenericError(err)
102
103    finally:
104        ## Wait
105        print("Wait a while")
106        time.sleep(5)  ## delay [sec]
107
108        ## Start landing
109        err = dev.Drone_startLanding(timeout)
110        print(f"Drone_startLanding, status: {err}")
111
112        ## Read landing status
113        landing_status = 0
114        print("Landing....")
115        while landing_status == 0:
116            landing_status = dev.Drone_getLandingStatus(timeout)
117            if landing_status == 1:
118                print("Landing successful!")
119
120        ## Disactivate drone
121        err = dev.Drone_deactivate(timeout)
122        print(f"Drone_deactivate, status: {err}")
123
124        ## Disconnect device
125        dev.disconnect()
126
127        ## Release device handle
128        dev.close()
129
130if __name__ == '__main__':
131    main()