ジャパンオープン用のメインプログラム
Dependencies: mbed AQM1602 HMC6352 PID
active.cpp
00001 #include "mbed.h" 00002 #include "extern.h" 00003 00004 void Active(void){ 00005 uint8_t i; 00006 void (*DutyFunction[DUTY_NUM])(void) = { 00007 Active2Command 00008 }; 00009 for(i=0; i<DUTY_NUM; i++){ 00010 Duty[i].attach(DutyFunction[i], dutycycle[i]); 00011 } 00012 sys.stopflag=0; 00013 //スタート直前の処理 00014 SetUp2(); 00015 while(1){ 00016 //pc.printf("sys.stopflag=%d\r\n", sys.stopflag); 00017 //StrategyFunction[sys.strategy](); 00018 act[sys.strategy].ActiveFunction(); 00019 if(sys.stopflag==1){ 00020 //システム上の停止処理 00021 button.detach(); 00022 last_statesum = statesum = 0; 00023 state[0] = state[1] = state[2] = state[3] = 0; 00024 00025 for(i=0; i<DUTY_NUM; i++){ 00026 Duty[DUTY_SW].detach(); 00027 } 00028 sys.stopflag=0; 00029 //その他停止処理 00030 StopProcess(); 00031 break; 00032 } 00033 } 00034 return; 00035 } 00036 void Active_old(void){ 00037 uint8_t i; 00038 void (*DutyFunction[DUTY_NUM])(void) = { 00039 Active2Command 00040 }; 00041 void (*StrategyFunction[STRATEGY_NUM])(void) = { 00042 //modeAttack5, 00043 modeAttack2, 00044 //modeAttack4, 00045 modeAttack1, 00046 modeAttack2, 00047 modeAttack3, 00048 modeAttack4, 00049 modeAttack5, 00050 00051 modeDebug0, 00052 modeDebug1, 00053 modeDebug2, 00054 modeDebug3, 00055 modeDebug4, 00056 modeDebug5, 00057 }; 00058 for(i=0; i<DUTY_NUM; i++){ 00059 Duty[i].attach(DutyFunction[i], dutycycle[i]); 00060 } 00061 sys.stopflag=0; 00062 //スタート直前の処理 00063 SetUp2(); 00064 while(1){ 00065 //pc.printf("sys.stopflag=%d\r\n", sys.stopflag); 00066 StrategyFunction[sys.strategy](); 00067 if(sys.stopflag==1){ 00068 //システム上の停止処理 00069 button.detach(); 00070 last_statesum = statesum = 0; 00071 state[0] = state[1] = state[2] = state[3] = 0; 00072 00073 for(i=0; i<DUTY_NUM; i++){ 00074 Duty[DUTY_SW].detach(); 00075 } 00076 sys.stopflag=0; 00077 //その他停止処理 00078 StopProcess(); 00079 break; 00080 } 00081 } 00082 return; 00083 } 00084 //for transition 00085 void ResetState(void){ 00086 last_statesum = statesum = 0; 00087 state[0] = state[1] = state[2] = state[3] = 0; 00088 } 00089 void Active2Command(void){ 00090 uint8_t i; 00091 for(i=0; i<4; i++){ 00092 if(CountSw(i)==1) state[i]=1; 00093 } 00094 last_statesum = statesum; 00095 statesum = state[0]+state[1]+state[2]+state[3]; 00096 if((statesum>=1)&&(!(statesum==last_statesum))){ 00097 button.attach(&ResetState, 1.0); 00098 } 00099 if((statesum>=2)&&(1)){ 00100 if((state[0]==1)&&(state[1]==1)&&(state[2]==0)&&(state[3]==0)){ 00101 sys.stopflag=1; 00102 } 00103 else{ 00104 button.detach(); 00105 ResetState(); 00106 } 00107 } 00108 }
Generated on Wed Jul 13 2022 02:59:03 by 1.7.2