Bài 6: Lập trình robot giáo dục KCbot và nhiều cảm biến siêu âm

Kidscode STEM
12 người theo dõi
122 Lượt xem video·20 thg 11, 2023
---------- ★ ----------
* Website: http://kidscode.edu.vn/
* Email: [email protected]
* Hotline: 0888 424 222.
---------- ★ ----------
Hello, teachers and students.
Today, we continue the next session of STEM Robot and Vehicle Science.
In the previous session, we talked about the 4th topic,
that is, robots avoid obstacles using ultrasonic sensors.
In the previous session, we learned about ultrasonic sensors
and how to use ultrasonic sensors
to train robots to meet building obstacles
and cross obstacles in a simple way.
Today, we will continue the 2nd session of the 4th topic,
robots avoid obstacles using ultrasonic sensors.
The content of today's session is divided into 3 parts.
How many ultrasonic sensors are there?
First, we need to determine the number of ultrasonic sensors
so that it is adequate for our application.
Next, I will take a typical example.
We use 3 ultrasonic sensors to apply in our robot.
The 3rd step is to simulate and run on the field to see how it reacts.
First, how many ultrasonic sensors do we need?
1 ultrasonic sensor like this robot
or a lot of ultrasonic sensors like this robot?
How do we use 1 ultrasonic sensor?
How do we use a lot of ultrasonic sensors?
There are also cases where we use 2 ultrasonic sensors like this
or 3 ultrasonic sensors like this.
This is a picture of a robot with a lot of wires
capable of using Arduino.
This is a robot that uses a module to make it look neater.
These are some images that you will often see.
1 ultrasonic sensor, a lot of ultrasonic sensors, 2 ultrasonic sensors, 3 ultrasonic sensors.
So how many ultrasonic sensors are enough?
It depends on our geography and layout.
There are also robots that use full ultrasonic sensors.
All directions can be used to process ultrasonic sensors.
This way, we can be sure that no objects will be damaged.
As we know from the previous article,
the ultrasonic sensors we use are HCE-R04.
The frequency range of the ultrasonic sensor is about 30 degrees.
Suppose each beam like this represents a 30-degree angle.
As we can see here,
we need to have a lot of sensors to be able to manage more angles.
For example, this is about 180 degrees.
We need about 6 sensors like this.
However, if we can see 3 or 4 ultrasonic sensors in front,
it may not be necessary.
Because this angle is relatively clear.
If we only use it to go straight, left and right,
we may only need 3 sensors in these 3 angles.
The next question is how to arrange the sensors to make them suitable.
For example, I am using 3 ultrasonic sensors.
Our goal is to use a lot of ultrasonic sensors to upgrade the robot's vision.
Here we use 3 sensors.
Suppose we put 3 sensors in fixed angles next to each other.
Here we are talking about fixed angles.
These 3 sensors do not change their positions next to each other.
In this way, each module will be able to measure a distance to the object.
For example, module 1 will be able to measure the distance to the object in front.
Module 2 will be able to measure the distance to the object in front.
Module 3 will be able to measure the distance to the object in front.
We will use these 3 sensors to determine whether the robot is in a safe position or not.
A safe position is when we do not encounter obstacles in the designated area.
For example, about 20 cm, 15 cm or 5 cm.
It depends on the path we take and the way we define the safety level.
For example, in a safe position, we will let the robot continue to travel.
For example, continue to go straight.
Conversely, if it is not safe, we can let the robot turn left or turn right.
It depends on our design.
I also refer to the blog at max.dunoo.blogspot.com
You can also access this link to see more details.
We will arrange the sensors like this.
For example, each sensor has an observation angle of about 30 degrees.
First, we will remove 2 sensors, module 1 and module 3.
Module 2 is the sensor in front of the robot.
We define it.
And module 3 is the distance we will measure in front.
Distance from the sensor to the object.
We set module 2.
Then we set module 3.
And rotate a 30-degree angle to the left.
We will mark a point like this.
And we will set sensor 1.
Similarly, we will set sensor 3.
This is a way to set sensors.
This 30-degree angle can be set more.
It depends on the calculation we need to solve.
We can set this distance to be wider.
This is a theoretical example, so I can set it closer.
So how do we do it?
With the above parameters, we can extract useful information from these 3 sensors.
Suppose we have some parameters to care about.
H1, H2, L1, L2, L3, R and P.
Based on the formula, you can calculate these distances.
After a series of calculations, you can calculate H1 by dividing D1 by 2 plus 21.
H2 by dividing D3 by 2 plus 21.
21 here is all centimeters.
Similarly, L1, L2, L3.
After calculating based on some parameters and formulas,
we can calculate the distance.
Here I do not analyze the calculation process in detail.
You can calculate it yourself.
Or you can look at the link above.
Here I only talk about how to use the useful information.
H1 and H2 are the position of our robot.
These are 3 sensors.
HCR041, HCR042 and HCR043.
This is the front of the robot.
And D1 is the distance from sensor 1 to object 1.
D2 and D3 are the distance from sensor 2 and 3 to objects in front.
These 3 sensors may be 3 long sensors.
It can also be a path like this.
For example, the next day we will have a maze or a tunnel.
These sensors are continuous.
However, we care about these 3 distances.
D1, D2 and D3.
H1 is the distance from the center of object 1 to the center of object 2.
H2 is the same.
Let's say our robot is arranged like this.
We want to go through objects 1 and 2.
We have to do this.
There are some simple algorithms.
We call Rw the width of the robot.
S is the safe distance that we want to limit the robot.
We can set S to be large or small depending on our algorithm.
The larger S, the safer it is.
But on the other hand, it will have to pay a price.
Our processing will be more expensive.
The smaller S, the better the processing will be.
A simple algorithm like this.
Let's start the program.
We have 3 sensors here.
Sensor 1, Sensor 2 and Sensor 3.
Each sensor measures the distance to the object in front of it.
Next, we will calculate all the parameters.
D1, H1, D2, D3, H2, L1, L2, L3.
We will calculate all these parameters according to the above algorithm.
If H1 is larger than the width of the robot plus a safe distance S.
If H2 is larger than the width of the robot plus a safe distance S.
This means that the robot will go straight.
If correct, we will let the robot go straight.
If not, it means that one of these distances is smaller than our safe distance.
Let's compare.
If D1 is larger than D3.
This means that the distance on the left hand side is larger.
We will turn 30 degrees to the left.
Let the robot turn to the left to go to the wider side.
Then let the robot go straight.
Conversely, if D3 is larger than D1.
This means that the distance on the right hand side is larger.
We will turn 30 degrees to the right.
Then let the robot go straight.
We will turn back and continue to measure a new algorithm.
Measure, calculate, compare and decide.
This is a simple algorithm that we can use to calculate the robot.
With this basic algorithm,
you will arrange the robot according to your algorithm.
The robot may be close to each other or wider.
It depends on the relationship between the robot and the distance we have to cross.
For example, in the next round, we need to cross a tunnel.
You know that this tunnel is already set up.
This week, we will announce the details of this competition.
The tunnel has a fixed shape.
You base it on the same algorithm as today.
You will try to calculate how to arrange these sensors.
You can use 2 sensors or 3 sensors or 5 or 6 sensors.
It depends on you.
On the stembox, we can hold up to 7 sensors.
If you use IOs for other external devices, you have to reduce it.
Our goal today is to help you optimize your solution.
To make the robot go smoothly and get past the tunnel as quickly as possible.
Here, I only talk about the arrangement of sensors.
To filter these sensors, it will be in another part.
Maybe at the end of this course.
In other words, in the higher parts.
Our robot to run smoothly and smoothly,
we have to arrange the sensors well and filter them.
This is another very important step.
Let's watch a video I downloaded.
In this movie 2.2, we will see how to wire and program 3 of 6 ultrasonic sensors.
Two of them look left and one looks forward.
After the proper programming, the robot can follow an obstacle on one of its sides as you can see in this movie.
We will concentrate on these three sensors.
This sensor looks for the object which appears at an angle of 90 degrees with the direction of travel.
We have to program a threshold value for this sensor.
If an object appears in a distance which is shorter than defined threshold 90 and longer than 0 cm, the robot will turn left.
After that, another sensor starts to see the object.
This sensor looks for object which appears at an angle of 30 degrees with the direction to travel.
We have to program a threshold value for it too.
The robot continues to turn left until sensor on the front notices the object.
Then, based on threshold min and threshold max values, the robot decides what it will do.
Whether it wants to go forward or backward.
We have been talking about it before in the movie 2.1.
You can find all links in description below.
We add two ultrasonic sensors to our wiring diagram.
Then solder some extra pins to motor shield board.
Before we go to programming window, I will show a diagram which presents the way we will program our conditions.
Let's say that these blue boxes are our IF conditions.
In order to follow the object properly, we have to set up priorities to IF conditions.
Our objective is to make the robot follow or avoid an object.
But it can't do this if this object is on the side.
Next, let's move on to the third part of today's lesson.
We will see how to simulate on the Qiskode software and how to program using 3 ultrasonic sensors.
Before we watch this video, I would like to describe how we will arrange 3 ultrasonic sensors.
First, we will arrange 3 ultrasonic sensors in a way that they are not completely close to each other.
Then, if the ultrasonic sensor is in the middle and the distance is the largest, we will continue to go straight.
If the sensor is smaller than the previous section, we will continue to compare the two left and right sensors.
If the sensor is larger than the previous section, we will continue to compare the two left and right sensors.
Today, we will go to the next section.
In this section, we will program multiple ultrasonic sensors with the STEMBot framework.
This is the programming exercise of the previous lesson.
We will program an ultrasonic sensor with the STEMBot framework.
In order to simulate, you will need 2 ultrasonic sensors.
You will need 2 ultrasonic sensors.
There are 2 ultrasonic sensors with 1 left and 1 right.
We will have 2 more sensors, which are 2 and 3.
We will connect 2 more TRIG and ESO pins.
Go to the terminal 1, select Default, and set the name of the pin.
The name of the pin is T2 and E2.
The name of the pin is T3 and E3.
The name of the pin is T3 and ESO 3.
The name of the pin is T3 and E3.
After setting the name, we will connect the STEMBot framework.
We will use pins 9, 10, 11 and 13.
We will connect pins T2, 13, E2, 11, T3, 10, E3 and 9.
The name of the pin is T2, E2, T3, E3.
Connected.
To simulate, we will need a controller to control the STEMBot.
Go to the TRIG and connect to pin 2.
Go to the terminal 1, select Default, and set the name of the pin.
The name of the pin is T3 and E3.
Connected.
To simulate, we will need a controller to control the STEMBot.
Go to the terminal 1, select Default, and connect to pin 2.
Go to the terminal 1, select Default, and set the name of the pin.
The name of the pin is T3 and E3.
Now we can simulate STEMBot.
To simulate, we will need a controller to control the STEMBot.
First, we will check the parameters of each pin by sending the data to the computer.
Go to the TRIG and set the speed to 9600.
Next, go to the CARD SPOT and set the speed to 9600.
To send the data, go to the TRIG and set the speed to 9600.
First, you will assign a name to each pin.
As in the example, we have the pins 1, 2, and 3.
Here, I will assign a name.
You continue with the version.
I will assign the first pin.
And you put it in the zero-in command.
Here, I will write the password CP1.
After sending CP1, I will send the value of each pin.
Continue.
You take the password and send it.
This is the zero-in command.
Then go to the CARD SPOT and take the value of each pin.
You put it in the zero-in command.
Continue.
To make it faster, double each block.
You put the right pin in the first block.
Create a star.
Here, we will do the second variation.
Continue.
Double.
Here, you will do the second variation.
You move the check pin to pin 13.
You move the check pin to pin 13 and the extro to pin 11.
The check pin is the forward pin.
The extro will receive.
You will replace the correct pin to pin 13 and 11.
Do the same with pin 3.
You will change it to CP3.
And the pin is here.
The check pin is pin 10.
The extro is pin 9.
Finally, we will go to the time table, you take the image like this, then you will go to the black zoid to check the error.
If the verification is successful, you will return to the sample.
You click on the StampBot tab, select the bitcode sketch.bilo.h, then you will run the sample.
You will see that the value of variable 1 is 26.16, the value of variable 2 and variable 3 is 30.
We will adjust the value of variable 2.
Here, the variable receives the value after the value below is smaller than the value of the variable below which is smaller than the value of 47.
We will reduce it to 30.
You will see that the value of variable 2 is 300cm, the value of variable 2 is 100cm.
You will see that the value of variable 1 is 26, the value of variable 2 is 123, the value of variable 3 is 111.
So, we have completed the test to check the value of each variable.
Now, we will connect the hardware.
You can see that I already have 2 microprocessors here.
Now, I will connect them.
First, we will connect the 5V cable from the power supply to the StampBot.
You will plug it from the 5V pin to the StampBot.
Similarly, with the ground pin, you will plug it into the ZND pin and connect it to the StampBot.
Now, we will connect StampBot and StampBot.
We use 2 wires to connect the power supply to ZND and 5V.
The orange wire is from the 5V pin and the yellow wire is from the ZND pin.
You will plug it into the 2 wires and plug it in.
The orange wire is connected to the CC pin of StampBot.
The yellow wire is connected to the ZND pin.
For example, with the ground pin, we also have 2 wires, orange and yellow.
The orange wire is connected to the 5V pin and the yellow wire is connected to the ZND pin.
Similarly, with the ground pin, the orange wire is connected to the CC pin and the yellow wire is connected to the ZND pin.
Next, we will connect the hardware.
Here, we use 2 green wires, the ground pin and the ground pin.
Next, we have 2 pins, the CHIC pin and the ESCO pin.
We will connect 2 wires to each other.
Here is pin 2.
The CHIC pin is connected to pin 13.
You will connect the CHIC pin to pin 13.
Similarly, the ESCO pin is connected to pin 11.
Next, you will connect the same to the remaining pins.
Pin 3.
We will also connect the CHIC pin and the ESCO pin.
The CHIC pin is connected to pin 10.
The ESCO pin is connected to pin 9.
Here, we have finished connecting all the pins to our hardware.
Now, we will start the program.
First, we will connect the cable to the robot.
The other end of the cable will be connected to our hardware.
Now, we will start the program.
First, you will go to the Connection tab.
Select the Connection port.
Click on the Connection port.
Here is pin 4.
You will choose Fire.
Click Return.
After that, you will press the Play button to start the program.
As you can see, the program is successfully started.
Now, we will run the program.
You will go to the Hardware tab.
Select the Display tab.
As you can see, on the robot, we have selected 9x6.
Select the port.
We will select port 4.
Click Connect.
As you can see, port 1, port 2, and port 3 are displayed.
Now, we will try to turn on the robot.
We will turn on the robot's eyes.
This is port 1.
You will press the Power button.
The robot will automatically go down.
We will press the Power button first.
This is port 1.
As you can see, port 1 has a value of 5.4 cm.
Similarly, port 2 has a value of 6.86 cm.
Similarly, port 3 has a value of 8.7 cm.
As you can see, the sensors are working normally.
They have returned the values to us.
Now, we don't want the robot to be confused.
So, we have checked the data from the sensors.
Now, we will adjust ourselves.
That is, we keep the robot moving.
When we turn on the sensor, the robot will check which side has a greater distance.
Then, it will turn to that side.
Now, we will leave the program.
In order to check which side has a greater distance, it will turn to that side.
You will need to use the program.
You will go to the program.
You will choose the program name.
The purpose is to adjust the values of the sensors on the left side.
You just need to take the next one, the 13th and the 11th
It will be like this
And we do the same with the last one
Type the variable
The right variable
And we will leave the rest
And now, to check, we will use the values
The middle, the left and the right
Similarly, you take the traditional zero in
You enter the variable
Select the name
And then, you will
Change it to
The right one
And the left one
If you click here, the variable will appear automatically
The left one
But the rule is
We will check if the values are correct
Then, we will go to the program
You will get the rule if it works
And notice, you will click on the braces
It will appear on the window
You will drag the zero and the zero
The zero will appear at the bottom, if it works
Next, we go to the logic
Take the table
Now, we will check if there are objects in the middle
If there are objects, we will handle it
You will take the middle value
And enter the rule
Next, we will go to the arithmetic value
Here, we will check if the middle value is smaller than 10 cm
Then, we will stop the robot
Stop moving
We will stop in 200 milliseconds
So that the robot can be stable
Then, we will continue to
Determine the value of the two variables
The left and the right
Continue for the right
So, we have the left and the right
Now, we will compare
Continue, we will go to the logic
Take the result
Now, we will compare the left and the right
We will take the arrow
First, if the left is smaller than the right
The left
The back
And the right
If the left is smaller than the right
That is, if the right is bigger
Then, we will go to the right
You will press Ctrl C
We will go to the right
The speed is set to 50
We will go in 500 milliseconds
And the back
You will click on the arrow
If not
If the left is bigger than the right
And if not
If the left is bigger than the right
Then, we will go to the left
You will click on the arrow
Turn right to turn left
And the time is also 500 milliseconds
Done, we will go to the back
If not
If the back and the middle
If the value is greater than 10
Then, we just need to move forward
You can move up
The speed is set to 50
So, the process is done
Now, we will run the simulation
Before running the simulation
You will translate
If the simulation is successful
You will run the simulation
This is the first value
This is the middle value
The middle value is set to 33
Greater than 10
So, 20 seconds we are turning forward
Turn back
Now, we will set the value to 10
Here
This is 4
And the left side
The right side is greater than the left
This is the second value
This is 145
The left side is 135
So, the robot will turn to the right
Turn back
I will set the value
The left side is greater than
Here
Notice that the left side is 167
And the right side is 145
The left side is greater than the right
So, our robot
The robot will turn to the opposite direction
To the left
So, we are successful
Now, we will run the simulation
In this part of the program
You will see 2 times
The first time, the robot will go straight like this
When the distance to the front
It is smaller than an allowed radius
It will measure the left and right
See the right side is wider
The robot will turn to the right
Similarly, here
The robot will turn to the front
It will measure the left and right
At this time, the left side is wider
The robot will turn to the right
So, we are successful
Now, we will run the simulation
In this part of the program
You will see 2 times
The first time, the robot will go straight like this
When the distance to the front
It is smaller than an allowed radius
It will measure the left and right
At this time, the robot will turn to the front
Similarly, here
The robot will turn to the front
It will measure the left and right
At this time, the robot will turn to the front
That's all for today
If you have any questions
Please feel free to contact us
Goodbye
