![](/media/cache/profiles/68a15b5278e4f7c4c056df9d5f1d3b1f.jpg.50x50_q85.jpg)
save loops
classLaserSensingTrajectory.h@1:3be7b7d050f4, 2014-12-02 (annotated)
- Committer:
- mbedalvaro
- Date:
- Tue Dec 02 08:29:59 2014 +0000
- Revision:
- 1:3be7b7d050f4
- Parent:
- 0:df6fdd9b99f0
updated
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbedalvaro | 0:df6fdd9b99f0 | 1 | #ifndef LSDTRAJECTORY_H |
mbedalvaro | 0:df6fdd9b99f0 | 2 | #define LSDTRAJECTORY_H |
mbedalvaro | 0:df6fdd9b99f0 | 3 | |
mbedalvaro | 0:df6fdd9b99f0 | 4 | #include <vector> |
mbedalvaro | 0:df6fdd9b99f0 | 5 | using namespace std; |
mbedalvaro | 0:df6fdd9b99f0 | 6 | |
mbedalvaro | 0:df6fdd9b99f0 | 7 | // Thresholding mode: |
mbedalvaro | 0:df6fdd9b99f0 | 8 | enum thresholdingMode {FIXED, AUTO}; |
mbedalvaro | 0:df6fdd9b99f0 | 9 | enum lightStateMode {TOUCHED, ALL_LIGHT, ALL_DARK}; |
mbedalvaro | 0:df6fdd9b99f0 | 10 | |
mbedalvaro | 0:df6fdd9b99f0 | 11 | //(1) fixed threshold: |
mbedalvaro | 0:df6fdd9b99f0 | 12 | #define FIXED_THRESHOLD 35 |
mbedalvaro | 0:df6fdd9b99f0 | 13 | |
mbedalvaro | 0:df6fdd9b99f0 | 14 | //(1) Autothreshold: |
mbedalvaro | 0:df6fdd9b99f0 | 15 | // CONTRAST RATIO to compute autoThreshold: |
mbedalvaro | 0:df6fdd9b99f0 | 16 | // MIN_CONTRAST_RATIO is the minimum contrast between max and min intensity necessary to "accept" a black and white zone: |
mbedalvaro | 0:df6fdd9b99f0 | 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 | 0:df6fdd9b99f0 | 18 | // THRESHOLD_FACTOR is where the threshold is actually placed between the min and max detected (with good contrast): |
mbedalvaro | 0:df6fdd9b99f0 | 19 | #define THRESHOLD_FACTOR 0.5 //0.75 // 2/3 or 1/2 are good values |
mbedalvaro | 0:df6fdd9b99f0 | 20 | #define MIN_ACCEPTABLE_INTENSITY 16 // if maxI< this then we consider all the saccade on something black |
mbedalvaro | 0:df6fdd9b99f0 | 21 | |
mbedalvaro | 0:df6fdd9b99f0 | 22 | struct laserSensingPoint { |
mbedalvaro | 0:df6fdd9b99f0 | 23 | // Position and color (after rendering) |
mbedalvaro | 0:df6fdd9b99f0 | 24 | unsigned short x, y; // position of the point (after rendering - its integer, because it is in "laser projector pixels") |
mbedalvaro | 0:df6fdd9b99f0 | 25 | // char color; // per point laser color (not used yet) |
mbedalvaro | 0:df6fdd9b99f0 | 26 | // Detection: |
mbedalvaro | 0:df6fdd9b99f0 | 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 | 0:df6fdd9b99f0 | 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 | 0:df6fdd9b99f0 | 29 | }; |
mbedalvaro | 0:df6fdd9b99f0 | 30 | |
mbedalvaro | 0:df6fdd9b99f0 | 31 | |
mbedalvaro | 0:df6fdd9b99f0 | 32 | class LaserSensingTrajectory { |
mbedalvaro | 0:df6fdd9b99f0 | 33 | |
mbedalvaro | 0:df6fdd9b99f0 | 34 | public: |
mbedalvaro | 0:df6fdd9b99f0 | 35 | |
mbedalvaro | 0:df6fdd9b99f0 | 36 | LaserSensingTrajectory(); |
mbedalvaro | 0:df6fdd9b99f0 | 37 | ~LaserSensingTrajectory(); |
mbedalvaro | 0:df6fdd9b99f0 | 38 | |
mbedalvaro | 0:df6fdd9b99f0 | 39 | // METHODS: |
mbedalvaro | 0:df6fdd9b99f0 | 40 | bool processSensedData(); |
mbedalvaro | 0:df6fdd9b99f0 | 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 | 0:df6fdd9b99f0 | 42 | void addDelayMirrors(int add_delay); |
mbedalvaro | 0:df6fdd9b99f0 | 43 | |
mbedalvaro | 0:df6fdd9b99f0 | 44 | void setThresholdMode(unsigned char value) {modeThreshold=(value>0? AUTO : FIXED);}; |
mbedalvaro | 0:df6fdd9b99f0 | 45 | void setFixedThreshold(unsigned char value) {fixedThreshold=value;}; |
mbedalvaro | 0:df6fdd9b99f0 | 46 | void setMinContrastRatio(float value) {min_contrast_ratio=value;}; |
mbedalvaro | 0:df6fdd9b99f0 | 47 | void setThresholdFactor(float value) {threshold_factor=value;}; |
mbedalvaro | 0:df6fdd9b99f0 | 48 | void setMinAcceptableIntensity(unsigned char value) {min_acceptable_intensity=value;}; |
mbedalvaro | 0:df6fdd9b99f0 | 49 | void multMinContrastRatio(float multfactor) {min_contrast_ratio*=multfactor;}; |
mbedalvaro | 0:df6fdd9b99f0 | 50 | void multThresholdFactor(float multfactor) {threshold_factor*=multfactor;}; |
mbedalvaro | 0:df6fdd9b99f0 | 51 | |
mbedalvaro | 0:df6fdd9b99f0 | 52 | // DATA: |
mbedalvaro | 0:df6fdd9b99f0 | 53 | vector <laserSensingPoint> lsdTrajectory; |
mbedalvaro | 0:df6fdd9b99f0 | 54 | unsigned char displayColor; // per blob color |
mbedalvaro | 0:df6fdd9b99f0 | 55 | |
mbedalvaro | 0:df6fdd9b99f0 | 56 | // software adjustement of mirror delay: |
mbedalvaro | 0:df6fdd9b99f0 | 57 | unsigned char delayMirrorSamples; // this is required because it will affect the way the blob behaves - it |
mbedalvaro | 0:df6fdd9b99f0 | 58 | //could be in the laser renderer, but by putting it here we can have more per-blob fine tunning |
mbedalvaro | 0:df6fdd9b99f0 | 59 | |
mbedalvaro | 0:df6fdd9b99f0 | 60 | // parameters for thresholding and thresholding mode: |
mbedalvaro | 0:df6fdd9b99f0 | 61 | thresholdingMode modeThreshold; |
mbedalvaro | 0:df6fdd9b99f0 | 62 | float min_contrast_ratio, threshold_factor, min_acceptable_intensity; |
mbedalvaro | 0:df6fdd9b99f0 | 63 | unsigned char autoThreshold, fixedThreshold; // 0 to 255 |
mbedalvaro | 0:df6fdd9b99f0 | 64 | |
mbedalvaro | 0:df6fdd9b99f0 | 65 | // Statistics and tests: |
mbedalvaro | 0:df6fdd9b99f0 | 66 | //float lightRatio; |
mbedalvaro | 0:df6fdd9b99f0 | 67 | unsigned char maxI, minI; // Max and Min intensity RATIOS (normalized between 0 and 255) |
mbedalvaro | 0:df6fdd9b99f0 | 68 | // The following is a little redundant, but useful: |
mbedalvaro | 0:df6fdd9b99f0 | 69 | bool lightZone, darkZone; // better than a boolean lightTouched variable, but lightTouched may still be useful |
mbedalvaro | 0:df6fdd9b99f0 | 70 | lightStateMode lightState; |
mbedalvaro | 0:df6fdd9b99f0 | 71 | bool lightTouched; // when there is at least one black zone and one light zone |
mbedalvaro | 0:df6fdd9b99f0 | 72 | }; |
mbedalvaro | 0:df6fdd9b99f0 | 73 | |
mbedalvaro | 0:df6fdd9b99f0 | 74 | #endif |
mbedalvaro | 0:df6fdd9b99f0 | 75 | |
mbedalvaro | 0:df6fdd9b99f0 | 76 |