Commit d3ef6b18 authored by Jake Read's avatar Jake Read
Browse files

near how to make week completion

parent e7179286
......@@ -2,13 +2,29 @@
## Motivation
w/ AS5304 / AS5306
I want an encoder! Encoders<sup>1</sup> read position, generally by counting 'ticks' on some reference. For example, an Optical Encoder uses a reference with openings that allow light to pass, and count whenever a photodiode goes high or low to indicate that some motion has occurred.
Pins for Quadrature Input on ATSAMS70?
![encoder-basically](https://gitlab.cba.mit.edu/jakeread/mkencoder/raw/master/images/encoder-basically.jpg)
A key limitation in my previous work here was encoder positioning. I wanted to use a ring magnet and off-axis linear sensor to decode rotary position - the trouble was I could only find one supplier of ring magnets with the right pole spacing, and it was ~38mm ID. The whole gist of the mechanical design here is to bring the diameter way up, so this was not satisfactory, or, at least, it was a constraint.
Then, you add the ticks together to get your position. In order to detect direction, a technique called 'quadrature' is used:
Here I am going to try to use discrete magnets in an assembly of my own... I am basically just building a big ring magnet, and trying to read that.
![quadrature-basically](https://gitlab.cba.mit.edu/jakeread/mkencoder/raw/master/images/quadrature-basically.jpg)
Super simple, very neat. Here's picture of a *fancy* encoder:
![encoder-fancy](https://gitlab.cba.mit.edu/jakeread/mkencoder/raw/master/images/encoder-fancy.jpg)
You'll notice this encoder has two other reference markings - those are super interesting as well, and encode *absolute* position into the ring - there is only one uniqe combination of holes-or-not-holes on those rings for every single indicated position. This is good news because then your joint / axis does not have to touchoff on a known reference point - aka a 'home' or 'limit' switch - before it starts counting. If this looks expensive, it's because it is. An encoder like this might run ~ $300, and they're super sensitive to dust, misalignment etc. That's no bueno.
**So** my goal here is develop an encoder that I can put on whatever-I-want without spending too much money, and without fussing too much about setup. Critically, I also want to un-constrain myself from particular sizes - whenever I have to source a particular size ring or strip (for reference) I end up boxed-in in terms of the *~ design spaces ~* I can get into. I don't like that.
## Solution?
So I'm going to try rolling<sup>2</sup> a magnetic encoder<sup>3</sup> with a custom array of magnets. This way I can roll a ring or line of magnets into whatever structure I want, and hover one of these encoders above it to read position.
The chip I'm going to use is an AS5304 - a product offered by AMS that does all of the hard work on the hall-array end for me. I can read quadrature output from this ('ABI' interface - 'I' being an Index Pulse)
So, in summary, I am basically just building a big ring magnet, and trying to read that with the AS5304.
## Problems
......@@ -18,17 +34,17 @@ angular resolution = 360 / (((PI x D)/pole_length) x 160)
Of course, I have to set the circumference equal to an integer value of magnets. I wrote a quick spreadsheet for this, and get that w/ a Diameter ~ 100mm (where the gearbox currently stands) I can get 0.017 deg/step with a 2.4mm pole pair, and ~ 0.03 deg/step with a 4mm pole spacing. Nice.
![rough spreadsheet](https://gitlab.cba.mit.edu/jakeread/mkencoder/raw/master/images/spreasheet-resolution-approx.jpg)
![rough spreadsheet](https://gitlab.cba.mit.edu/jakeread/mkencoder/raw/master/images/spreasheet-resolution-approx.png)
Now, this is not so straightforward. The important thing to remember is that **Resolution != Accuracy** - while I have ~ 0.03 deg / step, those steps are not exactly mapped perfectly in a circle. I will actually be referencing magnets that are glued in place - so my glueing and magnet placement would have to be *perfect* for Resolution to = Accuracy. In addition, not all magnetic fields will be identical, etc. Everything is crooked.
Now, this is not so straightforward. The important thing to remember is that **Resolution != Accuracy** - while I have ~ 0.03 deg / step, those steps are not exactly mapped perfectly in a circle. I will actually be referencing magnets that are glued in place - so my glueing and magnet placement would have to be *perfect<sup>4</sup>* for Resolution to = Accuracy. In addition, not all magnetic fields will be identical, etc.
In addition to these mappings between poles, I will have some deviation, I'm sure, within the poles. As in, the magnets will likely have small gaps (finding a magnet which is perfectly 4mm across... not likely) and so I expect readings to kind of sine-wave around linear.
In addition to these mappings between poles, I will have some deviation, I'm sure, within the poles. As in, the magnets will likely have small gaps (finding a magnet which is perfectly 2mm across... not likely) and so I expect readings to deviate in a kind of sine-wave around *actual* position... one period of the wave corresponding to one period of the poles.
This can be overcome in implementation by mapping in memory a lookup table, with respect to some 'home' position, of how measured ticks of the encoder match up with reference positions. For example, I would rotate the encoder to known positions (with some other, higher precision system) and map readings -> known values.
This is not ideal! And it requires a deal of labor, some good routines and memory-storage games, and a reference point.
In this exercise (which I am trying to keep bounded)<sup>1</sup> I will try only to measure this deviation-from-perfection. Or, at least, deviation from some other, better positioning system.
In this exercise (which I am trying to keep bounded)<sup>5</sup> I will try only to measure this deviation-from-perfection. Or, at least, deviation from some other, better positioning system.
At best, I hope to cancel periodic deviation (i.e. map the sine-wave between individual poles into a more linear interpolation. my encoders have an Index pulse (on every top-of-pole) that I can use as a reference point for this.
......@@ -54,15 +70,15 @@ And started laying out a schematic. Had to build the footprint in Eagle.
![board schematic](https://gitlab.cba.mit.edu/jakeread/mkencoder/raw/master/images/board-schematic.jpg)
If you're wondering why I have SPI pins labelled, it's because I'm actually connecting this to a plug on my Networking Switch - these are the pinouts. Instead of SPI I will just configure those pins to do GPIO.
If you're wondering why I have SPI pins labelled, it's because I'm actually connecting this to a plug on my [Networking Switch](https://github.com/jakeread/tinynets/tree/master/circuit) - these are the pinouts. Instead of SPI I will just configure those pins to do GPIO.
THIS is a big what-if for me. As in, what if I get my switch boards back from the fab and it turns out I can't get GPIO to work on these particular pins? I have trapped myself. !
I also have voltage dividers set up here - the AS5304 drives 5v, and I don't want to pump that into my puny 3v3 logic lines on the ATSAMS70.
I also have a jumper / pin header footprint setup on the Analog Out pin - this will let me read the strength of the magnetic fields, making sure I am aligned.
I also have a jumper / pin header footprint setup on the Analog Out pin - this will let me read the strength of the magnetic fields, making sure I am aligned, and that the field strength does not deviate too wildly between poles.
Ideally, I would tie these to an ADC on the ATSAM, but I haven't broken any of those out on the BLDC encoder board... this is a long chain of interconnects. I am rethinking my overall switch -> peripheral strategies now. A good learning / systems design moment. OR I could tie it to some kind of comparator, and have an LED turn on only when that voltage was in a particular range. *shrugguy*
Ideally, I would tie this voltage out to an ADC on the ATSAM, but I haven't broken any of those out on the BLDC encoder board... this is a long chain of interconnects. I am rethinking my overall switch -> peripheral strategies now. A good learning / systems design moment. OR I could tie it to some kind of comparator, and have an LED turn on only when that voltage was in a particular range. *shrugguy*. This is helping me design the modular switch, so that's good news.
OK, Routed
......@@ -70,6 +86,10 @@ OK, Routed
Exporting to mods from Eagle is a bit of a pain. In the fullness of time I would write a MOD to do GERBERS -> Milling, however.
In Eagle, I do this
Options -> Settings -> Misc -> don't display pad names or signals on traces
Layers -> none
Layers -> Top, Pads
export image monochrome
......@@ -86,7 +106,7 @@ Back to my layout, and working back into my sheet, I'm going to add magnets here
And then to test this against some reference, I'm going to use a stepper motor. With the current diameter I'll have 0.05 deg resolution (or, I would ideally) - this means I would need 1/32 microstepping to match up on a stepper motor - I want my reference to have a bit more resolution than what I'm measuring, so I'll try to find a stepper motor with 400 steps / rev, and do 1/32 microstepping on that. Then I have 0.028 deg / step. I'll also bring the diameter down on my encoder to 58 poles, so I'll have 0.077 deg / step there. This means I have about 3x the resolution on my reference than I do on my measured-thing, and intuitively that feels like a good spec. Thumbs up.
ALSO - I knew I should check this, and I'm glad I did - here's a #2 and a #0 screw - the #2 contacts the encoder ring. Noice.<sup>2</sup>
ALSO - I knew I should check this, and I'm glad I did - here's a #2 and a #0 screw - the #2 contacts the encoder ring. Noice.<sup>6</sup>
![cad screw clearance](https://gitlab.cba.mit.edu/jakeread/mkencoder/raw/master/images/cad-screw-clearance.jpg)
......@@ -118,24 +138,43 @@ Also, a moment of appreciation for the new *Leica* microscope that showed up at
I printed the hardware on the Eden. The Eden's washing-up station is currently broken, and I spent the better part of an afternoon trying to cobble together a fittings-and-adapters solution to unbreak it, to no avail. I await McMaster parts.
## Programming
Update: I borrow Biomechatronics' eden waterjet blaster. I have parts now.
First order is getting these magnets in. They're small!
I accidentally put a few poles side-by-side (rather than alternating) - a bit of a bummer. But this is good enough for my test... Here's the ring
![magnets-in-place](https://gitlab.cba.mit.edu/jakeread/mkencoder/raw/master/images/magnets-in-place.jpg)
Ok I got this mostly together - made one mistake, where the motor floats a bit behind the mount. I kind of knew this might be an issue - also, generally, I am overconstrained w/ the motor bearings fighting my ring bearing. In hindsight I didn't even need this ring bearing, but it's something I also wanted to prototype for later development, so here we are. Belt and Suspenders.
![motor-and-encoder](https://gitlab.cba.mit.edu/jakeread/mkencoder/raw/master/images/motor-and-encoder.jpg)
## Testing
I'm using my ATSAMS70 Switch (link?) - I actually used this project as an excuse to bring the GPIO (in SAM-speak, this is just 'PIO' and stands for Parallel Input and Output). Looks like it's datasheet-o-clock again...
Before I get into the meat of programming interrupts etc for this, I'm going to first get some voltage on this board alone and scope the lines to see that I am getting (1) the voltage I want out of the magnetic-field sensing pin, and (2) the ticks I want on the ABI lines.
## Measurements
## Programming, Measurements & Corrections
I want to be like Sam. Sam measures *everything* and he does it really beautifully. This is some of the functionality I really want to be able to bring into mods - the ability to quickly pull test data out of systems, do computation with it, and learn.
With that motivation, I want to take this chance to run a test cast of that. The Goal here:
- Use one of the 'network switches' (or are they routers? vagueness rules in this project at the moment)<sup>3</sup>
- Gateway it to MODS
- Build a basic interface to do this test, where I spin the stepper around a few times and measure devation from 'linear' rotation between the stepper and the encoder.
- Pull this data out and chart it in mods, using javascript to do the maths.
- Have some conclusions, or solutions, to whatever I see in this data.
- First, do ATSAM Router -> MODS pipeline
- Read Encoder with GPIO Interrupts or QED<sup>7</sup> and report periodically to MODS
- Bones of step & dir control on the ATSAMS70
- Stateless Stepper Motor Drive on MODS -> ATSAMS70
- Graphs & Charts & Realtime Data Capture in MODS
- Push a line to the stepper, read encoder, watch linear != linear
- Think long & hard about how to cancel observed differences?
That's a lot! I'm not going to get into it this week, but maybe this is a good project for next week.
# Footnotes
1. But I am also planning on actually using this encoder in my implementation of an arm, and later in linear applications, so having an idea of how to *really* pull this off is - I am hoping - something that will come to me. But I make no plans as such. Seems hard.
2. Ideally I would solder small threaded-things on to the back of the PCB, then I could mount it from the rear and really pinch the rest of it against the plate. Also this would allow me to adjust the encoder position with the ring already in place.
3. In any case, they are modular hardware - ATSAMS70 chip w/ a 40 pin extension header that I plan to do 'stuff' with. I want a good backbone for motion control, a chip to get cozy with.
\ No newline at end of file
1. In the sense I am familiar with - that is, machine design and motion control.
2. ~ pun alert ~
3. Also cool, footnoted to reduce rambling nature of this document, magnetic encoders use an array of hall sensors to sense and a changing magnetic field as a reference. Were I to go even finer grain with this, I would build my own array of hall sensors, but I am a mere mortal and that's the kind of project that belongs in Sam's domain, or until I significantly up my signal processing game.
4. And remember, in the words of Morty: "everything is crooked, the world is a lie!"
5. But I am also planning on actually using this encoder in my implementation of an arm, and later in linear applications, so having an idea of how to *really* pull this off is - I am hoping - something that will come to me. But I make no plans as such. Seems hard.
6. Ideally I would solder small threaded-things on to the back of the PCB, then I could mount it from the rear and really pinch the rest of it against the plate. Also this would allow me to adjust the encoder position with the ring already in place.
7. Quadrature Encoder Decoder - a timer implementation available on the ATSAMS70 that is meant for this.
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment