I'm doing a propeller pendulum, but the controller output is always 0.
What do I do? I need to solve this urgent problem.
#include <PID_v1.h>
#define PIN_REFERENCE A2
#define PIN_SENSOR_MOTOR A1
#define PIN_PWM 9
//variaveis que usaremos para armazenar os valores
double sensorMotorValue, referenceValue, outputController;
//parametros iniciais que estamos utilizando
double Kp = 60 , Ki = 0.290 , Kd = 0.0750 ;
PID myPID(&referenceValue, &outputController, &sensorMotorValue, Kp, Ki, Kd, DIRECT);
unsigned long timet;
unsigned long previousTime;
bool enterFunction = true;
void setup(){
Serial.begin(115200);
pinMode(PIN_REFERENCE, INPUT);
pinMode(PIN_SENSOR_MOTOR, INPUT);
pinMode(PIN_PWM, OUTPUT);
// atribuindo valores as nossas variaves
referenceValue = analogRead(PIN_REFERENCE);
sensorMotorValue = analogRead(PIN_SENSOR_MOTOR);
// ligando o PID
myPID.SetMode(AUTOMATIC);
}
void loop(){
referenceValue = map(analogRead(PIN_REFERENCE), 0, 1023, 0, 100);
sensorMotorValue = map(analogRead(PIN_SENSOR_MOTOR), 0, 1023, 170, -94);
myPID.Compute();
analogWrite(PIN_PWM, outputController);
timet = micros();
if (entrar_na_funcao == true){
previousTime = timet;
//inicie o codigo abaixo
Serial.print(sensorMotorValue);
Serial.print(" ");
Serial.print(referenceValue);
Serial.print(" ");
Serial.println(outputController);
}
if (timet - previousTime < 99999){
enterFunction = false;
}else{
enterFunction = true;
}
}
pendulo-helice.ino (1.49 KB)