# Auto/Fixed Focus

## Overview

| Parameter | Fixed-Focus (FF) | Auto-Focus (AF) |
| --- | --- | --- |
| [Vibration Tolerance](#Auto%252FFixed%2520Focus-Vibration%2520Tolerance) | High | Low |
| [Focus Range](#Auto%252FFixed%2520Focus-Focus%2520Range) | 50 cm to infinity | 10 cm to infinity |
| [Manual Focus](#Auto%252FFixed%2520Focus-Manual%2520Focus) | No - lens is glued | Yes - programmatically |

Overall, Auto-Focus cameras are more versatile and can be used for a wider range of applications, while Fixed-Focus cameras are
more robust in high-vibration environments. See [Recognizing focus type](#Auto%252FFixed%2520Focus-Recognizing%2520focus%2520type)
for how to tell which type of camera module you have.

## Vibration Tolerance

Fixed-Focus (FF) is better for handling high-vibration environments.

Auto-Focus uses Voice Coil Motor (VCM) to move the magnet that is mounted to a free-moving lens. In high vibrations, this
electromagnetic force is overpowered and the lens vibrates all over the place, causing blurry/weird/"jello" frames.

Some applications, where of high-vibrations:

 * Drone
 * Lawn mower
 * Heavy machinery
 * Harley Davidson motorcycles (which are notorious for their vibrations), etc.

## Focus Range

Auto-Focus (AF) is best here. Fixed-Focus can see clearly from ~50 cm (~20 inches) to infinity, whereas Auto-Focus can see clearly
from 10 cm (~4 inches) to infinity.

Auto-Focus accomplishes this wider Depth of Field (DoF) by actually moving the lens to a different position (~255 different steps)
to focus at specific distances. The Auto-Focus model can be manually controlled via API as well, in 1/256 steps (see below).

## Manual Focus

Auto-Focus cameras can be manually controlled via DepthAI API. You can set the focus value (0..255) either in:

 * Runtime, with [example here](https://docs.luxonis.com/software/depthai/examples/rgb_camera_control.md#rgb-camera-control) you
   can use , and . to change focus
 * At boot time, with the following Python code:

```python
pipeline = dai.Pipeline()
rgbCam = pipeline.create(dai.node.ColorCamera)
rgbCam.initialControl.setManualFocus(100) # 0..255
```

Note that in high-vibration environments, even if you set manual focus, the AF coil (which holds the lens) won't be able to keep
the lens in place, which will result in a blurry image.

## Recognizing focus type

If you aren't sure whether the OAK in front of you has Auto-Focus or Fixed-Focus color camera, you can recognize it by the silver
metal ring on the Auto-Focus mechanism, as shown in the image below.

Another possibility would be to query this information using DepthAI API library:

```python
import depthai as dai
with dai.Device() as device:
    print(device.getConnectedCameraFeatures())
```

Which will print something like below. The hasAutofocusIC field will be 1 for the AF camera, and 0 for the FF camera. So in this
case, our OAK-D camera is AF:

```python
[
    {socket: CAM_A, sensorName: IMX378, width: 4056, height: 3040, orientation: AUTO, supportedTypes: [COLOR], hasAutofocus: 0, hasAutofocusIC: 1, name: color},
    {socket: CAM_B, sensorName: OV9282, width: 1280, height: 800, orientation: AUTO, supportedTypes: [MONO], hasAutofocus: 0, hasAutofocusIC: 0, name: left},
    {socket: CAM_C, sensorName: OV9282, width: 1280, height: 800, orientation: AUTO, supportedTypes: [MONO], hasAutofocus: 0, hasAutofocusIC: 0, name: right}
]
```

Note that there are 2 fields:

 * hasAutofocus field is what is stored in EEPROM (can be incorrect) and is mostly there for backwards compatibility.
 * hasAutofocusIC field is the actual value read from the camera module (VCM controller). This field is the one you should rely
   on.
