Alvaro Cassinelli
/
skinGames_forktest
just a test
Fork of scoreLight_Advanced by
classLaserSensingTrajectory.h@48:7633d8e7b0d3, 2014-12-02 (annotated)
- Committer:
- mbedalvaro
- Date:
- Tue Dec 02 04:28:42 2014 +0000
- Revision:
- 48:7633d8e7b0d3
- Parent:
- 45:a3b984a79d5d
this is the working version of the skin games sowtware (aka, scorelight but with pre-determined "games")
Who changed what in which revision?
User | Revision | Line number | New 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 | 45:a3b984a79d5d | 9 | enum lightStateMode {TOUCHED, ALL_LIGHT, ALL_DARK}; |
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 | 48:7633d8e7b0d3 | 17 | #define MIN_CONTRAST_RATIO 2.0//2.5//1.6//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 | 32:52273c3291fe | 22 | struct laserSensingPoint { |
mbedalvaro | 32:52273c3291fe | 23 | // Position and color (after rendering) |
mbedalvaro | 32:52273c3291fe | 24 | unsigned short x, y; // position of the point (after rendering - its integer, because it is in "laser projector pixels") |
mbedalvaro | 32:52273c3291fe | 25 | // char color; // per point laser color (not used yet) |
mbedalvaro | 32:52273c3291fe | 26 | // Detection: |
mbedalvaro | 32:52273c3291fe | 27 | 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 | 28 | 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 | 29 | }; |
mbedalvaro | 32:52273c3291fe | 30 | |
mbedalvaro | 32:52273c3291fe | 31 | |
mbedalvaro | 32:52273c3291fe | 32 | class LaserSensingTrajectory { |
mbedalvaro | 32:52273c3291fe | 33 | |
mbedalvaro | 32:52273c3291fe | 34 | public: |
mbedalvaro | 32:52273c3291fe | 35 | |
mbedalvaro | 32:52273c3291fe | 36 | LaserSensingTrajectory(); |
mbedalvaro | 32:52273c3291fe | 37 | ~LaserSensingTrajectory(); |
mbedalvaro | 32:52273c3291fe | 38 | |
mbedalvaro | 32:52273c3291fe | 39 | // METHODS: |
mbedalvaro | 36:233b12d0b1f0 | 40 | bool processSensedData(); |
mbedalvaro | 32:52273c3291fe | 41 | 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 | 42 | void addDelayMirrors(int add_delay); |
mbedalvaro | 32:52273c3291fe | 43 | |
mbedalvaro | 33:43e8bc451ef0 | 44 | void setThresholdMode(unsigned char value) {modeThreshold=(value>0? AUTO : FIXED);}; |
mbedalvaro | 33:43e8bc451ef0 | 45 | void setFixedThreshold(unsigned char value) {fixedThreshold=value;}; |
mbedalvaro | 32:52273c3291fe | 46 | void setMinContrastRatio(float value) {min_contrast_ratio=value;}; |
mbedalvaro | 32:52273c3291fe | 47 | void setThresholdFactor(float value) {threshold_factor=value;}; |
mbedalvaro | 33:43e8bc451ef0 | 48 | void setMinAcceptableIntensity(unsigned char value) {min_acceptable_intensity=value;}; |
mbedalvaro | 32:52273c3291fe | 49 | void multMinContrastRatio(float multfactor) {min_contrast_ratio*=multfactor;}; |
mbedalvaro | 32:52273c3291fe | 50 | void multThresholdFactor(float multfactor) {threshold_factor*=multfactor;}; |
mbedalvaro | 32:52273c3291fe | 51 | |
mbedalvaro | 32:52273c3291fe | 52 | // DATA: |
mbedalvaro | 32:52273c3291fe | 53 | vector <laserSensingPoint> lsdTrajectory; |
mbedalvaro | 32:52273c3291fe | 54 | unsigned char displayColor; // per blob color |
mbedalvaro | 32:52273c3291fe | 55 | |
mbedalvaro | 32:52273c3291fe | 56 | // software adjustement of mirror delay: |
mbedalvaro | 32:52273c3291fe | 57 | unsigned char delayMirrorSamples; // this is required because it will affect the way the blob behaves - it |
mbedalvaro | 32:52273c3291fe | 58 | //could be in the laser renderer, but by putting it here we can have more per-blob fine tunning |
mbedalvaro | 32:52273c3291fe | 59 | |
mbedalvaro | 33:43e8bc451ef0 | 60 | // parameters for thresholding and thresholding mode: |
mbedalvaro | 33:43e8bc451ef0 | 61 | thresholdingMode modeThreshold; |
mbedalvaro | 32:52273c3291fe | 62 | float min_contrast_ratio, threshold_factor, min_acceptable_intensity; |
mbedalvaro | 33:43e8bc451ef0 | 63 | unsigned char autoThreshold, fixedThreshold; // 0 to 255 |
mbedalvaro | 32:52273c3291fe | 64 | |
mbedalvaro | 32:52273c3291fe | 65 | // Statistics and tests: |
mbedalvaro | 32:52273c3291fe | 66 | //float lightRatio; |
mbedalvaro | 32:52273c3291fe | 67 | unsigned char maxI, minI; // Max and Min intensity RATIOS (normalized between 0 and 255) |
mbedalvaro | 45:a3b984a79d5d | 68 | // The following is a little redundant, but useful: |
mbedalvaro | 45:a3b984a79d5d | 69 | bool lightZone, darkZone; // better than a boolean lightTouched variable, but lightTouched may still be useful |
mbedalvaro | 45:a3b984a79d5d | 70 | lightStateMode lightState; |
mbedalvaro | 45:a3b984a79d5d | 71 | bool lightTouched; // when there is at least one black zone and one light zone |
mbedalvaro | 32:52273c3291fe | 72 | }; |
mbedalvaro | 32:52273c3291fe | 73 | |
mbedalvaro | 32:52273c3291fe | 74 | #endif |
mbedalvaro | 32:52273c3291fe | 75 | |
mbedalvaro | 32:52273c3291fe | 76 |