0

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)?

Jonas
  • 121,568
  • 97
  • 310
  • 388
  • Does nvidia-jetson support python? If so cool. A PID Controller is a type of positioner. I suggest you abstract a positioner and then PID is one of the options for the positioner. You will have an immediate issue with PID as you need to control in a two-variable co-ordinate system and a PID is classically just one. – jwal Apr 27 '21 at 10:01
  • Yes, Nvidia Jetson (I tested Nano and Xavier NX) default OS is modified version of Ubuntu.I think by postioner you mean a motor controller which can remember it's position (like in servo motors). As I mentioned I think it's an option but I wonder if it is possible to implement PID in my controller, which is kind of loopback controller. – Maciej Kobuszewski Apr 27 '21 at 11:09
  • I meant an abstraction of the control loop rather than a motor controller. To start with you should just implement bang-bang control https://en.wikipedia.org/wiki/Bang%E2%80%93bang_control. You may have to do co-ordinate conversion between camera and object position and you'll need to sort this first. If you are tracking a moving object the complexity will increase. PID _might_ be part of the solution. I'd start with https://en.wikipedia.org/wiki/PID_controller#Discrete_implementation form. – jwal Apr 27 '21 at 18:14

0 Answers0