Go Down

Topic: creating a "True Voting Logic" program for 3 sensors............... (Read 888 times) previous topic - next topic

concretefreak

Morning!!!!

I'm currently in the process of finishing a circuit with an Arduino Mega that analyzes three sensors and outputs a voltage in mV's.   I have been doing some research on "Voting Logic" circuitry and I'm hoping someone has done something similar who can offer a bit of advice on where to start.  The program should be able use what is called "True Voting Logic" to analyze the input from 3 Oxygen sensors.
     Essentially, the program will look at the output of the 3 sensors independently, and compare them against the others. Should one sensor fall outside a given parameter, established by the program (at this stage, that parameter would be +/- 20%) the output of that sensor is IGNORED by the electronics, and the other 2 sensors are then averaged together to determine a final set value.  This "Voting Logic" must be repeated every 500ms(+-200ms).

Thank you in advance for your input!!
Dave

AWOL

Good afternoon.

What do you mean by "IGNORED by the electronics"?
Taken out circuit permanently?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

concretefreak

Hi there...

Sorry what I should have said is, after being voted out it would be ignored by the PID that drives the relay injecting the oxygen.

CrossRoads

Seems straightforward enough:
Code: [Select]

void loop(){
if (millis()>=nextcompareTime){
nextcompareTime = nextcompareTime + 500;
average = 0;
sum = 0;
digitalWrite (errorPin, LOW);
errorState = LOW; // LOW is 2 or more good readings, HIGH is 0 or 1 good readings

sensor1 = analogRead (A1);
sensor1 = analogRead (A1);  // read twice to allow for settling
if (sensor1>= lowParamater && sensor1<=highParameter){
average = average+1;
sum = sum+sensor1;
}

sensor2 = analogRead (A2);
sensor2 = analogRead (A2);  // read twice to allow for settling
if (sensor2>= lowParamater && sensor2<=highParameter){
average = average+1;
sum = sum+sensor2;
}
sensor3 = analogRead (A3);
sensor3 = analogRead (A3);  // read twice to allow for settling
if (sensor3>= lowParamater && sensor3<=highParameter){
average = average+1;
sum = sum+sensor3;
}
if (sum>=2){
errorState = LOW;
sensorAverage = sum/average;
Serial.print(" Good reading: ")
Serial.println(sensorAverage, DEC); // may have to tweat this line
}
else{
errorState = HIGH;
digitalWrite (errorPIN,  HIGH);
if (average == 1){
sensorAverage = sum;
Serial.print(" Questionable reading: ")
Serial.println(sensorAverage, DEC); // may have to tweat this line
}
if (average == 0){
Serial.print(" No readings in range ");
}
} // end else
} // end time check
} // end void loop


Or something along those lines ...

Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

concretefreak


Seems straightforward enough:
Code: [Select]

void loop(){
if (millis()>=nextcompareTime){
nextcompareTime = nextcompareTime + 500;
average = 0;
sum = 0;
digitalWrite (errorPin, LOW);
errorState = LOW; // LOW is 2 or more good readings, HIGH is 0 or 1 good readings

sensor1 = analogRead (A1);
sensor1 = analogRead (A1);  // read twice to allow for settling
if (sensor1>= lowParamater && sensor1<=highParameter){
average = average+1;
sum = sum+sensor1;
}

sensor2 = analogRead (A2);
sensor2 = analogRead (A2);  // read twice to allow for settling
if (sensor2>= lowParamater && sensor2<=highParameter){
average = average+1;
sum = sum+sensor2;
}
sensor3 = analogRead (A3);
sensor3 = analogRead (A3);  // read twice to allow for settling
if (sensor3>= lowParamater && sensor3<=highParameter){
average = average+1;
sum = sum+sensor3;
}
if (sum>=2){
errorState = LOW;
sensorAverage = sum/average;
Serial.print(" Good reading: ")
Serial.println(sensorAverage, DEC); // may have to tweat this line
}
else{
errorState = HIGH;
digitalWrite (errorPIN,  HIGH);
if (average == 1){
sensorAverage = sum;
Serial.print(" Questionable reading: ")
Serial.println(sensorAverage, DEC); // may have to tweat this line
}
if (average == 0){
Serial.print(" No readings in range ");
}
} // end else
} // end time check
} // end void loop


Or something along those lines ...




This is very interesting!!!!
Thank you so much for your input, i'll play around with this and see what happens.  This is a great start!!

Many thanks!
Dave

Graynomad

#5
May 18, 2012, 05:26 pm Last Edit: May 18, 2012, 05:31 pm by Graynomad Reason: 1
Just off the top of my head, something like this may be a start

Code: [Select]
int diffs [3];
int jump_val = 0;

diffs [0] = sens1_val - sens2_val;
diffs [1] = sens2_val - sens3_val;
diffs [2] = sens3_val - sens1_val;

jump_val |= (diffs[0] < threshold) ? 1 : 0;
jump_val |= (diffs[1] < threshold) ? 2 : 0;
jump_val |= (diffs[2] < threshold) ? 4 : 0;

switch (jump_val) {

case 0:
case 1:
case 2:
case 4:
// invalid because no two sensors are within the threshold
break:

case 3:
    // use sensors 1 and 2
break:

case 5:
    // use sensors 1 and 3
break:

case 6:
    // use sensors 2 and 3
break:

case 7:
    // use all sensors
break:
}


______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

PeterH

If you're doing something like that which will demote a sensor then I suggest you also look at the other side of the equation and design your algorithm to promote it back into the system when it looks credible. Otherwise, each sensor is only allowed to fail once, and when the second sensor fails your design fails.
I only provide help via the forum - please do not contact me for private consultancy.

CrossRoads

No problem Dave. You'll have to do the variable data type assignments, pinModes, etc.

PeterH,
I set up loop to read each sensor fresh every time, no sensor is kicked out unless the its reading was bad for that set of readings.

Robert
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Go Up