[spam][crazy][random] Rotary Encoder: Slightly More Productive Goal
As I try to move from goals that are intentionally pointless to those that have some utility, I now want to resume my project of providing a way to build a free high quality servo. Servos are motors that can go to a specific orientation and optionally measure their orientation and/or applied force. Where I'm at, is I want to make a script that generates a printout to make a rotary encoder. Servos usually use potentiometers, which are inaccurate. Rotary encoders can be more precise. Unfortunately, I've misplaced or lost my existing work. But the subgoal is quite simple: A script that generates a wheel of color according to a provided radial function. I think if the darkness of the bands on the wheels increases linearly as a function of angle, the encoder could be calibrated to measure possibly-arbitrary precision via a photocell facing the rotary encoder. The script should be generalisable to various encoding norms. You can read more about optical rotary encoders at https://en.wikipedia.org/wiki/Rotary_encoder#Ways_of_encoding_shaft_position .
Did not mean to repeatedly send. My fingers did spazz out during the process of composition and a window opened or something. I didn't refresh a page or hit stop after hitting send or anything, that I was consciously aware of, but maybe the emails show this did happen in some way, unsure.
I've made https://github.com/xloem/encoder . This will help future pursuit of the task, to have a place to put work.
y'know there must be code for this somewhere already. but this makes a quick analog image.
commit 7e23db09ca066d41c7e1227d5444c2d5f3482151 (HEAD -> main, origin/main, origin/HEAD) Author: xloem <0xloem@gmail.com> Date: Sun Mar 27 23:13:15 2022 -0400 implement quickly diff --git a/gen_encoder_wheel/__main__.py b/gen_encoder_wheel/__main__.py index f1bd4f6..608eb43 100644 --- a/gen_encoder_wheel/__main__.py +++ b/gen_encoder_wheel/__main__.py @@ -3,6 +3,12 @@ from imageio import v3 as iio import numpy as np import click +# i used to have an idea for very precise position detection. +# i do not remember what that idea was. + +def angle2intensity(distance, angle): + return angle / np.pi / 2 + @click.command() @click.option('--size', default=4096, help='Height of wheel.') @click.option('--ratio', default=1.0, help='Aspect ratio of wheel. width = ratio * size') @@ -10,8 +16,13 @@ import click @click.option('--output', help='Output filename.') def generate(size, ratio, dpi, output): height = size * dpi - width = height * ratio - img = np.random.randint(0,0xffff,size=(int(width+.5),height,3),dtype=np.uint16) + fwidth = height * ratio + width = int(fwidth+.5) + x = np.tile(np.arange(width) / (fwidth - 1) * 2 - 1, (height, 1)) + y = np.tile((np.arange(height) / (height - 1) * 2 - 1)[:, None], width) + dists = np.sqrt(x * x + y * y) + angs = np.arctan2(x, y) + img = (angle2intensity(dists, angs) * 0xffff + np.random.random((width, height))).astype(np.uint16) return write(output, img) def write(fn, ndimg):
participants (1)
-
Undiscussed Horrific Abuse, One Victim of Many