You are on page 1of 18

SW·AI Educational Contents with AIBot

[03] Control AIBot by Angle


[03] Control AIBot by Angle
[01] AIBot과 친해지기

Learning Goal
Ask and wait, Variables, Repeat

✓ You can learn about the ‘variables’ and use them.

✓ Using the ‘ask and wait’ block, You can control the AIBot by
asking for the axis and angle and receiving an answer.

✓ You can continue to control the AIBot using ‘repeat’.


1. What is Coding

Coding is the composition of sequences of instructions, called programs,


that computers can follow to perform tasks.

It's the process of realizing what you imagine,


and the tool is programming language

But

So Easy & Fast

www.jinirobot.com 3
2. 4 Keywords in Coding

Variables If Repeat Event

A space Process Handle similar tasks Notify


to store data given conditions in succession when to start work

Coding (programming) is not something you memorize like studying for a test.
Only through a lot of coding experience can naturally develop your skills.

www.jinirobot.com 4
3. What is Varibales?
1 Definition

✓ It’s a memory space assigned a name by a program to store data, such as number, text, etc.

2 Make variables in scratch


1
[Stage]

[Code]

5
2

[code] → [Variables]
Enter ‘new variable name’ and click ‘ok’ New variable
→ [Make a Variable]

www.jinirobot.com 5
4. Preview

Mission Control the robot by asking for the axis and angle and receiving the answer!

[1] When the sprite asks for the desired axis and angle, the user enters the answer.

[2] These answers are saved in axis and angle variables respectively and control the robot using them.

[3] Let's continue to control the robot using loop statements.

www.jinirobot.com 6
5. Think about Algorithm

1 | When you start the program, it sets the module speed and returns to the home
position of all modules.

2 | Ask which axis you want, enter the answer, and save it in a variable.

3 | Ask at what angle you want to move, enter the answer, and save it in a variable

4 | Control the robot using the axis and angle saved in variables.

5 | Repeat step 2 through 4 above to continue controlling the robot.

www.jinirobot.com 7
6. Sprites & Blocks

1) Sprite 2) Mainly used blocks

Category Block

AIBot

Sensing

Variables

Control

www.jinirobot.com 8
7. Ready to Code

1 Add Sprites

Click ‘Choose
2
a sprite’

4 Sprite addition completed

1 Delete unnecessary sprites

Search and
3
select sprites

www.jinirobot.com 9
7. Ready to Code

2 Add Variables

✓ Make variables [axis] and [angle] to save your answers respectively

2 Click ‘Make a Variables’ [Code]

3
axis

Enter [New variable name]


1
And click [ok].
[Stage]

Check adding new variables


www.jinirobot.com 10
8. Make Code
Step.0 The first things the program does when it starts

- [When the green flag is clicked]


(1) Set the module speed to 3
(2) Control all modules to home position(90 °)

2 Select
1
module speed
Drga
&1drop
1

Drga
&1drop
3

www.jinirobot.com 11
8. Make Code
Step.1 Control and move the 1st-axis to the desired angle.

① Wait for the robot to perform the action of returning to home position.

② Ask for the desired angle and wait.

① ③ When the desired angle is entered as the answer,


move module 1 to the angle of [answer]

★ Enter various numbers between 0 and 170 and run it!

www.jinirobot.com 12
8. Make Code
Step.2 Move other axes to the desired angle.
- What code can you modify in <Step.1> to move another axis?

주의!! The gripper angle of Module 4 can only be entered between 0 and 90 degrees.
If you input more than 90°, the motor will overheat and cause failure.
www.jinirobot.com 13
8. Make Code
Step.2 Save the selected axis and angle using variables and then move the robot.

① Initialization of variables
- Initialize [Axis] to 0 and [Angle] to 90.

② When the sprite asks for the axis the user wants to move and enters
the answer, this answer is saved in the variable [axis].

① ③ When the sprite asks for the angle the user wants to move and enters
the answer, this answer is saved in the variable [angle].


④ Control the robot using two variables: [Axis] and [Angle].

www.jinirobot.com 14
8. Make Code
Step.4 You can continue to control the robot using loops.

① Use the [forever] block to continuously repeat the content


within the [forever] block

② Add the [wait ○ seconds] block to allow the robot to perform


one action and then repeat the next action.


www.jinirobot.com 15
9. Completed Code

www.jinirobot.com 16
10. [Experiential Program] Control AIBoy by Angle

Mission Control each axis of AIBot by angle!


[1] Add variables that save the angles of each axis of AIBot.

[2] Add sprites that select the axis of AIBot.

[2] When the user selects an axis and enters an angle value as the answer,
the robot will be controlled with the angle you entered for the selected axis.

■ Experiential Program : [aibotscratch103]ControlAIBotByAngle_ex.sb3

www.jinirobot.com 17
10. Experiential Program: AIBot Control by Angle

Download the experiential program


from the jinirobot website(https://www.jinirobot.com/) and use it!

Click ‘English
1 3
in upper menu bar

4
2 Click & download

[download file]

www.jinirobot.com 18

You might also like