1
00:00:06,020 --> 00:00:12,920
Hey, now we're going to add the last topic in the code and our report will be ready.

2
00:00:12,920 --> 00:00:21,440
And this topic is on which we will be publishing velocity and report will be we are going to utilize

3
00:00:21,440 --> 00:00:24,320
this code and make some changes in our code.

4
00:00:28,500 --> 00:00:31,290
It is important to twist message.

5
00:00:31,290 --> 00:00:34,320
So we will be copying this and paste it here.

6
00:00:34,350 --> 00:00:39,630
This is the first step and then then it is adding the objects of subscriber and the messages.

7
00:00:39,630 --> 00:00:46,650
And in here there is a callback function that it is calling and here it is, the Micro-roasters subscriber.

8
00:00:47,040 --> 00:00:50,400
Here are the objects of the subscriber and the message.

9
00:00:50,400 --> 00:00:53,340
And now we are going to add the subscriber.

10
00:00:54,690 --> 00:00:58,020
Here it is, the subscriber with the topic.

11
00:00:58,950 --> 00:01:06,270
And under here we are going to add a new thread and here we will just write it for because this is a

12
00:01:06,270 --> 00:01:11,610
new thread and here it is, the callback function that we are going to define up here.

13
00:01:12,510 --> 00:01:18,960
And this is the callback function in which we are just getting the value of the linear x and, and the

14
00:01:18,960 --> 00:01:24,720
we are getting the value of angular C and we are assigning it to the angular and then we are calculating

15
00:01:24,720 --> 00:01:32,020
the motor speed and the motor speed is the linear minus angular over two multiply by 2000.

16
00:01:32,050 --> 00:01:38,950
This is not the actual formula to calculate the speed of the motor, but for the sake of simplicity,

17
00:01:38,950 --> 00:01:44,010
we are using this formula so that we can move our robot at the basic level.

18
00:01:44,020 --> 00:01:47,490
Now we have to move our fields as well.

19
00:01:47,500 --> 00:01:59,320
We have connected our fields on PIN 25, 26 and 27 and 14, and here are the pins.

20
00:01:59,350 --> 00:02:03,970
If we give some value to the PIN 14, then the left motor will be moving forward.

21
00:02:03,970 --> 00:02:11,590
And if we give some value to the 27 pin, it will be moving backward, the left motor and for the right

22
00:02:11,590 --> 00:02:13,990
motor these two pins are choosing.

23
00:02:14,020 --> 00:02:19,450
Now we have to set the mode of these pins to the output mode and the void setup.

24
00:02:21,840 --> 00:02:30,840
Now we will again go to the callback function and we also have to initialize these motor speed variables

25
00:02:32,310 --> 00:02:39,120
and we will be initializing it here and come back to the callback function callback.

26
00:02:39,120 --> 00:02:45,720
And in here we are going to use some flex and heresy logic for motor speed.

27
00:02:45,720 --> 00:02:47,160
Left is greater than zero.

28
00:02:47,190 --> 00:02:53,340
Then the left motor is going to move and here we are playing with the number 4010.

29
00:02:53,370 --> 00:02:54,570
What does it do?

30
00:02:54,600 --> 00:02:59,700
The value on which the words is from 0 to 255.

31
00:02:59,730 --> 00:03:05,880
But if we give a value of ten, the motor does not move because the motor has the internal resistance.

32
00:03:05,880 --> 00:03:07,770
There is also some weight of the robot.

33
00:03:07,770 --> 00:03:09,510
So this is why the motor does not move.

34
00:03:09,510 --> 00:03:15,570
So if we give 40 value to the pen, then it starts to move very slowly.

35
00:03:15,570 --> 00:03:20,850
Then we can increase and the speed will be gradually increased with this, with the higher value of

36
00:03:20,940 --> 00:03:21,520
petroleum.

37
00:03:21,520 --> 00:03:26,830
Now we have to assign these speed value to the particular fields of the robot.

38
00:03:28,200 --> 00:03:30,540
For that, we are going to create a function.

39
00:03:30,540 --> 00:03:38,430
And in here, here it is the function set motor and it takes the left speed and speed, right.

40
00:03:38,460 --> 00:03:46,110
If the speed left is greater than zero, then it is going to set the end to pin to low.

41
00:03:46,140 --> 00:03:51,750
Because if the this pin is high, then the left motor will be moving backward.

42
00:03:51,750 --> 00:03:54,600
So if this is low, then it's fine.

43
00:03:54,600 --> 00:03:59,520
It is not going to move anywhere and then it assigns the value to the end pin.

44
00:03:59,560 --> 00:04:02,610
Fun in pin one will be driving left wheel.

45
00:04:02,820 --> 00:04:10,680
There is also a limit to the pin it the maximum it can go as to 50 because if we give the higher speed

46
00:04:10,680 --> 00:04:16,230
of the value to the motor driver, the motor cross a lot of current and in some cases it it turns off

47
00:04:16,230 --> 00:04:17,340
the esp32.

48
00:04:17,340 --> 00:04:19,290
So this is like a precaution.

49
00:04:19,290 --> 00:04:24,690
You can play with your robot and you can also find out what value suits your robot.

50
00:04:24,810 --> 00:04:31,210
If the left speed is less than zero, then it is setting the in one pin low and then giving the value

51
00:04:31,210 --> 00:04:32,430
to the into.

52
00:04:32,440 --> 00:04:33,820
The same is the case with the speed.

53
00:04:33,820 --> 00:04:34,140
Right.

54
00:04:34,150 --> 00:04:34,600
Okay.

55
00:04:34,600 --> 00:04:36,790
And this condition checks.

56
00:04:36,790 --> 00:04:42,370
If the boats speeds are zero, then it's going to set all the pins to low.

57
00:04:42,400 --> 00:04:42,760
Okay.

58
00:04:42,760 --> 00:04:46,870
So this is the function that we are going to call in here.

59
00:04:47,740 --> 00:04:50,110
And we will also have to define the prototype.

60
00:04:50,950 --> 00:04:53,290
So these are the function prototypes.

61
00:04:53,290 --> 00:04:55,150
And now we are going to upload the code.

62
00:04:55,150 --> 00:05:02,140
So now plug the esp32 in upload so the upload is successful.

63
00:05:02,140 --> 00:05:09,090
Now plug out the esp32 and turn on the robot connected via microprocessor.

64
00:05:09,100 --> 00:05:12,940
So go to your robot workspace and solve it first.

65
00:05:20,620 --> 00:05:22,120
And there you are connecting.

66
00:05:22,120 --> 00:05:23,950
So we will give it a restart.

67
00:05:30,180 --> 00:05:31,500
This is connected now.

68
00:05:35,460 --> 00:05:36,090
So there we go.

69
00:05:36,090 --> 00:05:37,410
There is the topic.

70
00:05:37,410 --> 00:05:39,480
Now we are going to publish our.

71
00:05:45,400 --> 00:05:49,180
And now press I and support is moving.

72
00:05:49,210 --> 00:05:54,550
The value is a little bit higher, so I will decrease it via pressing the Z.

73
00:06:03,100 --> 00:06:03,640
There you go.

74
00:06:03,640 --> 00:06:04,780
It is working now.
