Alvaro Cassinelli / Mbed 2 deprecated skinGames_forktest

Dependencies:   mbed

Fork of scoreLight_Advanced by Alvaro Cassinelli

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers classLaserSensingTrajectory.h Source File

classLaserSensingTrajectory.h

00001 #ifndef LSDTRAJECTORY_H
00002 #define LSDTRAJECTORY_H
00003 
00004 #include <vector>
00005 using namespace std;
00006 
00007 // Thresholding mode: 
00008 enum thresholdingMode {FIXED, AUTO};
00009 enum lightStateMode {TOUCHED, ALL_LIGHT, ALL_DARK};
00010 
00011 //(1) fixed threshold: 
00012 #define FIXED_THRESHOLD 35
00013 
00014 //(1) Autothreshold:
00015 // CONTRAST RATIO to compute autoThreshold:
00016 // MIN_CONTRAST_RATIO is the minimum contrast between max and min intensity necessary to "accept" a black and white zone:
00017 #define MIN_CONTRAST_RATIO 2.0//2.5//1.6//1.8//1.7 // 3 seems good when lookup table does not work 
00018 // THRESHOLD_FACTOR is where the threshold is actually placed between the min and max detected (with good contrast):
00019 #define THRESHOLD_FACTOR 0.5 //0.75 // 2/3 or 1/2 are good values 
00020 #define MIN_ACCEPTABLE_INTENSITY 16 // if maxI< this then we consider all the saccade on something black
00021 
00022 struct laserSensingPoint {
00023     // Position and color (after rendering)
00024    unsigned short x, y; // position of the point (after rendering - its integer, because it is in "laser projector pixels")
00025     // char color; // per point laser color (not used yet)
00026     // Detection:
00027     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. 
00028     signed char lightZone; // the thresholded light zone (allow for negative values for simply computing "negative" forces - although this is not necessarily the best option)
00029 };
00030 
00031 
00032 class LaserSensingTrajectory  {
00033 
00034 public:
00035 
00036     LaserSensingTrajectory();
00037     ~LaserSensingTrajectory();
00038 
00039     // METHODS:
00040     bool processSensedData();
00041     void setDelayMirrors(int); // in general, the delay will depend on the number of points being DISPLAYED (in other terms, on the size of lsdTrajectory).
00042     void addDelayMirrors(int add_delay);
00043 
00044     void setThresholdMode(unsigned char value) {modeThreshold=(value>0? AUTO : FIXED);};
00045     void setFixedThreshold(unsigned char value) {fixedThreshold=value;};
00046     void setMinContrastRatio(float value) {min_contrast_ratio=value;};
00047     void setThresholdFactor(float value) {threshold_factor=value;};
00048     void setMinAcceptableIntensity(unsigned char value) {min_acceptable_intensity=value;};
00049     void multMinContrastRatio(float multfactor) {min_contrast_ratio*=multfactor;};
00050     void multThresholdFactor(float multfactor) {threshold_factor*=multfactor;};
00051 
00052     // DATA:
00053     vector <laserSensingPoint> lsdTrajectory;
00054     unsigned char displayColor; // per blob color
00055 
00056     // software adjustement of mirror delay:
00057     unsigned char delayMirrorSamples; // this is required because it will affect the way the blob behaves - it 
00058     //could be in the laser renderer, but by putting it here we can have more per-blob fine tunning
00059 
00060     // parameters for thresholding and thresholding mode:
00061     thresholdingMode modeThreshold;
00062     float min_contrast_ratio, threshold_factor, min_acceptable_intensity;
00063     unsigned char autoThreshold, fixedThreshold; // 0 to 255
00064     
00065     // Statistics and tests:
00066     //float lightRatio;
00067     unsigned char maxI, minI;     // Max and Min intensity RATIOS (normalized between 0 and 255)
00068     // The following is a little redundant, but useful:
00069     bool lightZone, darkZone; // better than a boolean lightTouched variable, but lightTouched may still be useful
00070     lightStateMode lightState;
00071     bool lightTouched;     // when there is at least one black zone and one light zone
00072 };
00073 
00074 #endif
00075 
00076