Hiromasa Oku
/
linearMirrorMotion1017
this version 10/17
Fork of linearMirrorMotion by
laserProjectorHardware/laserProjectorHardware.cpp@3:3fe7d6b5cf24, 2012-10-04 (annotated)
- Committer:
- mbedalvaro
- Date:
- Thu Oct 04 05:16:25 2012 +0000
- Revision:
- 3:3fe7d6b5cf24
- Child:
- 4:e00e709d7173
simplest control X Y mirrors;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbedalvaro | 3:3fe7d6b5cf24 | 1 | #include "laserProjectorHardware.h" |
mbedalvaro | 3:3fe7d6b5cf24 | 2 | |
mbedalvaro | 3:3fe7d6b5cf24 | 3 | HardwareIO IO; // preintantiation of cross-file global object IO |
mbedalvaro | 3:3fe7d6b5cf24 | 4 | |
mbedalvaro | 3:3fe7d6b5cf24 | 5 | // -------------------------------------- (0) SETUP ALL IO (call this in the setup() function in main program) |
mbedalvaro | 3:3fe7d6b5cf24 | 6 | |
mbedalvaro | 3:3fe7d6b5cf24 | 7 | Serial pc(USBTX, USBRX); // tx, rx |
mbedalvaro | 3:3fe7d6b5cf24 | 8 | |
mbedalvaro | 3:3fe7d6b5cf24 | 9 | SPI spiDAC(MOSI_PIN, MISO_PIN, SCK_PIN); // mosi, miso, sclk |
mbedalvaro | 3:3fe7d6b5cf24 | 10 | DigitalOut csDAC(CS_DAC_MIRRORS); |
mbedalvaro | 3:3fe7d6b5cf24 | 11 | |
mbedalvaro | 3:3fe7d6b5cf24 | 12 | DigitalOut Laser_Red(LASER_RED_PIN); // NOTE: this is NOT the lock in sensing laser (actually, not used yet) |
mbedalvaro | 3:3fe7d6b5cf24 | 13 | DigitalOut Laser_Green(LASER_GREEN_PIN); |
mbedalvaro | 3:3fe7d6b5cf24 | 14 | DigitalOut Laser_Blue(LASER_BLUE_PIN); |
mbedalvaro | 3:3fe7d6b5cf24 | 15 | |
mbedalvaro | 3:3fe7d6b5cf24 | 16 | void HardwareIO::init(void) { |
mbedalvaro | 3:3fe7d6b5cf24 | 17 | Laser_Red = 0; // note: this is not the lockin-laser! |
mbedalvaro | 3:3fe7d6b5cf24 | 18 | Laser_Green = 0; |
mbedalvaro | 3:3fe7d6b5cf24 | 19 | Laser_Blue = 0; |
mbedalvaro | 3:3fe7d6b5cf24 | 20 | |
mbedalvaro | 3:3fe7d6b5cf24 | 21 | //Serial Communication setup: |
mbedalvaro | 3:3fe7d6b5cf24 | 22 | pc.baud(115200);// |
mbedalvaro | 3:3fe7d6b5cf24 | 23 | // pc.baud(921600);//115200);// |
mbedalvaro | 3:3fe7d6b5cf24 | 24 | |
mbedalvaro | 3:3fe7d6b5cf24 | 25 | // Setup the spi for 8 bit data, high steady state clock, |
mbedalvaro | 3:3fe7d6b5cf24 | 26 | // second edge capture, with a 10MHz clock rate |
mbedalvaro | 3:3fe7d6b5cf24 | 27 | csDAC = 1; |
mbedalvaro | 3:3fe7d6b5cf24 | 28 | spiDAC.format(16,0); |
mbedalvaro | 3:3fe7d6b5cf24 | 29 | spiDAC.frequency(16000000); |
mbedalvaro | 3:3fe7d6b5cf24 | 30 | |
mbedalvaro | 3:3fe7d6b5cf24 | 31 | // default initial mirror position: |
mbedalvaro | 3:3fe7d6b5cf24 | 32 | writeOutX(CENTER_AD_MIRROR_X); |
mbedalvaro | 3:3fe7d6b5cf24 | 33 | writeOutY(CENTER_AD_MIRROR_Y); |
mbedalvaro | 3:3fe7d6b5cf24 | 34 | |
mbedalvaro | 3:3fe7d6b5cf24 | 35 | } |
mbedalvaro | 3:3fe7d6b5cf24 | 36 | |
mbedalvaro | 3:3fe7d6b5cf24 | 37 | //write on the first DAC, output A (mirror X) |
mbedalvaro | 3:3fe7d6b5cf24 | 38 | void HardwareIO::writeOutX(unsigned short value){ |
mbedalvaro | 3:3fe7d6b5cf24 | 39 | if(value > MAX_AD_MIRRORS) value = MAX_AD_MIRRORS; |
mbedalvaro | 3:3fe7d6b5cf24 | 40 | if(value < MIN_AD_MIRRORS) value = MIN_AD_MIRRORS; |
mbedalvaro | 3:3fe7d6b5cf24 | 41 | |
mbedalvaro | 3:3fe7d6b5cf24 | 42 | value |= 0x7000; |
mbedalvaro | 3:3fe7d6b5cf24 | 43 | value &= 0x7FFF; |
mbedalvaro | 3:3fe7d6b5cf24 | 44 | |
mbedalvaro | 3:3fe7d6b5cf24 | 45 | csDAC = 0; |
mbedalvaro | 3:3fe7d6b5cf24 | 46 | spiDAC.write(value); |
mbedalvaro | 3:3fe7d6b5cf24 | 47 | csDAC = 1; |
mbedalvaro | 3:3fe7d6b5cf24 | 48 | } |
mbedalvaro | 3:3fe7d6b5cf24 | 49 | |
mbedalvaro | 3:3fe7d6b5cf24 | 50 | //write on the first DAC, output B (mirror Y) |
mbedalvaro | 3:3fe7d6b5cf24 | 51 | void HardwareIO::writeOutY(unsigned short value){ |
mbedalvaro | 3:3fe7d6b5cf24 | 52 | if(value > MAX_AD_MIRRORS) value = MAX_AD_MIRRORS; |
mbedalvaro | 3:3fe7d6b5cf24 | 53 | if(value < MIN_AD_MIRRORS) value = MIN_AD_MIRRORS; |
mbedalvaro | 3:3fe7d6b5cf24 | 54 | |
mbedalvaro | 3:3fe7d6b5cf24 | 55 | value |= 0xF000; |
mbedalvaro | 3:3fe7d6b5cf24 | 56 | value &= 0xFFFF; |
mbedalvaro | 3:3fe7d6b5cf24 | 57 | |
mbedalvaro | 3:3fe7d6b5cf24 | 58 | csDAC = 0; |
mbedalvaro | 3:3fe7d6b5cf24 | 59 | spiDAC.write(value); |
mbedalvaro | 3:3fe7d6b5cf24 | 60 | csDAC = 1; |
mbedalvaro | 3:3fe7d6b5cf24 | 61 | } |
mbedalvaro | 3:3fe7d6b5cf24 | 62 | |
mbedalvaro | 3:3fe7d6b5cf24 | 63 | void HardwareIO::setRedPower(int powerValue){ |
mbedalvaro | 3:3fe7d6b5cf24 | 64 | if(powerValue > 0){ |
mbedalvaro | 3:3fe7d6b5cf24 | 65 | Laser_Red = 1; |
mbedalvaro | 3:3fe7d6b5cf24 | 66 | } |
mbedalvaro | 3:3fe7d6b5cf24 | 67 | else{ |
mbedalvaro | 3:3fe7d6b5cf24 | 68 | Laser_Red = 0; |
mbedalvaro | 3:3fe7d6b5cf24 | 69 | } |
mbedalvaro | 3:3fe7d6b5cf24 | 70 | } |
mbedalvaro | 3:3fe7d6b5cf24 | 71 | void HardwareIO::setGreenPower(int powerValue){ |
mbedalvaro | 3:3fe7d6b5cf24 | 72 | if(powerValue > 0){ |
mbedalvaro | 3:3fe7d6b5cf24 | 73 | Laser_Green = 1; |
mbedalvaro | 3:3fe7d6b5cf24 | 74 | } |
mbedalvaro | 3:3fe7d6b5cf24 | 75 | else{ |
mbedalvaro | 3:3fe7d6b5cf24 | 76 | Laser_Green = 0; |
mbedalvaro | 3:3fe7d6b5cf24 | 77 | } |
mbedalvaro | 3:3fe7d6b5cf24 | 78 | } |
mbedalvaro | 3:3fe7d6b5cf24 | 79 | void HardwareIO::setBluePower(int powerValue){ |
mbedalvaro | 3:3fe7d6b5cf24 | 80 | if(powerValue > 0){ |
mbedalvaro | 3:3fe7d6b5cf24 | 81 | Laser_Blue = 1; |
mbedalvaro | 3:3fe7d6b5cf24 | 82 | } |
mbedalvaro | 3:3fe7d6b5cf24 | 83 | else{ |
mbedalvaro | 3:3fe7d6b5cf24 | 84 | Laser_Blue = 0; |
mbedalvaro | 3:3fe7d6b5cf24 | 85 | } |
mbedalvaro | 3:3fe7d6b5cf24 | 86 | } |
mbedalvaro | 3:3fe7d6b5cf24 | 87 | void HardwareIO::setRGBPower(unsigned char color) { |
mbedalvaro | 3:3fe7d6b5cf24 | 88 | //lockin.setLaserPower(color&0x04>0? false : true); |
mbedalvaro | 3:3fe7d6b5cf24 | 89 | Laser_Red=color&0x04>>2; |
mbedalvaro | 3:3fe7d6b5cf24 | 90 | Laser_Green=(color&0x02)>>1; |
mbedalvaro | 3:3fe7d6b5cf24 | 91 | Laser_Blue =color&0x01; |
mbedalvaro | 3:3fe7d6b5cf24 | 92 | } |
mbedalvaro | 3:3fe7d6b5cf24 | 93 | |
mbedalvaro | 3:3fe7d6b5cf24 | 94 | void HardwareIO::showLimitsMirrors(int times) { |
mbedalvaro | 3:3fe7d6b5cf24 | 95 | unsigned short pointsPerLine=150; |
mbedalvaro | 3:3fe7d6b5cf24 | 96 | int shiftX = (MAX_AD_MIRRORS - MIN_AD_MIRRORS) / pointsPerLine; |
mbedalvaro | 3:3fe7d6b5cf24 | 97 | int shiftY = (MAX_AD_MIRRORS - MIN_AD_MIRRORS) / pointsPerLine; |
mbedalvaro | 3:3fe7d6b5cf24 | 98 | |
mbedalvaro | 3:3fe7d6b5cf24 | 99 | Laser_Green=1; |
mbedalvaro | 3:3fe7d6b5cf24 | 100 | |
mbedalvaro | 3:3fe7d6b5cf24 | 101 | //for (int repeat=0; repeat<times; repeat++) { |
mbedalvaro | 3:3fe7d6b5cf24 | 102 | |
mbedalvaro | 3:3fe7d6b5cf24 | 103 | Timer t; |
mbedalvaro | 3:3fe7d6b5cf24 | 104 | t.start(); |
mbedalvaro | 3:3fe7d6b5cf24 | 105 | while(t.read_ms()<times*1000) { |
mbedalvaro | 3:3fe7d6b5cf24 | 106 | |
mbedalvaro | 3:3fe7d6b5cf24 | 107 | writeOutX(MIN_AD_MIRRORS);writeOutY(MIN_AD_MIRRORS); |
mbedalvaro | 3:3fe7d6b5cf24 | 108 | |
mbedalvaro | 3:3fe7d6b5cf24 | 109 | for(int j=0; j<pointsPerLine; j++){ |
mbedalvaro | 3:3fe7d6b5cf24 | 110 | wait_us(200);//delay between each points |
mbedalvaro | 3:3fe7d6b5cf24 | 111 | writeOutY(j*shiftY + MIN_AD_MIRRORS); |
mbedalvaro | 3:3fe7d6b5cf24 | 112 | } |
mbedalvaro | 3:3fe7d6b5cf24 | 113 | |
mbedalvaro | 3:3fe7d6b5cf24 | 114 | writeOutX(MIN_AD_MIRRORS);writeOutY(MAX_AD_MIRRORS); |
mbedalvaro | 3:3fe7d6b5cf24 | 115 | for(int j=0; j<pointsPerLine; j++) { |
mbedalvaro | 3:3fe7d6b5cf24 | 116 | wait_us(200);//delay between each points |
mbedalvaro | 3:3fe7d6b5cf24 | 117 | writeOutX(j*shiftX + MIN_AD_MIRRORS); |
mbedalvaro | 3:3fe7d6b5cf24 | 118 | } |
mbedalvaro | 3:3fe7d6b5cf24 | 119 | |
mbedalvaro | 3:3fe7d6b5cf24 | 120 | writeOutX(MAX_AD_MIRRORS);writeOutY(MAX_AD_MIRRORS); |
mbedalvaro | 3:3fe7d6b5cf24 | 121 | for(int j=0; j<pointsPerLine; j++) { |
mbedalvaro | 3:3fe7d6b5cf24 | 122 | wait_us(200);//delay between each points |
mbedalvaro | 3:3fe7d6b5cf24 | 123 | writeOutY(-j*shiftX + MAX_AD_MIRRORS); |
mbedalvaro | 3:3fe7d6b5cf24 | 124 | } |
mbedalvaro | 3:3fe7d6b5cf24 | 125 | |
mbedalvaro | 3:3fe7d6b5cf24 | 126 | writeOutX(MAX_AD_MIRRORS);writeOutY(MIN_AD_MIRRORS); |
mbedalvaro | 3:3fe7d6b5cf24 | 127 | for(int j=0; j<pointsPerLine; j++) { |
mbedalvaro | 3:3fe7d6b5cf24 | 128 | wait_us(200);//delay between each points |
mbedalvaro | 3:3fe7d6b5cf24 | 129 | writeOutX(-j*shiftX + MAX_AD_MIRRORS); |
mbedalvaro | 3:3fe7d6b5cf24 | 130 | } |
mbedalvaro | 3:3fe7d6b5cf24 | 131 | |
mbedalvaro | 3:3fe7d6b5cf24 | 132 | } |
mbedalvaro | 3:3fe7d6b5cf24 | 133 | t.stop(); |
mbedalvaro | 3:3fe7d6b5cf24 | 134 | Laser_Green=0; |
mbedalvaro | 3:3fe7d6b5cf24 | 135 | } |