Laser Sensing Display for UI interfaces in the real world

Dependencies:   mbed

Fork of skinGames_forktest by Alvaro Cassinelli

Committer:
mbedalvaro
Date:
Wed Nov 07 14:41:55 2012 +0000
Revision:
34:1244fa3f2559
Parent:
33:43e8bc451ef0
Child:
36:233b12d0b1f0
added hardware button & potentiometer to select the thresholding mode and parameters. Problems with the ADC conversion though...

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbedalvaro 32:52273c3291fe 1 #ifndef LSDTRAJECTORY_H
mbedalvaro 32:52273c3291fe 2 #define LSDTRAJECTORY_H
mbedalvaro 32:52273c3291fe 3
mbedalvaro 32:52273c3291fe 4 #include <vector>
mbedalvaro 32:52273c3291fe 5 using namespace std;
mbedalvaro 32:52273c3291fe 6
mbedalvaro 33:43e8bc451ef0 7 // Thresholding mode:
mbedalvaro 33:43e8bc451ef0 8 enum thresholdingMode {FIXED, AUTO};
mbedalvaro 33:43e8bc451ef0 9
mbedalvaro 33:43e8bc451ef0 10
mbedalvaro 33:43e8bc451ef0 11 //(1) fixed threshold:
mbedalvaro 33:43e8bc451ef0 12 #define FIXED_THRESHOLD 35
mbedalvaro 33:43e8bc451ef0 13
mbedalvaro 33:43e8bc451ef0 14 //(1) Autothreshold:
mbedalvaro 32:52273c3291fe 15 // CONTRAST RATIO to compute autoThreshold:
mbedalvaro 32:52273c3291fe 16 // MIN_CONTRAST_RATIO is the minimum contrast between max and min intensity necessary to "accept" a black and white zone:
mbedalvaro 32:52273c3291fe 17 #define MIN_CONTRAST_RATIO 1.8//1.7 // 3 seems good when lookup table does not work
mbedalvaro 32:52273c3291fe 18 // THRESHOLD_FACTOR is where the threshold is actually placed between the min and max detected (with good contrast):
mbedalvaro 32:52273c3291fe 19 #define THRESHOLD_FACTOR 0.5 //0.75 // 2/3 or 1/2 are good values
mbedalvaro 32:52273c3291fe 20 #define MIN_ACCEPTABLE_INTENSITY 16 // if maxI< this then we consider all the saccade on something black
mbedalvaro 32:52273c3291fe 21
mbedalvaro 33:43e8bc451ef0 22
mbedalvaro 32:52273c3291fe 23 struct laserSensingPoint {
mbedalvaro 32:52273c3291fe 24 // Position and color (after rendering)
mbedalvaro 32:52273c3291fe 25 unsigned short x, y; // position of the point (after rendering - its integer, because it is in "laser projector pixels")
mbedalvaro 32:52273c3291fe 26 // char color; // per point laser color (not used yet)
mbedalvaro 32:52273c3291fe 27 // Detection:
mbedalvaro 32:52273c3291fe 28 unsigned char intensity; // detected intensity (in fact, this will be the REFLECTIVITY RATIO if using LUT table, and it's between 0 and 1, but we will multiply by 255 to avoid using a float.
mbedalvaro 32:52273c3291fe 29 signed char lightZone; // the thresholded light zone (allow for negative values for simply computing "negative" forces - although this is not necessarily the best option)
mbedalvaro 32:52273c3291fe 30 };
mbedalvaro 32:52273c3291fe 31
mbedalvaro 32:52273c3291fe 32
mbedalvaro 32:52273c3291fe 33 class LaserSensingTrajectory {
mbedalvaro 32:52273c3291fe 34
mbedalvaro 32:52273c3291fe 35 public:
mbedalvaro 32:52273c3291fe 36
mbedalvaro 32:52273c3291fe 37 LaserSensingTrajectory();
mbedalvaro 32:52273c3291fe 38 ~LaserSensingTrajectory();
mbedalvaro 32:52273c3291fe 39
mbedalvaro 32:52273c3291fe 40 // METHODS:
mbedalvaro 32:52273c3291fe 41 void processSensedData();
mbedalvaro 32:52273c3291fe 42 void setDelayMirrors(int); // in general, the delay will depend on the number of points being DISPLAYED (in other terms, on the size of lsdTrajectory).
mbedalvaro 32:52273c3291fe 43 void addDelayMirrors(int add_delay);
mbedalvaro 32:52273c3291fe 44
mbedalvaro 33:43e8bc451ef0 45 void setThresholdMode(unsigned char value) {modeThreshold=(value>0? AUTO : FIXED);};
mbedalvaro 33:43e8bc451ef0 46 void setFixedThreshold(unsigned char value) {fixedThreshold=value;};
mbedalvaro 32:52273c3291fe 47 void setMinContrastRatio(float value) {min_contrast_ratio=value;};
mbedalvaro 32:52273c3291fe 48 void setThresholdFactor(float value) {threshold_factor=value;};
mbedalvaro 33:43e8bc451ef0 49 void setMinAcceptableIntensity(unsigned char value) {min_acceptable_intensity=value;};
mbedalvaro 32:52273c3291fe 50 void multMinContrastRatio(float multfactor) {min_contrast_ratio*=multfactor;};
mbedalvaro 32:52273c3291fe 51 void multThresholdFactor(float multfactor) {threshold_factor*=multfactor;};
mbedalvaro 32:52273c3291fe 52
mbedalvaro 32:52273c3291fe 53 // DATA:
mbedalvaro 32:52273c3291fe 54 vector <laserSensingPoint> lsdTrajectory;
mbedalvaro 32:52273c3291fe 55 unsigned char displayColor; // per blob color
mbedalvaro 32:52273c3291fe 56
mbedalvaro 32:52273c3291fe 57 // software adjustement of mirror delay:
mbedalvaro 32:52273c3291fe 58 unsigned char delayMirrorSamples; // this is required because it will affect the way the blob behaves - it
mbedalvaro 32:52273c3291fe 59 //could be in the laser renderer, but by putting it here we can have more per-blob fine tunning
mbedalvaro 32:52273c3291fe 60
mbedalvaro 33:43e8bc451ef0 61 // parameters for thresholding and thresholding mode:
mbedalvaro 33:43e8bc451ef0 62 thresholdingMode modeThreshold;
mbedalvaro 32:52273c3291fe 63 float min_contrast_ratio, threshold_factor, min_acceptable_intensity;
mbedalvaro 33:43e8bc451ef0 64 unsigned char autoThreshold, fixedThreshold; // 0 to 255
mbedalvaro 32:52273c3291fe 65
mbedalvaro 32:52273c3291fe 66 // Statistics and tests:
mbedalvaro 32:52273c3291fe 67 //float lightRatio;
mbedalvaro 32:52273c3291fe 68 unsigned char maxI, minI; // Max and Min intensity RATIOS (normalized between 0 and 255)
mbedalvaro 32:52273c3291fe 69 bool lightTouched; // true if something went over the autoThreshold for the whole loop
mbedalvaro 32:52273c3291fe 70 // char coko;
mbedalvaro 32:52273c3291fe 71 };
mbedalvaro 32:52273c3291fe 72
mbedalvaro 32:52273c3291fe 73 #endif
mbedalvaro 32:52273c3291fe 74
mbedalvaro 32:52273c3291fe 75