Pages: [1]   Go Down
Author Topic: creating a "True Voting Logic" program for 3 sensors...............  (Read 666 times)
0 Members and 1 Guest are viewing this topic.
Massachusetts
Offline Offline
Full Member
***
Karma: 0
Posts: 105
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 236
Posts: 24266
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Good afternoon.

What do you mean by "IGNORED by the electronics"?
Taken out circuit permanently?
Logged

"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.

Massachusetts
Offline Offline
Full Member
***
Karma: 0
Posts: 105
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Global Moderator
Boston area, metrowest
Online Online
Brattain Member
*****
Karma: 434
Posts: 23593
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Seems straightforward enough:
Code:
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 ...

Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Massachusetts
Offline Offline
Full Member
***
Karma: 0
Posts: 105
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Seems straightforward enough:
Code:
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
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 121
Posts: 8430
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Just off the top of my head, something like this may be a start

Code:
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
« Last Edit: May 18, 2012, 10:31:42 am by Graynomad » Logged

Rob Gray aka the GRAYnomad www.robgray.com

UK
Offline Offline
Shannon Member
****
Karma: 183
Posts: 11114
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Global Moderator
Boston area, metrowest
Online Online
Brattain Member
*****
Karma: 434
Posts: 23593
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Pages: [1]   Go Up
Jump to: