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.
Fork of mbed_droptest by
Diff: main.cpp
- Revision:
- 4:62aec4ae9f67
- Parent:
- 3:880d00d555c1
--- a/main.cpp Mon Aug 01 02:23:11 2016 +0000
+++ b/main.cpp Mon Aug 01 09:29:24 2016 +0000
@@ -8,13 +8,23 @@
Timer end;
int stat=1;
+volatile unsigned char tmp;
+void pc_isr(){
+ __disable_irq();
+ while(pc.readable()){
+ tmp = pc.getc();
+ }
+ __enable_irq();
+}
+
+
////////////////////////////////////
// GPS 5V p27(RX) //
// Bluetooth 3.3V p28(TX) //
////////////////////////////////////
Serial Blue_GPS(p28, p27);
-char GPS_msg[2000], ns, ew;
+char GPS_msg[150], ns, ew;
int i = 0, j=0, k=0, gps_ok=0, GPS_flag;
volatile unsigned char GPS_buffer[2];
float fix,sat,x,longitude=0.0f,latitude=0.0f, alt_GPS=0,lock, Kor_time;
@@ -30,12 +40,12 @@
if (GPS_flag == 1){GPS_flag = 0; gps_ok = 1; j=0;}
}
if ((i==5)&(GPS_buffer[0] == 'G')){GPS_flag=1;}
- if (GPS_flag==1){GPS_msg[j]=GPS_buffer[0]; j++; pc.printf("%d \r\n", j);}
+ if (GPS_flag==1){GPS_msg[j]=GPS_buffer[0]; j++; }
+// pc.putc(GPS_buffer[0]);
+// Blue_GPS.putc(GPS_buffer[0]);
}
-
- //Blue_GPS.printf("");
+ return;
}
-
float trunc(float v) {
if(v < 0.0) {
v*= -1.0;
@@ -95,7 +105,7 @@
else {
if (count<=19){alt_sum = alt_sum + alt; count++;}
else {
- Blue_GPS.printf("calibration\r\n");
+// Blue_GPS.printf("calibration\r\n");
alt_zero = alt_sum / (float)count;
count++;
}
@@ -122,6 +132,7 @@
float roll_buffer[2], pitch_buffer[2], yaw_buffer[2], w_attitude=0.8;
void AHRS_isr(){ //inturupt
+ __disable_irq();
while(AHRS.readable()){
AHRS_buffer[1] = AHRS_buffer[0];
AHRS_buffer[0] = AHRS.getc();
@@ -129,6 +140,7 @@
if (AHRS_buffer[0] == '*'){AHRS_flag=1;}
if (AHRS_flag==1){AHRS_msg[m] = AHRS_buffer[0]; m++;}
}
+ __enable_irq();
}
void get_AHRS(float*roll, float*pitch, float*yaw, float*accx, float*accy, float*accz)
@@ -203,10 +215,25 @@
fprintf(fp, "%i,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f\r\n",stat,Kor_time,latitude,longitude,alt,alt_GPS,roll,pitch,yaw,accx,accy,accz,unf_value,gf_value,linear_value);
}
+
+///////////////////////////New Add/////////////////
+void trans_blue_data(float in_data, int integer_point, int under_point){ // number of intefer and under_point
+ unsigned int conv_trans_data;
+ conv_trans_data = (unsigned int)abs(in_data * pow((float)10,under_point));
+ if(in_data<0) {while((LPC_UART2->LSR&0x20)==0); LPC_UART2->THR = '-';}
+ for(int cnt_num=(integer_point + under_point); cnt_num > 0; cnt_num--){
+ if(cnt_num == under_point) {while((LPC_UART2->LSR&0x20)==0); LPC_UART2->THR = '.'; }
+ while((LPC_UART2->LSR&0x20)==0); LPC_UART2->THR = (unsigned char)(conv_trans_data%(unsigned int)(pow((float)10,cnt_num))/(pow((float)10,cnt_num-1)) + 48); //convert to ASCII
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+
void send_Blue(){
if (blue_ok == 1){
blue_ok = 0;
- Blue_GPS.printf("%i,%.0f,%.6f,%.6f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f\r\n",stat,Kor_time,latitude,longitude,alt,del_alt,roll,pitch,yaw,accz,unf_value,gf_value,linear_value);
+ trans_blue_data(latitude,2,6);
+// Blue_GPS.printf("%i,%.0f,%.6f,%.6f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f\r\n",stat,Kor_time,latitude,longitude,alt,del_alt,roll,pitch,yaw,accz,unf_value,gf_value,linear_value);
}
}
void send_PC(){
@@ -223,6 +250,9 @@
void timer2_isr(){
blueFlag = 1;
}
+
+///////////////////////////////////////////////
+
/////////////////////////////////
// Main loop //
/////////////////////////////////
@@ -231,27 +261,40 @@
{
AHRS.baud(9600);
Blue_GPS.baud(9600);
-
+ pc.baud(9600);
+/*
while(Blue_GPS.readable()){
volatile unsigned char temp = Blue_GPS.getc();
}
Blue_GPS.printf("Buffer flushing\r\n");
-
- Blue_GPS.attach(&GPS_isr, Serial::RxIrq);
- AHRS.attach(&AHRS_isr, Serial::RxIrq);
- Blue_GPS.printf("Start\r\n");
+ */
+ Blue_GPS.attach(&GPS_isr);
+ pc.attach(&pc_isr);
+ AHRS.attach(&AHRS_isr);
+// Blue_GPS.printf("Start\r\n");
//Log_file();
timer1.attach(&timer1_isr, 1.0);
timer2.attach(&timer2_isr, 0.1);
gf_value = 0.7;
Micro_gf = gf_value;
while(1) {
+
switch(stat){
case 1 : //Calibration
if(gpsFlag)
{
get_GPS(&Kor_time,&latitude,&ns,&longitude,&ew,&fix,&sat,&x,&alt_GPS,&lock);
- Blue_GPS.printf("getGPS\r\n");
+// Blue_GPS.printf("getGPS\r\n");
+
+ while((LPC_UART2->LSR&0x20)==0); LPC_UART2->THR = 'g';
+ while((LPC_UART2->LSR&0x20)==0); LPC_UART2->THR = 'e';
+ while((LPC_UART2->LSR&0x20)==0); LPC_UART2->THR = 't';
+ while((LPC_UART2->LSR&0x20)==0); LPC_UART2->THR = 'G';
+ while((LPC_UART2->LSR&0x20)==0); LPC_UART2->THR = 'P';
+ while((LPC_UART2->LSR&0x20)==0); LPC_UART2->THR = 'S';
+ while((LPC_UART2->LSR&0x20)==0); LPC_UART2->THR = 13;
+ while((LPC_UART2->LSR&0x20)==0); LPC_UART2->THR = 10;
+
gpsFlag = 0;
}
if(blueFlag)
@@ -259,8 +302,24 @@
get_AHRS(&roll,&pitch,&yaw,&accx,&accy,&accz);
get_Baro(&t, &alt, &del_alt);
calb_alt();
- Blue_GPS.printf("%i,%.2f,%.2f,%.2f\r\n",count, alt, alt_sum, alt_zero);
+// Blue_GPS.printf("%i,%.2f,%.2f,%.2f\r\n",count, alt, alt_sum, alt_zero);
+ //////Count/////////
+ trans_blue_data((float)count,3,0);
+ while((LPC_UART2->LSR&0x20)==0); LPC_UART2->THR = ',';
+ /////////Alt///////
+
+ ////////Data Trans to Bluetooth ///
+ trans_blue_data(alt,3,6);
+ while((LPC_UART2->LSR&0x20)==0); LPC_UART2->THR = ',';
+ trans_blue_data(alt_sum,6,2);
+ while((LPC_UART2->LSR&0x20)==0); LPC_UART2->THR = ',';
+// float_2_ggaji(alt_zero);
+ trans_blue_data(alt_zero, 5, 3);
+ //////////Line Feed//
+ while((LPC_UART2->LSR&0x20)==0); LPC_UART2->THR = 13;
+ while((LPC_UART2->LSR&0x20)==0); LPC_UART2->THR = 10;
blueFlag = 0;
+
}
if (20<count) {
stat=2;
@@ -288,6 +347,7 @@
stat=3; send_Blue();
}
break;
+
/*case 3 : //Drop
get_GPS(&Kor_time,&latitude,&ns,&longitude,&ew,&fix,&sat,&x,&alt_GPS,&lock);
get_AHRS(&roll,&pitch,&yaw,&accx,&accy,&accz);
@@ -317,4 +377,5 @@
break;
}
}
-}
\ No newline at end of file
+}
+
