Absolute Position Encoders are Crazy
Вставка
- Опубліковано 12 вер 2024
- This strange-looking disk is incredibly useful in determining the absolute position of a rotating disk. I plan to use it to create an anemometer, which is a device used for measuring the wind's speed and direction.
I hope you found this video interesting! If you did, please consider checking out my other videos :)
#encoder #windmill #anemometer #diy #3dprinting #3dprinter #3dprinted #creality #ender #ender3 #prusa #wind #windpower #homemade #fdm #manufacturing #engineering #engineer #electronics #electricalengineering #microcontroller #arduino #arduinoproject
That disk is a really interesting visualization of binary
I agree! It almost seems more intuitive than other methods of teaching binary.
@@christophersfactory im not sure what the normal method of teaching would be cuz i taught myself years ago but i could see someone learning with this
That disk basically just one and zero but somehow my brain not hurt looking at that 😭
They use this design to make rotary switches with multiple states. Each ring doubling the states. 1,2,4,8,16,32...
Mind blown 🤯
I am impressed that so many people knew about grey code, and why it is necessary for this application.
I am too honestly. I’m also impressed that I did enough research for this video to build a working prototype and had never even heard of it, but literally everyone else had 🤣
@@christophersfactory
Lots of electronic/digital techs about here it seems.
- The way things are with the 'throw away society', possibly lots of former/retired/ unemployed techs. 😞
@@jabberwocky1707 20 years at NASA in robotics, but not a tech. ;-)
@@FelonyVideos
Design Engineer then, or Project Management, or ...? Just wondering, don't need to be specific.
- You didn't have anything to do with those outstanding Mars rovers that went *_way_* beyond their original mission length?
- Maybe grey code is 'old hat' as there are possibly other methods to achieve position measurement?
- One method IIRC used for 3D sight positioning determination for HMSD (helmet mounted sighting devices) to aim missile/gun 'by eye', used pulsed magnetic fields of different frequencies so the axes (2 or 3?) can be discriminated from each other.
@@jabberwocky1707 first analyst, then designer, the project manager, then department manager, then independent consultant.
The supercomputer that we ran our simulations on was the best in the world at the time- it had an unheard of 64k of core memory. 😂
You should use gray-code for the disk and convert to binary in the microcontroler. Your binary disk needs multiple sensors to switch exactly at the same time, which will never happen in practice. Gray-code only has one bit change for each angle so the sensor data is always consistent.
WHS
I approve this message.
Came to say this!
plus in grey code you always know where you are right now even if the disk stops between 2 segments (it will either put out the left or the right portion of where it stops). here in this disk the sensors will give out arbitrary values and you wont be able to know which portion you are on right now
Compass sensor. CDS cells old hat analog. Too many wires and sensors.
You should consider swapping to gray code to avoid synchonization issues between the bits. Otherwise you might run into miscounts.
The cool part is that the patterns are actually the same. Just by cleverly shifting them, you can make it such that only exactly 1 bit changes at a time. This eliminates read timing errors due to bits not physically toggling exactly simultaneously. Though this specific disk contains clock pulse ring which through additional hardware also eliminates read timing errors.
I suppose, not every gray code is easy to 3d print
@@JohnIdlewood Gray codes are easier to 3d print actually, because only 1 hole can appear at a time and everything else is still solid.
There is a simpler way, but please continue. I want to see it work.
Yeah. Watched then and started laughing. I do think it will work but I remember in College they said unread better to use a different encoding order wherein no more than one bit changed per step.
Am I on the right track?
@@jeromewink557Yes you are on the right track! With regular binary encoding, multiple bits will change on each angle and unless all of the sensors switch state at the EXACT same moment, there will be wildly off false readings during the transition between angles. That specific order of code where only one bit changes per angle is called Gray code, or Gray encoding. :3
@@MarbleStarry which now that you have said that and I think about his design he’s going to need layer outside his ring with holes offset from the reading that he can use as a trigger. Or he needs to offset his LSB to slightly trail the rest of the disc and use it’s bounced been logical 1 and 0 as a trigger to read the value.
Make the outer ring of dots a smidgen smaller, and make a latching circuit to enable 'valid position' detection during the rotation. This would eliminate transitional errors. Also, key the center of the hole so the shaft is fixed to the shaft in a way that cannot slip or be out of alignment.
@@frankens43 I was thinking the outer holes were there exactly for that purpose.
Trial and error will show they are small enough.
Use gray code: now say between "south" and "south-southwest" all bits will change. In practice that doesn't happen exactly at the same time. Thus you'll get a bunch of other directions when the vane goes between those two states. Gray code has only ONE change every transition, thus when it is somewhere in the middle between two states, it'll show one or the other but not a totally different state.
And there is a simple circuit that will convert gray code to binary.
Also you can save some diameter by putting the sensors for the highest bit and second highest bit on the same ring, but 90 degrees apart.
Why you have the sync in the outer ring ...
@@MorsDengse If gray code is used you don't need sync. The outer ring could be used to double the resolution, or eliminated to make it more compact.
@@GordieGii Im certainly not disputing that, just noting why the outer ring is there, as it wasnt mentioned.
On another note. No one in their right mind would use such a contraption today : )
@@MorsDengse The sync signal is an obvious solution for someone who is ignorant of the existence of gray code, which the OP admits he was.
Cool! A Gray code encoder might be more durable.
Wow! I can't believe I've looked into these encoders this much and haven't seen a Gray Encoder. That looks dope, thanks for the heads-up!
Grey encoding was my first thought, then I saw that it was binary ^^
@@christophersfactory You could go with just 4 sensors. 2 grey code for the four compass points and the other 2 for quadrature (incremental) in between. But then you would have to implement a quadrature decoder. (circuit or software)
@@christophersfactory Another thing that'd be much easier to manufacture would be essentially a potentiometer. To the shaft, add a disc with an inner and outer copper brush (a little bent strip of copper will work), connected with copper wire. Add a second (fixed) disc on a bearing, on it, have a copper wire/plate circle that the outer brush fully touches, regardless of rotation. On this outer ring you put some input voltage. For the inner ring, use graphite or resistive wire or so. Make sure this ring has a tiny break in it Connect a copper wire to this ring at the break. Now you can measure the resistance between the two wires dependent on axis position. Make a voltage divider with a resistance that fits your purpose. If your ring has a resistance from 0-100kOhm for example, you could choose a 10kOhm resistor to divide with to get an output voltage between 0 and 89%. You can read this on an analog pin and by measuring different points (careful: Not linear!) you can create a map/approximating function that calculates angle from voltage.
Imo easier to build and you can make it much smaller and can be useful if you have few digital pins available. Downside is, you need an analog input or ADC. Also, the longevity will be much shorter than your photo resistor approach which is why I think your approach is better for your use case. Just be aware that the accuracy is fully determined by the angle of the slots on the outermost ring, which in your case is ~3 degrees. You can also get significant jitter if the direction changes on a boundary of a slot, meaning your readings could look like 3°,6°,3°,6° even if the actual direction barely changes. If that is good enough for you, perfect!
@@xXIkaron potentiometers are kinda ugly for this, especially compared to photodiodes.
Yes. Most directional anemometers use a potentiometer. Lowest resistance value is set to north and you can calibrate direction based on the resistance.
You should swap the encoding out with a Gray encoder. Those rearrange the binary numbers so that each transition always only changes one bit, instead of binary where multiple bits flip. This is used for disc encoders to prevent intermittent wrong signals when multiple bits flip and not all sensors are crazy perfect aligned (which they never are)
also is should allow for a more supportive structure.
My first thoughts for angle sensing would be a magnetic sensor. Not exactly sure what they are called, but they used the Hall-effect to sense the magnetic field.
You should have used grayCode instead of simple Binary. Therfore you don't have errors on the boundaries, which you will probably have now if the angle is near the pattern change..
The main issue with this approach js the noise. If your bits don’t flip at the same time, you will read a bunch of odd angles during transitions. There are ways to fix that though. Easiest is to reorder the numbers so that only one bit changes at each transition. It is easy to build that sequence recursively for any number of bits. You might want to look up Hamming Distance. It is used in error detection and correction.
These are normally very expensive (amzn.to/3jEGN9r) hence trying to make my own :)
Be sure to check out part 2, where I took your suggestions into account! ua-cam.com/video/lwLOwk8zhh4/v-deo.html
Hall effect sensor.
Great job but check Gray code. It might be better then put binary pattern you have there
Yes when you get one thats made for 3000rpm they tend to cost quite a lot, but you can also get one for 10-20 bucks
@@taintedsasquatch398 thats an amazing solution that absolutely doesnt do anything, you can’t just slap a hall effect on something and have that work all of a sudden
@@Joshinken An absolute position encoder can be more expensive than a relative encoder. The former incorporates a disk with 8 to 12 or more tracks, whereas the latter only need two tracks and a special zero mark that the system has to find each time it starts up -- not really practical for a weather vane.
For those who are wondering what "Grey Code" is:
Grey Code is a binary system (1,0) where only 1 bit changes between each step/element (Only 1 change, unlike normal binary which can have multiple changes between each step/element).
Example:
Binary: Grey Code:
7 = 0111 7 = 0100
8 = 1000 8 = 1100
As one can see, in Binary, 4 bits change when it goes from 7 to 8 (First Zero changes to a 1, and the last three 1's change to 0); Whereas in Grey Code, only 1 bit changes when it goes from 7 to 8 (Only first zero changes to 1)
Gray code is also recommended to make sure only 1 bit changes during a transition
I was going to mention it as well, that one bit change per digit is really useful on stuff that moves quickly. They use it a lot for government radar dishes because of the reliable speed and precision they provide.
To determine direction you only need to signals A & B slightly offset by ~20 deg. And two LDRs.
If you see AB..AB..AB.. thats one direction, if you see BA..BA..BA thats the other direction. And by counting A only you can also determine RPM / speed based on the circumference at location A.
That (incremental encoder) just tells you what direction the encoder has moved, not where it is. You can track an incremental encoder to kinda fake an absolute one with a dead reckoning sort of mechanism, but absolute has advantages like it just telling you the state (position) without needing any zeroing/calibration, and not needing any memory to track the absolute position from step deltas.
@@treelineresearch3387 That is true, but the stated intent in the video was just determining direction of rotation.
@@DejitaruJini thought he was just looking for the angle of the wind and not the direction of rotation.
@@jamesharrell4360 After re-watching, yeah, I retract my statement; my mind interpreted "direction" as in _motor_ direction (where you'd usually find such an encoder disc) instead of _cardinal_ direction. I imagine the commenter at the top of this thread made the same mistake.
When I built one in class, I used two offset sensors on a one bit wheel for direction and change, plus a third sensor for passing North . The wheel was 2D printed on transparent plastic, 3D printing neither needed nor invented . A reflective paper disc would have been even simpler, but the class was focused on writing the code .
Incremental encoder with a and b signals with proper offsets. Uses a 3rd of hardware and is easier to print and fabricate. Obviously what you did is really cool. Nice job
How will the microcontroller know the absolute direction of the weather vane?
@@Graham_Wideman You re absolutely right.
If it was on a motor, you could add a calibration vane , but this is supposedly free rotating in the wind.
You re not going to wait for a specific wind direction after every time you power this thing.
Yeah but after losing power in the system you no longer know the position of the encoder, also incremental encoders are loosing steps. It's good for some aplications like encoder in 3d printer for screen control, but it won't work in getting position of stepper motor in 3d printer for example, it's too unreliable.
One issue with incremental is it only counts steps and does not give absolute position. Fine if you can A capture all the steps and B calibrate every time power goes out. However on power up the system has no idea what direction its pointing and just starts at 0. if you normaly consider 0 as north but you boot it up while wind is west its going to tell you its north.
Advantage of an absolute encoder is it does not mater what state its in. If its outputing a 10 and you know 10 = west it just works. you only have to figure out the alignment once.
@@merendell He said he wanted direction, not position.
An easier way to tell which way the wind is blowing?
I put a rag on the end of a stick. I call it my Fluctuating Lateral Air Gauge or FLAG for short.
;)
But the binary thing is pretty cool too.
there is a simpler way it's called a wind sock but this is awesome
The idea is to be able to know the wind direction without looking outside or being within range of sight of the measuring device (and maybe as cheaply as possible?).
Windsock and camera. Encoders are expensive because they’re typically used on servos/robotics.
Old school was a segmented ring with only one section energized and a series of contacts around the perimeter. The contact with power lit a bulb to show the wind direction. You don't need half degree resolution and hundred dollars in parts of the input is a wind vane.
wind sock on a potentiometer...
Wet finger works or looking at foliage or water…
if you just want to tell which DIRECTION the wind is blowing, have a transparent disc with a gradient printed on it. the resistance will either gradually increase and then suddenly drop and start over, or do the reverse. you could also tell the speed by how often those restarts happen and it will be more accurate because it happens only once per cycle.
Or just a potentiometer :)
Yes, you can use a single photo resistor and vary the thickness of the disk. So a single circle, progressively thinner, single LED pointing towards the resistor. Thickness of the disk blocks more or less light.
You could use more circles for more granularity, in the same vein of what you have.
You could probably achieve the same effect with a thin, single, or double layer on the bottom and use pin holes. So 120 deg with no layer, 120 deg with one layer, 120 with two layers (on the bottom). Instead of having large holes around the edge, each 120 deg segment has 12 sub sections where it's made of 0-11 pin holes. The light goes through the pin holes, hits the bottom layer, diffuses and creates a uniform but unique amount of light.
You could also use different colors of filament and different LEDs. Green filament absorbs mostly green light. So if you pointed an rgb led at the diffusion. Layer, a green filter would leave rb, red filter gb, blue - rg
Very smart use simple mechanics instead of complex digital methods. Basically bulletproof. Unless it would be subject to dirt or he plans to use sunlight for it. Wouldnt work then either
Elegant solution.
@@D3nn1sI think this is the first time I've ever seen an old comment and wasn't disappointed in myself
@@wilurbean in yourself? Did you come across the same ahort again while scrolling or what?
Your comment was very smart or sensible, so yeah :)
Since photoresistors dont output a discrete voltage, why not just have a spiral inside the disk so you can get an analog reading from the row of resistors? So like 0 degree rotation would mean the furthest diode is the lowest, and 359 degrees the closest diode, the middle diode 180 degrees, etc
I had also been interested in making my own anemometer at one point, but I felt that these ones where you measure something spinning might not hold up well. I did some digging and found out about ultrasonic anemometers. Because sound is transmitted through air and wind is air moving, that can make a sound wave travel faster or slower depending on the direction, I think. So the idea is that you could take two of these transducers, aim them at each other, and see how long it takes for the sound to travel between them, at least that's how I think they work. If you add another pair perpendicular to the first pair, then you can calculate the vector of the wind direction. You could even add another pair facing vertically and measure the wind in three dimensions.
I think these seem better than traditional anemometers because normally there would be some resistance to getting something spinning, so there would be a minimum speed that you could measure, but I think that an ultrasonic anemometer would be able to measure a lower wind speed.
I never actually did anything more on this project than research, but it will be neat to see what you do next.
1) You need gray code not plain binary, otherwise you will get nonsense codes at boundaries.
2) Photoresistors are probably too slow to react for this purpose. Try phototransistors or photodiodes as a sensor
We used very similar encoders like this in some navy equipment accurate to .1 degree. They were plated on a glass disk. And it used gray encoding to simplify timing. The key to gray encoding is that only one bit changes between each number.
Gray coding also helps with analog resolution. On optical encoders, you can read partial activations and get better instantaneous velocity readings (where you would otherwise need to integrate).
@@microcolonel I like the "self clocking" aspect of the gray code the most. A simple "or" gate of all the inputs, and you have your clock. No need to an extra clock input. On the design in this video, I think the holes on the outside edge are for clocking. But since that input needs to be narrower than the data bits, it just takes up more room and results in less resolution. In the same size disk with the same size bits, you could get at least one more digit of resolution if you changed the clock bit to a data bit.
Yes, rather than 3d printing this, it might be laser printed onto plastic sheet meaning it could be smaller, use a greater number of bits
I think this is mounted horizontally to give an absolute bearing of the wind. This is not connected to the blades to measure rotational velocity.
The binary code changes in direct relationship to the angular position.
No timing involved.
@@ahaveland Sorry, you miss understood what I was talking about. I was talking about clocking in multiple binary bits into some type of reader, like a microprocessor. If you study this wheel, there are 5 data bits and one clock bit on the wheel. The holes on the outside edge are the clock bits. When one those holes allows light to illuminate the sensor under it, all the other sensors should also be in position for reading, so the pulse caused by the hole can be used to clock in all the other bits. You can't just use the data bits themselves because more that one bit can change between one position and the next, but with gray code, only one bit ever changes, so you can use the change of data bits to act as the clock. All you need is a simple multi input 'or' gate connected to each input or a little code in the micro you are using. So, on the same size wheel, you can use that clock bit position as an added data bit and get 6 bits of resolution instead of 5. Wikipedia has a good discussion on gray code if you are interested.
There is math solution for optimal mecanical - numerical encoding. Gray code. If the disc was using piercings according to gray you can easily also determine speed and direction of the disk. With already available code.
Don't forget to add a back light for consistent lighting conditions and add a north sign to the design so that you can mount it aligned with a compass.
This many positions is good for telling exactly what position the disc is at. Also can be used to tell direction and speed at which the direction changes. Very nice.
Easier ways, sure.. More interesting... Probably not. I have a question though. Are you going to create a compete weather station? You need to keep us updated.
Thank you!! Yes, a complete weather station is definitely in my plans. I’m trying out a whole bunch of different things right now to see what I think is promising. Glad you’re following along. Eventually, when I’m living in a larger space, I would love to have a self-powering, IoT weather station. Probably a little too ambitious for this little balcony though. 🤣
I've often found that in any gust of wind, there can be a flag placed within its path to best indicate its direction.
Yes you should simply just connect the weather main to a potentiometer and then read the resistance and set each direction to its resistance value and write a simple interpolation that way you only need one component rather than several photo resistors and a binary disc
A pot has way too much mechanical resistance for his application
That won't allow for an infinite 360° rotation. The correct part would be a rotary encoder
@@AchievedZeus574 360 degrees potentiometers exist
@@maquez650 yes 360 does, but not infinite. When the pot reaches its limit you can’t nicely ask the wind to change directions.
@@TheOfficialOriginalChad how do car stereos/climate controls etc work then? I guess they would need constant power in order not to loose their position, but that should work.
Yes. You could have simply taken a senor and a wind sail. The wind sail turns when filled with air, showing you where the wind is coming from.
I think they normally use a sock type one for this device.
This thing you made would be good if you had a gear box for wind. You could have it swap gears as it moved to each faster ring on the sensor.
You didn't make a directional input, but a speed tracker
I think a wind sock and a pair of eyes have done a good job over the years but go for it!
Exactly and add a camera with a solar panel if its location is out of sight. Even using an old farmers barn wind vane with a camera looking down and at a pointer and dial.
The disc seems to be counting up, so each value will say where the wind is
(Edit)
It can track 16 positions and speed using the outer dots. By counting 0-15 twice for 180°. It seems like a good measure
0 n/s
2 nne/ssw
4 ne/sw
6 nee/sww
8 e/w
10 see/nww
12 se/nw
14 sse/nnw
16 s/n
You basically need only one of your rings and two light gates. Your ring hast to be in the pattern 101010. Based on wich of your light gates turned on or off first you can say in wich direction it turns. And you can count the wind speed as well. In German we call this thing "Drehgeber"
In english it is a rotational encoder
Sounds like he's going for absolute direction and not just left or right.
@@psywiped he can get absolute direction by measuring it and than calculating the new position with every turn the
@@Jason-hz2jy what if it lost power or steps?
This will not tell direction since the code from any starting point will be either 1010... or 0101... depending on the starting point. Simplest solution would be analog using a circle of wedges. Increasing signal over time implies one direction and decreasing signal implies the opposite direction. Also provides direction with smaller fractional movements.
One possible improvement: use gray code to encode the binary number. Gray code not just makes it easier to 3d-print, it also reduces the error, if any sensor has a wrong reading
A recently licked finger: *I’m gonna end this whole man’s career!*
Well, this is smart,
However, all you need to detect is the rotation of the wheel, for that, you can simply use a potentiometer, and depending upon the value of resistance detected, you can find out what direction the wind is blowing.
Indeed, there are waaaaaayyyy simpler ways but like everyone else says, please keep going.
😇😇👍🏻🙏🏻
For direction only (a relatively static value), i.e. Wind vane, an encoder with the required resolution (number of bits) is all that is needed.
All holes, segments are not required, outer ring used to "gate" the other "bits" to present binary value/byte/word to microcontroller.
To reduce the number of input pins required on the microcontroller, use a "parallel in - serial out shift register"
Use LED Photo Diodes and Emitters shielded/enclosed from ambient light.
Photo-resistors are slow analog components better used to measure analog light levels.
To inplement direction and speed, use dual edge-triggered optocouplers with an encoder disc with a missing pulse.
Correctly spaced Optocouplers provides direction from the edge timing and the "missing-pulse" provides a counter reset, speed comes from counting pulses/sec.
The difficulty occurs from measuring two different values, direction and speed, using either independent or interdependent sensors and software code.
If you don't need the absolute position, just having stripes and 2 sensors (offset by half step) works pretty well. Each change is a step. The 2nd sensor is used to determine direction (whether the change is equal or opposite). That's how old ball mice and current mice wheels work. If you DO need absolute position you can just add another sensor with just one signal in one spot of the wheel. Absolute encoders (like gray codes) are ideal for not losing the position if you lose power, but I can't think of many uses where you really need that.
Another way to have absolute position is to have a 2 axis magnetic sensor with a magnet on top of it. The resolution in this case depends on the ADCs used. Some sensors have the ADCs already included with some other features, like with the chips AS5147 or AS5047P which are designed for this purpose.
using Gray code lets you have an absolute encoder where only 1 bit changes at a time, which fixes the errors you would get on the edge case where 2 bits may have fuzzy edges read by the optical sensors.
It’s also a very good representation on how a digital storage disk works.
If you only need direction/speed and not any sort of position/angle data, a simple phase encoder would be adequate and probably simpler to implement and more reliable - typical phase encoders will have two rings with detection points that are offset so that one ring "makes or breaks" (e.g., interrupts light or not) before the other when rotated in one direction and after in the other. If the rings are A and B, and A is offset relative to B clockwise by 5 degrees, clockwise rotation would have B fire then A and counter-clockwise A then B and a circuit could see which one fires first to determine the direction of rotation. Pulse counts can also be used for rotation speed (RPM).
Also, instead of using optics, magnets in a wheel and Hall effect sensors might be more reliable as the circuitry could be coated or even potted.
Another alternative would involve a more "analog" approach: create your disk with a single "slit" that gets progressively wider as it rotates in a given direction. Next, shine a light onto the disk, then through a lens which focuses it onto a single photoresistor. Now, simply read the resistance of your device to determine its position.
Interesting project! My design choices would be gray code encoding, arc slots instead of completely open and connected sectors for better mechanical integrity and an electro/photoetched brass or stainless steel disc.
This one of the simplest and cheapest implemented to solve the problem 👏👏👏
You only need two points on a disc to tell which direction it is spinning. This disc would only be necessary if you needed to provide data instead of a simple rotation signal. You still have to implement to your use case.
You can use an incremental encoder to measure the direction as well. One photoresistor (out of 2) will always lead or lag behind the other. You simply measure at the falling edge of one bit. If the other is a logic high, you are spinning one direction. If the other is a logic low, you are spinning the other direction.
Just grabb an encoder that gives you two pulse trains (A & B). This gives you pulse + direction. Most microcontrollers already have direct support to decode this kind of encoder. You basically only need a "home" position to calibrate when you start up, then it will not be needen and the absolute position can be calculated by counting pulese according to the direction. A microcontroller may do this for you, in hardware, as well.
This was how old mechanical mouses worked, with way better accuracy than your binary wheel.
I worked at a steel rolling mill and was in charge of the automation. The system was circa 1970 and used a couple dozen of these. They were high resolution and each one cost around $12,000.
Use grey code. Not only will you only get one bit change per rotation, but mechanically the disk will be a lot stronger because its material will be better distributed.
It will also be better ballanced if your spinning it with speed.
Look up Gray Code and make your encoder with a Gray code for the number of bits you want. That way, only one bit changes with each position, making the encoder much less prone to false outputs as it moves from one state to the next. It should also make it easier to print and more robust.
If you only want the direction or even speed, a relative encoder will do, and is simpler/more robust. What you show is an absolute encoder which only makes sense if you care about absolute angle.
I like an analog solution to this, but it might not have the consistency or precision you want. I use an infinite turn pot and an AtoD converter. The pot will give different resistance depending on the turn. It takes some training to fill a table with the resistance values for the angles you care about.
That looks exactly like the things R2-D2 uses in starwars
⭐️🤺
Cool introduction to absolute digital encoders. As everyone else said, a gray code is better. Someone else mentioned a relative encoder, where you know the direction and quantity of motion but not exact position without calibration.
Well my friend did a thesis at University making a hybrid, where you know relative motion, and after a small number of moves you know absolute position. It involves creating a gray code sequence that has unique subsequences. Lots of graph theory and stuff.
urinate into the air, if you stay dry the wind is blowing away from you, if you get wet the wind is blowing towards you. one of the first life lessons;)
Just a single compass sensor would do the trick. This is more for those interested in proof of concepts. Also you'd be reliant on a source of light. So no tracking at night unless you provide your own.
Let's consider that one piece of data represented by area enclosed by two circles as shown in the video..... Now the total length of the boundary of circle is given by 2*PI*r
We divide it into n equal parts then
2*PI*r/n..... Now one junk of zero of 1 is represented by an arc length of 2*PI*r....
The sensor reads the inner most disc first and then outwards and so on
The inner most circle has small arc length compared with the outer most circle...... It would be able to store much less data then the outer one....
def an easier way to find the direction, but it's awesome for absolute positioning.
For an encoder like this i would propose using a Grey Code. Its a variation of binary BUT each neighboring number/value differ only by 1 bit. This makes detection more efficient and less susceptible to readout errors. Also of you use all the bits on the wheel you do not need all that much valies as only few readouts should tell you the direction of the spin. Unless you also require some precision on the actual orientation of the code wheel and studd attached to it
It's called a binary encoding wheel. 8 codes per quadrant. 32 codes represent 360 degrees. Therefore each code represents 11.5 degrees of rotational position resolution.
That's one of the mechanisms in an elevator-door-controller (open normal speed, low speed, open-position)
Close normal speed, low speed, close-position
For wind direction, you need just two channels shifted 90 degrees, and decide the direction based on the order they are triggered. This is an analog encoder that can indicate the position. Its overkill for that purpose.
There might be a simpler way but I like this way because you could use it to get more info, not just direction. A second thing you could get from it would be the speed of the wind.
If you don't care about absolute position and just want to know direction and distance/speed then quadrature encoding is simpler. You only need two sensors and a toothed wheel. That's what the knob on your car radio is. That and the rotary knobs in Arduino discovery kits.
A much simpler solution would be using an apsolute encoder that uses a magnet and a magnetic field sensor, you would get a lot more detail and it would fit within a smaller footprint. You just attach the magnet to the weathervane so it can rotate and put the sensor close enough to the magnet to read it’s poles
You can make it much more accurate by attaching a gear to it so that it spins at a known ratio. One more mechanism would need to detect which quadrant it is in. Theoretically, you could measure down to whatever the lash of the gear is. Given very tight gearing, it's possible to measure millionths of a degree. Another way would be a clear plate with opaque carbon encoding, a light source, and a magnifying lens.
if you only care about the direction, this can be accomplished with only one ring and time, or with two rings independent of time. for a single ring, you can have the increments increase as you turn clockwise. if youre current reading takes longer or shorter than the last, you'll know which direction its moving. if you use two rings, you can have two gaps staggered by half an increment and know which direction its going based on the rise-fall sequence of the rings. (ie fall-outer, fall-inner, rise-outer, rise-inner for cw, and vise versa for ccw)
if all you care is direction, all you need is two bits, phase shifted. E.g. you have 16 holes per rotation for both bits but one bit is phase shifted. Then by which ever of the two comes first, it can tell you the direction
Yeah, a standard quadrature encoder!
a much simpler way, no gray code or binary. take a disk with single row of wholes (like the outer ring), aka a regular encoder wheel and two sensors right next to each other, this will give you pulse counts on any of the sensors and will tell the direction by the phase difference between the two signals. a much simpler disk and only 2 LDRs. :) just make sure your encoder wheel has enough resolution to sample the signals you want to measure. if it spins at the point phases are halfway appart you "loose" the direction info, much like car wheels that seems to stop and sping backwards on video.
Cool! But you should use a gray encoder instead of plain binary, that way you will never get wild intermediate ireadings when switching from one position to the next, since gray encoding ensures that only 1 bit is modified at each step, making the maximum error 1 step.
Binary encoders on the other hand have wildly intermediate states, such as changing from:
0111 to 1000
When the sensors are in-between those two states, each sensor could be either a 1 or a 0, giving you potentionally any other position by mistake.
Depends on if you want an absolute encoder, but you could probably use a continuous rotation potentiometer to get an analog voltage for position (like set South to be 0v and 10v, and North is 5volts, etc). A reed switch could also be added close to South position, to tell if to are at South. No explicit need for a microcontroller then, unless you want to swap the voltage readout to words for the directions instead of having a chart with voltages that equal the directions. Just depends on if photoresistors are much cheaper than potentiometers, since you only need one sensor instead of several.
You can buy rotary encoders to do this sort of job, or use a directional magnetic sensor (e.g. AS5600) with a magnet on whatever spins. The magnetic sensor will be more reliable than a photosensor.
If you want to continue the diy approach, I'd use slits instead of holes around the outside :)
I began working on a simple model in openscad, about the binary coding, there exist an other version that uses gray's binary coding : you only change one bit each time you increment the number, it's a little bit more complex to process but generally way more precise.
Also, I wouldn't use a photo-resistor, but instead a photo-transistor, the photo transistor either conducts as a diode or blocks current as an open breaker. you would just have to plug it between ground and an input pullup of an arduino for example to get a more accurate reading
Easier way is it encode a shift in frequency, put the holes progressive closer together. One direction will give an FM chirp up, the other down. Pretty easy to decode with a timer input. You only need one track or bit this way.
Also it's not crucial here, but photodiodes or phototransistors would be better than LDRs as the sensing element. They switch quicker and give a more definite result. Generally you only use LDRs when you want an analogue result of brightness. For simple digital testing like here, use a phototransistor. That's the usual choice, a photodiode is quicker than a phototransistor so they're used where that matters, but you're nowhere near that speed with this application. A phototransistor ought to function connected straight to a pin on your micro.
Back in the good ol' days, people made phototransistors by cutting the lid off the metal housing ordinary transistors used, before modern plastic ones. Some modern transistors still use that packaging but not so much. Almost all transistors are nautrally light-sensitive, usually to infra-red, that's one reason for the packaging being dense black plastic, or metal, to keep the light out.
Of course "home made" phototransistors didn't come with the performance guarantees that properly purchased ones did, but they were more than good enough, at a time when the price difference made it something worth doing.
If you ever want a science experiment, to impress some young electronics geek, you could try it out. It should even work with plastic-housed transistors though buy a few, so you can work out where the wires are that you don't want to cut, and how much to sand off from which side is sufficient. Sunlight or incandescent bulbs would be a good source of wideband IR, maybe a candle.
Instead of using binary, just put the holes in a spiral toward the center so that each position activates its sensor. This input means this position. Easier programming and less prone to errors due to light activating the wrong sensors when in between positions. Also you could position sensors all around and use one hole, but I think the spiral method would be better.
Put 2 sensors about 5mm apart. Have a spinning disc with equally spaced holes. Whichever sensor detects the hole first determines the direction. You can also get speed data from this.
You could also use a potentiometer and read the resistance. Zero ohms for zero degrees, 10000 ohms for 359 degrees.
The simplest way to see what way the wind is blowing is just to go outside and feel what direction it's blowing from
Rotary encoders can be built with only 2 rings and a switch to know the start position. Offset of which ring switches first can tell you a direction.
Yes . Farmer: *puts a flag on it and marks the blades * *attaches a GoPro to watch the fan with his phone *
The crucial part is the outer ring with the equally spaced holes as it tells you when the readout is actually valid. Otherwise, if two of the inner rings go form hollow to filled you might get a grossly wrong reading.
AFAIK there are other ways to code absolute positions where only one bit changes for each increment. Of course they don't give you the binary value directly, you have to feed it through a deciding algorithm or table.
Quadrature encoder disc would be much simpler since it only needs two photo diodes. Absolute encoders are useful when you need to know the exact position of the shaft even when power is turned off and on again. Otherwise it is overkill.
So Simple, yet so elegantly effective.
Yes, you over thought it. Slotted disk with two slightly offset opto sensors. Direction can be determined by which drops first and speed by counting one of them.
i can easily fit 5 bits into two rings. First, don't do natural binary, do Grey encoding. Second, first two rings are phase shifted, so do one ring with two sensors. Third, if You have ring divided in quaters, You can just use every quater separately, as different frequency. Forth, one of those quaters is even (goes 0->1), so You need additional quater for 1->0. If You wanna more resolution, just add one more ring, it can theoretically fit 31 bits.
123 or 321 will give you spin direction. A BLDC motor used in RC hobby use this method of determining direction. For most this is sufficient as cogging only happens at startup ( not a condition for extracting power only when applying power). For applications that are sensitive to cogging.. eg rock crawler where any backwards movement of a tire counts as a penalty. They use a position sender to initiate movement.
Use Gray code. Here, there are several places where more than one bit changes at once. Right at the point of change over, you might get times where one light sensor is slightly to the left or right of being in a straight line. That will mean you can get the wrong results.
Gray code was designed to fix that. It's the same binary but in a different order, not just counting straight up and down. In Gray code, only one bit at a time ever changes, so the result will always be the correct one, or else out by just one position. It also means the disc will be stronger cos there's no bits where the plastic is hanging from nothing. In particular the third ring from the centre here has a quadrant where it, and the bits after, all hang from just one small piece on the eedge.
If you look up Gray Code it'll all be explained. It's also easy to convert in a microcontroller, you could just use a lookup table of, what, 32 bytes x 6 bits, and that can be stored in program ROM where you've plenty of space.
Magnetic encoders or Hall effect sensors would’ve been way more compact…
Nice idea. But overkill. If all you want is direction: 1. You can digitally encode with variable speed using two circles. 1010...for timing and 123123... for direction. 2. If you don't need near instantaneous direction at low speeds of rotation, you can assume near constant velocity and use a single circle of 123123... 3. Since your sensor is analog, just use one circle of tapering wedges. In one direction, the signal will increase, and in the other, it will decrease over time.
Yes there's a simpler way. Reed switches magnets and different resistors connected in series on each reed switch. resistance varies depending on which circuit is closed making you able to locate the direction. a cheap 16 bit ADC like the ADS1115 should do the trick for reading the total resistance.
You put the reeds in a star pattern on the stationary underside and float the magnet on top of them on the vane.
Less moving parts, you trade in some precision but if it's for a weather vane it will wiggle either way.
if you only want to get the direction and speed, but not absolute position 2 rings are enough. better yet, but get an end of shaft encoder. they are cheap and much more compact and can encode the direction and step
Everybody is talking about Gray encoding but there's an even easier way:
Assuming you have good control of your lighting setup (a dark enclosure with an LED maybe?) you should only need three states: low, middle, high resistance. Your microcontroller only needs one photoresistor, and checks every step to see if the resistance is going up or down (with some way to check for wrapping around). It's as simple as ABCABC vs CBACBA
This is cool but to your question. If you only care about direction and speed a simpler way with the same technology would be to use only 2 points of measure, regular spacing between the gaps, and measure time differentials. Or a magnet and 2 hall sensors so you can use it at night/under cloud cover/inside.
You didn't really need absolute position encoding, you just needed any sort of rotary encoding. Basically, just use the outer two rings and ignore everything else. That gives you speed and direction.
I think there are many far simpler ways to see which way the wind is blowing, like a sock, but this is definitely a very clever method, and I quite like it.
another way of finding whichway the wheel is turning: attaching a motor, measuring if volts are negative or positive: it will give you the info.
add the wheel to know how strong the wind blows: the rpm will tell that.
ps: dont use regular binary, because if sensors are misaligned, if you change from 0111 to 1000, the misalignment will give you unpredictable numbers like 1111 (draw 1000 and 0111 and use a straight object or a laser, you'll see every possibility)
in fact, you should use this way of counting:
000
001
011
010
110
100
101
111
where only a single bit change.
ps: there are already chips that do the Reflected Binary Count to regular binary count conversion ;) but you also can do it by yourself with programming, too. just a conversion table will do perfectly: one array containing the RBC numbers with keys will be ok. and output the key depending on the value received.
thanks for remembering a 3D printer can do this too since i got some electronic components in stock ^^