レーザー用のプログラムです(複数不可) 正規の方法じゃないから問題が起こるかもね がんばって

Dependencies:   mbed

Fork of VL53L0X_STM32compatible_2 by 2018年春ロボ1班

Committer:
riku3141
Date:
Tue Dec 26 03:39:31 2017 +0000
Revision:
2:30363c43d575
Parent:
1:4fe66089799c
Child:
3:ce75ca8e2011
test

Who changed what in which revision?

UserRevisionLine numberNew contents of line
open4416 0:d738e3a03cf8 1 #include "mbed.h"
open4416 0:d738e3a03cf8 2 #include "VL53L0X_SH.h"
open4416 0:d738e3a03cf8 3
riku3141 2:30363c43d575 4 #define Rms 500000 //TT rate
riku3141 1:4fe66089799c 5 #define dt 0.005f //lps rate
open4416 0:d738e3a03cf8 6
riku3141 1:4fe66089799c 7 //#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt))) //これはよく分からん
open4416 0:d738e3a03cf8 8
open4416 0:d738e3a03cf8 9 //↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓GPIO registor↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓//
open4416 0:d738e3a03cf8 10 //~~~structure~~~//
riku3141 2:30363c43d575 11 DigitalOut reset(PC_10);
riku3141 2:30363c43d575 12 DigitalIn button(USER_BUTTON);
open4416 0:d738e3a03cf8 13 //~~~VL53L0X_I2C~~~//
open4416 0:d738e3a03cf8 14 //I2C i2c(D14, D15); //I2C reg(SDA, SCL)
open4416 0:d738e3a03cf8 15 VL53L0X sensor;
open4416 0:d738e3a03cf8 16 //~~~Serial~~~//
riku3141 1:4fe66089799c 17 Serial pc(USBTX, USBRX); //Serial reg(TX RX)
open4416 0:d738e3a03cf8 18 //↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑end of GPIO registor↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑//
open4416 0:d738e3a03cf8 19 //↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓Varible registor↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓//
open4416 0:d738e3a03cf8 20 //~~~globle~~~//
open4416 0:d738e3a03cf8 21 Ticker TT; //call a timer
open4416 0:d738e3a03cf8 22 //~~~VL53L0X_I2C~~~//
open4416 0:d738e3a03cf8 23 int Distance = 0;
open4416 0:d738e3a03cf8 24 //↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑end of Varible registor↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑//
open4416 0:d738e3a03cf8 25 //↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓Function registor↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓//
open4416 0:d738e3a03cf8 26 void init_TIMER(); //set TT_main() rate
open4416 0:d738e3a03cf8 27 void TT_main(); //timebase function rated by TT
open4416 0:d738e3a03cf8 28 void init_IO(); //initialize IO state
open4416 0:d738e3a03cf8 29 float lpf(float input, float output_old, float frequency); //lpf discrete
open4416 0:d738e3a03cf8 30 //↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑end of Function registor↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑//
riku3141 1:4fe66089799c 31 //↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓Timebase funtion↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓//
riku3141 1:4fe66089799c 32 void init_TIMER() //set TT_main{} rate 割り込み用関数
riku3141 1:4fe66089799c 33 {
riku3141 1:4fe66089799c 34 TT.attach_us(&TT_main, Rms);
riku3141 1:4fe66089799c 35 }
riku3141 1:4fe66089799c 36 void TT_main() //interrupt function by TT 測定用関数
riku3141 1:4fe66089799c 37 {
riku3141 1:4fe66089799c 38 Distance = sensor.readRangeContinuousMillimeters();
riku3141 1:4fe66089799c 39 //for Serial-Oscilloscope
riku3141 2:30363c43d575 40 pc.printf("%d ", Distance);
riku3141 1:4fe66089799c 41 }
riku3141 1:4fe66089799c 42 //↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑end of Timebase funtion↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑//
riku3141 1:4fe66089799c 43 //↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓init_IO funtion↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓//
riku3141 2:30363c43d575 44 /*
riku3141 1:4fe66089799c 45 void init_IO(void) //initialize シリアル通信速度設定
riku3141 1:4fe66089799c 46 {
riku3141 1:4fe66089799c 47 pc.baud(9600); //set baud rate
riku3141 1:4fe66089799c 48 }
riku3141 2:30363c43d575 49 */
riku3141 1:4fe66089799c 50 //↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑end of init_IO funtion↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑//
riku3141 1:4fe66089799c 51 //↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓lpf funtion↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓//
riku3141 1:4fe66089799c 52 float lpf(float input, float output_old, float frequency) //ローパスフィルタ
riku3141 1:4fe66089799c 53 {
riku3141 1:4fe66089799c 54 float output = 0;
riku3141 1:4fe66089799c 55 output = (output_old + frequency*dt*input) / (1 + frequency*dt);
riku3141 1:4fe66089799c 56 return output;
riku3141 1:4fe66089799c 57 }
riku3141 1:4fe66089799c 58 //↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑end of lpf funtion↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑//
open4416 0:d738e3a03cf8 59 //↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓main funtion↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓//
open4416 0:d738e3a03cf8 60 int main()
open4416 0:d738e3a03cf8 61 {
riku3141 2:30363c43d575 62 reset = 1;
riku3141 2:30363c43d575 63 button.mode(PullDown);
riku3141 2:30363c43d575 64 sensor.setAddress(0x54);
riku3141 2:30363c43d575 65 // reset_2 = 0;
riku3141 2:30363c43d575 66 // reset_2 = 1;
riku3141 2:30363c43d575 67 // reset_2 = 1;
riku3141 1:4fe66089799c 68 printf("start\r\n");
riku3141 2:30363c43d575 69 //init_IO(); //initialized value
open4416 0:d738e3a03cf8 70 sensor.init(); //init SENSOR
open4416 0:d738e3a03cf8 71 sensor.setTimeout(500);
open4416 0:d738e3a03cf8 72 sensor.startContinuous();
open4416 0:d738e3a03cf8 73 NVIC_SetPriority(TIM5_IRQn, 51); //!!!!!!!!!!!!!!!!!!!!!!!!!
riku3141 2:30363c43d575 74 // sensor.setAddress(0x54);
riku3141 2:30363c43d575 75 reset =0;
riku3141 2:30363c43d575 76 reset =1;
riku3141 2:30363c43d575 77 sensor.address = 41;
riku3141 2:30363c43d575 78 sensor.init();
riku3141 2:30363c43d575 79 sensor.setTimeout(500);
riku3141 2:30363c43d575 80 sensor.startContinuous();
riku3141 2:30363c43d575 81 NVIC_SetPriority(TIM5_IRQn, 51); //!!!!!!!!!!!!!!!!!!!!!!!!!
riku3141 2:30363c43d575 82 sensor.address=84;
riku3141 2:30363c43d575 83 // reset = 0;
open4416 0:d738e3a03cf8 84 while(1) { //main() loop
riku3141 2:30363c43d575 85 reset =1;
riku3141 2:30363c43d575 86 pc.printf("number: %d ;;",sensor.address);
riku3141 1:4fe66089799c 87 TT_main();
riku3141 2:30363c43d575 88 sensor.address=41;
riku3141 2:30363c43d575 89 // wait(0.1);
riku3141 2:30363c43d575 90 pc.printf("number: %d ;;",sensor.address);
riku3141 2:30363c43d575 91 TT_main();
riku3141 2:30363c43d575 92 sensor.address=84;
riku3141 2:30363c43d575 93 pc.printf("\r");
riku3141 2:30363c43d575 94 // wait(0.1);
riku3141 2:30363c43d575 95 sensor.address=41;
riku3141 2:30363c43d575 96 pc.printf("button state %d \n", button.read());
riku3141 2:30363c43d575 97 if(button.read()==0){
riku3141 2:30363c43d575 98 sensor.init();
riku3141 2:30363c43d575 99 sensor.setTimeout(500);
riku3141 2:30363c43d575 100 sensor.startContinuous();
riku3141 2:30363c43d575 101 NVIC_SetPriority(TIM5_IRQn, 51); //!!!!!!!!!!!!!!!!!!!!!!!!!
riku3141 2:30363c43d575 102 }
riku3141 2:30363c43d575 103 sensor.address=84;
open4416 0:d738e3a03cf8 104 }
open4416 0:d738e3a03cf8 105 }
riku3141 1:4fe66089799c 106 //↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑end of main funtion↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑//