Escolar Documentos
Profissional Documentos
Cultura Documentos
1
Código do arduino - MA
int outPin = 9;
int inPin = A2;
float DC = 34.0; // em %
float h = 1.0; // Passo de cálculo do duty cycle
float DCmax = 40.0; // em %
float DCmin = 35.0; // em %
float t_DC = 5.0; // tempo para cada ducty cycle (em s)
int temp = 1; // Variável temporária
float npt = 500.0; // Número de pontos
float Vin;
void setup(){
pinMode(outPin, OUTPUT);
pinMode(inPin, INPUT);
Serial.begin(9600);
}
2
Código do arduino - MA
void loop(){
float T = (t_DC/npt) * 1000;
Serial.print(DC);
Serial.print(",");
Serial.println(Vin); // Último com println para pular linha
delay(T); // ms
}
3
Código do arduino - MA
Serial.print(DC);
Serial.print(",");
Serial.println(Vin); // Último com println para pular linha
delay(T); // ms
}
}else{
analogWrite(outPin, 0.0); // Para o motor
}
}
} 4
Código python
amostras = 5500
text = ''
for i in range(amostras):
data = str( ser.readline().decode('utf-8') )
text = text + data
print(i)
Sensor
6
Conversão dos dados
7
Função de malha aberta
● Domínio s:
● Domínio z
com
Ts = 0,01s:
8
Controlador PI - 1
A partir da função de transferência de malha aberta Gp(s), foram estabelecidos os parâmetros para
projetar o controlador PI.
PID Tuner
10
Controlador PI - 2
PID Tuner
11
Código arduino - MF
#define PIN_INPUT A2
#define PIN_OUTPUT 9
float setPoint;
float currentAngle;
float atuador;
//// PI ////
float erro;
float DC1;
float DC2 = 0;
float DC;
float t = 0;
12
Código arduino - MF
void setup() {
Serial.begin(9600);
pinMode(PIN_INPUT,INPUT);
pinMode(PIN_OUTPUT,OUTPUT);
void loop() {
if (t <= 10){
setPoint = 30;
}else{
if (t > 10 && t <= 15){
setPoint = 40;
}else{
if (t > 15 && t <= 20){
setPoint = 50;
}
}
}
13
Código arduino - MF
currentAngle = analogRead(PIN_INPUT)*(5.0/1023.0)/ajuste;
erro = (setPoint - currentAngle)*ajuste;
// Controlador PI
DC1 = kp*erro;
DC2 = DC2 + erro*Ts*ki;
DC = DC1 + DC2;
Serial.print(DC);
Serial.print(", ");
Serial.print(currentAngle);
Serial.print(", ");
Serial.print(erro);
Serial.print(", ");
Serial.println(setPoint);
14
Código arduino - MF
delay(Ts*1000);
t = t + Ts;
}
15
Resultados - 1
16
Resultados - 1
17
Resultados - 2
18
Resultados - 3
19