Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of skinGames_forktest by
classLaserSensingTrajectory.cpp@0:345b3bc7a0ea, 2012-03-28 (annotated)
- Committer:
- mbedalvaro
- Date:
- Wed Mar 28 14:40:01 2012 +0000
- Revision:
- 0:345b3bc7a0ea
- Child:
- 3:b44ff6de81bd
This version (using rigid frame, base and child classes, etc) works, but the blob is strangely smaller. Need to check this.
Who changed what in which revision?
User | Revision | Line number | New 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 | 0:345b3bc7a0ea | 10 | void LaserSensingTrajectory::processSensedData() { |
mbedalvaro | 0:345b3bc7a0ea | 11 | // Compute max and min intensity on the loop |
mbedalvaro | 0:345b3bc7a0ea | 12 | maxI=0; |
mbedalvaro | 0:345b3bc7a0ea | 13 | minI=4096; |
mbedalvaro | 0:345b3bc7a0ea | 14 | for (int i = 0; i < lsdTrajectory.size(); i++) { |
mbedalvaro | 0:345b3bc7a0ea | 15 | float mesI=lsdTrajectory[i].intensity; |
mbedalvaro | 0:345b3bc7a0ea | 16 | if (maxI<mesI) maxI=mesI; |
mbedalvaro | 0:345b3bc7a0ea | 17 | if (minI>mesI) minI=mesI; |
mbedalvaro | 0:345b3bc7a0ea | 18 | } |
mbedalvaro | 0:345b3bc7a0ea | 19 | |
mbedalvaro | 0:345b3bc7a0ea | 20 | // Compute autoThreshold: |
mbedalvaro | 0:345b3bc7a0ea | 21 | if (1.0*maxI/(minI+0.1) > MIN_CONTRAST_RATIO ) { |
mbedalvaro | 0:345b3bc7a0ea | 22 | autoThreshold = 1.0 * (maxI-minI) * THRESHOLD_FACTOR + minI; // THRESHOLD_FACTOR = 2/3 or 1/2 is a good value. |
mbedalvaro | 0:345b3bc7a0ea | 23 | } else {// ... otherwise, we consider that the saccade is FULL on something white |
mbedalvaro | 0:345b3bc7a0ea | 24 | autoThreshold=-1; |
mbedalvaro | 0:345b3bc7a0ea | 25 | } |
mbedalvaro | 0:345b3bc7a0ea | 26 | |
mbedalvaro | 0:345b3bc7a0ea | 27 | // 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 | 28 | // 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 | 29 | // 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 | 30 | // idea of the blob "constant" internal pressure... |
mbedalvaro | 0:345b3bc7a0ea | 31 | lightTouched=false; |
mbedalvaro | 0:345b3bc7a0ea | 32 | for (int i = 0; i < lsdTrajectory.size(); i++) { |
mbedalvaro | 0:345b3bc7a0ea | 33 | if (lsdTrajectory[i].intensity>autoThreshold) { // this means a WHITE zone: |
mbedalvaro | 0:345b3bc7a0ea | 34 | lsdTrajectory[i].lightZone= -1;//1; |
mbedalvaro | 0:345b3bc7a0ea | 35 | } else { // something touched: DARK ZONE |
mbedalvaro | 0:345b3bc7a0ea | 36 | lsdTrajectory[i].lightZone= 2;//0; |
mbedalvaro | 0:345b3bc7a0ea | 37 | lightTouched=true; // (for the whole loop) |
mbedalvaro | 0:345b3bc7a0ea | 38 | } |
mbedalvaro | 0:345b3bc7a0ea | 39 | } |
mbedalvaro | 0:345b3bc7a0ea | 40 | } |