Thread: Odor_grad
Constants:
alpha = 0.40;
one_alpha = 1.0 - alpha;
Variables:
// internal
byte x_old, // filtered old input value
x_new; // new
olfactory sensor data
int chng; // utility variable
/* External: These variables are actually in an array for the odor
detector
incrs[i], // increasing
gradient for odor 0 <= i <= 3
decrs[i], // decreasing
gradient
nochng[i]; // non-changing
gradient
Initialize:
x_old = 0;
x_new = odor_sensor[i]
Algorithm:
loop forever
x_new = odor_sensor[i]
// get current sensor reading
chng = x_new - x_old;
// compute temporal difference
incrs[i] = decrs[i] = nochng[i] = 0;
// init variables
if (chng > 0) incrs[i] = chng;
// positive means increase
else if (chng == 0) nochng[i] = 100;
// zero means no detectable change
else if (chng < 0) decrs[i] = (byte) -chng;
// negative means decrease
/* filter x_old for stability */
x_old = ((int)(alpha * x_new + 0.5)) + ((int)(one_alpha
* x_old + 0.5));
end loop