Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: ADXL345_I2C INA226 mbed SDFileSystem
main.cpp
00001 #include "mbed.h" 00002 00003 #define BUFFER 10 00004 00005 Serial rs485R(p13,p14); 00006 Serial rs485L(p28,p27); 00007 Serial pc(USBTX,USBRX); 00008 DigitalOut Driver_R(p5); 00009 DigitalOut Driver_L(p6); 00010 DigitalIn Switch(p20); 00011 Ticker CheckData; 00012 AnalogIn val1(p16); 00013 AnalogIn val2(p17); 00014 00015 void ch_data() 00016 { 00017 signed char rec_data_R[BUFFER]; 00018 signed char rec_data_L[BUFFER]; 00019 //signed char rec_data_R; 00020 rs485R.putc('P'); 00021 wait_ms(1); 00022 Driver_R = 0; 00023 wait_ms(120); 00024 if(rs485R.readable()) { 00025 for(int i = 0; i < BUFFER; i++) { 00026 rec_data_R[i] = rs485R.getc(); 00027 } 00028 for(int i = 0; i < BUFFER; i++) { 00029 if(rec_data_R[i + 1] != -1) { 00030 pc.printf("RIGHT : "); 00031 switch(rec_data_R[i]) { 00032 case 'X': 00033 pc.printf(" X : %5i",rec_data_R[i + 1]); 00034 break; 00035 case 'Y': 00036 pc.printf(" Y : %5i",rec_data_R[i + 1]); 00037 break; 00038 case 'Z': 00039 pc.printf(" Z : %5i",rec_data_R[i + 1]); 00040 break; 00041 case 'V': 00042 pc.printf(" V : %5i",rec_data_R[i + 1]); 00043 break; 00044 case 'C': 00045 pc.printf(" C : %5i",rec_data_R[i + 1]); 00046 break; 00047 } 00048 } 00049 } 00050 } 00051 pc.printf("\t"); 00052 00053 rs485L.putc('P'); 00054 Driver_L = 0; 00055 wait_ms(120); 00056 if(rs485L.readable()) { 00057 for(int i = 0; i < BUFFER; i++) { 00058 rec_data_L[i] = rs485L.getc(); 00059 } 00060 for(int i = 0; i < BUFFER; i++) { 00061 if(rec_data_L[i + 1] != -1) { 00062 pc.printf("LEFT : "); 00063 switch(rec_data_L[i]) { 00064 case 'X': 00065 pc.printf(" X : %5i",rec_data_L[i + 1]); 00066 break; 00067 case 'Y': 00068 pc.printf(" Y : %5i",rec_data_L[i + 1]); 00069 break; 00070 case 'Z': 00071 pc.printf(" Z : %5i",rec_data_L[i + 1]); 00072 break; 00073 case 'V': 00074 pc.printf(" V : %5i",rec_data_L[i + 1]); 00075 break; 00076 case 'C': 00077 pc.printf(" C : %5i",rec_data_L[i + 1]); 00078 break; 00079 } 00080 } 00081 } 00082 pc.printf("\n\r"); 00083 Driver_R = 1; 00084 Driver_L = 1; 00085 wait_ms(1); 00086 } 00087 } 00088 00089 void counter_checker(int *counter_A,int *counter_B,int *counter_C,int *counter_D) 00090 { 00091 00092 (*counter_A)++; 00093 if(*counter_A > 180) 00094 *counter_A = 0; 00095 00096 *counter_B = *counter_B + 2; 00097 if(*counter_B > 180) 00098 *counter_B = 0; 00099 00100 *counter_C = *counter_C + 3; 00101 if(*counter_C > 180) 00102 *counter_C = 0; 00103 00104 *counter_D = *counter_D + 4; 00105 if(*counter_D > 180) 00106 *counter_D = 0; 00107 } 00108 00109 int main() 00110 { 00111 /*右エルロン:A 00112 右翼端板 :B 00113 左エルロン:C 00114 左翼端板 :D 00115 */ 00116 rs485R.baud(38400); 00117 rs485L.baud(38400); 00118 Driver_R = 1; 00119 Driver_L = 1; 00120 int counter_A = 0; 00121 int counter_B = 0; 00122 int counter_C = 0; 00123 int counter_D = 0; 00124 pc.printf("Driver\n\r"); 00125 CheckData.attach(&ch_data,0.40); 00126 while(1) { 00127 rs485R.putc(counter_A); 00128 rs485R.putc('B'); 00129 rs485R.putc(counter_B); 00130 rs485L.putc('C'); 00131 rs485L.putc(counter_C); 00132 rs485L.putc('D'); 00133 rs485L.putc(counter_D); 00134 counter_checker(&counter_A,&counter_B,&counter_C,&counter_D); 00135 wait(0.25); 00136 } 00137 } 00138 00139
Generated on Thu Sep 1 2022 15:42:08 by
1.7.2