Programacion Fuzzy
Programacion Fuzzy
//***********************************************************************
//***********************************************************************
#include <AFMotor.h>
#include <QTRSensors.h>
#include "fis_header.h"
FIS_TYPE g_fisInput[fis_gcI];
FIS_TYPE g_fisOutput[fis_gcO];
AF_DCMotor motor1(4);
AF_DCMotor motor2(2);
void setup()
Serial.begin(9600);
motor1.run(RELEASE);
motor2.run(RELEASE);
delay(1500);
motor1.setSpeed(velcalibrate);
motor2.setSpeed(velcalibrate);
motor1.run(FORWARD);
motor2.run(BACKWARD);
else
motor2.run(FORWARD);
motor1.run(BACKWARD);
qtra.calibrate();
delay(20);
motor1.run(RELEASE);
motor2.run(RELEASE);
motor1.run(FORWARD);
motor2.run(FORWARD);
void loop()
{
g_fisInput[0] = sensorValues[1];
g_fisInput[1] = sensorValues[2];
g_fisInput[2] = sensorValues[3];
g_fisInput[3] = sensorValues[4];
g_fisOutput[0] = 0;
g_fisOutput[1] = 0;
fis_evaluate();
motor2.setSpeed(g_fisOutput[0]);
motor1.setSpeed(g_fisOutput[1]);
/*
Serial.print(g_fisInput[1]);
Serial.print('\t');
Serial.print(g_fisInput[1]);
Serial.print('\t');
Serial.print(g_fisInput[2]);
Serial.print('\t');
Serial.println(g_fisInput[3]);
Serial.print(g_fisOutput[0]);
Serial.print('\t');
Serial.println(g_fisOutput[1]);
delay(2000);
*/
}
//***********************************************************************
//***********************************************************************
return abs(t);
FIS_TYPE t = (x - c) / s;
}
FIS_TYPE fis_array_operation(FIS_TYPE *array, int size, _FIS_ARR_OP pfnOp)
int i;
FIS_TYPE ret = 0;
ret = array[0];
return ret;
//***********************************************************************
//***********************************************************************
_FIS_MF fis_gMF[] =
};
int fis_gIMFCount[] = { 3, 3, 3, 3 };
int fis_gOMFCount[] = { 3, 3 };
// Coefficients for the Input Member Functions
int fis_gMFI0[] = { 0, 2, 0 };
int fis_gMFI1[] = { 0, 2, 0 };
int fis_gMFI2[] = { 0, 2, 0 };
int fis_gMFI3[] = { 0, 2, 0 };
int fis_gMFO0[] = { 0, 2, 0 };
int fis_gMFO1[] = { 0, 2, 0 };
// Rule Weights
FIS_TYPE fis_gRWeight[] = { 1, 1, 1, 1, 1 };
// Rule Type
int fis_gRType[] = { 1, 1, 1, 1, 1 };
// Rule Inputs
int fis_gRI0[] = { 1, 3, 3, 1 };
int fis_gRI1[] = { 2, 3, 2, 1 };
int fis_gRI2[] = { 1, 2, 3, 2 };
int fis_gRI3[] = { 3, 3, 1, 1 };
int fis_gRI4[] = { 1, 1, 3, 3 };
// Rule Outputs
int fis_gRO0[] = { 2, 2 };
int fis_gRO1[] = { 1, 3 };
int fis_gRO2[] = { 3, 1 };
int fis_gRO3[] = { 1, 2 };
int fis_gRO4[] = { 3, 1 };
FIS_TYPE fis_gIMin[] = { 0, 0, 0, 0 };
//***********************************************************************
//***********************************************************************
FIS_TYPE mfOut;
int r;
if (index > 0)
index = index - 1;
index = -index - 1;
else
mfOut = 0;
}
fuzzyRuleSet[0][r] = fis_min(mfOut, fuzzyRuleSet[1][r]);
FIS_TYPE area = 0;
FIS_TYPE momentum = 0;
int i;
area += slice;
momentum += slice*dist;
//***********************************************************************
//***********************************************************************
void fis_evaluate()
FIS_TYPE fuzzyInput0[] = { 0, 0, 0 };
FIS_TYPE fuzzyInput1[] = { 0, 0, 0 };
FIS_TYPE fuzzyInput2[] = { 0, 0, 0 };
FIS_TYPE fuzzyInput3[] = { 0, 0, 0 };
FIS_TYPE fuzzyOutput1[] = { 0, 0, 0 };
FIS_TYPE fuzzyRules[fis_gcR] = { 0 };
FIS_TYPE fuzzyFires[fis_gcR] = { 0 };
FIS_TYPE sW = 0;
int i, j, r, o;
fuzzyInput[i][j] =
(fis_gMF[fis_gMFI[i][j]])(g_fisInput[i], fis_gMFICoeff[i][j]);
int index = 0;
if (fis_gRType[r] == 1)
fuzzyFires[r] = FIS_MAX;
index = fis_gRI[r][i];
if (index > 0)
else
else
fuzzyFires[r] = FIS_MIN;
index = fis_gRI[r][i];
if (index > 0)
else
sW += fuzzyFires[r];
if (sW == 0)
else
}
}
PROGRAMACION PID
#include <AFMotor.h>
#include <QTRSensors.h>
//------------------------------------------------------------------------------------//
//Sensores de Linea PD
AF_DCMotor motor1(4);
AF_DCMotor motor2(2);
//--------------------------------------------------------------------------------------//
//--------------------------------------------------------------------------------------//
int VProporcional = 6;
int VDerivativo = 2;
//--------------------------------------------------------------------------------------//
//Velocidad de Calibracion
//--------------------------------------------------------------------------------------//
void setup()
motor1.run(RELEASE);
motor2.run(RELEASE);
delay(1500);
motor1.setSpeed(velcalibrate);
motor2.setSpeed(velcalibrate);
motor1.run(FORWARD);
motor2.run(BACKWARD);
else
motor2.run(FORWARD);
motor1.run(BACKWARD);
qtra.calibrate();
delay(20);
motor1.run(RELEASE);
motor2.run(RELEASE);
motor1.run(FORWARD);
motor2.run(FORWARD);
}
long integral = 0;
void loop()
// Calculos PD
integral += proportional;
last_proportional = proportional;
power_difference = maximum;
power_difference = -maximum;
if (power_difference < 0)
motor1.setSpeed(maximum);
motor2.setSpeed(maximum + power_difference);
else
motor1.setSpeed(maximum - power_difference);
motor2.setSpeed(maximum);
}
};