But in this lecture, I'm going to show you how to use a mini circumlunar like the one on this video.
Now, I just wanted to mention before the game is that this particular a motor that I'm using is damaged
the integrated stops that it contains in this container to prevent the shaft from moving beyond its
available range, which usually is about zero degrees or most properly built and working in good working
order.
Servo motors can operate at about a zero to one hundred and eighty degrees.
That's the range of movement that they have.
This particular one is damaged.
So if I tried to turn the shaft to anything less than 20 degrees, it's going to go beyond its limit
and actually get it to act as a continuous rotation.
Seven.
I'm going to show you what I mean by this at the moment when I do the demonstration.
But I thought I would still use this just to show you how we can control the range of motion of this
sort of a motor, even if it is damaged in terms of connections.
Servo motors come with a with three wires that are color coded.
So the brown wire goes to ground.
The orange you should it's an orange or red wire goes to five four votes.
It's connected to the final pin on the specific two and the orange one here.
So there's the red one four five volt the orange one in this color coding of connected to Tiberio two.
Or you can connect it to any capable p. m..
Higher on your ID to anyone who do this embedded with the hardware.
Let's have a look at the software side now.
We've got a demo script here that I found here, and this is the URL where you find the original with
additional documentation written by George and take from take to think it works really well.
The principle of operation of this script is to use a mapping function, this function right here.
So what this function does and actually how it works, it works in a very similar way to how the map
function works in the doing the language.
So if you're familiar with it, actually, if you're not familiar with the mapping function and the
idea is that you have a number X which is within a particular range, and then you want to convert it
into a new range or a different range, which you can mark in the parameters here and the map function.
And what you get back is a number that falls in the target range.
The original, again, falls within this range.
In this example, the Y would be the equivalent number that falls within a new range.
And that's exactly how this map function works in this example script.
So what we going to do with a map function is to give it a number in degrees which falls in the range
of zero to 180 degrees.
And what this map function does is to give us back a number which represents a p m value, which falls
in the range of twenty to one hundred twenty.
So then that value can be given to the tuti method of the object and that make the shaft work and rotate
the shift to the appropriate degree value.
So that's the basis of this script.
As you can see, it's self-contained.
We don't need to import anything other than the machine module and the time module for a bit of a delay.
There is pretty self-explanatory by this time.
As you've been following through this course, we'll create the several PIN object as connected to the
orange wire from the server motor to Tapio to it that goes there.
Then we get the object connected to that several Penge Aperio two.
We set the frequency for the object and found that 50 Hertz works for this particular server motor.
This is something that I found empirically.
You may need to tweak that number a little bit if you're using different many servo motor, but just
start with 50 hertz and see how you go.
We reset the server motor by sending value pitiably in value zero to the object via the duty method.
We've already seen the map and several functions.
Let's go ahead and use the server functions.
So here we go.
This is, for example, will drive the shaft of the mini servo motor to twenty degrees and then wait
for one second there.
Then move it to 90 degrees, wait for another second and move it to the other extreme, 170, and wait
for another second notice here that I'm not going to zero because I found that if I did go to zero,
then driving the mini survey motor to a degree value that is beyond its capability to handle.
So that just makes it rotate as if it was a continuous rotation.
Seven motor up.
Change this to a zero.
A bit later to see so we can see what the effect of this is.
And I'm doing the same thing up here at the other extreme.
And I'm not going all the way to one hundred and eighty degrees because my mini motor miniature memory
can't handle it.
So I'm just going up to one hundred seventy degrees.
That is his current limit after that, going into an infinite loop where I'm simply moving the mini
servo from its lowest, it's highest degree and a step of ten can change that to whichever step you
want and staying there for half a second and then moving back from the highest degree value to the lowest
degree value that it can handle at a step of minus 10 degrees.
All right.
I'm going to upload this sketch, this script.
To the east because they didn't see it in action.
Go up and then moving down.
No problems.
Now see what happens if I change this to zero and that to zero as well, that control, say, to stop
execution and then save it.
And I will run it again.
Try one time.
OK, try again.
You have my minister right now working as if it was a continuous rotation system, so going up there's
no problem of the 170 is OK going back.
Once it goes past 20.
It continues to rotate beyond its limits.
All right, that's about it.
So, as you can see, it's fairly easy to control a sort of a motor using the example sketch that I've
shown.
You can move on to the next picture now where I'll show you how to control a DC motor using the Garveys
eight eight seven one.