In mechanical engineering, there are parts that are very tedious to draw by hand. These are, for example, gears or an optical encoder disk. Not all free software is able to generate a symmetrical and predictable pattern in a circle.
How do you draw N=500 trapezoidal windows around the perimeter of a circle? And in such a way that everything is symmetrical. How do you draw a child’s Sun with only exactly 600 rays?
To solve such problems, there are text-based drawing languages: Graphviz, Asymptote etc.
At first, I was looking in the direction of Graphviz, but Graphviz distorts the shape of the shapes when rotated. We had to look for an alternative to Graphviz.
I liked the programming language for drawing Asymptote: The Vector Graphics Language. It turned out to be a great option for auto drawing generation.
Problem statement.
It is necessary to draw the disk of the optical encoder according to the parameters.
№ |
Parameter |
Variable |
1 |
Number of dashes or trapezoidal holes |
N |
2 |
Duty cycle |
T |
3 |
Outside Diameter |
D |
4 |
bore |
d |
Such narrow trapezoids should line up in a circle.
It is clear that you can get tired of drawing each window of such a disk by hand already on the 8th window, but usually you need 500-800 windows. This is where the interpreted precision graphics markup language comes in, for example, Asymptote: The Vector Graphics Language. You can install it here https://asymptote.sourceforge.io/
After installing Asymptote, the folder C:\Program Files\Asymptote appears. It also requires the GPL Ghostscript utility to work. C:\Program Files\gs\gs10.01.2
By default, the asy utility generates a *.eps file. But you can also force *.pdf to be generated.
settings.outformat = "pdf";
unitsize(1mm);
real in_radius = 25.0;
real out_radius = 50.0;
real number_of_strips = 365.0;
real belt = 10.0;
real step_deg=360.0/number_of_strips;
//draw((0,0)--(8,8),0.2bp+red);
dot((0.0,0.0));
draw(circle((0.0,0.0), out_radius+belt), 0.1bp+ black);
fill(circle((0.0,0.0), out_radius+belt),black);
fill(circle((0.0,0.0), out_radius),white);
draw(circle((0.0,0.0), in_radius), 0.1bp+ black);
fill(circle((0.0,0.0), in_radius),black);
fill(circle((0.0,0.0), 3),white);
draw(circle((0.0,0.0), out_radius), 0.1bp+ black);
real phi_deg;
real phi_rad;
real phi_deg1;
real phi_rad1;
real phi_deg2;
real phi_rad2;
real phi_mid_deg;
real phi_mid_rad;
real N;
for( N=0.0; N<number_of_strips; N += 1){
phi_deg = step_deg*N;
phi_deg1 = phi_deg;
phi_deg2 = phi_deg+step_deg/2;
phi_mid_deg = (phi_deg1+phi_deg2)/2.0;
phi_mid_rad = phi_mid_deg*3.14159/180.0;
phi_rad1 = phi_deg1*3.14159/180.0;
phi_rad2 = phi_deg2*3.14159/180.0;
path req =(in_radius*cos(phi_rad1),in_radius*sin(phi_rad1))--(out_radius*cos(phi_rad1),out_radius*sin(phi_rad1))--(out_radius*cos(phi_mid_rad),out_radius*sin(phi_mid_rad))--(out_radius*cos(phi_rad2),out_radius*sin(phi_rad2))--(in_radius*cos(phi_rad2),in_radius*sin(phi_rad2))--cycle;
//draw(req,0.05bp+black);
fill(req,black);
//draw((4.0*cos(phi_rad),4.0*sin(phi_rad))--(8.0*cos(phi_rad),8.0*sin(phi_rad)),0.05bp+black);
}
fill(circle((out_radius+belt/2.0,0.0), 3),white);
Minimal script for running the Asymptote interpreter
cls
"C:\Program Files\Asymptote\asy.exe" -V -f pdf EncoderDisk.asy
It turned out to be a *.pdf file with a disk picture like this
Moreover, in order to draw this complex detail in theory, you don’t even need a mouse. This is the path of the *.asy source file before becoming the *.svg drawing file.
Here’s the simplest build script
cls
"C:\Program Files\Asymptote\asy.exe" -V -f pdf drawing.asy
inkscape.exe --without-gui --file=drawing.pdf --export-plain-svg=drawing.svg
start chrome -open %cd%/drawing.svg
This disc with dashes is not just an abstract ephemeral puzzle. This is the basis of precision angle sensors based on moiré Effect. So-called Raster Potentiometric Interpolator.
The bottom line is very simple. If you take 2 transparent discs (e.g. plexiglass), draw this pattern on them, put 2 discs with patterns on one axis and start rotating disc 2 in relation to disc 1, then when you move to an angle of 1/N, the light will change from maximum brightness to minimum brightness. In one rotation of the disc, the brightness will change N times, where N is the number of dashes. This means that you can increase the accuracy simply by increasing the N number of dashes.
At the same time, these changes in light transmission can be registered with an LED and a photoresistor, between which there are 2 disks.
If you superimpose 2 discs of 500 strokes and 510 strokes, then 10 moiré stripes are formed on the total picture. Just like the difference between the number of strokes 510-500 = 10.
If the number of stripes differs by 5 stripes, then 5 moiré sectors are formed.
If the number of stripes differs by 4 stripes, then 4 moiré sectors are formed.
If you install 2 LEDs and photoresistors, you will get an angle sensor.
Advantages of moiré angle sensors:
++1 Very high angle measurement accuracy can be achieved. The more strokes per back, the higher the accuracy. High resolution of up to 20 arcseconds.
++2 It doesn’t really matter where the light is installed and the size of the light source and brightness sensor. The area of the possible installation site can be selectedIn this case, it is important to note that this is not the case.
++3 If you make a different number of strokes on the discs, you can determine not only the angular speed of rotation, but also the direction of rotation. You’ll need another pair of LEDs and a light sensor. The result is an incremental encoder based on the moiré effect.
++4 No precise light source required. A regular LED with a lens and a photoresistor with a quick response will do.
Disadvantages of moiré effect sensors:
–1 Discs with dashes must be made very carefully
–2 It is not possible to measure the absolute value of the angle. You have to make a key on the disc like in the flywheels of a car. The encoder turns out to be incremental.
–3 If there is dust or sand between the LED and the light sensor, the sensor will stop working. A structure with dust insulation is needed.
–4 There may be a very high repetition rate of the quadrature signal at high rpm, higher than the clock rate of the microcontroller.
Inference
To be a draftsman, you need to be a programmer and know trigonometry.
Acronym |
Decoding |
CCW |
counterclockwise |
CW |
clockwise |
GPIO |
general-purpose input/output |
ADC |
analog-to-digital converter |
MCU |
MicroController Unit |
LED |
light-emitting diode |
Links
https://convertio.co/ru/pdf-svg/
https://habr.com/ru/articles/466863/
https://bstudy.net/847709/estestvoznanie/datchiki_osnovannye_muarovom_affekte
https://en.wikipedia.org/wiki/Moiré_pattern
https://habr.com/ru/articles/505190/
https://www.youtube.com/watch?v=46FTKEdsFPs&lc=Ugym_bJ-jQ5ncP_aBTV4AaABAg
https://www.youtube.com/watch?v=TBu9EZhWAeM
https://www.youtube.com/watch?v=17_-DeitsJU
textbook “Circuitry of analog-to-digital converters”, V.B. Topilsky, Mir Elektronics, 2014
———-
Acknowledgment and Usage Notice
The editorial team at TechBurst Magazine acknowledges the invaluable contribution of the author of the original article that forms the foundation of our publication. We sincerely appreciate the author’s work. All images in this publication are sourced directly from the original article, where a reference to the author’s profile is provided as well. This publication respects the author’s rights and enhances the visibility of their original work. If there are any concerns or the author wishes to discuss this matter further, we welcome an open dialogue to address potential issues and find an amicable resolution. Feel free to contact us through the ‘Contact Us’ section; the link is available in the website footer.