![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
shoot
Dependencies: mbed SBDBT arrc_mbed Servo air
main.cpp@2:0428390d7c90, 2022-02-24 (annotated)
- Committer:
- asumamatsumura
- Date:
- Thu Feb 24 01:50:43 2022 +0000
- Revision:
- 2:0428390d7c90
- Parent:
- 1:cae30876c429
servo;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
asumamatsumura | 0:6f9a457b09e1 | 1 | #include "mbed.h" |
asumamatsumura | 0:6f9a457b09e1 | 2 | #include "air.hpp" |
asumamatsumura | 0:6f9a457b09e1 | 3 | #include "sbdbt.hpp" |
asumamatsumura | 2:0428390d7c90 | 4 | #include "Servo.h" |
asumamatsumura | 0:6f9a457b09e1 | 5 | sbdbt ds3(A0, A1); |
asumamatsumura | 0:6f9a457b09e1 | 6 | DigitalIn limitA(PA_9,PullUp); |
asumamatsumura | 0:6f9a457b09e1 | 7 | Air hassya(PA_0); |
asumamatsumura | 2:0428390d7c90 | 8 | Servo myservo(PB_0); |
asumamatsumura | 0:6f9a457b09e1 | 9 | Timer timer; |
asumamatsumura | 0:6f9a457b09e1 | 10 | //↓モータ用 |
asumamatsumura | 0:6f9a457b09e1 | 11 | void driveMotorS(double pwm){ |
asumamatsumura | 0:6f9a457b09e1 | 12 | PwmOut up_pin_A(PB_13); |
asumamatsumura | 0:6f9a457b09e1 | 13 | PwmOut up_pin_B(PB_14); |
asumamatsumura | 0:6f9a457b09e1 | 14 | up_pin_A.period_us(2048); |
asumamatsumura | 0:6f9a457b09e1 | 15 | up_pin_B.period_us(2048); |
asumamatsumura | 0:6f9a457b09e1 | 16 | if (!pwm) { |
asumamatsumura | 0:6f9a457b09e1 | 17 | up_pin_A = 0; |
asumamatsumura | 0:6f9a457b09e1 | 18 | up_pin_B = 0; |
asumamatsumura | 0:6f9a457b09e1 | 19 | } else if (0 < pwm) { |
asumamatsumura | 0:6f9a457b09e1 | 20 | up_pin_A = pwm; |
asumamatsumura | 0:6f9a457b09e1 | 21 | up_pin_B = 0; |
asumamatsumura | 0:6f9a457b09e1 | 22 | } else { |
asumamatsumura | 0:6f9a457b09e1 | 23 | up_pin_A = 0; |
asumamatsumura | 0:6f9a457b09e1 | 24 | up_pin_B= -pwm; |
asumamatsumura | 0:6f9a457b09e1 | 25 | } |
asumamatsumura | 0:6f9a457b09e1 | 26 | } |
asumamatsumura | 0:6f9a457b09e1 | 27 | // ↓サーボ用(未実装) |
asumamatsumura | 0:6f9a457b09e1 | 28 | void Servo(bool data){ |
asumamatsumura | 2:0428390d7c90 | 29 | if(data==0){ |
asumamatsumura | 2:0428390d7c90 | 30 | myservo = 0; |
asumamatsumura | 2:0428390d7c90 | 31 | }else{ |
asumamatsumura | 2:0428390d7c90 | 32 | myservo = 0.2; |
asumamatsumura | 0:6f9a457b09e1 | 33 | } |
asumamatsumura | 2:0428390d7c90 | 34 | } |
asumamatsumura | 0:6f9a457b09e1 | 35 | //↓発射用 |
asumamatsumura | 0:6f9a457b09e1 | 36 | void Hassya(bool data,int tim){ |
asumamatsumura | 1:cae30876c429 | 37 | if(data==1 || timer.read_ms()-tim<3000){ |
asumamatsumura | 1:cae30876c429 | 38 | if(timer.read_ms()-tim>2000){ |
asumamatsumura | 1:cae30876c429 | 39 | hassya.move(1); |
asumamatsumura | 1:cae30876c429 | 40 | }else{ |
asumamatsumura | 1:cae30876c429 | 41 | hassya.move(0); |
asumamatsumura | 1:cae30876c429 | 42 | } |
asumamatsumura | 0:6f9a457b09e1 | 43 | if(timer.read_ms()-tim>1000) Servo(1); |
asumamatsumura | 0:6f9a457b09e1 | 44 | }else{ |
asumamatsumura | 0:6f9a457b09e1 | 45 | if(limitA){ |
asumamatsumura | 0:6f9a457b09e1 | 46 | driveMotorS(0); |
asumamatsumura | 0:6f9a457b09e1 | 47 | Servo(0); |
asumamatsumura | 0:6f9a457b09e1 | 48 | }else{ |
asumamatsumura | 0:6f9a457b09e1 | 49 | driveMotorS(0.06); |
asumamatsumura | 0:6f9a457b09e1 | 50 | } |
asumamatsumura | 0:6f9a457b09e1 | 51 | } |
asumamatsumura | 0:6f9a457b09e1 | 52 | } |
asumamatsumura | 0:6f9a457b09e1 | 53 | int main(){ |
asumamatsumura | 0:6f9a457b09e1 | 54 | //↓宣言 |
asumamatsumura | 0:6f9a457b09e1 | 55 | bool shoot; |
asumamatsumura | 0:6f9a457b09e1 | 56 | int tim,old_square=0; |
asumamatsumura | 0:6f9a457b09e1 | 57 | timer.start(); |
asumamatsumura | 0:6f9a457b09e1 | 58 | while(true){ |
asumamatsumura | 0:6f9a457b09e1 | 59 | //コントローラ関係 |
asumamatsumura | 1:cae30876c429 | 60 | if(old_square<ds3.square() && (!shoot || limitA)){ |
asumamatsumura | 1:cae30876c429 | 61 | |
asumamatsumura | 0:6f9a457b09e1 | 62 | shoot=!shoot; |
asumamatsumura | 0:6f9a457b09e1 | 63 | tim=timer.read_ms(); |
asumamatsumura | 0:6f9a457b09e1 | 64 | } |
asumamatsumura | 0:6f9a457b09e1 | 65 | old_square=ds3.square(); |
asumamatsumura | 0:6f9a457b09e1 | 66 | //関数 |
asumamatsumura | 0:6f9a457b09e1 | 67 | Hassya(shoot,tim); |
asumamatsumura | 0:6f9a457b09e1 | 68 | } |
asumamatsumura | 0:6f9a457b09e1 | 69 | } |