Inverted Pendulum with control fuzzy logic

PROJECT DESCRIPTION

The Furuta pendulum, or rotational inverted pendulum, consists of a driven arm which rotates in the horizontal plane and a pendulum attached to that arm which is free to rotate in the vertical plane. It was invented in 1992 at Tokyo Institute of Technology by Katsuhisa Furuta and his colleagues. It is an example of a complex nonlinear oscillator of interest in control system theory. The pendulum is underactuated and extremely non-linear due to the gravitational forces and the coupling arising from the Coriolis and centripetal forces. Since then, dozens, possibly hundreds of papers and theses have used the system to demonstrate linear and non-linear control laws. The system has also been the subject of two texts.

Fuzzy logic is a form of many-valued logic that deals with approximate, rather than fixed and exact reasoning. Compared to traditional binary logic (where variables may take on true or false values), fuzzy logic variables may have a truth value that ranges in degree between 0 and 1. Fuzzy logic has been extended to handle the concept of partial truth, where the truth value may range between completely true and completely false. Furthermore, when linguistic variables are used, these degrees may be managed by specific functions.

The term "fuzzy logic" was introduced with the 1965 proposal of fuzzy set theory by Lotfi A. Zadeh. Fuzzy logic has been applied to many fields, from control theory to artificial intelligence. Fuzzy logic had, however, been studied since the 1920s, as infinite-valued logic—notably by Łukasiewicz and Tarski.

#include "Energia.h"
void setup();
void loop();
void Motor_Parada();
void Motor_Izquierda(int dutty);
void Motor_Derecha(int dutty);
/***********************************************************/
/*datos del conversor analogo digital*/
float alpha=0.15;
int fxg=0;
int sensorValue = 0; // value read from the pot
/***********************************************************/
//pines de control para el puente H
#define PIN1 PB_5 
#define PIN2 PB_0

void setup() 
{
pinMode(PIN1, OUTPUT); // sets the pin as output
pinMode(PIN2, OUTPUT); // sets the pin as output
}
void loop()
{
sensorValue = analogRead(A0); //lectura del puerto ADC 
float Xg=sensorValue*3.3/4095; //Conversion del dato ADC
int angulo = (int)(-714.29*Xg + 2018.6); //ecuacion de la recta para el angulo
fxg = (int) (angulo *alpha + fxg * (1 - alpha)); // filtro digital, elimina altas frecuencias


/*Agregar tipo de control fuzzy*/
//nota: limites del pendulo 70° y 110°
if(fxg<75&&fxg>105)
Motor_Parada() ; // cuando se supera los 110 grados o es menor a 70 grados el motor se apaga, parte de seguridad


else if(fxg>75&&fxg<80)
Motor_Izquierda(85); //para angulos cercanos a los limites los impulsos deben ser mas fuertes
else if(fxg>80&&fxg<85)
Motor_Izquierda(80); //para angulos cercanos a los limites los impulsos deben ser mas fuertes 
else if(fxg>85&&fxg<87)
Motor_Izquierda(70); //para angulos cercanos a los limites los impulsos deben ser mas fuertes


/*etapa de banda muerte no debe dar respuesta cuando esta en equilibrio el sistema*/
else if(fxg>88&&fxg<92)
Motor_Parada() ; //para angulos cercanos a los limites los impulsos deben ser mas fuertes

/*etapa para el giro en el sentido contrario; angulos superiores a 90 grados*/
else if(fxg>92&&fxg<95)
Motor_Derecha(70) ; //para angulos cercanos a los limites los impulsos deben ser mas fuertes
else if(fxg>95&&fxg<100)
Motor_Derecha(80) ; //para angulos cercanos a los limites los impulsos deben ser mas fuertes
else if(fxg>100&&fxg<103)
Motor_Derecha(85) ; //para angulos cercanos a los limites los impulsos deben ser mas fuertes

/*Salida de la señal de control*/ 
delay(2); // 2ms de retardo en cada respuesta para asegurar estabilidad del sistema 
}
void Motor_Parada() {
analogWrite(PIN1, 0);
analogWrite(PIN2, 0);
}
void Motor_Izquierda(int dutty) {
dutty = (int) dutty * 255 / 100;
analogWrite(PIN2, 0);
analogWrite(PIN1, dutty);
}
void Motor_Derecha(int dutty) {
dutty = (int) dutty * 255 / 100;
analogWrite(PIN2, dutty);
analogWrite(PIN1, 0);
}

RESOURCES:

Furuta Pendulum.rar

Some Pictures


 


VIDEO