Flight Control

Now we will create a remote control program. Last time for the challenge you used many different buttons to get the CoDrone to fly in a square, and each of these buttons made the drone move a certain distance. However for our code we want it to move while we are pressing the button, not move a second and then have to press it again. To do this we will not use the Screenshot (171)blocks, but instead will use some new ones. If we look under the sensing tab, we will see the Screenshot (173)  block. Notice that it has the diamond ends, just like the condition part of our if statements from before. We can use these with our if statements to see if a key is pressed, and set the values accordingly.

To control the CoDrone for each value (throttle, yaw, roll, pitch) we have three possible values to set it to, positive, negative, and zero. So we will use two keys for each direction, one for positive, one for negative, and no key for zero. To do this we will use two if else statements, with the second one inside of the else part of the first.

Then we will add in the values for each direction, I will start with throttle.

RB Flight 1

Then we need to send the values to the CoDrone. We will use the “Sending command” block  to do so. But we also want our code to run more than once, so we will put in inside of a forever loop.

RB Flight 2

Make sure to add in your kill button from lesson 2 so that we can easily stop the CoDrone.

RB flight 3

Try it Out

Now we will add in another set of if statements for each of the other directions. Pick your keys for each direction. I chose a and d for yaw, up and down arrows for pitch, and right and left arrow keys for roll. You are welcome change these. Just add each of the sets of if statements after the throttle one, but before the sending command.

Screenshot (175)

Try it Out