Codes Explanation of LiteBee Go
Python tutorial Contents
I、 Brief Intro
II、 Basic operation and example
- 1. Basic Operation
- 2. Examples
- Import time
- Conditional and loop statement
- Formation example
III、 Instruction explanation
- 1. LiteBee Wing
- litebeeWing_calibration() calibrate
- litebeeWing_autoLand() land
- litebeeWing_getAnglePitch() the angle of pitch is
- litebeeWing_getAngleRoll() the angle of roll is
- litebeeWing_getAngleYaw() the angle of yaw is
- litebeeWing_getHigh() the height is
- litebeeWing_getVol() the voltage is
- litebeeWing_setBuzzer(['E4', 0.5]) set the buzzer
- litebeeWing_setDir([0, 0, 0, 10]) set the drone to fly horizontally
- litebeeWing_setHigh([110]) set the flight height as
- litebeeWing_setMotor([1, 50]) test the rotor
- litebeeWing_setYaw([1, 90]) yaw the drone
- litebeeWing_takeOff() take off
- 2. litebeeWingAvoidance With the obstacle avoiding module
- litebeeWingAvoidance_autoLand() land
- litebeeWingAvoidance_backward() sense the obstacle behind
- litebeeWingAvoidance_calibration() calibrate
- litebeeWingAvoidance_center() sense the obstacle below
- litebeeWingAvoidance_forward() sense the obstacle ahead
- litebeeWingAvoidance_left() sense the obstacle on the left
- litebeeWingAvoidance_right() sense the obstacle on the right
- litebeeWingAvoidance_setDir([0, 0, 0, 10]) set the drone to fly horizontally
- litebeeWingAvoidance_setHigh([110]) set the flight height
- litebeeWingAvoidance_setVXYZ([0, 0, 0, 10, 0, 0]) set the drone fly
- litebeeWingAvoidance_setYaw([1, 90]) Yaw the drone
- litebeeWingAvoidance_takeOff() take off
- 3. litebeeWingFormation Formation mode
- litebeeWingFormation_allLand() crash-land
- litebeeWingFormation_autoLand() land
- litebeeWingFormation_calibration([5]) calibrate
- litebeeWingFormation_circle([66, 77, 0, 2, 15]) circle
- litebeeWingFormation_circleZ([66, 77, 0, 150, 15]) ircle and adjust drone's height
- litebeeWingFormation_clear() clear all setting
- litebeeWingFormation_code([66, 10]) fly to the given QR code
- litebeeWingFormation_codeS(['12 23 27', 15]) fly multiple QR codes in order
- litebeeWingFormation_codeZ([66, 120, 10]) fly to the given QR code and adjust drone's height
- litebeeWingFormation_flightNum([1]) set for the given drone
- litebeeWingFormation_missionSend() send the mission to drones
- litebeeWingFormation_missionStart() start the mission
- litebeeWingFormation_RGB([1]) turn the LED on
- litebeeWingFormation_setZ([100, 3]) set the flight height
- litebeeWingFormation_takeOff([100, 5]) take off
- 4. litebeeWingLine with line tracking module
- litebeeWingLine_autoLand() land
- litebeeWingLine_calibration() calibrate
- litebeeWingLine_color() the color of tracking line
- litebeeWingLine_control([1, 15]) Line tracking setting
- litebeeWingLine_crossDetrct() at the crossroads
- litebeeWingLine_crossX() Distance from the cross-point in X-axis
- litebeeWingLine_crossY() Distance from the cross-point in Y-axis
- litebeeWingLine_open() start line tracking module
- litebeeWingLine_setRGBLed([1, 255, 255, 255]) LED module setting
- litebeeWingLine_takeOff() take off
- litebeeWingLine_type() the mode of line tracking
- 5. ghost2
- ghost2_autoLand() land
- ghost2_calibration() calibration
- ghost2_getAnglePitch() the angle of pitch is
- ghost2_getAngleRoll() the angle of roll is
- ghost2_getAngleYaw() the angle of yaw is
- ghost2_getHigh() the height is
- ghost2_getVol() the voltage is
- ghost2_setDir([1, 1]) set the drone to fly
- ghost2_setHigh([110]) set the flight height as
- ghost2_setMotor([1, 50]) test the rotor
- ghost2_setYaw([1, 90]) yaw the drone
- ghost2_takeOff() take off
- 6. ghost2Avoidance with the obstacle avoiding module
- ghost2Avoidance_autoLand() land
- ghost2Avoidance_backward() sense the obstacle behind
- ghost2Avoidance_calibration() calibrate
- ghost2Avoidance_center() sense the obstacle above
- ghost2Avoidance_forward() sense the obstacle ahead
- ghost2Avoidance_setDir([0, 0, 0, 10]) set thedrone fly horizontally
- ghost2Avoidance_setHigh([110]) set the flight height as
- ghost2Avoidance_setVXYZ([0, 0, 0, 10, 0, 0]) set the drone to fly
- ghost2Avoidance_setYaw([1, 90]) yaw the drone
- ghost2Avoidance_takeOff() take off
I. Brief Intro
The python programming in LiteBeeGo can be applied for both LiteBee Wing and Ghost II, and it works with different modes such as drone only, obstacle avoiding, formation, and line tracking. Each Python instruction corresponds to the graphic code of scratch mode, and there will be an explanation when you input the relevant instructions. Details will be list in Chapter 3.
II. Basic operation and examples
1.Basic operation
:Just as the picture shows, we can start LiteBeeGo and click “python” to enter the interface of Python. Connect the drone with the computer, then click "run" to execute the Python program
Hover the mouse on the “run” button to choose other operations such as Open, Save, and Stop. Attention, for easy to find and open, suffix it as “.py” when saving the file.
2.Example
import time
:Excepting formation, all the programming mode have to apply the “import time” to give a time for executing the mission.
For example:
import time //Write “import time” in the first line litebeeWing_calibration() //calibrate litebeeWing_takeOff() take off time.sleep(10) //wait 10s litebeeWing_autoland() //land
Conditional and loop statement Conditional and loop statement is needed when using these instructions, such as “if-elif-else”, “for”, “while”, here is an example: import time //import execution time litebeeWing_calibration() //calibration time.sleep(5) //wait 5s litebeeWing_takeOff() //take off time.sleep(5) //wait 5s if litebeeWing_getVol() > 7.5: //if litebee’s voltage >7.5v
litebeeWing_setHigh([50]) //set the flight height as 50cm
while True: //execute “while” loop
if litebeeWing_getVol() < 7.2: //if litebee’s voltage < 7.2v litebeeWing_autoLand() //land break; //break the loop
Formation example When we program for a formation, we need to program for each drone; take a 2 drones formation as an example:
litebeeWingFormation_flightnum([1]) //program for drone No. 1 litebeeWingFormation_calibration([5]) //calibrate for 5s litebeeWingFormation_takeOff([100,5]) //fly to the height 100cm in 5s litebeeWingFormation_code([10,5]) //move to QR code No.10 in 5s litebeeWingFormation_RGB([1]) //red light on litebeeWingFormation_autoLand() //land
litebeeWingFormation_flightnum([2]) //program for drone No.2 litebeeWingFormation_calibration([5]) //calibrate for 5s litebeeWingFormation_takeOff([100,5]) //fly to the height 100cm in 5s litebeeWingFormation_code([20,5]) //move to the QR code No. 20 in 5s litebeeWingFormation_RGB([2]) //green light on litebeeWingFormation_autoLand() //land
litebeeWingFormation_missionSend() //send these mission to drones time.sleep(3) //wait 3 s litebeeWingFormation_missionStart() //start the mission
III. Instruction explanation Note: p1, p2, p3, p4 are the parameter after the instruction (from left to right). And those instructions without parameter can be use directly. litebeeWing_setDir([0, 10, 1, 20]) Set the drone to fly horizontally
- p1: 0 - left; 1 - right
- p2: 0 ~ 100 cm/s for left/right
- p3: 0 - forward; 1 - backward
- p4: 0 ~ 100 cm/s for forward/backward
The following are relevant instructions and their explanation
1.litebeeWing
litebeeWing_calibration() calibrate litebeeWing_autoLand() land litebeeWing_getAnglePitch() the angle of pitch is litebeeWing_getAngleRoll() the angle of roll is litebeeWing_getAngleYaw() the angle of yaw is litebeeWing_getHigh() the flight height is litebeeWing_getVol() the voltage is litebeeWing_setBuzzer(['E4', 0.5]) set for the buzzer
- p1: scale
It can be:
- 'B0', 'C1', 'CS1', 'D1','DS1', 'E1', 'F1', 'FS1','G1', 'GS1', 'A1', 'AS1','B1', 'C2', 'CS2', 'D2',
'DS2', 'E2', 'F2', 'FS2','G2', 'GS2', 'A2', 'AS2','B2', 'C3', 'CS3', 'D3','DS3', 'E3', 'F3', 'FS3', 'G3', 'GS3', 'A3', 'AS3','B3', 'C4', 'CS4', 'D4','DS4', 'E4', 'F4', 'FS4','G4', 'GS4', 'A4', 'AS4', 'B4', 'C5', 'CS5', 'D5','DS5', 'E5', 'F5', 'FS5','G5', 'GS5', 'A5', 'AS5','B5', 'C6', 'CS6', 'D6', 'DS6', 'E6', 'F6', 'FS6','G6', 'GS6', 'A6', 'AS6','B6', 'C7', 'CS7', 'D7','DS7', 'E7', 'F7', 'FS7', 'G7', 'GS7', 'A7', 'AS7','B7', 'C8', 'CS8', 'D8', 'DS8']
- p2: metre
It can be:
- 0.5 ,1 ,1.5 ,2 ,2.5
litebeeWing_setDir([0, 0, 0, 10]) set the drone to fly horizontally
- p1: 0 - left; 1 - right
- p2: speed 0-100 cm/s for left/right
- p3: 0 - forward; 1 - backward
- p4: speed 0-100 cm/s for forward/backward
litebeeWing_setHigh([110]) Set flight height: #cm litebeeWing_setMotor([1, 50]) rotor test It’s invalid to test the rotor when drone is flying; the advised rev is 5~50rpm for the test
- p1: which rotor
- p2: rev
litebeeWing_setRGBLed([1, 255, 255, 255]) Set for the LED module
- p1: which LED
- p2: value of red 0~255
- p3: value of green 0~255
- p4: value of blue 0~255
litebeeWing_setYaw([1, 90]) Yaw the drone
- p1: 1 - cw: 2 - ccw
- p2: angle for rotation
litebeeWing_takeOff() take off
2.litebeeWingAvoidance With obstacle avoiding mode litebeeWingAvoidance_autoLand() land litebeeWingAvoidance_backward() Sense the obstacle behind
- it is invalid when the value is 0(max sense range:240cm)
litebeeWingAvoidance_calibration() calibrate litebeeWingAvoidance_center() Sense the obstacle below
- it is invalid when the value is 0(max sense range:240cm)
litebeeWingAvoidance_forward() Sense the obstacle ahead
- it is invalid when the value is 0(max sense range:240cm)
litebeeWingAvoidance_left() Sense the obstacle on the left
- it is invalid when the value is 0(max sense range:240cm)
litebeeWingAvoidance_right() Sense the obstacle on the right
- it is invalid when the value is 0(max sense range:240cm)
litebeeWingAvoidance_setDir([0, 0, 0, 10]) Set the drone to fly horizontally
- p1: 0 - left; 1 - right
- p2: 0 ~ 100 cm/s for left/right
- p3: 0 - forward; 1 - backward
- p4: 0 ~ 100 cm/s for forward/backward
litebeeWingAvoidance_setHigh([110]) Set the flight height litebeeWingAvoidance_setVXYZ([0, 0, 0, 10, 0, 0]) Set the drone to fly freely
- p1: 0 - left; 1 - right
- p2: 0 ~ 100 cm/s for left/right
- p3: 0 - forward; 1 - backward
- p4: 0 ~ 100 cm/s for forward/backward
- p5: 0 - up; 1 - down
- p6: 0~100 cm/s for up/down
litebeeWingAvoidance_setYaw([1, 90]) Yaw the drone
- p1: 1 - cw; 2 - ccw
- p2: degree of yaw
litebeeWingAvoidance_takeOff() take off
3.litebeeWingFormation formation litebeeWingFormation_allLand() crash-land
- crash-land can be used for every drone, and it prior to other instruction
litebeeWingFormation_autoLand() land litebeeWingFormation_calibration([5]) calibrate
- p1: # s for execution time
litebeeWingFormation_circle([66, 77, 0, 2, 15]) circle
- p1: QR code No. #
- p2: QR code No. #
- p3: 0 - cw; 1 - ccw
- p4: # half-circle
- the drone circle around the point between #p1 and #p2, circle 2 semicircle, the drone will fly back to the origin
litebeeWingFormation_circleZ([66, 77, 0, 150, 15]) half-circle and adjust its height
- p1: QR code No. #
- p2: QR code No. #
- p3: 0 - cw; 1 - ccw
- p4: fly up for # cm
- p5: in # seconds
- the drone will take the mid-point between #p1 and #p2 as the center and circle #p5 half-circle, meanwhile fly up for #p4 cm
litebeeWingFormation_clear() reset all setting litebeeWingFormation_code([66, 10]) move to QR code
- p1: move to QR code No. #p1
- p2: in #p2 seconds
litebeeWingFormation_codeS(['12 23 27', 15]) move in order
- p1: move to QR code No.#, No.#, No.#, No.#, No.#, one by one
- p2: execution time #s
litebeeWingFormation_codeZ([66, 120, 10]) Move to QR code No. #p1 and adjust its height to #p2 in #p3 seconds litebeeWingFormation_flightNum([1]) Set for drone No.# litebeeWingFormation_missionSend() Send the mission to drone
- wait a few seconds after the mission sent
litebeeWingFormation_missionStart() Mission start litebeeWingFormation_RGB([1]) Set the color of the LED module
- p1: set the LED light as #p1: 0 - black; 1 - red; 2 - green; 3 - yellow; 4 - blue; 5 - purple; 6 - cyan; 7 - white
litebeeWingFormation_setZ([100, 3]) Set the flight height
- p1: height #p1 cm
- p2: execution time #p2 second
litebeeWingFormation_takeOff([100, 5]) Take off
- p1: height of take-off #p1 cm
- p2: execution time #p2 seconds
4.litebeeWingLine Line tracking
litebeeWingLine_autoLand() land
litebeeWingLine_calibration() calibrate
litebeeWingLine_color() The color of the line
- the value can be: R: red; G: green; B: blue
- for example: if litebeewingline_color() == ‘R’
litebeeWingLine_control([1, 15]) Line tracking control
- p1: it can be: 0 - yaw; 1 - speed; 2 - height
- p2: corresponding value # degree; #cm/s; #cm
litebeeWingLine_crossDetrct() At the crossroad litebeeWingLine_crossX() Distance from the cross-point in X-axis litebeeWingLine_crossY() Distance from the cross-point in Y-axis litebeeWingLine_open() Open the line tracking mode
litebeeWingLine_setRGBLed([1, 255, 255, 255]) Set for the LED module
- p1: LED No. #p1
- p2: value of R 0~255
- p3: value of G 0~255
- p4: value of B 0~255
litebeeWingLine_takeOff() Take off
litebeeWingLine_type() The type of line tracking is
- the value and its corresponding type of line tracking
FRLR //route of tracking is ┼ FBL //route of tracking is ┤ FBR //route of tracking is ├ BL //route of tracking is ┃ BR //route of tracking is ┐ B //route of tracking is ┌
- 如: if litebeeWingLine_type() == “FBLR”
5.ghost2 Drone only ghost2_autoLand() land ghost2_calibration() calibrate ghost2_getAnglePitch() the angle of pitch is ghost2_getAngleRoll() the angle of roll is ghost2_getAngleYaw() the angle of yaw is ghost2_getHigh() The flight height is ghost2_getVol() the voltage is ghost2_setDir([1, 1]) set the drone to fly
- p1: 1- forward; 2- backward; 3- right; 4- right; 5- up; 5:down: 7- stop
- p2: speed 1 - slow; 2 - normal; 3 - fast
ghost2_setHigh([110]) Set flight height as # cm ghost2_setMotor([1, 50]) test the rotor
- it’s invalid to test the rotor when the drone is flying. Recommended test rev: 5~50
- p1: which rotor
- p2: rev
ghost2_setYaw([1, 90]) yaw the drone
- p1: yaw 1 - cw; 2 - ccw
- p2: degree of yaw
ghost2_takeOff() take off
6.ghost2Avoidance Obstacle avoiding mode ghost2Avoidance_autoLand() land ghost2Avoidance_backward() Sense the obstacle behind
- it is invalid when the value is 0(max sense range:240cm)
ghost2Avoidance_calibration() calibration ghost2Avoidance_center() Sense the distance from the obstacle above
- it is invalid when the value is 0(max sense range:240cm)
ghost2Avoidance_forward() Sense the distance from the obstacle ahead
- it is invalid when the value is 0(max sense range:240cm
ghost2Avoidance_left() Sense the distance from the obstacle on the left
- it is invalid when the value is 0(max sense range:240cm)
ghost2Avoidance_right() Sense the distance from the obstacle on the left
- it is invalid when the value is 0(max sense range:240cm)
ghost2Avoidance_setDir([0, 0, 0, 10]) Set the drone fly horizontally
- p1: 0 - left; 1 - right
- p2: 0 ~ 100 cm/s for left/right
- p3: 0 - forward; 1 - backward
- p4: 0 ~ 100 cm/s for forward/backward
ghost2Avoidance_setHigh([110]) Set the flight height ghost2Avoidance_setVXYZ([0, 0, 0, 10, 0, 0]) Set the drone to fly freely
- p1: 0 - left; 1 - right
- p2: 0 ~ 100 cm/s for left/right
- p3: 0 - forward; 1 - backward
- p4: 0 ~ 100 cm/s for forward/backward
- p5: 0 - up; 1 - down
- p6: 0~100 cm/s for up/down
ghost2Avoidance_setYaw([1, 90]) Yaw the drone
- p1: yaw 1- cw; 2 - ccw
- p2: degree of yaw
ghost2Avoidance_takeOff() Take off