ジャパンオープン用のメインプログラム

Dependencies:   mbed AQM1602 HMC6352 PID

Committer:
lilac0112_1
Date:
Sun Mar 27 13:04:39 2016 +0000
Revision:
38:67bc78f3c0ab
Parent:
25:a7460e23e02e
JapanSoccerOpen2016 CatPot Program(main)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lilac0112_1 0:ea35c18c85fc 1 #include "mbed.h"
lilac0112_1 0:ea35c18c85fc 2 #include "extern.h"
lilac0112_1 0:ea35c18c85fc 3
lilac0112_1 5:5ff3a7d5d8c2 4 void Active(void){
lilac0112_1 0:ea35c18c85fc 5 uint8_t i;
lilac0112_1 0:ea35c18c85fc 6 void (*DutyFunction[DUTY_NUM])(void) = {
lilac0112_1 0:ea35c18c85fc 7 Active2Command
lilac0112_1 0:ea35c18c85fc 8 };
lilac0112_1 8:25c8c75d182a 9 for(i=0; i<DUTY_NUM; i++){
lilac0112_1 8:25c8c75d182a 10 Duty[i].attach(DutyFunction[i], dutycycle[i]);
lilac0112_1 8:25c8c75d182a 11 }
lilac0112_1 8:25c8c75d182a 12 sys.stopflag=0;
lilac0112_1 8:25c8c75d182a 13 //スタート直前の処理
lilac0112_1 8:25c8c75d182a 14 SetUp2();
lilac0112_1 8:25c8c75d182a 15 while(1){
lilac0112_1 8:25c8c75d182a 16 //pc.printf("sys.stopflag=%d\r\n", sys.stopflag);
lilac0112_1 8:25c8c75d182a 17 //StrategyFunction[sys.strategy]();
lilac0112_1 8:25c8c75d182a 18 act[sys.strategy].ActiveFunction();
lilac0112_1 8:25c8c75d182a 19 if(sys.stopflag==1){
lilac0112_1 8:25c8c75d182a 20 //システム上の停止処理
lilac0112_1 8:25c8c75d182a 21 button.detach();
lilac0112_1 8:25c8c75d182a 22 last_statesum = statesum = 0;
lilac0112_1 8:25c8c75d182a 23 state[0] = state[1] = state[2] = state[3] = 0;
lilac0112_1 8:25c8c75d182a 24
lilac0112_1 8:25c8c75d182a 25 for(i=0; i<DUTY_NUM; i++){
lilac0112_1 8:25c8c75d182a 26 Duty[DUTY_SW].detach();
lilac0112_1 8:25c8c75d182a 27 }
lilac0112_1 8:25c8c75d182a 28 sys.stopflag=0;
lilac0112_1 8:25c8c75d182a 29 //その他停止処理
lilac0112_1 8:25c8c75d182a 30 StopProcess();
lilac0112_1 8:25c8c75d182a 31 break;
lilac0112_1 8:25c8c75d182a 32 }
lilac0112_1 8:25c8c75d182a 33 }
lilac0112_1 8:25c8c75d182a 34 return;
lilac0112_1 8:25c8c75d182a 35 }
lilac0112_1 8:25c8c75d182a 36 void Active_old(void){
lilac0112_1 8:25c8c75d182a 37 uint8_t i;
lilac0112_1 8:25c8c75d182a 38 void (*DutyFunction[DUTY_NUM])(void) = {
lilac0112_1 8:25c8c75d182a 39 Active2Command
lilac0112_1 8:25c8c75d182a 40 };
lilac0112_1 0:ea35c18c85fc 41 void (*StrategyFunction[STRATEGY_NUM])(void) = {
lilac0112_1 5:5ff3a7d5d8c2 42 //modeAttack5,
lilac0112_1 0:ea35c18c85fc 43 modeAttack2,
lilac0112_1 0:ea35c18c85fc 44 //modeAttack4,
lilac0112_1 0:ea35c18c85fc 45 modeAttack1,
lilac0112_1 0:ea35c18c85fc 46 modeAttack2,
lilac0112_1 0:ea35c18c85fc 47 modeAttack3,
lilac0112_1 0:ea35c18c85fc 48 modeAttack4,
lilac0112_1 0:ea35c18c85fc 49 modeAttack5,
lilac0112_1 0:ea35c18c85fc 50
lilac0112_1 0:ea35c18c85fc 51 modeDebug0,
lilac0112_1 0:ea35c18c85fc 52 modeDebug1,
lilac0112_1 0:ea35c18c85fc 53 modeDebug2,
lilac0112_1 0:ea35c18c85fc 54 modeDebug3,
lilac0112_1 0:ea35c18c85fc 55 modeDebug4,
lilac0112_1 0:ea35c18c85fc 56 modeDebug5,
lilac0112_1 0:ea35c18c85fc 57 };
lilac0112_1 0:ea35c18c85fc 58 for(i=0; i<DUTY_NUM; i++){
lilac0112_1 0:ea35c18c85fc 59 Duty[i].attach(DutyFunction[i], dutycycle[i]);
lilac0112_1 0:ea35c18c85fc 60 }
lilac0112_1 0:ea35c18c85fc 61 sys.stopflag=0;
lilac0112_1 0:ea35c18c85fc 62 //スタート直前の処理
lilac0112_1 0:ea35c18c85fc 63 SetUp2();
lilac0112_1 0:ea35c18c85fc 64 while(1){
lilac0112_1 0:ea35c18c85fc 65 //pc.printf("sys.stopflag=%d\r\n", sys.stopflag);
lilac0112_1 0:ea35c18c85fc 66 StrategyFunction[sys.strategy]();
lilac0112_1 0:ea35c18c85fc 67 if(sys.stopflag==1){
lilac0112_1 0:ea35c18c85fc 68 //システム上の停止処理
lilac0112_1 0:ea35c18c85fc 69 button.detach();
lilac0112_1 0:ea35c18c85fc 70 last_statesum = statesum = 0;
lilac0112_1 0:ea35c18c85fc 71 state[0] = state[1] = state[2] = state[3] = 0;
lilac0112_1 0:ea35c18c85fc 72
lilac0112_1 0:ea35c18c85fc 73 for(i=0; i<DUTY_NUM; i++){
lilac0112_1 0:ea35c18c85fc 74 Duty[DUTY_SW].detach();
lilac0112_1 0:ea35c18c85fc 75 }
lilac0112_1 0:ea35c18c85fc 76 sys.stopflag=0;
lilac0112_1 0:ea35c18c85fc 77 //その他停止処理
lilac0112_1 0:ea35c18c85fc 78 StopProcess();
lilac0112_1 0:ea35c18c85fc 79 break;
lilac0112_1 0:ea35c18c85fc 80 }
lilac0112_1 0:ea35c18c85fc 81 }
lilac0112_1 0:ea35c18c85fc 82 return;
lilac0112_1 0:ea35c18c85fc 83 }
lilac0112_1 0:ea35c18c85fc 84 //for transition
lilac0112_1 0:ea35c18c85fc 85 void ResetState(void){
lilac0112_1 0:ea35c18c85fc 86 last_statesum = statesum = 0;
lilac0112_1 0:ea35c18c85fc 87 state[0] = state[1] = state[2] = state[3] = 0;
lilac0112_1 0:ea35c18c85fc 88 }
lilac0112_1 0:ea35c18c85fc 89 void Active2Command(void){
lilac0112_1 0:ea35c18c85fc 90 uint8_t i;
lilac0112_1 0:ea35c18c85fc 91 for(i=0; i<4; i++){
lilac0112_1 0:ea35c18c85fc 92 if(CountSw(i)==1) state[i]=1;
lilac0112_1 0:ea35c18c85fc 93 }
lilac0112_1 0:ea35c18c85fc 94 last_statesum = statesum;
lilac0112_1 0:ea35c18c85fc 95 statesum = state[0]+state[1]+state[2]+state[3];
lilac0112_1 0:ea35c18c85fc 96 if((statesum>=1)&&(!(statesum==last_statesum))){
lilac0112_1 25:a7460e23e02e 97 button.attach(&ResetState, 1.0);
lilac0112_1 0:ea35c18c85fc 98 }
lilac0112_1 0:ea35c18c85fc 99 if((statesum>=2)&&(1)){
lilac0112_1 25:a7460e23e02e 100 if((state[0]==1)&&(state[1]==1)&&(state[2]==0)&&(state[3]==0)){
lilac0112_1 25:a7460e23e02e 101 sys.stopflag=1;
lilac0112_1 25:a7460e23e02e 102 }
lilac0112_1 25:a7460e23e02e 103 else{
lilac0112_1 25:a7460e23e02e 104 button.detach();
lilac0112_1 25:a7460e23e02e 105 ResetState();
lilac0112_1 25:a7460e23e02e 106 }
lilac0112_1 0:ea35c18c85fc 107 }
lilac0112_1 0:ea35c18c85fc 108 }