get_height() function can be used in a loop to measure one height after the other. In this program, you’re going to measure the altitude of your drone as it keeps throttling up.
To start, import the CoDrone Mini and time libraries, create the drone object, and then pair to CoDrone Mini. Next, create a variable called
throttle and set it to 20, which is its power percentage. Then reset your drone’s barometer.
This next part is optional! If you see that your drone is drifting in a certain direction instead of flying straight up, you can include the
set_trim() function to fix the roll and pitch. If you decide to do this, include a sleep command so that your takeoff isn’t skipped.
Include a print command that will print the drone’s initial height, which should be the floor. Next, create a list called
height_data . This will store all of the altitudes that your drone reaches.
Set up a for loop that repeats three times. Your drone should takeoff and throttle up for 1.5 seconds at the percentage stored in the throttle variable, which starts out at 20. The
get_height() function should then get the altitude and add that value to the
height_data() list. The drone should then land and then sleep for 5 seconds, which will give you time to reposition it if needed. Next, a value of 10 should be added to
After the loop, include a command to print the data that was stored in the
height_data() list. Does the data look like what you expected?
Your program should look something like this:
drone = CoDrone_mini.CoDrone()
throttle = 20
drone.set_trim(25,15) # set your own trim values
time.sleep(1) # to avoid skipping takeoff()
print("Initial: ", drone.get_height())
height_data = 
for i in range(3):
time.sleep(5) # gives time to reposition your drone on the ground
throttle = throttle + 10