How to apply PID controller to my problem? Pan-tilt camera tracking

683 Views Asked by At

The background

I recently designed pan-tilt camera module which utilizes stepper motors to control the camera motion and Jetson Xavier NX for object recognition.

The workflow is simple:

  1. Program written in Python is analyzing video input and looking for object.
  2. When object is found it calculates the difference between image center and object position (in both X and Y axes) and enables motors.
  3. When object is far from center it sets bigger speed for motors. Whent it's close it runs motors with minimum speed.

IMPORTANT: The program doesn't have any knowledge about the relation between distance on the screen and amount of steps to make by stepper motor to center. It just enable the stepper motor and constantly check until the difference between center and object is very small. Maybe this method is wrong...

The problem

I read about applying PID controllers for that kind of problems to minimize deviation, but I can't understand how I can apply in my situation. It seems to be simpler when there is an absolute value we want to reach (like an angle in case of servo motors). There is a good example by PyImageSearch.com how to use PID Controller to minimize deviation on servo-motors based pan-tilt module. PID Controller tread constantly calculates the angle value based on the current error (difference between the object postition and center of camera frame) and adjusts the angle.

The question

I want to ask how I can think about PID Controller (if it is possible at all), when I have only the speed variable to control the motor instead of the angle like in servos.

Maybe I have to change the way it works and implement the feature which will give me the information about current stepper motor position (like an angle in servos)?

0

There are 0 best solutions below