Laser Sensing Display for UI interfaces in the real world

Dependencies:   mbed

Fork of skinGames_forktest by Alvaro Cassinelli

Committer:
mbedalvaro
Date:
Thu Apr 05 13:06:24 2012 +0000
Revision:
6:444859c27e78
Parent:
5:73cd58b58f95
Child:
7:0df17f3078bc
solved one problem related to the initialization of the positions, so now the "relax contract central blob" works as before.; - strange first point; - still did not try the strange problem with the variable on the class laser sensing trajectory (required...

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbedalvaro 0:345b3bc7a0ea 1 #include "classLaserSensingTrajectory.h"
mbedalvaro 0:345b3bc7a0ea 2
mbedalvaro 0:345b3bc7a0ea 3 LaserSensingTrajectory::LaserSensingTrajectory(): lightTouched(false) {
mbedalvaro 0:345b3bc7a0ea 4 }
mbedalvaro 0:345b3bc7a0ea 5
mbedalvaro 0:345b3bc7a0ea 6 LaserSensingTrajectory::~LaserSensingTrajectory() {
mbedalvaro 0:345b3bc7a0ea 7 // lsdTrajectory.clear(); // there is no need to clear the vector, the destructor of this vector is called by default (and it's NOT a vector of pointers)
mbedalvaro 0:345b3bc7a0ea 8 }
mbedalvaro 0:345b3bc7a0ea 9
mbedalvaro 4:f9d364f10335 10
mbedalvaro 4:f9d364f10335 11 void LaserSensingTrajectory::setDelayMirrors(int delay) {
mbedalvaro 4:f9d364f10335 12 delayMirrorSamples=delay;
mbedalvaro 4:f9d364f10335 13 }
mbedalvaro 4:f9d364f10335 14
mbedalvaro 0:345b3bc7a0ea 15 void LaserSensingTrajectory::processSensedData() {
mbedalvaro 0:345b3bc7a0ea 16 // Compute max and min intensity on the loop
mbedalvaro 0:345b3bc7a0ea 17 maxI=0;
mbedalvaro 0:345b3bc7a0ea 18 minI=4096;
mbedalvaro 4:f9d364f10335 19 int auxSize=lsdTrajectory.size();
mbedalvaro 4:f9d364f10335 20
mbedalvaro 5:73cd58b58f95 21 // Compute minimum and maximum intensities:
mbedalvaro 0:345b3bc7a0ea 22 for (int i = 0; i < lsdTrajectory.size(); i++) {
mbedalvaro 5:73cd58b58f95 23 float mesI=lsdTrajectory[i].intensity;
mbedalvaro 0:345b3bc7a0ea 24 if (maxI<mesI) maxI=mesI;
mbedalvaro 0:345b3bc7a0ea 25 if (minI>mesI) minI=mesI;
mbedalvaro 0:345b3bc7a0ea 26 }
mbedalvaro 0:345b3bc7a0ea 27
mbedalvaro 0:345b3bc7a0ea 28 // Compute autoThreshold:
mbedalvaro 0:345b3bc7a0ea 29 if (1.0*maxI/(minI+0.1) > MIN_CONTRAST_RATIO ) {
mbedalvaro 0:345b3bc7a0ea 30 autoThreshold = 1.0 * (maxI-minI) * THRESHOLD_FACTOR + minI; // THRESHOLD_FACTOR = 2/3 or 1/2 is a good value.
mbedalvaro 0:345b3bc7a0ea 31 } else {// ... otherwise, we consider that the saccade is FULL on something white
mbedalvaro 0:345b3bc7a0ea 32 autoThreshold=-1;
mbedalvaro 0:345b3bc7a0ea 33 }
mbedalvaro 0:345b3bc7a0ea 34
mbedalvaro 0:345b3bc7a0ea 35 // Segment the trajectory (only two levels for the time being, but we can have more - meaning different forces, real or even complex values to have different angle forces...):
mbedalvaro 0:345b3bc7a0ea 36 // NOTE: if using 1 and -1 instead of 1 and 0, we can avoid having to add a "blob internal pressure"! -1 means a force towards the interior, and +1 outwards...
mbedalvaro 0:345b3bc7a0ea 37 // This means that the loop will naturally become inside-out depending on the color of the main surface! (but will mantain its normal size). Much better and elegant solution than the
mbedalvaro 0:345b3bc7a0ea 38 // idea of the blob "constant" internal pressure...
mbedalvaro 0:345b3bc7a0ea 39 lightTouched=false;
mbedalvaro 5:73cd58b58f95 40 // int counterLight=0;
mbedalvaro 0:345b3bc7a0ea 41 for (int i = 0; i < lsdTrajectory.size(); i++) {
mbedalvaro 6:444859c27e78 42 int delayedpoint=(i+auxSize+delayMirrorSamples)%auxSize; // this way we can have negative delayMirrorSamples
mbedalvaro 4:f9d364f10335 43 if (lsdTrajectory[delayedpoint].intensity>autoThreshold) { // this means a WHITE zone:
mbedalvaro 6:444859c27e78 44 lsdTrajectory[i].lightZone= -1;//1;
mbedalvaro 5:73cd58b58f95 45 // counterLight++;
mbedalvaro 0:345b3bc7a0ea 46 } else { // something touched: DARK ZONE
mbedalvaro 6:444859c27e78 47 lsdTrajectory[i].lightZone= 2;//0;
mbedalvaro 0:345b3bc7a0ea 48 lightTouched=true; // (for the whole loop)
mbedalvaro 0:345b3bc7a0ea 49 }
mbedalvaro 0:345b3bc7a0ea 50 }
mbedalvaro 5:73cd58b58f95 51 //coko=counterLight;
mbedalvaro 5:73cd58b58f95 52 // lightRatio=1.0*counterLight/lsdTrajectory.size();
mbedalvaro 0:345b3bc7a0ea 53 }