My first post here is going to be on the nuts-and-bolts of how Integrated Motor Encoders (IMEs) work and a few of the uses. My next post will address some of the pitfalls to be aware of so that you don’t expect the world from these little sensors (hint: sadly, they cannot deliver the world).
What are they for?
IMEs count the number of times that the motor turns around. You can then use this information to control the robot in various ways.
- In autonomous, you could instruct the motor to turn a specified # of turns, in lieu of controlling the robot using time intervals.
- You could also use the IME counter as a way to make the motor, essentially, not turn — such as when you want to hold an arm in place in mid-air, and need to apply a small amount of motor power to keep it from falling down.
- If you have 2 axles spinning, and want to keep them at the same speed, you can have an IME on each motor and compare the readouts from each sensor and adjust the motor power in small increments so that both axles turn at the same rate.
- You can use them to calculate how fast a wheel is turning, by counting the number of rotations over time and calculating an average rate.
OK, so how do they do that?
The IME package comes with a replacement cap and a replacement gear that go on the back of a standard 393 motor. You remove the green cap from the back of the motor, and remove the first gear you can reach, and replace it with the black-and-white gear that comes with the IME. The electronics in the large black cap that now goes on the back of the motor counts as the black and white segments whiz by as the motor turns.
NB: The IMEs come with special, extra-long screws that hold the big black cap onto the back of the motor. They strip rather easily, and you cannot buy extra. At least now they give you 5 in a package (it used to be 4), so you can burn 1 of them, but do have your team be really careful with these screws. Last year we had some IMEs that were held on with only 3 screws because that’s all we had.
Here is the VEX official info-sheet PDF that has the instructions on how to assemble the IME and motor.
So, does it just count 1 for each rotation of my motor shaft? No, silly! That would be far too simple. Here’s the official VEX specs, depending on what type of internal gearing your motor is using (standard/torque, high-speed, or the not-often-used-because-you-must-buy-it-separately turbo-speed).
|Internal Gearing||Ticks per Revolution|
|High Speed||392 ticks|
(must buy separately)
So, if you did not change the internal gears on your motor from when you bought them (standard/torque settings), then the spinning of the little black-and-white gear will give an IME reading of 627 when the motor shaft has turned once. If you changed your motor to high-speed gearing after you bought it, then when the shaft has turned all the way around one time, the IME would give a reading of 392.
Sneaky Negative Numbers
But wait! There’s more you need to remember! We had to learn this one the hard way about 10 times before it stuck. ENCODER VALUES CAN BE NEGATIVE. If the motor spins in one direction (since I can’t remember, let’s say clockwise) it will return positive values. If you spin it all the way back to where it started, it will go back to 0; if you keep spinning it in that counter-clockwise direction, the IME numbers will be negative.
Your team will need to figure out which direction gives positive & which way gives negative readings using the online window or the LCD screen in their initial testing before they go off and do their programming.
To Infinity, and Beyond!
Just like encoder values can go up or down from their 0 staring place, if you have an encoder attached to something that’s spinning really fast, like our Nothing But Net flywheel last year, that’s only ever spinning in one direction, the encoder values—from an absolute perspective—become meaningless very quickly, because they just keep counting up, forever! It’s not long before you’re over a billion. But for our flywheel, we were not interested in the absolute number of ticks; we were interested in calculating the rotations per second on each side of our double-flywheel and comparing those rates to each other to (try) to keep them even over time.
IMEs are wired differently than pretty much any other VEX component: all of the IMEs on your robot are daisy-chained together and plug into a single port on the cortex, labeled “I2C.” If you look at the black cap of the IME end-on, you’ll see that the plug slot is quite thick/tall — that’s because it needs to be able to fit an incoming wire and an outgoing wire of the daisy-chain. Look closely at the plug, and you can see that there is a place for input pins and a place for output pins, stacked on top of one another.
The diagram below shows how the encoders are chained together and plugged into the cortex.
So if they’re all chained together, how does the cortex know what data is coming from which sensor? Aha! Yes, you must set this up first in the configuration screen (shown here in easyC). You must set information in 2 sections: you must tell it the correspondence between the motor number and the encoder-daisy-chain number, and then you must also tell it which type of encoder is being used on each motor. Don’t forget to make your students fill out the “description” field for EVERY MOTOR and EVERY IME.They will thank you later.
The RobotC blog has a lengthy page describing how to implement the above steps in RobotC, along with screenshots and all-around helpful how-to steps.
One Note About Programming
I’m nearing the end here, as this post is just meant to tell you all about all the little pieces and how they must fit together for this system to work.
In our lab we have a poster on the wall that we had made at Kinko’s called “Pearls of Wisdom” of all the stuff that we learned the hard way, that is so important that we need to have it screaming at us in the face on a regular basis so we don’t keep forgetting it. We add to it with post-it notes periodically. One of our pearls of wisdom is “Encoder values can be negative!” as I have tried to scream at you above. Here’s the other one, that is really close to the top of the poster:
ENCODERS MUST BE INITIALIZED FIRST!
Whenever you’re using IMEs, you not only have to set things up on the configuration screen as shown above, but at the *very* start of your program (before any while loops), you must drag over one of the “Initialize” blocks from the “Integrated Motor Encoders” section of the function block list. That’s all you have to do — no parameters, nothing to select. All you have to do is remember to do it. Sadly, if you forget, you will not get any errors, your sensors will just not give you any data and you’ll be left scratching your head and frustrated. Until you maybe put this on a big poster on the wall of YOUR lab…
Isn’t life perfect now? We can do anything!!
Well, unfortunately, not really. My next post addressed the limitations of integrated motor encoders, and where you can save yourself some time by not attempting to do things that won’t work.