yei
Dependencies: interface mbed enc_1multi calPID motorout KondoServoLibrary
Fork of cat18_operate by
main.cpp@19:48c3af917932, 2018-08-17 (annotated)
- Committer:
- shimizuta
- Date:
- Fri Aug 17 08:47:23 2018 +0000
- Revision:
- 19:48c3af917932
- Parent:
- 18:05f5a3323bda
- Child:
- 20:13934809e117
ok
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shimizuta | 0:c3a72fe24137 | 1 | #include <mbed.h> |
shimizuta | 0:c3a72fe24137 | 2 | #include "debug.h"//DEBUG("",変数);でデバッグ。 |
shimizuta | 1:cc056c41ae30 | 3 | #include "state.h" |
shimizuta | 1:cc056c41ae30 | 4 | #include "go.h" |
shimizuta | 3:05b1dcb3634e | 5 | #include "servo.h" |
shimizuta | 2:4515e8cc6b60 | 6 | #include "interrupt.h" |
shimizuta | 16:b2358fd35999 | 7 | #include "workposition.h" |
shimizuta | 3:05b1dcb3634e | 8 | #include "controller.h" |
shimizuta | 10:6d1d44fa9739 | 9 | //debug用に追加 |
shimizuta | 8:cabc50cf3e1e | 10 | #include "interface.h" |
shimizuta | 10:6d1d44fa9739 | 11 | #include "coordinate.h" |
shimizuta | 18:05f5a3323bda | 12 | |
shimizuta | 18:05f5a3323bda | 13 | const int kWait_ms = 500; |
shimizuta | 18:05f5a3323bda | 14 | |
shimizuta | 18:05f5a3323bda | 15 | //#define FORDEBUG |
shimizuta | 1:cc056c41ae30 | 16 | ///setup関連を集めた |
shimizuta | 0:c3a72fe24137 | 17 | void Setups(); |
shimizuta | 0:c3a72fe24137 | 18 | void Tests(); |
shimizuta | 8:cabc50cf3e1e | 19 | Interface interface(USBTX, USBRX); |
shimizuta | 0:c3a72fe24137 | 20 | int main() |
shimizuta | 0:c3a72fe24137 | 21 | { |
shimizuta | 0:c3a72fe24137 | 22 | DEBUG("setup start\r\n"); |
shimizuta | 0:c3a72fe24137 | 23 | Setups(); |
shimizuta | 13:126c3f7f9b89 | 24 | |
shimizuta | 4:187c62291654 | 25 | //スタート指示受付 |
shimizuta | 19:48c3af917932 | 26 | DEBUG("stand by"); |
shimizuta | 10:6d1d44fa9739 | 27 | while(CanStart() == 0) {}; |
shimizuta | 0:c3a72fe24137 | 28 | DEBUG("main start"); |
shimizuta | 10:6d1d44fa9739 | 29 | InterruptSetup(); |
shimizuta | 4:187c62291654 | 30 | int worknum = 0; |
shimizuta | 18:05f5a3323bda | 31 | |
shimizuta | 18:05f5a3323bda | 32 | #ifdef FORDEBUG |
shimizuta | 18:05f5a3323bda | 33 | for(int i = kCommonStart; i < kCommonStart + kCommonAreaNum - 2; i++) work[i].is_exist = 0; |
shimizuta | 18:05f5a3323bda | 34 | #endif |
shimizuta | 4:187c62291654 | 35 | while( (worknum = CalPickPlace()) != 23 ) { |
shimizuta | 18:05f5a3323bda | 36 | Close(); |
shimizuta | 4:187c62291654 | 37 | //ワークに向かう |
shimizuta | 16:b2358fd35999 | 38 | DEBUG("worknum %d, color %d, area %d, position %f, %f, %f\r\n", worknum, work[worknum].color, work[worknum].areaname, work[worknum].position[0],work[worknum].position[1],work[worknum].position[2]); |
shimizuta | 16:b2358fd35999 | 39 | DEBUG("go to work\r\n"); |
shimizuta | 2:4515e8cc6b60 | 40 | if(Go(work[worknum]) != 0) continue; |
shimizuta | 16:b2358fd35999 | 41 | DEBUG("close\r\n"); |
shimizuta | 4:187c62291654 | 42 | //掴む |
shimizuta | 2:4515e8cc6b60 | 43 | Close(); |
shimizuta | 16:b2358fd35999 | 44 | DEBUG("above\r\n"); |
shimizuta | 18:05f5a3323bda | 45 | wait_ms(kWait_ms); |
shimizuta | 4:187c62291654 | 46 | //上に持ち上げる |
shimizuta | 18:05f5a3323bda | 47 | Above(work[worknum].areaname); |
shimizuta | 18:05f5a3323bda | 48 | wait_ms(kWait_ms); |
shimizuta | 4:187c62291654 | 49 | //取り上げたことを保存 |
shimizuta | 2:4515e8cc6b60 | 50 | work[worknum].is_exist = 0; |
shimizuta | 4:187c62291654 | 51 | //シュート位置計算 |
shimizuta | 16:b2358fd35999 | 52 | DEBUG("cal put place\r\n"); |
shimizuta | 4:187c62291654 | 53 | int boxspace = CalPutPlace(work[worknum].color); |
shimizuta | 2:4515e8cc6b60 | 54 | //ボックスに行く(失敗(-1)したらcontinue) |
shimizuta | 16:b2358fd35999 | 55 | DEBUG("go to box %d\r\n",boxspace); |
shimizuta | 2:4515e8cc6b60 | 56 | if(Go(shootingbox[boxspace]) != 0) continue; |
shimizuta | 16:b2358fd35999 | 57 | DEBUG("open\r\n"); |
shimizuta | 4:187c62291654 | 58 | //放す |
shimizuta | 2:4515e8cc6b60 | 59 | Open(); |
shimizuta | 18:05f5a3323bda | 60 | wait_ms(kWait_ms); |
shimizuta | 16:b2358fd35999 | 61 | DEBUG("above\r\n"); |
shimizuta | 4:187c62291654 | 62 | //上に持ち上げる |
shimizuta | 18:05f5a3323bda | 63 | Above(BOX); |
shimizuta | 18:05f5a3323bda | 64 | wait_ms(kWait_ms); |
shimizuta | 16:b2358fd35999 | 65 | DEBUG("finish\r\n"); |
shimizuta | 4:187c62291654 | 66 | //置いたことを保存 |
shimizuta | 4:187c62291654 | 67 | shootingbox[boxspace].is_exist = 1; |
shimizuta | 2:4515e8cc6b60 | 68 | shootingbox[boxspace].color = work[worknum].color; |
shimizuta | 0:c3a72fe24137 | 69 | } |
shimizuta | 0:c3a72fe24137 | 70 | } |
shimizuta | 0:c3a72fe24137 | 71 | void Setups() |
shimizuta | 0:c3a72fe24137 | 72 | { |
shimizuta | 1:cc056c41ae30 | 73 | GoSetup(); |
shimizuta | 2:4515e8cc6b60 | 74 | SetupPosition(); |
shimizuta | 18:05f5a3323bda | 75 | StartCheck(); |
shimizuta | 0:c3a72fe24137 | 76 | } |
shimizuta | 0:c3a72fe24137 | 77 | void Tests() |
shimizuta | 0:c3a72fe24137 | 78 | { |
shimizuta | 0:c3a72fe24137 | 79 | static int count = 0; |
shimizuta | 0:c3a72fe24137 | 80 | count ++; |
shimizuta | 0:c3a72fe24137 | 81 | if (count > 100000) { |
shimizuta | 0:c3a72fe24137 | 82 | count =0; |
shimizuta | 0:c3a72fe24137 | 83 | } |
shimizuta | 16:b2358fd35999 | 84 | } |