SD ni Hozon dekinai program
Dependencies: mbed SDFileSystem BME280 MPU9250
Revision 2:d83d5822dc25, committed 2020-08-07
- Comitter:
- momoa
- Date:
- Fri Aug 07 10:08:33 2020 +0000
- Parent:
- 1:d77a49b0e9ff
- Commit message:
- initialize
Changed in this revision
--- a/SDFileSystem.lib Fri Jul 31 04:44:04 2020 +0000 +++ b/SDFileSystem.lib Fri Aug 07 10:08:33 2020 +0000 @@ -1,1 +1,1 @@ -https://os.mbed.com/teams/2020NSE_SSLB4/code/SDFileSystem/#28ac6b98391b +https://os.mbed.com/users/tubemerc/code/SDFileSystem/#1427f73ac782
--- a/main.cpp Fri Jul 31 04:44:04 2020 +0000 +++ b/main.cpp Fri Aug 07 10:08:33 2020 +0000 @@ -23,16 +23,18 @@ Serial pc(PA_9,PA_10); //pin19,20 TX,RX BME280 bmp = BME280(PB_7, PB_6); // pin30,29 SDA,SCL MPU9250 mpu = MPU9250(PB_7, PB_6); // pin30,29 SDA,SCL +CAN can(PA_11, PA_12,100000); //pin21,22 rd,td #define PI 3.14159265358979323846f #define N 5 // 5回移動平均 #define sampleFreq 100.0f #define beta 0.33f // gain(大きいと加速度による補正が早い) +Timer timea; -char senddate[5]; union Float2Byte{ float _float; char _byte[4]; -}f2b; +}; +typedef union Float2Byte Float2Byte; float pressure_ave = 0.0f; // 気圧[hPa] float pressure_new = 0.0f; @@ -42,6 +44,7 @@ float tem = 0.0f; // 温度[C] FILE *fp; +CANMessage msg; void mpu_init(){ uint8_t whoami_MPU9250, whoami_AK8963; @@ -72,11 +75,32 @@ } } +void send(float senddata,int id){ + pc.printf("Master send()\n\r"); + + /*ID: 0x01*/ + Float2Byte sendFloat; + sendFloat._float = senddata; + //ここに送りたい値を入れる. + + char serialData[4]; + for(int i=0;i<4;++i){ + serialData[i] = sendFloat._byte[i]; + pc.printf("send_char: %d\n\r", serialData[i]); + } + pc.printf("sendFloat: %f\n\r", sendFloat._float); + if(can.write(CANMessage(id, serialData, 4))){ + pc.printf("Send.\n\r"); + } + //myled = !myled; +} + int main(){ fp = fopen("/sd/log.txt","a"); if(fp != NULL){ - fprintf(fp,"Start.\n"); + fprintf(fp,"Start.\n\r"); + fprintf(fp,"time,ax_ave,ay_ave,az_ave,gx_ave,gy_ave,gz_ave,Pre[hPa],Tem[C]\n\r"); fclose(fp); } else{ @@ -110,6 +134,8 @@ float qdot0, qdot1, qdot2, qdot3; float _2q0, _2q1, _2q2, _2q3, _4q0, _4q1, _4q2 ,_8q1, _8q2, _q0q0, _q1q1, _q2q2, _q3q3; + float f = 0.0; + wait(0.1); mpu_init(); bmp.initialize(); @@ -150,10 +176,11 @@ pc.printf("gyr_ini:%f,%f,%f\n\r", gx_i, gy_i, gz_i); wait(0.1); + timea.start(); pc.printf("Start.\n\r"); while(1){ - //timea.start(); + mpu.readGyroData(gyr); mpu.readAccelData(acc); mpu.readMagData(mag); @@ -300,27 +327,32 @@ if(fp != NULL){ //fprintf(fp,"a_norm:%f\n\r", a_norm); - fprintf(fp,"acc_ave:%f,%f,%f\n\r", ax, ay, az); - fprintf(fp,"gyr_ave:%f,%f,%f\n\r", gx, gy, gz); + //fprintf(fp,"acc_ave:%f,%f,%f\n\r", ax, ay, az); + //fprintf(fp,"gyr_ave:%f,%f,%f\n\r", gx, gy, gz); //fprintf(fp,"mag_ave:%f,%f,%f\n\r", mx, my, mz); //fprintf(fp,"%f,%f,%f,%f\n\r", q0, q1, q2, q3); //fprintf(fp,"angle: %f, %f, %f\n\r", psi, cta, eta); //fprintf(fp,"%f\n\r", timea.read()); - fprintf(fp,"Pre[hPa]: %f\n\r", pressure_ave); - fprintf(fp,"Tem[C] : %f\n\r", tem); + //fprintf(fp,"Pre[hPa]: %f\n\r", pressure_ave); + //fprintf(fp,"Tem[C] : %f\n\r", tem); + //fprintf(fp,"ax_ave,ay_ave,az_ave,gx_ave,gy_ave,gz_ave,Pre[hPa],Tem[C]\n\r"); + fprintf(fp,"%f,%f,%f,%f,%f,%f,%f,%f,%f\n\r",timea.read(),ax, ay, az, gx, gy, gz, pressure_ave, tem); + cntsd++; if(cntsd == 10){ fclose(fp); pc.printf("Save.\n\r"); - int cntsd = 0; - break; + cntsd = 0; } }else{ pc.printf("Failed.\n\r"); } - //timea.read + timea.read(); + send(f,0x03); + f = f + 0.86; + pc.printf("%d", cntsd); wait(0.001); } } \ No newline at end of file
--- a/mbed.bld Fri Jul 31 04:44:04 2020 +0000 +++ b/mbed.bld Fri Aug 07 10:08:33 2020 +0000 @@ -1,1 +1,1 @@ -https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400 \ No newline at end of file +https://os.mbed.com/users/mbed_official/code/mbed/builds/e95d10626187 \ No newline at end of file