![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
4/2にちゃんと動いたやつ
Dependencies: mbed SBDBT arrc_mbed
main.cpp@7:59be95fceafa, 2022-02-03 (annotated)
- Committer:
- guesta
- Date:
- Thu Feb 03 13:31:38 2022 +0000
- Revision:
- 7:59be95fceafa
- Parent:
- 6:fd9b59f828e8
- Child:
- 8:e76d6c16d7af
add
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
guesta | 0:d8faed605a5c | 1 | #include "mbed.h" |
guesta | 3:e4b5563563af | 2 | #include "scrp_slave.hpp" |
guesta | 3:e4b5563563af | 3 | #include "sbdbt.hpp" |
guesta | 0:d8faed605a5c | 4 | |
guesta | 0:d8faed605a5c | 5 | int main(){ |
guesta | 1:642ee25ea489 | 6 | //---------------初期設定--------------- |
guesta | 3:e4b5563563af | 7 | //scrp_slave |
guesta | 3:e4b5563563af | 8 | ScrpSlave scrp(PC_12,PD_2,PH_1,0x0807f800); |
guesta | 6:fd9b59f828e8 | 9 | |
guesta | 3:e4b5563563af | 10 | //sbdbt |
guesta | 6:fd9b59f828e8 | 11 | sbdbt sb(A0,A1); |
guesta | 6:fd9b59f828e8 | 12 | |
guesta | 3:e4b5563563af | 13 | //scrp_slaveのid設定 |
guesta | 6:fd9b59f828e8 | 14 | const int wheel_num = 1; |
guesta | 3:e4b5563563af | 15 | const int BeanbagGet_num = 2; |
guesta | 3:e4b5563563af | 16 | const int BeanbagShot_num = 3; |
guesta | 3:e4b5563563af | 17 | const int TakoGetPut_num = 4; |
guesta | 6:fd9b59f828e8 | 18 | const int tape_LED_num = 5; |
guesta | 6:fd9b59f828e8 | 19 | const int remort_stop_num = 6; |
guesta | 6:fd9b59f828e8 | 20 | const int send_all = 255; |
guesta | 6:fd9b59f828e8 | 21 | |
guesta | 3:e4b5563563af | 22 | //コマンド番号設定 |
guesta | 6:fd9b59f828e8 | 23 | //足回り用 |
guesta | 3:e4b5563563af | 24 | const int x_component_cmd = 1; |
guesta | 3:e4b5563563af | 25 | const int y_component_cmd = 2; |
guesta | 3:e4b5563563af | 26 | const int l2_cmd = 3; |
guesta | 3:e4b5563563af | 27 | const int r2_cmd = 4; |
guesta | 7:59be95fceafa | 28 | const int l1_cmd = 5; |
guesta | 6:fd9b59f828e8 | 29 | |
guesta | 6:fd9b59f828e8 | 30 | //ビーンバッグ回収用 |
guesta | 6:fd9b59f828e8 | 31 | |
guesta | 6:fd9b59f828e8 | 32 | //ビーンバッグ発射用 |
guesta | 7:59be95fceafa | 33 | const int load = 3; |
guesta | 7:59be95fceafa | 34 | const int revolver = 4; |
guesta | 7:59be95fceafa | 35 | const int back = 5; |
guesta | 7:59be95fceafa | 36 | const int shot = 6; |
guesta | 6:fd9b59f828e8 | 37 | |
guesta | 6:fd9b59f828e8 | 38 | //農作物回収・設置用 |
guesta | 6:fd9b59f828e8 | 39 | const int up = 1; |
guesta | 6:fd9b59f828e8 | 40 | const int down = 2; |
guesta | 6:fd9b59f828e8 | 41 | |
guesta | 6:fd9b59f828e8 | 42 | //テープLED用 |
guesta | 6:fd9b59f828e8 | 43 | |
guesta | 6:fd9b59f828e8 | 44 | //遠隔非常停止受信用 |
guesta | 6:fd9b59f828e8 | 45 | |
guesta | 6:fd9b59f828e8 | 46 | //全体送信用 |
guesta | 6:fd9b59f828e8 | 47 | const int select = 50;//手動・自動切り替え |
guesta | 6:fd9b59f828e8 | 48 | const int stop_all = 51;//全プログラム停止 |
guesta | 6:fd9b59f828e8 | 49 | |
guesta | 1:642ee25ea489 | 50 | //変数 |
guesta | 7:59be95fceafa | 51 | bool auto_mode = false; |
guesta | 7:59be95fceafa | 52 | bool auto_start; |
guesta | 3:e4b5563563af | 53 | int x_component; |
guesta | 3:e4b5563563af | 54 | int y_component; |
guesta | 3:e4b5563563af | 55 | int l2_num; |
guesta | 3:e4b5563563af | 56 | int r2_num; |
guesta | 3:e4b5563563af | 57 | //------------------------------------- |
guesta | 6:fd9b59f828e8 | 58 | |
guesta | 1:642ee25ea489 | 59 | while(true){ |
guesta | 3:e4b5563563af | 60 | sb.button_state(); |
guesta | 6:fd9b59f828e8 | 61 | x_component = sb.rsx(); |
guesta | 6:fd9b59f828e8 | 62 | y_component = sb.rsy(); |
guesta | 3:e4b5563563af | 63 | l2_num = sb.l2An(); |
guesta | 3:e4b5563563af | 64 | r2_num = sb.r2An(); |
guesta | 7:59be95fceafa | 65 | if(select() == 1){ |
guesta | 7:59be95fceafa | 66 | auto_mode =! auto_mode; |
guesta | 7:59be95fceafa | 67 | } |
guesta | 6:fd9b59f828e8 | 68 | |
guesta | 6:fd9b59f828e8 | 69 | //足回り |
guesta | 3:e4b5563563af | 70 | scrp.send1(wheel_num,x_component_cmd,x_component); |
guesta | 7:59be95fceafa | 71 | wait_ms(2); |
guesta | 3:e4b5563563af | 72 | scrp.send1(wheel_num,y_component_cmd,y_component); |
guesta | 7:59be95fceafa | 73 | wait_ms(2); |
guesta | 3:e4b5563563af | 74 | scrp.send1(wheel_num,l2_cmd,l2_num); |
guesta | 7:59be95fceafa | 75 | wait_ms(2); |
guesta | 3:e4b5563563af | 76 | scrp.send1(wheel_num,r2_cmd,r2_num); |
guesta | 7:59be95fceafa | 77 | wait_ms(2); |
guesta | 7:59be95fceafa | 78 | scrp.send1(wheel_num,l1_cmd,sb.l1()); |
guesta | 7:59be95fceafa | 79 | wait_ms(2); |
guesta | 6:fd9b59f828e8 | 80 | |
guesta | 6:fd9b59f828e8 | 81 | //ビーンバッグ回収 |
guesta | 6:fd9b59f828e8 | 82 | |
guesta | 6:fd9b59f828e8 | 83 | //ビーンバッグ発射 |
guesta | 7:59be95fceafa | 84 | if(auto_mode == true){ |
guesta | 7:59be95fceafa | 85 | scrp.send1(BeanbagShot_num,load,down()); |
guesta | 7:59be95fceafa | 86 | wait_ms(2); |
guesta | 7:59be95fceafa | 87 | scrp.send1(BeanbagShot_num,revolver,right()); |
guesta | 7:59be95fceafa | 88 | wait_ms(2); |
guesta | 7:59be95fceafa | 89 | scrp.send1(BeanbagShot_num,back,up()); |
guesta | 7:59be95fceafa | 90 | wait_ms(2); |
guesta | 7:59be95fceafa | 91 | scrp.send1(BeanbagShot_num,shot,left()); |
guesta | 7:59be95fceafa | 92 | wait_ms(2); |
guesta | 7:59be95fceafa | 93 | } |
guesta | 6:fd9b59f828e8 | 94 | |
guesta | 6:fd9b59f828e8 | 95 | //農作物回収・設置 |
guesta | 6:fd9b59f828e8 | 96 | |
guesta | 6:fd9b59f828e8 | 97 | //全体送信 |
guesta | 7:59be95fceafa | 98 | scrp.send1(send_all,select,auto_mode);//自動・手動モード切り替え |
guesta | 3:e4b5563563af | 99 | wait_ms(1); |
guesta | 1:642ee25ea489 | 100 | } |
guesta | 0:d8faed605a5c | 101 | } |