1
\$\begingroup\$

I have a PID program that sends my linear actuator with potentiometer feedback to roughly the same position within 0.05 inches accuracy as the result of several measurements I've taken.

When it reaches the target position it makes a droning sound that comes from the motor getting small inputs from the PID function.

Here is the graph of the result. https://imgur.io/a/9qZsM2N

  • Does this damage the motor?
  • What is the best way to get rid of this droning sound?
  • Should I have it time out?
  • Is my PID incorrectly tuned?
#include <PID_v1.h>
#include "CytronMotorDriver.h"
#include <SimpleKalmanFilter.h>

double Input, Output; // ,Setpoint
double Setpoint = 88; 

// Specify the links and initial tuning parameters
double Kp = 48, Ki = .1, Kd = 17.6;

PID myPID(&Input, &Output, &Setpoint, Kp, Ki, Kd, DIRECT);
SimpleKalmanFilter simpleKalmanFilter(2.0f, 2.0f, 0.01f);
CytronMD motor(PWM_DIR, 9, 8);  
    
void setup() {
  Serial.begin(9600);
  myPID.SetSampleTime(200);
  myPID.SetOutputLimits(-255, 255);
  myPID.SetMode(AUTOMATIC);
}
    
void loop() {
  Input = simpleKalmanFilter.updateEstimate(analogRead(A0));
  myPID.Compute();
  Serial.println(Output);
    
  motor.setSpeed(Output);
      
  Serial.print("analog value on Pot:");
  Serial.print(analogRead(A0));
  Serial.print("input:");
  Serial.print(Input);
  Serial.print(",");
  Serial.print("output:");
  Serial.print(Output);
  Serial.print('\n');
}
\$\endgroup\$
8
  • 4
    \$\begingroup\$ You need to measure the output and put it in a graph so you have an idea of that the PID is resulting in. Maybe the P is oscillating for example. Without measurements it's all guessing. \$\endgroup\$
    – Lundin
    Commented Feb 7, 2023 at 15:41
  • 1
    \$\begingroup\$ You can add a dead-band to 0.03 inches for example, so the motor stops when the position is within 0.03 inches of the target. \$\endgroup\$ Commented Feb 7, 2023 at 16:11
  • \$\begingroup\$ How do I add the picture of the graph? It says it is forbidden \$\endgroup\$
    – belza00
    Commented Feb 7, 2023 at 16:45
  • 1
    \$\begingroup\$ @belza00 If you use the insert image button in the editor, it'll show a link until someone with enough rep enables it to appear directly in the post. \$\endgroup\$ Commented Feb 7, 2023 at 17:56
  • \$\begingroup\$ Either your PID parameters need some trimming or your input signal is a bit noisy. The digital filter might not make it alone or also needs more tuning. Log the PID input values - how stable are they for a set position? What is the application? Does it sit longer times on a fixed position? \$\endgroup\$
    – datenheim
    Commented Feb 7, 2023 at 18:51

0