![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
kakuninonegai
Dependencies: mbed SBDBT arrc_mbed air
main.cpp@2:3dcf3fcb4921, 2022-01-19 (annotated)
- Committer:
- asumamatsumura
- Date:
- Wed Jan 19 07:40:28 2022 +0000
- Revision:
- 2:3dcf3fcb4921
- Parent:
- 1:bf629e5bf337
change comment;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
asumamatsumura | 0:b03df060dbea | 1 | #include "mbed.h" |
asumamatsumura | 0:b03df060dbea | 2 | #include "scrp_slave.hpp" |
asumamatsumura | 0:b03df060dbea | 3 | #include "air.hpp" |
asumamatsumura | 0:b03df060dbea | 4 | #include "sbdbt.hpp" |
asumamatsumura | 0:b03df060dbea | 5 | sbdbt ds3(A0, A1); |
asumamatsumura | 0:b03df060dbea | 6 | DigitalIn limitA(PA_9,PullUp); |
asumamatsumura | 0:b03df060dbea | 7 | DigitalIn limitB(PC_5,PullUp); |
asumamatsumura | 0:b03df060dbea | 8 | Air catch_no(PA_0); |
asumamatsumura | 0:b03df060dbea | 9 | |
asumamatsumura | 1:bf629e5bf337 | 10 | //↓モーター |
asumamatsumura | 0:b03df060dbea | 11 | void driveMotorS(double pwm){ |
asumamatsumura | 0:b03df060dbea | 12 | PwmOut up_pin_A(PB_13); |
asumamatsumura | 0:b03df060dbea | 13 | PwmOut up_pin_B(PB_14); |
asumamatsumura | 0:b03df060dbea | 14 | up_pin_A.period_us(2048); |
asumamatsumura | 0:b03df060dbea | 15 | up_pin_B.period_us(2048); |
asumamatsumura | 0:b03df060dbea | 16 | if (!pwm) { |
asumamatsumura | 0:b03df060dbea | 17 | up_pin_A = 0; |
asumamatsumura | 0:b03df060dbea | 18 | up_pin_B = 0; |
asumamatsumura | 0:b03df060dbea | 19 | } else if (0 < pwm) { |
asumamatsumura | 0:b03df060dbea | 20 | up_pin_A = pwm; |
asumamatsumura | 0:b03df060dbea | 21 | up_pin_B = 0; |
asumamatsumura | 0:b03df060dbea | 22 | } else { |
asumamatsumura | 0:b03df060dbea | 23 | up_pin_A = 0; |
asumamatsumura | 0:b03df060dbea | 24 | up_pin_B= -pwm; |
asumamatsumura | 0:b03df060dbea | 25 | } |
asumamatsumura | 0:b03df060dbea | 26 | } |
asumamatsumura | 1:bf629e5bf337 | 27 | //↓昇降 |
asumamatsumura | 2:3dcf3fcb4921 | 28 | //速さはテキトー |
asumamatsumura | 0:b03df060dbea | 29 | void Up(int data){ |
asumamatsumura | 0:b03df060dbea | 30 | if(data==1 && !limitA){ |
asumamatsumura | 0:b03df060dbea | 31 | driveMotorS(0.06); |
asumamatsumura | 0:b03df060dbea | 32 | }else if(data==-1 && !limitB){ |
asumamatsumura | 0:b03df060dbea | 33 | driveMotorS(-0.06); |
asumamatsumura | 0:b03df060dbea | 34 | }else{ |
asumamatsumura | 0:b03df060dbea | 35 | driveMotorS(0); |
asumamatsumura | 0:b03df060dbea | 36 | } |
asumamatsumura | 0:b03df060dbea | 37 | } |
asumamatsumura | 1:bf629e5bf337 | 38 | //↓回収用 |
asumamatsumura | 0:b03df060dbea | 39 | void CATCH_NO(bool data){ |
asumamatsumura | 0:b03df060dbea | 40 | catch_no.move(data); |
asumamatsumura | 0:b03df060dbea | 41 | } |
asumamatsumura | 0:b03df060dbea | 42 | |
asumamatsumura | 0:b03df060dbea | 43 | int main(){ |
asumamatsumura | 0:b03df060dbea | 44 | int up; |
asumamatsumura | 0:b03df060dbea | 45 | bool catch_no=0,old_circle; |
asumamatsumura | 0:b03df060dbea | 46 | while(true){ |
asumamatsumura | 1:bf629e5bf337 | 47 | //↓コントローラー関係 |
asumamatsumura | 0:b03df060dbea | 48 | up=ds3.up()+ds3.down(); |
asumamatsumura | 0:b03df060dbea | 49 | if(old_circle<ds3.circle()) catch_no=!catch_no; |
asumamatsumura | 0:b03df060dbea | 50 | old_circle=ds3.circle(); |
asumamatsumura | 1:bf629e5bf337 | 51 | //↓関数関係 |
asumamatsumura | 0:b03df060dbea | 52 | Up(up); |
asumamatsumura | 0:b03df060dbea | 53 | CATCH_NO(catch_no); |
asumamatsumura | 0:b03df060dbea | 54 | } |
asumamatsumura | 0:b03df060dbea | 55 | } |