About this video
A coin detector is built by changing a motor program so the robot waits for a coin to be placed and rotated, then compares the motor's position reading to a narrow accept range. Readings inside the range, such as about 91 degrees for coin A, are accepted; everything else is rejected. The main engineering task is finding the right range for each coin by testing the sensor several times.
You'll be able to
- explain how a sensor reading can stand in for identifying a coin
- describe the three changes needed to turn a tone program into a coin detector
- reason about why an accept range is a slice rather than a single value
Key words
- Hard stop
- A fixed piece that stops the beam so the coin always sits in the same place on the surface.
- Rotation sensor
- The sensor inside the motor that reports the beam's position as an angle in degrees.
- Range A (accept region)
- The narrow slice of sensor readings that represents a particular coin and is accepted.
- Reject region
- Every other sensor reading, which the program treats as not the correct coin.
- Variance
- Small differences between repeated readings for the same coin, which is why the accept range must be a slice.
Transcript
So far, you have a beam attached to a motor in a simple program that generates a tone-- a high pitched tone if it's somewhere between 100 and 200 degrees. And if it's anywhere else, it generates a low pitched tone. So let's modify this to make an actual coin detector.
Let's say you have a hard stop here, some piece of plastic or a beam, that doesn't move so that you can lie a coin-- let's say this is coin A-- on the surface. And as you rotate the motor, the beam will eventually hit coin A. And it will have rotated x degrees.
Remember, we have our rotation sensor inside the motor. We'll say it's reading x at all times, where x is the position of this beam. And let's say, for example, coin A is that 91 degrees. Now, if we're thinking like a robot, we don't actually see the coin. The only thing we see is this number.
So for the robot, 91 degrees is somehow representing coin A. And if we put in a smaller coin, this beam will rotate further down, and it might register 98. So the robot will know, oh, we're in 98. This is not the correct coin. So the problem here is to basically squeeze your range to be some tiny slice here that represents coin A.
And it won't be one reading such as 91 degrees, because there'll be a tiny bit of variance here. It could be 91, 92, or 93 degrees, perhaps. And this all depends on your system. You have to figure out what this range is. So if it's inside this little slice, we'll call it range A.
And if it's anywhere else, it's our reject region. So this'll be our accept region, think of it. And the rest is our reject region. And to make this work, you need to modify your program in three ways. We don't want to generate a tone in real time as before. We want to actually wait for the user to put in their coin and rotate the motor.
And then the user will hit the orange Enter button. So that means you're going to introduce a wait block inside your infinite loop. So it will wait for the user before it goes and plays a tone. And after the user presses the orange button, you will either generate an accept or a reject sound file.
So don't generate a tone. It needs to be meaningful, such as yes or no. And the third step and the main engineering problem here is to figure out what the range is for your system. Remember, this is zero, so you're going to have to pull your sensor and experiment a few times to figure out what is your range for, say, a five-cent coin, and change your range values inside your existing range block.
And if you do these three things correctly, you should have the following working coin detector.
Video © Khan Academy, used under CC BY-NC-SA. Watch on Khan Academy. Puzzicle is not affiliated with Khan Academy.