NHK2018Bチームの手動ロボットのプログラムです。(製作中)
Dependencies: HCSR04 PID PS3viaSBDBT QEI mbed
Diff: main.cpp
- Revision:
- 4:58a2afff53a4
- Parent:
- 3:f462b1244d77
- Child:
- 5:79cc2a126504
--- a/main.cpp Thu Sep 27 09:25:21 2018 +0000 +++ b/main.cpp Mon Oct 01 08:21:32 2018 +0000 @@ -88,6 +88,7 @@ int mode = true; int table; double looptime; +float timer1 = 0; //プロトタイプ宣言 //メイン制御関数 @@ -126,20 +127,17 @@ pc.printf("\x1b[0m"); while(true) { looptime = mainloop.read(); - pc.printf("%3d,%3d,%f,%d\n\r",front_roller_rpm, back_roller_rpm, looptime, sonicval); mainloop.reset(); mainloop.start(); - roller_PID(777,655); - //front_roller_data[0] = 0x80; - //back_roller_data[0] = 0x80; - i2c.write(0x18, front_roller_data, 1, false); - i2c.write(0x20, back_roller_data, 1, false); + //roller_PID(777,655); + //i2c.write(0x18, front_roller_data, 1, false); + //i2c.write(0x20, back_roller_data, 1, false); topsonic.start(); wait(0.01); sonicval = topsonic.get_dist_cm(); - //ps3s.getdata(); - //ps3s.checkdata(); - //ctrl(); + ps3s.getdata(); + ps3s.checkdata(); + ctrl(); //printdata(); mainloop.stop(); } @@ -418,6 +416,7 @@ //平均値をRPMへ変換 front_roller_rpm = ave_front_roller_pulse * 25 * 60 / 1200; back_roller_rpm = ave_back_roller_pulse * 25 * 60 / 1200; + pc.printf("%3d,%3d,%f\n\r",abs(front_roller_rpm), abs(back_roller_rpm), sonicval); } //ローラー @@ -447,46 +446,24 @@ //投擲動作 void shoot() { - int time; - int front; - int back; - if(table == 0) { - front = 666; - back = 666; - } else if(table == 1) { - front = 777; - back = 777; - } + shootpet.start(); while(true) { - shootpet.start(); - roller_PID(front,back); - i2c.write(0x18, front_roller_data, 1, false); - i2c.write(0x20, back_roller_data, 1, false); - if(shootpet.read() == 10) { + timer1 = shootpet.read(); + if(timer1 > 10) { break; } + roller_PID(1000,1000); + //i2c.write(0x18, front_roller_data, 1, false); + i2c.write(0x20, back_roller_data, 1, false); } + back_roller_data[0] = 0x80; + i2c.write(0x20, back_roller_data,1,false); shootpet.stop(); shootpet.reset(); - shootpet.start(); - while(true) { - time = shootpet.read(); - if(time <= 0.5) { - send_data2[0] = 0x0F; - i2c.write(0x40, send_data2, 1); - } else { - send_data2[0] = 0x80; - i2c.write(0x40, send_data2, 1); - i2c.write(0x18, send_data2, 1, false); - i2c.write(0x20, send_data2, 1, false); - shootpet.stop(); - shootpet.reset(); - break; - } - } } + //セミオートプレイテスト void semiauto()