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: MODGPS MODSERIAL SDFileSystem mbed
Revision 8:0ce247da6370, committed 2013-05-27
- Comitter:
- njewin
- Date:
- Mon May 27 17:22:36 2013 +0000
- Parent:
- 7:af9f373ac87b
- Child:
- 9:7dcfa24d5e7a
- Commit message:
- output weird values for Longitude and 0 for Latitude. Not converting from 32bit IEEE floating point properly?
Changed in this revision
| UM6_config/UM6_config.h | Show annotated file Show diff for this revision Revisions of this file |
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/UM6_config/UM6_config.h Sat May 25 14:29:36 2013 +0000
+++ b/UM6_config/UM6_config.h Mon May 27 17:22:36 2013 +0000
@@ -92,8 +92,8 @@
#define UM6_ERROR_COV_32 (DATA_REG_START_ADDRESS + 31)
#define UM6_ERROR_COV_33 (DATA_REG_START_ADDRESS + 32)
#define UM6_GPS_LONGITUDE (DATA_REG_START_ADDRESS + 34)
-#define UM6_GPS_LATITUDE (DATA_REG_START_ADDRESS + 35)
-#define UM6_GPS_COURSE_SPEED (DATA_REG_START_ADDRESS + 40)
+#define UM6_GPS_LATITUDE (DATA_REG_START_ADDRESS + 35)
+#define UM6_GPS_COURSE_SPEED (DATA_REG_START_ADDRESS + 40)
@@ -142,8 +142,8 @@
float Roll;
float Pitch;
float Yaw;
-float GPS_long;
-float GPS_lat;
+double GPS_long;
+double GPS_lat;
float GPS_course;
float GPS_speed;
};
@@ -166,8 +166,8 @@
int16_t MY_DATA_EULER_PHI;
int16_t MY_DATA_EULER_THETA;
int16_t MY_DATA_EULER_PSI;
-int32_t MY_DATA_GPS_LONG;
-int32_t MY_DATA_GPS_LAT;
+double MY_DATA_GPS_LONG;
+double MY_DATA_GPS_LAT;
int16_t MY_DATA_GPS_COURSE;
int16_t MY_DATA_GPS_SPEED;
@@ -462,12 +462,12 @@
// Ground course
MY_DATA_GPS_COURSE = (int16_t)new_packet.packet_data[0]<<8; //bitshift it
MY_DATA_GPS_COURSE |= new_packet.packet_data[1];
- data.GPS_course = MY_DATA_GPS_COURSE; // need to divide by 100 to get ground course in degrees
+ data.GPS_course = MY_DATA_GPS_COURSE*0.01; // scaled by 0.01 to get ground course in degrees
// Speed
MY_DATA_GPS_SPEED = (int16_t)new_packet.packet_data[2]<<8; //bitshift it
MY_DATA_GPS_SPEED |= new_packet.packet_data[3];
- data.GPS_speed = MY_DATA_GPS_SPEED*0.01; // need to divide by 100 to get speed in m/s
+ data.GPS_speed = MY_DATA_GPS_SPEED*0.01; // scaled by 0.01 to get speed in m/s
//------------------------------------------------------------
@@ -475,15 +475,17 @@
//-------------------------------------------------------------------
// GPS long
if (new_packet.address == UM6_GPS_LONGITUDE) {
- // Longitude
- data.GPS_long = MY_DATA_GPS_LONG;
+ // Longitude
+ MY_DATA_GPS_LONG = (int32_t)new_packet.packet_data;
+ data.GPS_long = MY_DATA_GPS_LAT;
}
//------------------------------------------------------------
//-------------------------------------------------------------------
// GPS lat
if (new_packet.address == UM6_GPS_LATITUDE) {
// Latitude
- data.GPS_lat = MY_DATA_GPS_LAT;
+ MY_DATA_GPS_LAT = (int32_t)new_packet.packet_data;
+ data.GPS_lat = MY_DATA_GPS_LONG;
}
//------------------------------------------------------------
} // end if(ADDRESS_TYPE_DATA)
@@ -507,4 +509,19 @@
} // end get_gyro_x()
-#endif
\ No newline at end of file
+#endif
+
+/* debugging GPS lat & long
+ // code snippets and print out
+
+//code
+double GPS_long;
+double MY_DATA_GPS_LONG;
+MY_DATA_GPS_LONG = (int32_t)new_packet.packet_data;
+data.GPS_long = MY_DATA_GPS_LAT;
+//print out
+Long 0.000000
+Long -2.000001
+Long -2.000001
+Long -26815635079454453000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+*/
\ No newline at end of file
--- a/main.cpp Sat May 25 14:29:36 2013 +0000
+++ b/main.cpp Mon May 27 17:22:36 2013 +0000
@@ -17,10 +17,9 @@
SDFileSystem sd(p5, p6, p7, p8, "sd"); // the pinout on the mbed Cool Components workshop board
-//------------ interrupt and variable setup --------------------------//
+//------------ variables setup ---------------------------------------//
Ticker tick;
Timer t;
-int counter=0;
int flag=0;
// interupt function for processing uart messages --------------------//
@@ -33,7 +32,6 @@
//------------ LogData interrupt function ----------------------------//
void LogData() {
- counter++;
flag=1;
}
@@ -50,32 +48,53 @@
//---------- setup sd card -----------------------------//
mkdir("/sd/mydir", 0777);
- FILE *fp = fopen("/sd/mydir/sdtest.csv", "w");
+ FILE *fp = fopen("/sd/mydir/log1.csv", "w");
if(fp == NULL) {
error("Could not open file for write\n");
}
-//////////// FILE *fp = fopen("/local/log1.csv", "w");
- fprintf(fp,"time(s),count,Yaw(deg),Accel(m/s2),GPS Speed(m/s) \r");
+//////////////////////////// FILE *fp = fopen("/local/log1.csv", "w");
+ // print TEST signals to file, header
+// fprintf(fp,"time(s),Yaw(deg),Accel(m/s2),GPS Speed(m/s) \r");
+ // print ALL signals to file, header
+ fprintf(fp, "time(s),Yaw(deg),Roll(deg),Pitch(deg),GyroX(deg/s),GyroY(deg/s),GyroZ(deg/s),AccelX(g),AccelY(g),AccelZ(g),GPScourse(deg),GPSspeed(m/s),Latitude(deg),Longitude(deg) \r"); // sends header to file
+
//---- main while loop ----------------------------------//
//--(interrupt sets flag that causes variables to be logged)
while(1) {
- if(flag==1) { // prints counter value every interrupt raises flag
+ if(flag==1) {
log_led=1; // turns on LED3 to indicate logging
+ float time=t.read();
float Yaw=data.Yaw;
- float AccelX=data.Accel_Proc_X;
- float GPSspeed=data.GPS_speed;
- fprintf(fp,"%.3f,%d,%f,%f,%f \r",t.read(),counter,Yaw,AccelX,GPSspeed);
- pc.printf("time %.3f, count %d,Yaw %f,Accel %f, Speed %f \n",t.read(),counter,Yaw,AccelX,GPSspeed);
- flag=0;
- pc_led = !pc_led; // Lights LED1 when uart RxBuff has > 40 bytes
+ float Roll=data.Roll;
+ float Pitch=data.Pitch;
+ float GyroX=data.Gyro_Proc_X;
+ float GyroY=data.Gyro_Proc_Y;
+ float GyroZ=data.Gyro_Proc_Z;
+ float AccelX=data.Accel_Proc_X;
+ float AccelY=data.Accel_Proc_Y;
+ float AccelZ=data.Accel_Proc_Z;
+ double GPSlong=data.GPS_long; // currently I can get GPS longitude to out data
+ double GPSlat=data.GPS_lat; // currently I can get GPS latitude to out data
+ float GPScourse=data.GPS_course;
+ float GPSspeed=data.GPS_speed;
+
+ //----- print TEST signals to file -------------------//
+ // fprintf(fp,"%.3f,%.2f,%.4f,%.2f \r",time,Yaw,AccelX,GPSspeed);
+ pc.printf("time %.3f,Yaw %f, Speed %f, Lat %f, Long %f \n",time,Yaw,GPSspeed,GPSlat,GPSlong);
+ // pc.printf("0x%08X, %f\n", *(int *)&GPSlong, GPSlong);
+
+ //----- print ALL signals to file --------------------//
+ fprintf(fp, "%3.3f, %3.1f,%3.1f,%3.1f, %3.2f,%3.2f,%3.2f, %3.4f,%3.4f,%3.4f, %3.1f,%3.2f,%f,%f\r",time,Yaw,Roll,Pitch,GyroX,GyroY,GyroZ,AccelX,AccelY,AccelZ,GPScourse,GPSspeed,GPSlat,GPSlong);
+ flag=0; // recents LogData interrupt flag
+ pc_led = !pc_led; // Lights LED1 when transmitting to PC screen
} // end if(flag=1) loop
if(enable==0) {
- break; // breaks while loop in enable switched off
+ break; // breaks while loop if enable switched off
}
} // end while(1) loop
- pc.printf(" done. "); // prints 'done when logging is finished/enable switched off
+ pc.printf(" done. \n"); // prints 'done when logging is finished/enable switched off
log_led=0; // turns off LED logging is finished/enable switched off
wait(0.5); // debug wait for pc.printf
fclose(fp); // closes log file