User avatar
HermannSW
Posts: 6250
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany

Re: diy autofocus with /dev/video16 and stepper motor?

Wed Jul 08, 2020 6:34 am

Yesterday I did hunt for qcam display scale bug a long time, and finally identified it, with help from Naushir:
viewtopic.php?f=43&t=273018&p=1692574#p1692390

And I found a workaround (instead requesting 800x600 and getting 800x472, request 800x472 and get that).
With that workaround display is not compressed in y direction anymore:
viewtopic.php?f=43&t=273018&p=1692574#p1692431

Before porting my Arduino sketch C code to control microscope z axis 28BYJ-48 stepper motor with half steps, I wanted to just test the hardware being controlled from Pi:
Image

I looked into Joan's pigpio library and found (Python) example code to control stepper motors. The one I used was "Control stepper motor using keyboard left and right keys":
https://github.com/stripcode/pigpio-ste ... right-keys

I took a short video (37s) of focusing microscope, first from below focus drive fast up (keep KEY_LEFT pressed) and overshoot focus, then drive fast down overshooting again, followed by fine focusing until maximum of 587:
https://www.youtube.com/watch?v=sBHFPR84UAw

What you hear is constant voltage power supply providing 9V/161mA to 800lm led lighting microscope scene.
What you see in terminal window at bottom is output of this command:

Code: Select all

$ LIBCAMERA_LOG_LEVELS=RPiFocus:DEBUG build/src/qcam/qcam | grep Focus
microscope.z-axis.key-control.jpg
microscope.z-axis.key-control.jpg
microscope.z-axis.key-control.jpg (106.85 KiB) Viewed 1132 times
https://github.com/Hermann-SW/RSA_numbers_factored
https://stamm-wilbrandt.de/GS_cam_1152x192@304fps
https://hermann-sw.github.io/planar_graph_playground
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://stamm-wilbrandt.de/

User avatar
HermannSW
Posts: 6250
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany

Re: diy autofocus with /dev/video16 and stepper motor?

Fri Jul 10, 2020 6:12 pm

For AF I have nearly everything needed:
  • AF0.c showed how to extract focus values from qcam without modifying it
  • half-stepping in z direction allows for 4.4µm wide steps
Before I want to do autofocus I will do one more step:
Evaluate whether microstepping allows that repeatable movements as with half-stepping, just with shorter steps.
The two coils will get sin()/cos() PWM values, for angles x*9° for x in 0..39. This would give 5 steps between the 8 half-step positions, and so hopefully <1µm step-width.
All this because half-stepping as shown in the video did jump for 40 around maximum for single half-steps, better to be able to move more fine and get the real maximum (under constant lighting -- that is given by the very bright 9V 800lm lens lighting microscope scene).
https://github.com/Hermann-SW/RSA_numbers_factored
https://stamm-wilbrandt.de/GS_cam_1152x192@304fps
https://hermann-sw.github.io/planar_graph_playground
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://stamm-wilbrandt.de/

Return to “Camera board”