Snap Lesson 10: Remote Control
In this lesson we will learn about how to manually fly the CoDrone
So far we have only created autonomous programs. Now we will create a remote controlled program.
We will use the if statements form the last lesson to check which keys are being pressed. We will need to assign 8 keys for the controls, I will use the following setup:
- Throttle Up: w
- Throttle Down: s
- Yaw Left: a
- Yaw Right: d
- Pitch Forward: up key
- Pitch Backwards: down key
- Roll Left: left key
- Roll Left: left key
- Roll Right: right key
We need to be sure of two things. Firstly to takeoff when we start the program, and then to have the control code inside a forever loop so that it will keep flying:
Then we will have a stack of if else statements for the Throttle. The first if statement will check if the w key is pressed, if it is we will set the throttle to 75. Then we will have another if else block inside the else. This one will check if the s key is pressed, if it is then it will set the throttle to -75. Then in the else of this if statement we will set the throttle to 0 since no throttle key is being pressed we don’t want to move at all.
Then we need to send the these values to the CoDrone. We will add in a sending command and a short delay so that we do not over send commands to the CoDrone.
We will also need to add in our emergency stopping code, so that we can test the throttle controls.
Then we will add in the controls for each of the other directions, we will start with the yaw.
Then we will add in the movements for the roll and the pitch.
Activity: Fast Precise Flying
The challenge is to enable the CoDrone to fly both precisely and to be able to fly quickly.
Challenge Rules:
- You should make a code that lets you complete two races, one is landing on a target platform, the other is a race around a race course.
- There are two options, either find a speed that you like, or create a speed key. If the key is pressed then it will fly at one speed, and if it is not pressed it will fly at another speed.