A while ago, we purchased a pair of 12-bit magnetic angular encoders from Digikey. They’re not real expensive, and they have a resolution of 0.0879 degrees. If you’re up for it, check out Angular Measurements on Cool Cosmos.
Now, let’s do some math:
For 12 bits, the encoder output value can range from 0 to 2^12, so: 2^12 = 4096 and, there are 360 degrees in a full revolution, so: 4096 count / 360 degrees = 11.38 count / degree and, 60 arcminutes make up one degree, so: (60 arcminutes / degree) * (1 degree / 11.38 count) = 5.27 arcminutes / count
That means our 12-bit magnetic encoders have a resolution of 5.27 arcminutes. This is great! It’s about a tenth the width of your pinky, if you held your pinky at arms length towards the sky.
Not bad. One of the tasks of the Motor Library will be to take some angular measurement (which will consist of degrees, arcminutes, and arcseconds) and translate it into a 12-bit number, and vice versa. This is because one of the motor library’s primary functions is a GOTO function, which may receive a pair of angles as input. The library function ought to translate those pairs of angles into a 12-bit equivalent, so we have something to compare with the output of the 12-bit magnetic encoder. (An alternative way to do it is to convert the 12-bit magnetic encoder’s output into an angle, every time we poll the sensor, then compare it to the target angle. It might be more efficient the first way, who knows?)
The only problem I foresee is that it’s non-trivial to physically re-orient the magnet within the magnetic encoder, so it will probably cross over the 0-degree position. Crossing over means we might go from 12 degrees to 0 degrees to end up at 350 degrees. This is one of the reasons we might use the motor’s quadrature rotary encoder to indicate position. The only solution I can think of is a function like this
if our motion is clockwise { if current > target { subtract 4096 from current for an adjusted current position } keep spinning while adjusted current position is less than target } else if our motion is counterclockwise { if current < target { add 4096 to current for an adjusted current position } keep spinning while adjusted current position is more than target } else {}
There may be a way to do it better. I will think of one later.
Anyhow, what the GOTO function would do is A) slowly accelerate the azimuth motor and altitude motor, B) continue rotating until it approaches the target angles, C) slowly and gradually decelerate the azimuth motor and altitude motor, until it actually lands on the target angles. Now, getting it to land exactly on the target angles will be tricky.
As a part of the library, there will be some set of functions which will test the speeds of the motors and the amount of overshoot that occurs when told to stop (or slow down). Basically, we’re going to teach the arduino to anticipate how much overshoot. This may or may not involve us learning how to code PID. (In fact, we might even use PID for parts A and C to ensure smooth acceleration, and in part B for constant speed. With all the other potential overhead, it might be hand coded. But for now, we could implement one just to see how it works??)
Where does this leave us? Well, we need to finish the motor instruction buffer – because I want to try out canned operations like part A), B), and C) in one smooth motion. The next step is we write the conversion functions for the 12-bit magnetic encoder. And, write up the funky code that handles crossing over the 0-degree line.
-david