Arducam B029001 autofocus not triggering when robot arm approaches object

Hi everyone. I’ve got an Arducam B029001 16MP autofocus USB camera (the one with the mini metal case) mounted on a robot arm. The problem is that when the arm moves in close to an object, sometimes the autofocus just doesn’t trigger and the image stays blurry in my application’s camera feed. It doesn’t happen every time, but when it does the feed is basically useless until I back away and come in again. Is there any setting or function to trigger autofocus manually, or to enable it programmatically? I’d really like to be able to force a refocus from code.

Welcome to the forum. From what you’re describing, the camera’s focusing process doesn’t have a dedicated signal that automatically triggers autofocus on its own, so relying on it happening by itself won’t be reliable for your use case. The good news is you can drive it manually. The general flow is:

  1. Send a manual focusing command first to initiate the camera’s focusing process.
  2. Then send an autofocus command to actually trigger the camera to autofocus.

To see what’s going on and check the focus controls, v4l2-ctl is your friend. You can list the controls and watch the focus values change when you send those commands. Let me know if you need help reading the control output.

Thanks for the quick reply. I’m trying to put this into a C# program that controls the robot arm, so I need to send the manual focusing command and then the autofocus command from C#. The camera feed viewer app is also written in C#. Do you have any documentation or recommendations on how to send those commands from C# for the B029001 (IMX298)? I’d like to keep everything in one place if possible.

To be honest, our team works primarily in C/C++ and Python, so I don’t have C# experience to draw from here and I may not be able to give you reliable C# guidance. I don’t want to point you in the wrong direction with guesswork. If you’re open to a small helper in C/C++ or Python instead, I can definitely help with that side of things.

That’s fair. If C# is off the table for you, could you give me the C++ or C approach instead? Even a small C++ helper that I could call would be better than nothing. I mainly need to see how the focus commands should be structured so I can translate the idea.

Sure, that’s doable. The approach we usually recommend for manual focus on an autofocus UVC camera is covered here:

https://docs.arducam.com/UVC-Camera/Appilcation-Note/OpenCV-Python-GStreamer-on-linux/#how-to-achieve-manual-focus-of-autofocus-camera-using-opencv

That section walks through achieving manual focus of an autofocus camera using OpenCV. The concept is the same: set the focus mode to manual, adjust the focus value, and switch back to auto when needed. Since you’re on C++, the OpenCV approach should map over cleanly. Let me know if anything on that page is unclear for your setup.