1
00:00:05,980 --> 00:00:09,560
Hey, now we are going to read the values of the encoders.

2
00:00:09,580 --> 00:00:17,080
Each motor have three magnetic encoders and we will get three value encoder spin are connected to 2322

3
00:00:17,200 --> 00:00:21,940
for the left motor, 19 and 18 for the right motor.

4
00:00:21,940 --> 00:00:27,400
We are going to digitally these pins and convert it to the encoder texts.

5
00:00:27,430 --> 00:00:34,480
We use the encoders for the odometry calculation that how much the robot has traveled after implementing

6
00:00:34,480 --> 00:00:35,920
some mathematical equation.

7
00:00:36,940 --> 00:00:41,230
So let's modify our micro Ros code.

8
00:00:41,560 --> 00:00:46,870
Now we are going to make two Publisher one will be publishing the left encoder ticks, the other one

9
00:00:46,870 --> 00:00:49,630
will be publishing the right encoder ticks.

10
00:00:49,900 --> 00:00:59,290
Now we will import Int32 because this is going to handle a bigger number this time zero and 32.

11
00:00:59,320 --> 00:01:05,890
As we have created the publisher for the Battery, we are going to create two publishers more.

12
00:01:05,890 --> 00:01:10,690
And now we have to define the pins for the encoders of the motor.

13
00:01:10,720 --> 00:01:18,340
The C1 of the left motor is connected at 23 and C2 for the left motor is connected at 22.

14
00:01:18,340 --> 00:01:26,980
And in the case of the right motor, the C1 is connected at 19 and C2 is connected at 18 right it here

15
00:01:26,980 --> 00:01:28,090
encoder spin.

16
00:01:28,090 --> 00:01:34,210
And now we will be creating the variables that will be storing value of encoder from the left and right

17
00:01:34,210 --> 00:01:34,570
motors.

18
00:01:34,570 --> 00:01:41,020
Also their particular prototype function that will be calculating the number of ticks.

19
00:01:41,050 --> 00:01:48,640
Now we are going to add two publisher in the world setup as we have added some previous publishers.

20
00:01:48,640 --> 00:01:51,220
And here it is the battery publisher.

21
00:01:51,220 --> 00:01:54,280
Under this, we will be adding our two new publishers.

22
00:01:54,400 --> 00:01:58,510
These two are the topic of publisher, the left motor tics and the right motor ticks.

23
00:01:58,510 --> 00:02:04,690
And down here we will not need to change anything because these additional publisher will be publishing

24
00:02:04,690 --> 00:02:08,410
the value inside the timer callback function.

25
00:02:08,410 --> 00:02:16,690
So will we will not change any parameter here because we have already set up the timer and it sets will

26
00:02:16,720 --> 00:02:19,180
be three again and above here.

27
00:02:19,180 --> 00:02:24,160
We also have to set up the pins and we will set up two input mode.

28
00:02:24,160 --> 00:02:31,120
And we have also used the interrupt convention when the Esp32 pin will be detecting a change in the

29
00:02:31,120 --> 00:02:38,050
pin, it will go to the callback function and we are going to define these two callback function in

30
00:02:38,050 --> 00:02:40,870
the end like this.

31
00:02:41,020 --> 00:02:48,070
So these two are the callback functions for the left encoder and the right encoder we have to set same

32
00:02:48,070 --> 00:02:48,580
as previous.

33
00:02:48,580 --> 00:02:50,470
Then it will be adding the number by one.

34
00:02:50,470 --> 00:02:54,550
And if state is not the same, it will be decreasing the number by one.

35
00:02:54,550 --> 00:03:01,180
So now we are going to publish this number on to the topics and the timer callback.

36
00:03:01,180 --> 00:03:09,650
So here we will first set the the message of the left motor encoder and the right motor encoder because

37
00:03:09,680 --> 00:03:12,500
these two motors are placed opposite to each other.

38
00:03:12,500 --> 00:03:14,750
So the right water will be working fine.

39
00:03:14,750 --> 00:03:20,480
But in the case of left motor, when the wheel goes forward, it will be giving us the value in the

40
00:03:20,480 --> 00:03:21,110
minus.

41
00:03:21,110 --> 00:03:24,440
But if it goes backward, it will be giving us the positive.

42
00:03:24,470 --> 00:03:30,440
So this is why we will put an extra negative sign in in front of the left encoder count.

43
00:03:30,470 --> 00:03:34,520
Now, we are publishing these messages in here.

44
00:03:34,550 --> 00:03:39,590
Now we are going to connect the robot esp32 with the PC.

45
00:03:39,890 --> 00:03:41,450
Upload the sketch.

46
00:03:41,960 --> 00:03:44,810
This sketch is uploaded successfully.

47
00:03:44,810 --> 00:03:49,940
Now we will plug out this connected for a micro Ros agent.

48
00:03:52,400 --> 00:03:54,860
And turn on the button.

49
00:03:55,430 --> 00:03:56,570
It will be connecting.

50
00:03:59,400 --> 00:04:00,780
This is connected.

51
00:04:01,110 --> 00:04:02,280
Ross Topic list.

52
00:04:02,400 --> 00:04:03,280
There we go.

53
00:04:03,300 --> 00:04:07,200
Left motor takes and the right motor takes.

54
00:04:07,350 --> 00:04:11,550
And we will be echoing both of them.

55
00:04:14,490 --> 00:04:18,600
Left motor dick and it is saying that it is zero.

56
00:04:18,600 --> 00:04:21,900
And we are also going to echo, right?

57
00:04:21,930 --> 00:04:22,920
Motor encoder.

58
00:04:26,350 --> 00:04:27,820
And this is also zero.

59
00:04:27,820 --> 00:04:30,920
Now, first, let's let's change the left motor encoder.

60
00:04:30,940 --> 00:04:34,900
And we are going to rotate the wheel in the forward direction.

61
00:04:36,310 --> 00:04:38,620
There is changing the value.

62
00:04:39,190 --> 00:04:44,950
And if we see the right encoder, we are moving it forward.

63
00:04:44,950 --> 00:04:47,410
And this is adding.

64
00:04:48,490 --> 00:04:52,600
And if we move it backward, this is going to subtract.

65
00:04:53,570 --> 00:04:55,180
Alright, this is working.

66
00:04:55,210 --> 00:04:56,290
That's good.

67
00:04:58,220 --> 00:05:01,790
Now we are going to see the RCT.

68
00:05:06,020 --> 00:05:07,940
She has the lion turtle.

69
00:05:07,970 --> 00:05:13,640
Esp32 is publishing the left and right motor ticks.
