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

Dependencies:   mbed AQM1602 HMC6352 PID

Committer:
lilac0112_1
Date:
Thu Mar 10 03:03:50 2016 +0000
Revision:
10:6df631c39f9b
Parent:
5:5ff3a7d5d8c2
Child:
16:4fadb7a87497
pid+alpha

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 0:ea35c18c85fc 4 //line
lilac0112_1 0:ea35c18c85fc 5 void ReadLine(void){
lilac0112_1 0:ea35c18c85fc 6 static uint8_t line_buf[3]={0,0,0};
lilac0112_1 0:ea35c18c85fc 7 wait_us(100);
lilac0112_1 0:ea35c18c85fc 8 if(Line[0].read()==1) line_buf[0] = 100;
lilac0112_1 2:635947de1583 9 if(line_buf[0]==0) data.lnFlag[0]=0;
lilac0112_1 2:635947de1583 10 else data.lnFlag[0]=1;
lilac0112_1 0:ea35c18c85fc 11 if(line_buf[0]>0) line_buf[0]--;
lilac0112_1 0:ea35c18c85fc 12
lilac0112_1 0:ea35c18c85fc 13 if(Line[1].read()==1) line_buf[1] = 100;
lilac0112_1 2:635947de1583 14 if(line_buf[1]==0) data.lnFlag[1]=0;
lilac0112_1 2:635947de1583 15 else data.lnFlag[1]=1;
lilac0112_1 0:ea35c18c85fc 16 if(line_buf[1]>0) line_buf[1]--;
lilac0112_1 0:ea35c18c85fc 17
lilac0112_1 0:ea35c18c85fc 18 if(Line[2].read()==1) line_buf[2] = 100;
lilac0112_1 2:635947de1583 19 if(line_buf[2]==0) data.lnFlag[2]=0;
lilac0112_1 2:635947de1583 20 else data.lnFlag[2]=1;
lilac0112_1 0:ea35c18c85fc 21 if(line_buf[2]>0) line_buf[2]--;
lilac0112_1 0:ea35c18c85fc 22 }
lilac0112_1 0:ea35c18c85fc 23 //ball
lilac0112_1 0:ea35c18c85fc 24 uint8_t ReadBall(void){//1or0
lilac0112_1 2:635947de1583 25 data.ball = !BallChecker;
lilac0112_1 2:635947de1583 26 return (data.ball>0);
lilac0112_1 0:ea35c18c85fc 27 }
lilac0112_1 0:ea35c18c85fc 28 void ReadGyro(void){
lilac0112_1 0:ea35c18c85fc 29 //Data can be got by interrupt.
lilac0112_1 0:ea35c18c85fc 30 }
lilac0112_1 0:ea35c18c85fc 31 void ReadCmps(void){
lilac0112_1 0:ea35c18c85fc 32 cmps_set.cmps = hmc.sample()/10.0;
lilac0112_1 0:ea35c18c85fc 33 }
lilac0112_1 10:6df631c39f9b 34 void ValidPing(void){
lilac0112_1 10:6df631c39f9b 35 if(sys.UswFlag==0){
lilac0112_1 10:6df631c39f9b 36 sys.UswFlag=1;
lilac0112_1 10:6df631c39f9b 37 }
lilac0112_1 10:6df631c39f9b 38 }
lilac0112_1 10:6df631c39f9b 39 void ValidPing2(void){
lilac0112_1 10:6df631c39f9b 40 if(sys.UswFlag2==0){
lilac0112_1 10:6df631c39f9b 41 sys.UswFlag2=1;
lilac0112_1 10:6df631c39f9b 42 }
lilac0112_1 10:6df631c39f9b 43 }
lilac0112_1 0:ea35c18c85fc 44 void ReadPing(void){
lilac0112_1 0:ea35c18c85fc 45 uint16_t spi_data;
lilac0112_1 0:ea35c18c85fc 46 //Ultra Sonic Wave
lilac0112_1 0:ea35c18c85fc 47 spi_ss[1]=0;
lilac0112_1 0:ea35c18c85fc 48 wait_us(200);
lilac0112_1 0:ea35c18c85fc 49
lilac0112_1 0:ea35c18c85fc 50 spi_data = spi.write(0xABCD);
lilac0112_1 0:ea35c18c85fc 51
lilac0112_1 0:ea35c18c85fc 52 wait_us(200);
lilac0112_1 0:ea35c18c85fc 53 spi_ss[1]=1;
lilac0112_1 0:ea35c18c85fc 54
lilac0112_1 2:635947de1583 55 data.ping[0] = (spi_data&0x00FF)>>0;
lilac0112_1 2:635947de1583 56 data.ping[1] = (spi_data&0xFF00)>>8;
lilac0112_1 0:ea35c18c85fc 57 }
lilac0112_1 10:6df631c39f9b 58 void ReadPing2(void){
lilac0112_1 0:ea35c18c85fc 59 uint16_t spi_data;
lilac0112_1 0:ea35c18c85fc 60 //Ultra Sonic Wave
lilac0112_1 0:ea35c18c85fc 61 spi_ss[0]=0;
lilac0112_1 0:ea35c18c85fc 62 wait_us(200);
lilac0112_1 0:ea35c18c85fc 63
lilac0112_1 0:ea35c18c85fc 64 spi_data = spi.write(0xABCD);
lilac0112_1 0:ea35c18c85fc 65
lilac0112_1 0:ea35c18c85fc 66 wait_us(200);
lilac0112_1 0:ea35c18c85fc 67 spi_ss[0]=1;
lilac0112_1 0:ea35c18c85fc 68
lilac0112_1 2:635947de1583 69 data.ping[2] = (spi_data&0x00FF)>>0;
lilac0112_1 2:635947de1583 70 data.ping[3] = (spi_data&0xFF00)>>8;
lilac0112_1 0:ea35c18c85fc 71 }
lilac0112_1 0:ea35c18c85fc 72 void ValidIr(void){
lilac0112_1 0:ea35c18c85fc 73 if(sys.IrFlag==0){
lilac0112_1 0:ea35c18c85fc 74 sys.IrFlag=1;
lilac0112_1 0:ea35c18c85fc 75 }
lilac0112_1 0:ea35c18c85fc 76 }
lilac0112_1 0:ea35c18c85fc 77 void ReadIr(void){
lilac0112_1 0:ea35c18c85fc 78 uint16_t spi_data;
lilac0112_1 0:ea35c18c85fc 79
lilac0112_1 0:ea35c18c85fc 80 //Ir
lilac0112_1 0:ea35c18c85fc 81 spi_ss[3]=0;
lilac0112_1 0:ea35c18c85fc 82 wait_us(200);
lilac0112_1 0:ea35c18c85fc 83
lilac0112_1 0:ea35c18c85fc 84 spi_data = spi.write(0xABCD);
lilac0112_1 0:ea35c18c85fc 85
lilac0112_1 0:ea35c18c85fc 86 wait_us(200);
lilac0112_1 0:ea35c18c85fc 87 spi_ss[3]=1;
lilac0112_1 2:635947de1583 88 /*
lilac0112_1 1:3e013ae7900d 89 //key/phaseL/phaseS/long/short/
lilac0112_1 1:3e013ae7900d 90 // 2/ 3/ 3/ 4/ 4/
lilac0112_1 2:635947de1583 91 data.irKey = (spi_data&0xC000)>>14;//1100000000000000
lilac0112_1 2:635947de1583 92 data.irValPhase[IR_LONG] = (spi_data&0x3800)>>11;//0011100000000000
lilac0112_1 2:635947de1583 93 data.irValPhase[IR_SHORT] = (spi_data&0x0700)>>8;///0000011100000000
lilac0112_1 2:635947de1583 94 data.irSpot[IR_LONG] = (spi_data&0x00F0)>>4;///0000000011110000
lilac0112_1 2:635947de1583 95 data.irSpot[IR_SHORT] = (spi_data&0x000F)>>0;///0000000000001111
lilac0112_1 2:635947de1583 96 */
lilac0112_1 0:ea35c18c85fc 97
lilac0112_1 2:635947de1583 98 //key/phaseL/phaseS/diffL/position/
lilac0112_1 2:635947de1583 99 // 2/ 3/ 3/ 3/ 5/
lilac0112_1 2:635947de1583 100 data.irKey = (spi_data&0xC000)>>14;//1100000000000000
lilac0112_1 2:635947de1583 101 data.irValPhase[IR_LONG] = (spi_data&0x3800)>>11;//0011100000000000
lilac0112_1 2:635947de1583 102 data.irValPhase[IR_SHORT] = (spi_data&0x0700)>>8;///0000011100000000
lilac0112_1 2:635947de1583 103 data.irDif[IR_LONG] = (spi_data&0x00E0)>>5;///0000000011100000
lilac0112_1 2:635947de1583 104 data.irPosition = (spi_data&0x001F)>>0;///0000000000011111
lilac0112_1 1:3e013ae7900d 105
lilac0112_1 2:635947de1583 106 if(data.irKey!=0x2) data.irNotice=IR_NONE;
lilac0112_1 2:635947de1583 107
lilac0112_1 2:635947de1583 108
lilac0112_1 2:635947de1583 109 if(data.irValPhase[IR_SHORT]>=DIS_7){
lilac0112_1 10:6df631c39f9b 110 if(data.irValPhase[IR_LONG]>=DIS_5){
lilac0112_1 2:635947de1583 111 data.irNotice=IR_NONE;
lilac0112_1 1:3e013ae7900d 112 }
lilac0112_1 1:3e013ae7900d 113 else{
lilac0112_1 2:635947de1583 114 if(data.irDif[IR_LONG]<=DIS_6){
lilac0112_1 2:635947de1583 115 data.irNotice=IR_NONE;
lilac0112_1 1:3e013ae7900d 116 }
lilac0112_1 1:3e013ae7900d 117 else{
lilac0112_1 2:635947de1583 118 data.irNotice=IR_FAR;
lilac0112_1 1:3e013ae7900d 119 }
lilac0112_1 1:3e013ae7900d 120 }
lilac0112_1 1:3e013ae7900d 121 }
lilac0112_1 2:635947de1583 122 else{
lilac0112_1 2:635947de1583 123 if(data.irValPhase[IR_SHORT]>=DIS_3){
lilac0112_1 2:635947de1583 124 data.irNotice = IR_CLOSE;
lilac0112_1 2:635947de1583 125 }
lilac0112_1 2:635947de1583 126 else{
lilac0112_1 2:635947de1583 127 data.irNotice = IR_CLOSER;
lilac0112_1 2:635947de1583 128 }
lilac0112_1 2:635947de1583 129 }
lilac0112_1 1:3e013ae7900d 130
lilac0112_1 2:635947de1583 131 /*if(data.irValPhase[IR_LONG]>=DIS_7){
lilac0112_1 2:635947de1583 132 data.irNotice=IR_NONE;
lilac0112_1 2:635947de1583 133 }
lilac0112_1 2:635947de1583 134 else{
lilac0112_1 2:635947de1583 135 if(data.irValPhase[IR_SHORT]>=DIS_7){
lilac0112_1 2:635947de1583 136 data.irNotice=IR_FAR;
lilac0112_1 2:635947de1583 137 }
lilac0112_1 2:635947de1583 138 else{
lilac0112_1 2:635947de1583 139 if(data.irValPhase[IR_LONG]>=DIS_4){
lilac0112_1 2:635947de1583 140 data.irNotice = IR_CLOSE;
lilac0112_1 2:635947de1583 141 }
lilac0112_1 2:635947de1583 142 else{
lilac0112_1 2:635947de1583 143 data.irNotice = IR_CLOSER;
lilac0112_1 2:635947de1583 144 }
lilac0112_1 2:635947de1583 145 }
lilac0112_1 2:635947de1583 146 }*/
lilac0112_1 2:635947de1583 147 /*
lilac0112_1 2:635947de1583 148 if(data.irNotice == IR_NONE) data.irPosition=11;
lilac0112_1 2:635947de1583 149 if(data.irNotice == IR_FAR) data.irPosition=data.irSpot[IR_LONG]-1;
lilac0112_1 2:635947de1583 150 if(data.irNotice == IR_CLOSE) data.irPosition=data.irSpot[IR_SHORT]+7;
lilac0112_1 2:635947de1583 151 if(data.irNotice == IR_CLOSER) data.irPosition=data.irSpot[IR_SHORT]+7;
lilac0112_1 2:635947de1583 152 */
lilac0112_1 5:5ff3a7d5d8c2 153 //LED[1] = LED[0];
lilac0112_1 5:5ff3a7d5d8c2 154 //LED[0] = !LED[0];
lilac0112_1 0:ea35c18c85fc 155 }
lilac0112_1 0:ea35c18c85fc 156 void ReadInfo(void){
lilac0112_1 0:ea35c18c85fc 157
lilac0112_1 0:ea35c18c85fc 158 }