Air vehicles move a little differently than land vehicles. Since land vehicles operate in two dimensions (we can call these X and Y), they only move forward and backward or left and right. Air vehicles, however, move in three dimensional space (X,Y, and Z). This means that they not only move in the same directions as a land vehicle, but they also move up and down and can spin. Because of this we have different terms to describe how air vehicles move through the sky as you will see below
Movement Commands
Key Terms
Parameter: a placeholder for a value that a function will use. These let the user know that values are required for the function to behave properly.
Argument: the actual value that a user puts into a function when it is called. For example, in the code drone.set_roll(25) the value 25 is the argument for this function.
There are three components to each movement of the drone that you will specify in order to make it behave properly:
- The movement you want the drone to make (Roll, Pitch, Yaw, Throttle)
- How much power to apply to the movement (How fast you want the movement to be)
- How long you want the movement to execute or last
As you see in the image above, each of the movement commands follows the same format. You specify the drone object that you want to move, tell it which of the movement commands to do, and then specify what direction and speed you want the movement to occur. When setting the speed and direction, you put into the commands an argument value ranging from -100 to 100. The values 0-100 are the percentage of the drone’s power you want to use. 0 would be no power while 100 would be full power (100%). Whether the argument value is positive or negative determines the direction the drone will take. For example, -50 and 50 will move at the same speed but in opposite directions.
BE CAREFUL! Setting the drone’s power to 100% will make it move very quickly and result in collisions with objects. We recommend that you start at lower power settings and work your way up to higher settings once you understand how quickly the drone moves.
Calling the function takes care of steps 1 and 2, but not step 3. You will notice that there is no parameter in the movement commands that tells the drone how long to move. This is because the movement commands are all SET commands. What this means is that we are changing the value of a variable (the movement) to a new value. We will learn the difference between setter and getter commands and what variables are in later lessons. Since we are only setting or changing the speed and direction of the drone with the movement commands, we have a separate function called move that tells the drone the duration or time that it should move:
move(int or decimal seconds)
drone.move(1) # has the drone move for 1 second
drone.move(2.5) # has the drone move for two and a half seconds
By combining the movement and move commands, we can make the drone move in a specific direction for an amount of time. So, each time we program one of the movement commands, don’t forget to pair it with a move() command as well!
Roll
This function controls the CoDrone Mini’s horizontal, or side to side, movement. Positive roll will make the CoDrone Mini move to the right, and negative roll will make the drone move to the left. This will look like the drone is sliding to the left or the right. Take a moment and consider how the drone’s propellers generate thrust. What do you think is happening when the drone rolls right or left?
The general format of this command can be seen here:
drone.set_roll(power) # power represents power out of 100%
# power can be between -100 and 100
To test out this code, enter the following code into your roll.py file between the takeoff and land functions:
drone.set_roll(10) # setting the roll value to 10
drone.move(1) # drone will roll for 1 second
What did you observe? The drone should have moved slowly to the right for 1 second. Try making the drone roll to the LEFT for 2 seconds. What does your code look like?
Pitch
This is the CoDrone Mini’s forward and backward tilt. Positive pitch will make the CoDrone Mini tilt and move forward, and negative pitch will make the CoDrone Mini tilt and move backwards.
drone.set_pitch(power) # power represents power out of 100%
# power can be between -100 and 100
To test out this code, make a copy of your roll.py file and call it pitch.py. Now change set_roll to set_pitch. You can leave all other values the same. So your code should look like:
drone.set_pitch(10) # setting the pitch value to 10
drone.move(1) # drone will pitch for 1 second
What did you observe? The drone should have moved slowly forward for 1 second. Try making the drone move backwards for one and a half seconds. What does your code look like?