WEBVTT

00:00.180 --> 00:05.940
Now that you have added ultrasonics insult to your in a secret, let's understand a few things about

00:05.940 --> 00:12.630
it and how it works so we can better understand then how to control it in the original code.

00:12.870 --> 00:15.240
So what does the ultrasonic sensor do?

00:15.510 --> 00:21.120
Well, it will measure a distance from an object on a wall that is in front of the sensor.

00:21.330 --> 00:31.080
OK, so here we are using the HTC as our four sensor and here are the practical characteristics of the

00:31.080 --> 00:31.550
sensor.

00:31.570 --> 00:36.530
So the characteristic you need to know in order to use it correctly.

00:36.960 --> 00:43.710
So the range of the sensor is between two centimetre and 400 centimeter, which means that, as you

00:43.710 --> 00:51.540
can see here on this diagram, you can start measuring objects and obstacles from two centimeters away

00:51.540 --> 01:00.810
from the sensor up to about four meter here, which is about one hundred and fifty something inches.

01:00.900 --> 01:09.930
If you need the conversion to whatever is to close from the sensor, less than two centimeter will not

01:09.930 --> 01:14.260
be measured and whatever is too far will not be measured either.

01:14.530 --> 01:18.630
OK, then you have the measuring angle, which is 15 degrees.

01:18.670 --> 01:22.340
OK, so on this diagram, it's not exactly 15 degrees.

01:22.370 --> 01:26.280
OK, just so you can understand, but you can see the angle.

01:26.280 --> 01:32.590
So everything which is below that angle or above that angle will not be measured.

01:32.970 --> 01:37.830
So the sensor, as you can see, will measure mostly what is in front of it.

01:37.860 --> 01:44.500
OK, you don't need to remember 15 degrees, just that the sensor will measure what is in front of it.

01:44.520 --> 01:46.420
OK, not on the side of the sensor.

01:46.500 --> 01:52.050
OK, mostly what's in front and from two centimeter to four meters.

01:52.350 --> 01:59.400
And so it's not uncommon in a robot, for example, a mobile robot to have multiple of those sensors.

01:59.580 --> 02:04.950
OK, we can have different sensors for different angles of the robots and different positions.

02:05.420 --> 02:07.680
Now, how does it work?

02:07.680 --> 02:08.460
Very quickly.

02:09.060 --> 02:12.160
So you don't need to understand everything that is written here.

02:12.930 --> 02:16.430
This is just the diagram from the sensor data sheet.

02:16.800 --> 02:19.110
So here, what are you going to do first?

02:19.130 --> 02:23.860
You have seen that we have a trigger in your trigger digital.

02:24.610 --> 02:31.500
What you are going to do to start measuring the distance is you're going to send so the signal will

02:31.510 --> 02:32.580
be low by default.

02:32.940 --> 02:41.880
You are going to send a high signal or 10 microseconds and then look after the ultrasonic sensor will

02:41.880 --> 02:45.060
be triggered and thus will start to measure the distance.

02:45.270 --> 02:48.710
OK, this is an active measurement, not a passive one.

02:49.050 --> 02:56.040
So because this is active, what the ultrasonic sensor will do, it will send burst, OK, with some

02:56.040 --> 02:57.540
wave or some pulse.

02:57.780 --> 03:07.200
It will send it in front of its OK to the range that is in front of it and then it will just wait until

03:07.200 --> 03:09.570
it receives some pulse back.

03:09.670 --> 03:16.530
OK, so if there is an object in front of the sensor, the wave will bounce on the object and will be

03:16.530 --> 03:17.760
returned to the sensor.

03:18.120 --> 03:25.460
OK, so the sensor will measure the duration of how long the wave takes to come back to the sensor.

03:25.860 --> 03:33.110
And then once it has measured this, then you will get some data on the echo pin.

03:33.270 --> 03:40.770
OK, so you have the training and equipping so the equipment will be low by default and then the ultrasonic

03:40.770 --> 03:44.730
sensor will simply but this thing.

03:44.740 --> 03:46.800
So you will read this as an input.

03:47.040 --> 03:53.130
It will put this being high for a certain duration and then low and these duration will be proportional

03:53.130 --> 03:55.050
to the distance of the object.

03:55.260 --> 04:02.190
OK, so if the waves from the sensor comes back very quickly, then the time is quite quick and this

04:02.190 --> 04:04.140
pulse would be quite quick.

04:04.170 --> 04:13.740
Also, if the object is very far at the maximum distance, then these bursts will be longer and the

04:13.740 --> 04:19.710
exact computation for how to measure the distance from the duration here we are going to see that in

04:19.710 --> 04:20.090
the code.

04:20.730 --> 04:21.810
So to quickly, a record.

04:22.440 --> 04:25.920
As a practical recap, you only need to do two things.

04:25.920 --> 04:33.690
First, to send a 10 microsecond high signal on the trigger pin that we are going to do with data.

04:33.690 --> 04:34.020
Right.

04:34.650 --> 04:41.720
And then so this you just need to know it exists, but then you need to simply monitor the echo pin,

04:41.760 --> 04:49.020
OK, and measure the duration of that puts so that ECOFIN will be digital being set as input.

04:49.320 --> 04:52.110
But then how can we measure the duration of that.

04:52.110 --> 04:56.670
But this we are going to use the pulse in function.

04:57.070 --> 04:59.430
OK, and I'm just going to describe quickly.

04:59.690 --> 05:07.940
How does the policing function works so here, this signal here is that one, OK, so it is low and

05:07.940 --> 05:09.740
then it is high and then it is low.

05:10.040 --> 05:11.130
This is a pulse.

05:11.560 --> 05:15.760
Now, what do we want to do is to measure the duration of the outputs.

05:15.830 --> 05:17.570
OK, how do we do that?

05:17.780 --> 05:23.390
Because, well, with digital radio we can know if the signal is low or high, but then how do we measure

05:23.810 --> 05:26.660
the exact duration for the pulse?

05:26.990 --> 05:29.750
Well, we're going to use then the pulse in function.

05:30.110 --> 05:37.310
So when you call the pulse and function the four steps, first one, so you call it, it will start

05:37.550 --> 05:39.160
and then it will wait.

05:39.470 --> 05:42.590
OK, as long as the signal is low, it will wait.

05:42.750 --> 05:50.540
OK, then when the signal rises, so when the signal goes from low to high, the function we start to

05:50.540 --> 05:52.840
measure the duration.

05:53.300 --> 06:00.890
And when the signal goes back to low, the pulse in function will then be able to measure that direction

06:01.130 --> 06:05.510
and it will react in the pulse duration in microseconds.

06:05.780 --> 06:11.720
So you just need to use pulse in function and you can see how it works basically here and you will get

06:11.720 --> 06:14.510
the duration of the pulse.

06:14.880 --> 06:21.380
Also note that this is the high mode, which means that the signal will be first low and then you are

06:21.380 --> 06:25.690
going to measure the bones that is high, but you can also have the opposite.

06:25.710 --> 06:32.480
OK, imagine that the signal is always high and then the pulse is simply the signal going low like this

06:33.110 --> 06:34.790
and then going higher again.

06:35.120 --> 06:40.850
Then you can measure the pulse also with pulse in, but not with the high mode, but with the low mode.

06:41.360 --> 06:46.410
But of course here, because the sensor works like this, we're going to use the high mode.
