yei
Dependencies: interface mbed enc_1multi calPID motorout KondoServoLibrary
Fork of cat18_operate by
main.cpp@16:b2358fd35999, 2018-08-14 (annotated)
- Committer:
- shimizuta
- Date:
- Tue Aug 14 09:16:55 2018 +0000
- Revision:
- 16:b2358fd35999
- Parent:
- 13:126c3f7f9b89
- Child:
- 18:05f5a3323bda
a
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 | 1:cc056c41ae30 | 12 | ///setup関連を集めた |
shimizuta | 0:c3a72fe24137 | 13 | void Setups(); |
shimizuta | 0:c3a72fe24137 | 14 | void Tests(); |
shimizuta | 8:cabc50cf3e1e | 15 | Interface interface(USBTX, USBRX); |
shimizuta | 0:c3a72fe24137 | 16 | int main() |
shimizuta | 0:c3a72fe24137 | 17 | { |
shimizuta | 0:c3a72fe24137 | 18 | DEBUG("setup start\r\n"); |
shimizuta | 0:c3a72fe24137 | 19 | Setups(); |
shimizuta | 13:126c3f7f9b89 | 20 | |
shimizuta | 4:187c62291654 | 21 | //スタート指示受付 |
shimizuta | 10:6d1d44fa9739 | 22 | while(CanStart() == 0) {}; |
shimizuta | 0:c3a72fe24137 | 23 | DEBUG("main start"); |
shimizuta | 10:6d1d44fa9739 | 24 | InterruptSetup(); |
shimizuta | 4:187c62291654 | 25 | int worknum = 0; |
shimizuta | 4:187c62291654 | 26 | while( (worknum = CalPickPlace()) != 23 ) { |
shimizuta | 4:187c62291654 | 27 | //ワークに向かう |
shimizuta | 16:b2358fd35999 | 28 | 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 | 29 | DEBUG("go to work\r\n"); |
shimizuta | 2:4515e8cc6b60 | 30 | if(Go(work[worknum]) != 0) continue; |
shimizuta | 16:b2358fd35999 | 31 | DEBUG("close\r\n"); |
shimizuta | 4:187c62291654 | 32 | //掴む |
shimizuta | 2:4515e8cc6b60 | 33 | Close(); |
shimizuta | 16:b2358fd35999 | 34 | DEBUG("above\r\n"); |
shimizuta | 16:b2358fd35999 | 35 | wait(1); |
shimizuta | 4:187c62291654 | 36 | //上に持ち上げる |
shimizuta | 2:4515e8cc6b60 | 37 | Above(); |
shimizuta | 4:187c62291654 | 38 | //取り上げたことを保存 |
shimizuta | 2:4515e8cc6b60 | 39 | work[worknum].is_exist = 0; |
shimizuta | 4:187c62291654 | 40 | //シュート位置計算 |
shimizuta | 16:b2358fd35999 | 41 | DEBUG("cal put place\r\n"); |
shimizuta | 4:187c62291654 | 42 | int boxspace = CalPutPlace(work[worknum].color); |
shimizuta | 2:4515e8cc6b60 | 43 | //ボックスに行く(失敗(-1)したらcontinue) |
shimizuta | 16:b2358fd35999 | 44 | DEBUG("go to box %d\r\n",boxspace); |
shimizuta | 2:4515e8cc6b60 | 45 | if(Go(shootingbox[boxspace]) != 0) continue; |
shimizuta | 16:b2358fd35999 | 46 | DEBUG("open\r\n"); |
shimizuta | 4:187c62291654 | 47 | //放す |
shimizuta | 2:4515e8cc6b60 | 48 | Open(); |
shimizuta | 16:b2358fd35999 | 49 | wait(0.5); |
shimizuta | 16:b2358fd35999 | 50 | DEBUG("above\r\n"); |
shimizuta | 4:187c62291654 | 51 | //上に持ち上げる |
shimizuta | 2:4515e8cc6b60 | 52 | Above(); |
shimizuta | 16:b2358fd35999 | 53 | wait(0.1); |
shimizuta | 16:b2358fd35999 | 54 | DEBUG("finish\r\n"); |
shimizuta | 4:187c62291654 | 55 | //置いたことを保存 |
shimizuta | 4:187c62291654 | 56 | shootingbox[boxspace].is_exist = 1; |
shimizuta | 2:4515e8cc6b60 | 57 | shootingbox[boxspace].color = work[worknum].color; |
shimizuta | 0:c3a72fe24137 | 58 | } |
shimizuta | 0:c3a72fe24137 | 59 | } |
shimizuta | 0:c3a72fe24137 | 60 | void Setups() |
shimizuta | 0:c3a72fe24137 | 61 | { |
shimizuta | 1:cc056c41ae30 | 62 | GoSetup(); |
shimizuta | 2:4515e8cc6b60 | 63 | SetupPosition(); |
shimizuta | 16:b2358fd35999 | 64 | StartCheck(); |
shimizuta | 0:c3a72fe24137 | 65 | } |
shimizuta | 0:c3a72fe24137 | 66 | void Tests() |
shimizuta | 0:c3a72fe24137 | 67 | { |
shimizuta | 0:c3a72fe24137 | 68 | static int count = 0; |
shimizuta | 0:c3a72fe24137 | 69 | count ++; |
shimizuta | 0:c3a72fe24137 | 70 | if (count > 100000) { |
shimizuta | 16:b2358fd35999 | 71 | |
shimizuta | 0:c3a72fe24137 | 72 | count =0; |
shimizuta | 0:c3a72fe24137 | 73 | } |
shimizuta | 16:b2358fd35999 | 74 | } |