C++ Library for the PsiSwarm Robot - Version 0.8
Dependents: PsiSwarm_V8_Blank_CPP Autonomia_RndmWlk
Fork of PsiSwarmV7_CPP by
Diff: sensors.cpp
- Revision:
- 2:c6986ee3c7c5
- Parent:
- 1:060690a934a9
- Child:
- 5:3cdd1a37cdd7
diff -r 060690a934a9 -r c6986ee3c7c5 sensors.cpp --- a/sensors.cpp Thu Mar 03 23:21:47 2016 +0000 +++ b/sensors.cpp Fri Mar 11 13:51:24 2016 +0000 @@ -5,9 +5,9 @@ * (C) Dept. Electronics & Computer Science, University of York * James Hilder, Alan Millard, Alexander Horsfield, Homero Elizondo, Jon Timmis * - * PsiSwarm Library Version: 0.4 + * PsiSwarm Library Version: 0.41 * - * February 2016 + * March 2016 * * */ @@ -395,7 +395,31 @@ } } +// Returns the subtraction of the background base IR value from the reflection based on last call of store_illuminated_base_ir_values +unsigned short calculate_base_ir_value ( char index ){ + // If the index is not in the correct range or the base IR values have not been stored, return zero + if (index>4 || base_ir_values_stored == 0) return 0.0; + // If the reflection value is greater than the background value, return the subtraction + if(illuminated_base_ir_values[index] > background_base_ir_values[index]){ + return illuminated_base_ir_values[index] - background_base_ir_values[index]; + //Otherwise return zero + } else { + return 0.0; + } +} +// Returns the subtraction of the background side IR value from the reflection based on last call of store_illuminated_base_ir_values +unsigned short calculate_side_ir_value ( char index ){ + // If the index is not in the correct range or the base IR values have not been stored, return zero + if (index>7 || ir_values_stored == 0) return 0.0; + // If the reflection value is greater than the background value, return the subtraction + if(illuminated_ir_values[index] > background_ir_values[index]){ + return illuminated_ir_values[index] - background_ir_values[index]; + //Otherwise return zero + } else { + return 0.0; + } +} void calibrate_base_ir_sensors (void) {