Lesson 8. Block coding with a coding drone (2)
[Outline]
In this lecture, we will code to control the drone by pressing the button on the remote controller.
Isn't it strange to think that the drone is controlled by pressing a button instead of using the lever on the remote controller?
If you use the remote controller button event block among the blocks for coding drones, you can give movement commands for each button.
Here we are going to take off and land and do basic flight (forward, reverse, move left, move right).
So shall we start?
[Thinking of code]
In Rokitbrick, there are two types of remote controller buttons and lever-related blocks.
Remote Controller Button Event Block |
▶ Generates a signal when a button on the remote controller is pressed and returns a True value.
|
|
|
button type
|
1. Front Left Top/Bottom Button
2. Front right top/bottom button 3. Top Left/Right Buttons 4. Bottom left/right button 5. Center Up/Down/Left/Right Buttons (=Trim Button) |
Remote Controller Joystick (Lever) Event Block |
▶ When the joystick (lever) of the remote controller is moved in a specific direction, it generates a signal and returns a True value.
|
|
|
Joystick (Lever) Direction(Common left/right)
|
Total 9 directions: top, top left, top right, bottom, bottom left, bottom right, left, right, center
|
As follows, assemble and use the conditional block of Rocket Brick as a judgment block.
|
Let's code the drone to operate as follows depending on the remote controller button.
|
|
Take off: lower left button
|
Landing: bottom right button
|
|
|
1m forward: button above center
|
Reverse 1m: button below center
|
|
|
Move 1m left: Center left button
|
Move 1m to the right: Center right button
|
So first, think about how to create the code for each command.
Command
|
code
|
Explanation
|
take off
|
|
If you press the lower left button (=S button) on the remote controller, the drone will hover for 3 seconds after take off.
|
to land
|
|
If you press the bottom right button (=P button) on the remote controller, the drone will hover for 3 seconds and then land.
|
go forward 1 m
|
|
The button above the center of the remote controller (=trim▲button) to start the dronem Hover for 3 seconds after moving forward.
|
back 1m
|
|
The lower center button on the remote controller (=Trim▼button) to start the dronem Hover for 3 seconds after reversing
|
move 1m to the left
|
|
The button above the center of the remote controller (=trim◀button) to start the dronem Move left and hover for 3 seconds.
|
move 1m to the right
|
|
The button above the center of the remote controller (=trim▶button) to start the dronem Move right and hover for 3 seconds.
|
Now let's combine the above codes to make one code.
code
|
Explanation
|
|
Put all the code for each instruction into a repeat block and assemble it into a single code.
Because RockitBrick is a sequential coding program, blocks are executed sequentially only once. Therefore, the repeat block must be used to continuously detect a button action signal from the remote controller and execute the command. |
[Coding and running]
1. Coding
Let's make code by assembling blocks in Rokitbrick.
2. Running
When you have created the code, click the Start button to run it.
Before executing, first check the following:
A while! Check it out one more time before running the drone autonomous flight code on Rokitbrick!
1) Secure a safe distance (2m or more) from the drone. 2) Make sure there are no people or obstacles around the drone. ☞ Make sure that there are no people or obstacles in the path by predicting the direction and distance of the drone's movement in the code. 3) Check how to forcefully stop the drone in case of a malfunction of the drone or a rocket brick error. |
When you are ready, run the code and press the bottom left button (=S button) on the remote controller.
Do drones take off? Then, press the center up, down, left, and right buttons (=trim button) in sequence and check if the drone flies according to the command.
If it doesn't fly as expected, check which part is wrong, correct it, and try again.
[Organize]
In this lecture, I tried coding to control the drone by pressing the button on the remote controller.
Isn't it fun to control the drone with buttons instead of levers on the remote controller?
In this way, by using the remote controller button and lever event block, you can not only fly the drone as if you were actually controlling it, but you can also make your own remote controller by coding the drone to operate differently from the actual control method.
1) When you press a button on the remote controller or move the joystick (lever), you can use the remote controller event block to make the drone perform a specific command.
2) There are two types of remote controller event blocks (button event block, Joystick (Lever) event block), It is used as a judgment block of the conditional block. 3) Since the remote controller event block must continuously check whether a button or joystick (lever) operation signal has occurred, the repeat block is used together. |
Coding with a coding drone (English)
- Make friends with Coding Drone!
- Let's fly a coding drone
- I code cards with a coding drone (1)
- I code cards with a coding drone (2)
- I code cards with a coding drone (3)
- Motion coding with a coding drone
- Block coding with a coding drone(1)
- Block coding with a coding drone (2)
Modified : 2021.7.16