Hola,
Tengo un problema con la libreria PID_v1 del Arduino.
Declaración
//PID
float outputRollStable;
float outputPitchStable;
float outputYawStable;
float targetYaw
float targetPitch;
float targetRoll;
PID yawReg(&ypr[0], &outputYawStable, &targetYaw, YAW_P_VAL, YAW_I_VAL, YAW_D_VAL, DIRECT);
PID pitchReg(&ypr[1], &outputPitchStable, &targetPitch, PITCH_P_VAL, PITCH_I_VAL, PITCH_D_VAL, REVERSE);
PID rollReg(&ypr[2], &outputRollStable, &targetRoll, ROLL_P_VAL, ROLL_I_VAL, ROLL_D_VAL, REVERSE);
Función de inicialización en setup()
bool initPID()
{
yawReg.SetMode(AUTOMATIC);
pitchReg.SetMode(AUTOMATIC);
rollReg.SetMode(AUTOMATIC);
yawReg.SetOutputLimits(-YAW_PID_LIMIT, YAW_PID_LIMIT);
pitchReg.SetOutputLimits(-PITCH_PID_LIMIT, PITCH_PID_LIMIT);
rollReg.SetOutputLimits(-ROLL_PID_LIMIT, ROLL_PID_LIMIT);
//yawReg.SetSampleTime(10);
//pitchReg.SetSampleTime(10);
//rollReg.SetSampleTime(10);
return true;
}
Compute
void computePID()
{
//RX
channel[THRO] = receiverInputChannel3;
channel[YAW] = receiverInputChannel4;
channel[PITCH] = receiverInputChannel2;
channel[ROLL] = receiverInputChannel1;
targetYaw = map((float)channel[YAW], RC_MIN, RC_MAX, -YAW_PID_INFLUENCE, YAW_PID_INFLUENCE);
targetPitch = map((float)channel[PITCH], RC_MIN, RC_MAX, -PITCH_PID_INFLUENCE, PITCH_PID_INFLUENCE);
targetRoll = map((float)channel[ROLL], RC_MIN, RC_MAX, -ROLL_PID_INFLUENCE, ROLL_PID_INFLUENCE);
yawReg.Compute();
pitchReg.Compute();
rollReg.Compute();
}
Cuando voy a ver los valores del output, solo me hace el rollReg.
Por lo que visto, si en la declación pongo el último el pitch, solo hace el pitch.
//PID
float outputRollStable;
float outputPitchStable;
float outputYawStable;
float targetYaw
float targetPitch;
float targetRoll;
PID yawReg(&ypr[0], &outputYawStable, &targetYaw, YAW_P_VAL, YAW_I_VAL, YAW_D_VAL, DIRECT);
PID rollReg(&ypr[2], &outputRollStable, &targetRoll, ROLL_P_VAL, ROLL_I_VAL, ROLL_D_VAL, REVERSE);
PID pitchReg(&ypr[1], &outputPitchStable, &targetPitch, PITCH_P_VAL, PITCH_I_VAL, PITCH_D_VAL, REVERSE);
(ahora el pitch funciona pero el resto no)
Lo único que he modificado de la librería es que en vez de doubles sean floats, adjunto la librería.
Los valores de la radio funcionan bien, de echo, los pids funcionan (todos) cuando usa la IMU (ypr[3]) pero solo uno al de la radio según el orden.
Alguna idea? No hay funciones estáticas y son punteros... No veo pq no funciona
Gracias.
PID.cpp (6.4 KB)
PID.h (3.47 KB)