Laser Sensing Display for UI interfaces in the real world

Dependencies:   mbed

Fork of skinGames_forktest by Alvaro Cassinelli

Committer:
mbedalvaro
Date:
Sun Sep 23 10:11:43 2012 +0000
Revision:
31:5f039cbddee8
Child:
34:1244fa3f2559
this is quite nice, but  I am going to make a deep modification of the bouncing principle: instead of depending on the penetration, it will just be a factor over the speed (perfect elastic bouncing being factorElastic=1, and perfectly absorption=0);

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbedalvaro 31:5f039cbddee8 1
mbedalvaro 31:5f039cbddee8 2 #ifndef hardwareIO_h
mbedalvaro 31:5f039cbddee8 3 #define hardwareIO_h
mbedalvaro 31:5f039cbddee8 4
mbedalvaro 31:5f039cbddee8 5 #include "mbed.h"
mbedalvaro 31:5f039cbddee8 6 #include "lockin.h"
mbedalvaro 31:5f039cbddee8 7
mbedalvaro 31:5f039cbddee8 8
mbedalvaro 31:5f039cbddee8 9 // potentiometer to change sensitivity by hand, or other things.
mbedalvaro 31:5f039cbddee8 10 #define POT_ANALOG_INPUT p15 // note: analog inputs in the mbed are from 15 to 20
mbedalvaro 31:5f039cbddee8 11
mbedalvaro 31:5f039cbddee8 12 // NOTE: the SPI library uses the following pins, but we don't have to set them and inputs or outputs (this is done when the library is initialized, which is done by pre-instantiation.
mbedalvaro 31:5f039cbddee8 13 #define SCK_PIN p7 //SPI Clock
mbedalvaro 31:5f039cbddee8 14 #define MISO_PIN p6 //SPI input (data comming from DAC, here not connected)
mbedalvaro 31:5f039cbddee8 15 #define MOSI_PIN p5 //SPI output (data going to DAC)
mbedalvaro 31:5f039cbddee8 16
mbedalvaro 31:5f039cbddee8 17 //**** CHIP SELECT pins for MP4922 DAC (mirrors and red laser)
mbedalvaro 31:5f039cbddee8 18 // VERY IMPORTANT: the chip select for the DACs should be different from the default SPI "SS" pin (Slave Select), which is 53 by default (and will be used by the Ethernet Shield).
mbedalvaro 31:5f039cbddee8 19 #define CS_DAC_MIRRORS p8 //Chip Select of the first DAC (mirrors)
mbedalvaro 31:5f039cbddee8 20
mbedalvaro 31:5f039cbddee8 21 //**** LASERS pins:
mbedalvaro 31:5f039cbddee8 22 #define LASER_RED_PIN p28 // NOT YET USED!! (NOTE: this is NOT the locking sensing laser (also called red, but could be infrared...)
mbedalvaro 31:5f039cbddee8 23 #define LASER_GREEN_PIN p29 // USED (TTL control)
mbedalvaro 31:5f039cbddee8 24 #define LASER_BLUE_PIN p30 // USED (TTL control)
mbedalvaro 31:5f039cbddee8 25
mbedalvaro 31:5f039cbddee8 26 //**** MIRRORS:
mbedalvaro 31:5f039cbddee8 27 //The DAC is 12 bytes capable (Max=4096), but we will limit this a little.
mbedalvaro 31:5f039cbddee8 28 #define MAX_AD_MIRRORS 3845 // note: 4095 is the absolute maximum for the SPI voltage (5V). This is for checking hardware compliance, but max and min angles can be defined for X and Y in each LivingSpot instance.
mbedalvaro 31:5f039cbddee8 29 #define MIN_AD_MIRRORS 250 // note: 0 is 0 volts for the SPI voltage.
mbedalvaro 31:5f039cbddee8 30 // We assume that the center of the mirror is at MAX_AD_MIRRORS/2 = 2000:
mbedalvaro 31:5f039cbddee8 31 #define CENTER_AD_MIRROR_X 2047 // This MUST BE the direction of the photodetector.
mbedalvaro 31:5f039cbddee8 32 #define CENTER_AD_MIRROR_Y 2047 // This MUST BE the direction of the photodetector.
mbedalvaro 31:5f039cbddee8 33
mbedalvaro 31:5f039cbddee8 34
mbedalvaro 31:5f039cbddee8 35 //**** Look-Up Table:
mbedalvaro 31:5f039cbddee8 36 #define uint16 unsigned short
mbedalvaro 31:5f039cbddee8 37 #define LUT_RESOLUTION 33 // resolution of the Look-Up Table (power of 2 +1)
mbedalvaro 31:5f039cbddee8 38 #define LUT_BITS_SHIFT 7 // bits shift from mirror DAC (12 bits) to LUT ( root_square(LUT_RESOLUTION - 1) )
mbedalvaro 31:5f039cbddee8 39 #define LUT_BITS_MASK 127 // bits mask to obtain the position remainder ( 2^LUT_BITS_SHIFT - 1 )
mbedalvaro 31:5f039cbddee8 40 // possible configurations:
mbedalvaro 31:5f039cbddee8 41 // LUT_RESOLUTION LUT_BITS_SHIFT LUT_BITS_MASK
mbedalvaro 31:5f039cbddee8 42 // 9 9 511
mbedalvaro 31:5f039cbddee8 43 // 17 8 255
mbedalvaro 31:5f039cbddee8 44 // 33 7 127
mbedalvaro 31:5f039cbddee8 45 // 65 6 63
mbedalvaro 31:5f039cbddee8 46 // ...
mbedalvaro 31:5f039cbddee8 47 #define NB_SCANS 8 // number of scans performed to generate the LUT table (actually, each site CUMULATES NB_SCANS values)
mbedalvaro 31:5f039cbddee8 48 // IMPORTANT: NB_SCANS*4095 should not exceed the capacity of uint16, this is 2^16-1=65535.
mbedalvaro 31:5f039cbddee8 49 // In other terms, NB_SCANS should be < 65535/4095=16
mbedalvaro 31:5f039cbddee8 50
mbedalvaro 31:5f039cbddee8 51 #define LUT_FILENAME "/local/LUT.txt"
mbedalvaro 31:5f039cbddee8 52
mbedalvaro 31:5f039cbddee8 53 // For checking (define if human readable file is required - note: it is not used by the program, just as output for human reading)
mbedalvaro 31:5f039cbddee8 54 #define LUT_H_FILENAME "/local/LUT_pos.txt"
mbedalvaro 31:5f039cbddee8 55
mbedalvaro 31:5f039cbddee8 56 // Current Look-up table approximation (only one at a time!):
mbedalvaro 31:5f039cbddee8 57 //#define LUT_BILINEAR
mbedalvaro 31:5f039cbddee8 58 //#define LUT_DIRECT
mbedalvaro 31:5f039cbddee8 59 //#define LUT_LINEAR
mbedalvaro 31:5f039cbddee8 60 #define NO_LUT
mbedalvaro 31:5f039cbddee8 61
mbedalvaro 31:5f039cbddee8 62 //Current method for lockin data acquisition and correction
mbedalvaro 31:5f039cbddee8 63 #define lockin_read() lockin.getMedianValue() // lockin.getSmoothValue(); //return the average of the value stored on the buffer
mbedalvaro 31:5f039cbddee8 64 // lockin.getLastValue(); //return the last conversion of the ADC
mbedalvaro 31:5f039cbddee8 65 // lockin.getMedianValue(); //return the median value of the buffer
mbedalvaro 31:5f039cbddee8 66
mbedalvaro 31:5f039cbddee8 67
mbedalvaro 31:5f039cbddee8 68 extern DigitalOut Laser_Red, Laser_Green, Laser_Blue;
mbedalvaro 31:5f039cbddee8 69
mbedalvaro 31:5f039cbddee8 70 // **** REFERENCE SIGNAL:
mbedalvaro 31:5f039cbddee8 71 /*
mbedalvaro 31:5f039cbddee8 72 #define testPin_OC1A 11 // this is, output compare pin OC1A //connected to CK2 = lockIn clock
mbedalvaro 31:5f039cbddee8 73 #define testPin_OC1B 12 // this is, output compare pin OC1B //connected to CK1 = laser clock
mbedalvaro 31:5f039cbddee8 74 #define testPin_OC1C 13
mbedalvaro 31:5f039cbddee8 75 */
mbedalvaro 31:5f039cbddee8 76
mbedalvaro 31:5f039cbddee8 77 // ==================================================================================================================================================================
mbedalvaro 31:5f039cbddee8 78
mbedalvaro 31:5f039cbddee8 79 class HardwareIO {
mbedalvaro 31:5f039cbddee8 80 public:
mbedalvaro 31:5f039cbddee8 81
mbedalvaro 31:5f039cbddee8 82
mbedalvaro 31:5f039cbddee8 83 void init(void);
mbedalvaro 31:5f039cbddee8 84
mbedalvaro 31:5f039cbddee8 85 //Lock-in acquisition methods:
mbedalvaro 31:5f039cbddee8 86 // float LockInRead_Volts();
mbedalvaro 31:5f039cbddee8 87 // int LockInRead_AD();
mbedalvaro 31:5f039cbddee8 88 // float LockInAD_to_Volts(int);
mbedalvaro 31:5f039cbddee8 89
mbedalvaro 31:5f039cbddee8 90 //Look-Up Table:
mbedalvaro 31:5f039cbddee8 91 unsigned short lut[LUT_RESOLUTION][LUT_RESOLUTION]; //Look-Up Table (uint16 is "unsigned short")
mbedalvaro 31:5f039cbddee8 92 void scanLUT(); //create and save the Look-Up Table
mbedalvaro 31:5f039cbddee8 93 void setLUT(); //set the Look-Up Table: either from scanning, or from the file LUT.TXT (if it is present)
mbedalvaro 31:5f039cbddee8 94 float lockInCorrectedValue(unsigned short x, unsigned short y); //return the lockin value corrected with the Look-UpTable (this is, a RATIO of reflectivities, and <1)
mbedalvaro 31:5f039cbddee8 95
mbedalvaro 31:5f039cbddee8 96 void scan_serial(unsigned short pointsPerLine = 400);
mbedalvaro 31:5f039cbddee8 97
mbedalvaro 31:5f039cbddee8 98 void showLimitsMirrors( int times );
mbedalvaro 31:5f039cbddee8 99
mbedalvaro 31:5f039cbddee8 100 // SPI control for DAC for mirrors and red laser power (low level):
mbedalvaro 31:5f039cbddee8 101 void writeOutX(unsigned short value);
mbedalvaro 31:5f039cbddee8 102 void writeOutY(unsigned short value);
mbedalvaro 31:5f039cbddee8 103
mbedalvaro 31:5f039cbddee8 104 // mirror degree-to-AD units conversion factors:
mbedalvaro 31:5f039cbddee8 105 //float AD_to_Deg_MIRROR_X;//=1.0*(MAX_DEG_MIRROR_X-MIN_DEG_MIRROR_X)/(MAX_AD_MIRRORS-MIN_AD_MIRRORS);
mbedalvaro 31:5f039cbddee8 106 //float AD_to_Deg_MIRROR_Y;//=1.0*(MAX_DEG_MIRROR_Y-MIN_DEG_MIRROR_Y)/(MAX_AD_MIRRORS-MIN_AD_MIRRORS);
mbedalvaro 31:5f039cbddee8 107
mbedalvaro 31:5f039cbddee8 108 /*
mbedalvaro 31:5f039cbddee8 109 // Mirror position:
mbedalvaro 31:5f039cbddee8 110 void setMirrorX_Deg(float _Az);
mbedalvaro 31:5f039cbddee8 111 void setMirrorY_Deg(float _El);
mbedalvaro 31:5f039cbddee8 112 void setMirrorX_AD(int _AzAD);
mbedalvaro 31:5f039cbddee8 113 void setMirrorY_AD(int _ElAD);
mbedalvaro 31:5f039cbddee8 114 void setMirrorsXY_AD(int _xAD, int _yAD);
mbedalvaro 31:5f039cbddee8 115 void setMirrorsCenter();
mbedalvaro 31:5f039cbddee8 116 void getAnglesFromAD(float &Az, float &El, int _xAD, int _yAD);
mbedalvaro 31:5f039cbddee8 117 //void setZoneDelimiters(...) // this could be here, instead on the LivingSpot class
mbedalvaro 31:5f039cbddee8 118 */
mbedalvaro 31:5f039cbddee8 119
mbedalvaro 31:5f039cbddee8 120
mbedalvaro 31:5f039cbddee8 121 //Laser Power, for the moment laser are TTL but we can use int:
mbedalvaro 31:5f039cbddee8 122 //if powerValue > 0 ==> 'true'; else 'false'
mbedalvaro 31:5f039cbddee8 123 // Red laser:
mbedalvaro 31:5f039cbddee8 124 void setRedPower(int powerRed);
mbedalvaro 31:5f039cbddee8 125 // Green laser:
mbedalvaro 31:5f039cbddee8 126 void setGreenPower(int powerGreen);
mbedalvaro 31:5f039cbddee8 127 // Blue laser:
mbedalvaro 31:5f039cbddee8 128 void setBluePower(int powerBlue);
mbedalvaro 31:5f039cbddee8 129
mbedalvaro 31:5f039cbddee8 130 void setRGBPower(unsigned char color); // we will use the 3 LSB bits to set each color
mbedalvaro 31:5f039cbddee8 131
mbedalvaro 31:5f039cbddee8 132 //void setupPWM();
mbedalvaro 31:5f039cbddee8 133 /* IN ADVANCED HARDWARE:
mbedalvaro 31:5f039cbddee8 134 // init PWM for reference generation:
mbedalvaro 31:5f039cbddee8 135 void initPWM();
mbedalvaro 31:5f039cbddee8 136 // reference signal:
mbedalvaro 31:5f039cbddee8 137 void setRefFreq(int);
mbedalvaro 31:5f039cbddee8 138 void incRefFreq(int inc=1);
mbedalvaro 31:5f039cbddee8 139 void decRefFreq(int dec=1);
mbedalvaro 31:5f039cbddee8 140 */
mbedalvaro 31:5f039cbddee8 141
mbedalvaro 31:5f039cbddee8 142 //float refFreq; // could be private
mbedalvaro 31:5f039cbddee8 143
mbedalvaro 31:5f039cbddee8 144
mbedalvaro 31:5f039cbddee8 145 private:
mbedalvaro 31:5f039cbddee8 146
mbedalvaro 31:5f039cbddee8 147 };
mbedalvaro 31:5f039cbddee8 148
mbedalvaro 31:5f039cbddee8 149
mbedalvaro 31:5f039cbddee8 150 extern HardwareIO IO; // allows the object IO to be used in other .cpp files (IO is pre-instantiated in hardwareIO.cpp)
mbedalvaro 31:5f039cbddee8 151 // NOTE: IO encapsulates many IO functions, but perhaps it is better not to have an IO object - just use each IO function separatedly (as with pc object for instance)
mbedalvaro 31:5f039cbddee8 152 extern Serial pc; // allows pc to be manipulated by other .cpp files, even if pc is defined in the hardwareIO.cpp
mbedalvaro 31:5f039cbddee8 153
mbedalvaro 31:5f039cbddee8 154
mbedalvaro 31:5f039cbddee8 155 #endif