Motorized Zoom/Focus Lens Controller

Many lens used with CCTV cameras have motorized zoom and focus. The position of focus or zoom can be determined using a potentiometer. The idea here is to implement a simple closed-loop controller that would quickly set the zoom/focus to the correct position upon user command.

In many servo motors with position feedback, the controller is implemented by means of a dedicated chip like MC33030, M51660L (and its possible clone AA51880), NE554, and NJM2611. The parameters of these controllers can be changed using external components (resistors and capacitors).

The parameters of this servo controller as stated by the datasheet of the “Ace Digital Commander Servo Amplifier”, which is a very old servo motor that is based on the NE554:

  • Deadband: the minimum difference between input pulse and internally generated pulse to turn on the ouput
  • Minimum Output Pulse: the smallest output pulse that can be generated from the trigger circuit.
  • Pulse stretcher gain: the relationship between error pulse and output pulse.

Some of these controllers are DC driven (like the MC33030) most others are pulse width driven (like M51660L).

Bypassing SG90 controller to use the DC motor and potentiometer as a test setup

To test different control strategies, a cheap servo (SG90) was modified to bypass the built-in controller/driver chip (KC8801) and to directly read the potentiometer reading and drive the motor. The motor was connected to Arduino Nano through a motor driver (L9110) as shown below.

Schematics of the Test Bench

The simplest way to control the motor, is to read current position and move the motor accordingly to the target position while constantly reading the potentiometer until the difference between current and target position is small enough.

There are many issues with this naive approach of control:

  • Motor speed: we make no assumption about motor speed, and thus, the bahavior will be different with different motors or supply voltage.
  • Timing: this is related to the previous point, but we add to that the time it takes for ADC conversion, and the delay.
  • ADC Noise

These issues lead to oscillations around the target position until the final position is stabilized.

To handle oscillation and to move faster to the target position, a more advanced algorithm is needed.

Mathematically, the problem can be stated as following. Given the current position is $x_0$ and the target position is $x_p$. Given the maximum speed of the motor is $v_max$, the goal is to find a function $v(t)$ that would read the target position $x_p$ at minimum time.

Piecewise Linear Velocity Profile

An intuitive solution would be a piecewise linear function (three pieces), piece from initial time $t_0$ until maximum speed is reached, then linear (with $v_max$, and finally slowing down until $t_target$ and consequently $x_p$.

This is a typical contrained optimal control problem ($v_max$ is the constrained). Typical controllers are:

  • Bang-Bang controller.
  • PID Controller.

[Will be continued]