2018_Project-R
/
robokonDthrow_ver3
開発途中
Fork of robokonDthrow_ver2 by
Diff: main.cpp
- Revision:
- 3:0bfdc0f376a6
- Parent:
- 2:079ba2b551a4
- Child:
- 7:4816d59e5de0
--- a/main.cpp Mon Dec 25 09:29:29 2017 +0000 +++ b/main.cpp Mon Jan 15 08:49:44 2018 +0000 @@ -14,15 +14,21 @@ DigitalOut valve1(p15); //p21->p15 QEI rollen(p21, p22, NC, 1024); //p29->p21 p30->p22 +I2C vl53l0x_i2c(p9, p10); // vl53l0xのためのI2Cクラスのインスタンス化(sda, sclの順) p28->p9,p27->p10 +Timer vl53l0x_timer; // vl53l0xのためのTimerクラスのインスタンス化 + +VL53L0X sensor(&vl53l0x_i2c, &vl53l0x_timer); // i2cとtimerの実態のポインタを渡す + +PwmOut servo(p23);//サーボのやつ DigitalOut led1(LED1); DigitalOut led2(LED2); DigitalOut led3(LED3); DigitalOut led4(LED4); -DigitalIn button_hand(p5); -DigitalIn button_zero(p6); -DigitalIn button_charge(p7); +InterruptIn button_hand(p5); +InterruptIn button_zero(p6); +InterruptIn button_charge(p7); Serial pc(USBTX,USBRX); @@ -30,14 +36,19 @@ //timer初期化 Ticker rollening; +Ticker tick;// //グローバル変数 int enc_hand = 0; //int enc_belt = 0; char state = '0'; +int distance = 0; int enc_old = 0; //過去カウント比較用 +double ServoDeg = 0; //グローバル関数 + +//ハンドエンコーダ割り込み void Dthrow(){ enc_hand = rollen.getPulses(); @@ -126,54 +137,69 @@ enc_old = enc_hand; } +//超音波距離センサ測定 void dist(int distance){ //put code here to execute when the distance has changed - printf("Distance_1 %d mm\r\n", distance); + //printf("Distance_1 %d mm\r\n", distance); //printf("Distance_2 %d mm\r\n", distance); } -ultrasonic mu(p6, p7, .1, 1, &dist); +ultrasonic mu(p25, p26, .1, 1, &dist); //trig=>p6->p25,echo=>p7->p26 +//スイッチ@ハンド void hand(){ - + valve1=0 + ServoDeg = 180; + servo.pulsewidth(ServoDeg/100000+0.0006); + wait(0.25); } - + +//スイッチ@ゼロ点 void zero(){ enc_hand = 0; } - + +//スイッチ@タイミングベルト void charge(){ } + +//ToF割り込み +void warikomi(){ + } + //main関数 int main(){ + pc.baud(9600); + + + + sensor.init(); // vl53l0xの初期化 + sensor.setTimeout(500); // vl53l0xのタイムアウト時間の設定 + sensor.startContinuous(); // vl53l0xの連続データ取得開始 + button_hand.mode(PullUp); button_zero.mode(PullUp); button_charge.mode(PullUp); - button_hand.rise(&hand); - button_zero.rise(&zero); - button_charge.rise(&charge); + //button_hand.rise(&hand); + //button_zero.rise(&zero); + //button_charge.rise(&charge); + mu.startUpdates();//start measuring the distance + rollening.attach(&Dthrow, 0.01); - valve1 = 1; - //メモ:attaach_usでマイクロ秒もいけるらしいですがいけませんでした + //tick.attach(&warikomi, 0.01); // setup ticker to call flip every 0.01 seconds + + valve1 = 1;//ハンドの初期状態は開 + + servo.period(0.020); while(1){ mu.checkDistance(); - pc.printf("state:%c\t encoder:%d\n",state,enc_hand); + pc.printf("state:%c\tencoder:%d\tdistance:%d\n",state,enc_hand,distance); if(pc.readable()) state = pc.getc(); - if(button == 1){ - valve1 = 1 - led4 = 1; - } - else if(button == 0){ - valve1 = 0; - led4 = 0; - wait(0.5); - - } - wait(0.01); + } }