1
00:00:00,660 --> 00:00:06,830
But in this lecture, I'm going to show you how to use a mini circumlunar like the one on this video.

2
00:00:07,320 --> 00:00:14,430
Now, I just wanted to mention before the game is that this particular a motor that I'm using is damaged

3
00:00:14,430 --> 00:00:22,530
the integrated stops that it contains in this container to prevent the shaft from moving beyond its

4
00:00:22,590 --> 00:00:29,550
available range, which usually is about zero degrees or most properly built and working in good working

5
00:00:29,550 --> 00:00:29,970
order.

6
00:00:30,060 --> 00:00:35,020
Servo motors can operate at about a zero to one hundred and eighty degrees.

7
00:00:35,700 --> 00:00:37,410
That's the range of movement that they have.

8
00:00:37,620 --> 00:00:39,540
This particular one is damaged.

9
00:00:39,570 --> 00:00:46,230
So if I tried to turn the shaft to anything less than 20 degrees, it's going to go beyond its limit

10
00:00:46,230 --> 00:00:50,490
and actually get it to act as a continuous rotation.

11
00:00:50,490 --> 00:00:50,840
Seven.

12
00:00:51,390 --> 00:00:54,660
I'm going to show you what I mean by this at the moment when I do the demonstration.

13
00:00:55,080 --> 00:01:01,200
But I thought I would still use this just to show you how we can control the range of motion of this

14
00:01:01,200 --> 00:01:05,280
sort of a motor, even if it is damaged in terms of connections.

15
00:01:05,460 --> 00:01:10,530
Servo motors come with a with three wires that are color coded.

16
00:01:10,860 --> 00:01:13,860
So the brown wire goes to ground.

17
00:01:14,940 --> 00:01:19,910
The orange you should it's an orange or red wire goes to five four votes.

18
00:01:20,290 --> 00:01:25,750
It's connected to the final pin on the specific two and the orange one here.

19
00:01:25,770 --> 00:01:32,340
So there's the red one four five volt the orange one in this color coding of connected to Tiberio two.

20
00:01:32,700 --> 00:01:35,670
Or you can connect it to any capable p. m..

21
00:01:36,390 --> 00:01:41,310
Higher on your ID to anyone who do this embedded with the hardware.

22
00:01:41,320 --> 00:01:44,220
Let's have a look at the software side now.

23
00:01:44,700 --> 00:01:52,410
We've got a demo script here that I found here, and this is the URL where you find the original with

24
00:01:52,410 --> 00:01:58,620
additional documentation written by George and take from take to think it works really well.

25
00:01:58,980 --> 00:02:06,450
The principle of operation of this script is to use a mapping function, this function right here.

26
00:02:06,930 --> 00:02:13,770
So what this function does and actually how it works, it works in a very similar way to how the map

27
00:02:13,770 --> 00:02:16,260
function works in the doing the language.

28
00:02:16,710 --> 00:02:22,170
So if you're familiar with it, actually, if you're not familiar with the mapping function and the

29
00:02:22,680 --> 00:02:30,960
idea is that you have a number X which is within a particular range, and then you want to convert it

30
00:02:30,960 --> 00:02:37,230
into a new range or a different range, which you can mark in the parameters here and the map function.

31
00:02:37,470 --> 00:02:41,400
And what you get back is a number that falls in the target range.

32
00:02:41,410 --> 00:02:44,670
The original, again, falls within this range.

33
00:02:44,880 --> 00:02:50,280
In this example, the Y would be the equivalent number that falls within a new range.

34
00:02:50,580 --> 00:02:56,440
And that's exactly how this map function works in this example script.

35
00:02:56,940 --> 00:03:04,830
So what we going to do with a map function is to give it a number in degrees which falls in the range

36
00:03:04,830 --> 00:03:07,350
of zero to 180 degrees.

37
00:03:07,680 --> 00:03:16,440
And what this map function does is to give us back a number which represents a p m value, which falls

38
00:03:16,440 --> 00:03:19,140
in the range of twenty to one hundred twenty.

39
00:03:19,140 --> 00:03:29,430
So then that value can be given to the tuti method of the object and that make the shaft work and rotate

40
00:03:29,430 --> 00:03:32,630
the shift to the appropriate degree value.

41
00:03:33,150 --> 00:03:37,170
So that's the basis of this script.

42
00:03:37,620 --> 00:03:39,140
As you can see, it's self-contained.

43
00:03:39,150 --> 00:03:46,010
We don't need to import anything other than the machine module and the time module for a bit of a delay.

44
00:03:46,590 --> 00:03:49,620
There is pretty self-explanatory by this time.

45
00:03:49,620 --> 00:03:58,750
As you've been following through this course, we'll create the several PIN object as connected to the

46
00:03:58,770 --> 00:04:05,640
orange wire from the server motor to Tapio to it that goes there.

47
00:04:05,940 --> 00:04:12,330
Then we get the object connected to that several Penge Aperio two.

48
00:04:12,810 --> 00:04:20,200
We set the frequency for the object and found that 50 Hertz works for this particular server motor.

49
00:04:20,230 --> 00:04:22,680
This is something that I found empirically.

50
00:04:22,980 --> 00:04:29,880
You may need to tweak that number a little bit if you're using different many servo motor, but just

51
00:04:29,880 --> 00:04:32,100
start with 50 hertz and see how you go.

52
00:04:33,180 --> 00:04:42,510
We reset the server motor by sending value pitiably in value zero to the object via the duty method.

53
00:04:43,380 --> 00:04:46,050
We've already seen the map and several functions.

54
00:04:46,060 --> 00:04:47,700
Let's go ahead and use the server functions.

55
00:04:47,700 --> 00:04:48,450
So here we go.

56
00:04:48,810 --> 00:04:58,800
This is, for example, will drive the shaft of the mini servo motor to twenty degrees and then wait

57
00:04:58,800 --> 00:04:59,740
for one second there.

58
00:05:00,020 --> 00:05:06,500
Then move it to 90 degrees, wait for another second and move it to the other extreme, 170, and wait

59
00:05:06,500 --> 00:05:11,570
for another second notice here that I'm not going to zero because I found that if I did go to zero,

60
00:05:11,570 --> 00:05:18,830
then driving the mini survey motor to a degree value that is beyond its capability to handle.

61
00:05:18,830 --> 00:05:23,420
So that just makes it rotate as if it was a continuous rotation.

62
00:05:23,810 --> 00:05:25,750
Seven motor up.

63
00:05:25,750 --> 00:05:26,870
Change this to a zero.

64
00:05:26,900 --> 00:05:29,960
A bit later to see so we can see what the effect of this is.

65
00:05:30,350 --> 00:05:33,170
And I'm doing the same thing up here at the other extreme.

66
00:05:33,200 --> 00:05:38,440
And I'm not going all the way to one hundred and eighty degrees because my mini motor miniature memory

67
00:05:38,480 --> 00:05:39,470
can't handle it.

68
00:05:39,740 --> 00:05:42,160
So I'm just going up to one hundred seventy degrees.

69
00:05:42,170 --> 00:05:50,750
That is his current limit after that, going into an infinite loop where I'm simply moving the mini

70
00:05:50,750 --> 00:05:57,350
servo from its lowest, it's highest degree and a step of ten can change that to whichever step you

71
00:05:57,350 --> 00:06:06,380
want and staying there for half a second and then moving back from the highest degree value to the lowest

72
00:06:06,380 --> 00:06:11,690
degree value that it can handle at a step of minus 10 degrees.

73
00:06:12,650 --> 00:06:13,220
All right.

74
00:06:13,220 --> 00:06:17,980
I'm going to upload this sketch, this script.

75
00:06:19,710 --> 00:06:21,690
To the east because they didn't see it in action.

76
00:06:24,980 --> 00:06:28,130
Go up and then moving down.

77
00:06:28,270 --> 00:06:28,910
No problems.

78
00:06:30,130 --> 00:06:44,050
Now see what happens if I change this to zero and that to zero as well, that control, say, to stop

79
00:06:44,050 --> 00:06:45,880
execution and then save it.

80
00:06:47,000 --> 00:06:48,070
And I will run it again.

81
00:06:51,700 --> 00:06:52,570
Try one time.

82
00:06:56,120 --> 00:06:57,080
OK, try again.

83
00:06:58,270 --> 00:07:08,140
You have my minister right now working as if it was a continuous rotation system, so going up there's

84
00:07:08,140 --> 00:07:11,740
no problem of the 170 is OK going back.

85
00:07:14,560 --> 00:07:16,240
Once it goes past 20.

86
00:07:18,440 --> 00:07:21,530
It continues to rotate beyond its limits.

87
00:07:22,490 --> 00:07:24,030
All right, that's about it.

88
00:07:24,560 --> 00:07:32,600
So, as you can see, it's fairly easy to control a sort of a motor using the example sketch that I've

89
00:07:32,600 --> 00:07:32,870
shown.

90
00:07:32,870 --> 00:07:41,620
You can move on to the next picture now where I'll show you how to control a DC motor using the Garveys

91
00:07:41,640 --> 00:07:43,540
eight eight seven one.
