Enhanced moving

It is now time for the last important movement and movement-related commands.

The move()-command combines all the basic movements that have already been introduced. So you can make the drone fly to the right, backwards, down and turn to the right at the same time; and with different speed in each direction.

##### Suggested clean drone startup sequence #####
import time, sys
import ps_drone                                    # Import PS-Drone-API

drone = ps_drone.Drone()                           # Start using drone
drone.startup()                                    # Connects to drone and starts subprocesses

drone.reset()                                      # Sets drone's status to good
while (drone.getBattery()[0]==-1): time.sleep(0.1) # Wait until drone has done its reset
print "Battery: "+str(drone.getBattery()[0])+"% "+str(drone.getBattery()[1]) # Battery-status
if drone.getBattery()[1]=="empty":  sys.exit()     # Give it up if battery is empty

drone.useDemoMode(True)                            # Set 15 basic dataset/sec (default anyway)
drone.getNDpackage(["demo"])                       # Packets, which shall be decoded
time.sleep(0.5)                                    # Give it some time to awake fully

drone.trim()                                       # Recalibrate sensors
drone.getSelfRotation(5)                           # Get auto-alteration of gyroscope-sensor
print "Auto-alt.:"+str(drone.selfRotation)+"dec/s" # Showing value for auto-alteration

drone.takeoff()                                    # Fly, drone, fly !
while drone.NavData["demo"][0][2]: time.sleep(0.1) # Wait until drone is completely flying

##### Mainprogram begin #####
print "Drone is flying now"

print "Drone does a complex movement"
leftRight       = -0.02        # Move with 2% speed to the left
backwardForward = -0.1         # Move with 10% speed backwards
downUp          =  0.3         # Move with 30% speed upward
turnLeftRight   =    1         # Turn full speed right
drone.move(leftRight, backwardForward, downUp, turnLeftRight)  # Do movement

timeToFlight    = 2.5          # Time to move at all
refTime         = time.time()  # Start-time
end             = False
while not end:
    if drone.getKey():                       sys.exit() # Stop when any key is pressed
    if time.time()-refTime >= timeToFlight:  end = True # Stop when max flight-time reached

print "Drone stopped movement"
drone.stop()
time.sleep(2)

print "Drone turns 120 degree to the left"
drone.turnAngle(-120,1,1)      # Turn 120 deg to the left, full speed, accuracy of 1 deg
Download sample moveTurn.py

The move()-command expects four values for the directions 'right', 'forward', 'up' and 'turn right':
move(right, forward, up, turn right)
Like the basic movements, the range for the speed-value is 0.0 to 1.0, representing 0% to 100% of the drone's top speed. By setting a negative value, the drone will reverse its direction; for example, the value -0.5 for forward-speed lets the drone fly backwards.

The command turnAngle() lets the drone turn to the left or the right in the exact given degrees. This command requires values for a certain degree in order to turn to the right and the speed to do so. If you use a negative degree value, the drone rotates to the left. The command turnAngle() blocks which means that following commands are not processed until turnAngle() has been executed. So there is no clean way to stop the movement, for example as an emergency stop, until its done.
Optional, you can set a value for accuracy, the allowed mismatch of the given degree. The default value is ±0.005° and ±0.1°, depending on the drone’s Demo-Mode-status. The less accurate the turn is, the faster is it done. The maximum turn is a half rotation; the angle-value can be at most ±180.0°.
Known bug: this command is not able to perform an exact turn of 180.0°; instead, the drone tries to find its destination angle until the battery is dead and without the possibility to stop the drone neatly. This bugs will be fixed soon.

In order to hold position and not drift away slowly in any direction, the drone's sensors for orientation need to be calibrated on horizontal ground. The drone's firmware does a good job recalibrating these sensors in case of inaccuracy using the sensors for acceleration. If it is necessary to recalibrate the sensors later, use the command trim(). Use it before takeoff() and give the drone a second to calibrate.

Technically, the accuracy of a sensor's measurements differs from sensor to sensor also depending on external influences like temperature. So the gyroscope-sensor for rotation slowly alters its value, even if the drone is on the ground and not moved.
If it is necessary to be exact, you can get the false measured self-rotation by the command getSelfRotation(val) in degrees per second, stored in variable selfRotation. This command expects the time to measure as value. Of cause: the more time you give to measure the more accurate is the result. turnAngle() considers the value of selfRotation for exact turns.

Note: With the firmware version 2.2.6, the automatic value alteration of the gyroscope-sensor was around 0.0185°/sec. Parrot fixed this auto alteration with the firmware version 2.3.3, but now the entire drone rotates, about 360° in 20 minutes, without any recognition of the gyroscope-sensor. If you yet have not updated, the suggestion is to stay with version 2.2.6. Firmware-version 2.4.8 has not tested, yet.