操舵ソースコードの第一稿です。 メイン基盤用のソースコードです。

Dependencies:   ADXL345_I2C INA226 mbed SDFileSystem

Committer:
YusukeWakuta
Date:
Fri Jan 15 15:32:09 2016 +0000
Revision:
0:77917230ce6d
Child:
1:247ccea89495
???????????????; ?????????????;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
YusukeWakuta 0:77917230ce6d 1 #include "mbed.h"
YusukeWakuta 0:77917230ce6d 2
YusukeWakuta 0:77917230ce6d 3 #define BUFFER 10
YusukeWakuta 0:77917230ce6d 4
YusukeWakuta 0:77917230ce6d 5 Serial rs485R(p13,p14);
YusukeWakuta 0:77917230ce6d 6 Serial rs485L(p28,p27);
YusukeWakuta 0:77917230ce6d 7 Serial pc(USBTX,USBRX);
YusukeWakuta 0:77917230ce6d 8 DigitalOut Driver_R(p5);
YusukeWakuta 0:77917230ce6d 9 DigitalOut Driver_L(p6);
YusukeWakuta 0:77917230ce6d 10 DigitalIn Switch(p20);
YusukeWakuta 0:77917230ce6d 11 Ticker CheckData;
YusukeWakuta 0:77917230ce6d 12 AnalogIn val1(p16);
YusukeWakuta 0:77917230ce6d 13 AnalogIn val2(p17);
YusukeWakuta 0:77917230ce6d 14
YusukeWakuta 0:77917230ce6d 15 void ch_data()
YusukeWakuta 0:77917230ce6d 16 {
YusukeWakuta 0:77917230ce6d 17 signed char rec_data_R[BUFFER];
YusukeWakuta 0:77917230ce6d 18 signed char rec_data_L[BUFFER];
YusukeWakuta 0:77917230ce6d 19 //signed char rec_data_R;
YusukeWakuta 0:77917230ce6d 20 rs485R.putc('P');
YusukeWakuta 0:77917230ce6d 21 rs485L.putc('P');
YusukeWakuta 0:77917230ce6d 22 wait_ms(1);
YusukeWakuta 0:77917230ce6d 23 Driver_R = 0;
YusukeWakuta 0:77917230ce6d 24 Driver_L = 0;
YusukeWakuta 0:77917230ce6d 25 wait_ms(120);
YusukeWakuta 0:77917230ce6d 26 if(rs485R.readable()) {
YusukeWakuta 0:77917230ce6d 27 for(int i = 0; i < BUFFER; i++) {
YusukeWakuta 0:77917230ce6d 28 rec_data_R[i] = rs485R.getc();
YusukeWakuta 0:77917230ce6d 29 }
YusukeWakuta 0:77917230ce6d 30 for(int i = 0; i < BUFFER; i++) {
YusukeWakuta 0:77917230ce6d 31 if(rec_data_R[i + 1] != -1) {
YusukeWakuta 0:77917230ce6d 32 pc.printf("RIGHT : ");
YusukeWakuta 0:77917230ce6d 33 switch(rec_data_R[i]) {
YusukeWakuta 0:77917230ce6d 34 case 'X':
YusukeWakuta 0:77917230ce6d 35 pc.printf(" X : %5i",rec_data_R[i + 1]);
YusukeWakuta 0:77917230ce6d 36 break;
YusukeWakuta 0:77917230ce6d 37 case 'Y':
YusukeWakuta 0:77917230ce6d 38 pc.printf(" Y : %5i",rec_data_R[i + 1]);
YusukeWakuta 0:77917230ce6d 39 break;
YusukeWakuta 0:77917230ce6d 40 case 'Z':
YusukeWakuta 0:77917230ce6d 41 pc.printf(" Z : %5i",rec_data_R[i + 1]);
YusukeWakuta 0:77917230ce6d 42 break;
YusukeWakuta 0:77917230ce6d 43 case 'V':
YusukeWakuta 0:77917230ce6d 44 pc.printf(" V : %5i",rec_data_R[i + 1]);
YusukeWakuta 0:77917230ce6d 45 break;
YusukeWakuta 0:77917230ce6d 46 case 'C':
YusukeWakuta 0:77917230ce6d 47 pc.printf(" C : %5i",rec_data_R[i + 1]);
YusukeWakuta 0:77917230ce6d 48 break;
YusukeWakuta 0:77917230ce6d 49 }
YusukeWakuta 0:77917230ce6d 50 }
YusukeWakuta 0:77917230ce6d 51 }
YusukeWakuta 0:77917230ce6d 52 }
YusukeWakuta 0:77917230ce6d 53 pc.printf("\t");
YusukeWakuta 0:77917230ce6d 54
YusukeWakuta 0:77917230ce6d 55 if(rs485L.readable()) {
YusukeWakuta 0:77917230ce6d 56 for(int i = 0; i < BUFFER; i++) {
YusukeWakuta 0:77917230ce6d 57 rec_data_L[i] = rs485L.getc();
YusukeWakuta 0:77917230ce6d 58 }
YusukeWakuta 0:77917230ce6d 59 for(int i = 0; i < BUFFER; i++) {
YusukeWakuta 0:77917230ce6d 60 if(rec_data_L[i + 1] != -1) {
YusukeWakuta 0:77917230ce6d 61 pc.printf("LEFT : ");
YusukeWakuta 0:77917230ce6d 62 switch(rec_data_L[i]) {
YusukeWakuta 0:77917230ce6d 63 case 'X':
YusukeWakuta 0:77917230ce6d 64 pc.printf(" X : %5i",rec_data_L[i + 1]);
YusukeWakuta 0:77917230ce6d 65 break;
YusukeWakuta 0:77917230ce6d 66 case 'Y':
YusukeWakuta 0:77917230ce6d 67 pc.printf(" Y : %5i",rec_data_L[i + 1]);
YusukeWakuta 0:77917230ce6d 68 break;
YusukeWakuta 0:77917230ce6d 69 case 'Z':
YusukeWakuta 0:77917230ce6d 70 pc.printf(" Z : %5i",rec_data_L[i + 1]);
YusukeWakuta 0:77917230ce6d 71 break;
YusukeWakuta 0:77917230ce6d 72 case 'V':
YusukeWakuta 0:77917230ce6d 73 pc.printf(" V : %5i",rec_data_L[i + 1]);
YusukeWakuta 0:77917230ce6d 74 break;
YusukeWakuta 0:77917230ce6d 75 case 'C':
YusukeWakuta 0:77917230ce6d 76 pc.printf(" C : %5i",rec_data_L[i + 1]);
YusukeWakuta 0:77917230ce6d 77 break;
YusukeWakuta 0:77917230ce6d 78 }
YusukeWakuta 0:77917230ce6d 79 }
YusukeWakuta 0:77917230ce6d 80 }
YusukeWakuta 0:77917230ce6d 81 pc.printf("\n\r");
YusukeWakuta 0:77917230ce6d 82 Driver_R = 1;
YusukeWakuta 0:77917230ce6d 83 Driver_L = 1;
YusukeWakuta 0:77917230ce6d 84 wait_ms(1);
YusukeWakuta 0:77917230ce6d 85 }
YusukeWakuta 0:77917230ce6d 86 }
YusukeWakuta 0:77917230ce6d 87
YusukeWakuta 0:77917230ce6d 88 void counter_checker(int *counter_A,int *counter_B,int *counter_C,int *counter_D) {
YusukeWakuta 0:77917230ce6d 89
YusukeWakuta 0:77917230ce6d 90 (*counter_A)++;
YusukeWakuta 0:77917230ce6d 91 if(*counter_A > 180)
YusukeWakuta 0:77917230ce6d 92 *counter_A = 0;
YusukeWakuta 0:77917230ce6d 93
YusukeWakuta 0:77917230ce6d 94 *counter_B = *counter_B + 2;
YusukeWakuta 0:77917230ce6d 95 if(*counter_B > 180)
YusukeWakuta 0:77917230ce6d 96 *counter_B = 0;
YusukeWakuta 0:77917230ce6d 97
YusukeWakuta 0:77917230ce6d 98 *counter_C = *counter_C + 3;
YusukeWakuta 0:77917230ce6d 99 if(*counter_C > 180)
YusukeWakuta 0:77917230ce6d 100 *counter_C = 0;
YusukeWakuta 0:77917230ce6d 101
YusukeWakuta 0:77917230ce6d 102 *counter_D = *counter_D + 4;
YusukeWakuta 0:77917230ce6d 103 if(*counter_D > 180)
YusukeWakuta 0:77917230ce6d 104 *counter_D = 0;
YusukeWakuta 0:77917230ce6d 105 }
YusukeWakuta 0:77917230ce6d 106
YusukeWakuta 0:77917230ce6d 107 int main() {
YusukeWakuta 0:77917230ce6d 108 /*右エルロン:A
YusukeWakuta 0:77917230ce6d 109 右翼端板 :B
YusukeWakuta 0:77917230ce6d 110 左エルロン:C
YusukeWakuta 0:77917230ce6d 111 左翼端板 :D
YusukeWakuta 0:77917230ce6d 112 */
YusukeWakuta 0:77917230ce6d 113 rs485R.baud(38400);
YusukeWakuta 0:77917230ce6d 114 Driver_R = 1;
YusukeWakuta 0:77917230ce6d 115 Driver_L = 1;
YusukeWakuta 0:77917230ce6d 116 int counter_A = 0;
YusukeWakuta 0:77917230ce6d 117 int counter_B = 0;
YusukeWakuta 0:77917230ce6d 118 int counter_C = 0;
YusukeWakuta 0:77917230ce6d 119 int counter_D = 0;
YusukeWakuta 0:77917230ce6d 120 pc.printf("Driver\n\r");
YusukeWakuta 0:77917230ce6d 121 CheckData.attach(&ch_data,0.25);
YusukeWakuta 0:77917230ce6d 122 while(1) {
YusukeWakuta 0:77917230ce6d 123 rs485R.putc('A');
YusukeWakuta 0:77917230ce6d 124 rs485R.putc(counter_A);
YusukeWakuta 0:77917230ce6d 125 rs485R.putc('B');
YusukeWakuta 0:77917230ce6d 126 rs485R.putc(counter_B);
YusukeWakuta 0:77917230ce6d 127 rs485L.putc('C');
YusukeWakuta 0:77917230ce6d 128 rs485L.putc(counter_C);
YusukeWakuta 0:77917230ce6d 129 rs485L.putc('D');
YusukeWakuta 0:77917230ce6d 130 rs485L.putc(counter_D);
YusukeWakuta 0:77917230ce6d 131 counter_checker(&counter_A,&counter_B,&counter_C,&counter_D);
YusukeWakuta 0:77917230ce6d 132 wait(0.25);
YusukeWakuta 0:77917230ce6d 133 }
YusukeWakuta 0:77917230ce6d 134 }
YusukeWakuta 0:77917230ce6d 135
YusukeWakuta 0:77917230ce6d 136