Skip to content

Commit

Permalink
feat: refine gps value sse transmit
Browse files Browse the repository at this point in the history
  • Loading branch information
jeki committed May 7, 2021
1 parent 8b05435 commit 1cd7fa8
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 25 deletions.
13 changes: 10 additions & 3 deletions data/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,16 @@ <h1 id="loaderTxt">Loading...</h1>
<tr><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td></td><td></td><td></td><td></td><td></td></tr>
<tr>
<td>LatLong</td>
<td><input id="latitude" value="latitude"></input></td>
<td><input id="longitude" value="longitude"></input></td>
<td>LatLong1</td>
<td><input id="lat1" value="lat1"></input></td>
<td><input id="lng1" value="lng1"></input></td>
<td></td>
<td></td>
</tr>
<tr>
<td>LatLong2</td>
<td><input id="lat2" value="lat2"></input></td>
<td><input id="lng2" value="lng2"></input></td>
<td></td>
<td></td>
</tr>
Expand Down
2 changes: 1 addition & 1 deletion data/ssehandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function got_packet(msgdata) {
setMyJson("dqw"); setMyJson("dqx"); setMyJson("dqy"); setMyJson("dqz");
setMyJsonRadToDeg("r"); setMyJsonRadToDeg("p"); setMyJsonRadToDeg("y");
setMyJson("ax"); setMyJson("ay"); setMyJson("az");
setMyJson("latitude"); setMyJson("longitude");
setMyJson("lat1"); setMyJson("lat2"); setMyJson("lng1"); setMyJson("lng2");

if(chkMyJSON("h")) {
getID("heading").value = (myJSON.h*180/Math.PI).toFixed(2);
Expand Down
35 changes: 20 additions & 15 deletions gpsUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ Modified by MohammedDamirchi from https://github.com/mikalhart/TinyGPSPlus
*/

GPS_UTIL::GPS_UTIL(unsigned int _idx, unsigned int _RXPin, unsigned int _TXPin):gpsSerial(_RXPin, _TXPin) {
latitude = 0.0f;
longitude = 0.0f;

idx = _idx;
// TinyGPSCustom totalGPGSVMessages(gps, "GPGSV", 1); // $GPGSV sentence, first element
// TinyGPSCustom messageNumber(gps, "GPGSV", 2); // $GPGSV sentence, second element
Expand Down Expand Up @@ -78,11 +81,13 @@ void GPS_UTIL::displayInfo()

displayInfoTime = millis();

dtostrf(gps.location.lat(),4,8,latStr);
dtostrf(gps.location.lng(),4,8,longStr);
String str = "{\"latitude\":" + String(latStr) + ",\"longitude\":" + String(longStr) + "}";
SSEBroadcastTxt(str);
String fileStr = "#" + String(idx, DEC)+";"+String(latStr) + ", " + String(longStr) + ";";
latitude = (float)gps.location.lat();
longitude = (float)gps.location.lng();
// dtostrf(gps.location.lat(),4,8,latStr);
// dtostrf(gps.location.lng(),4,8,longStr);
// String str = "{\"latitude\":" + String(latStr) + ",\"longitude\":" + String(longStr) + "}";
// SSEBroadcastTxt(str);
String fileStr = "#" + String(idx, DEC)+";"+String(latitude) + ", " + String(longitude) + ";";

Serial.print(F("Location: "));
Serial.print(gps.location.lat(), 6);
Expand Down Expand Up @@ -127,16 +132,16 @@ void GPS_UTIL::displayInfo()
fileStr+=";";
appendFile(R"(/gpslog.txt)", fileStr.c_str() );
Serial.println();
} else {
if (latLongValid) {
if (millis() - latLongValidTime > latLongValidTimeOut) {
String str = "{\"latitude\":" + String(latStr) + ",\"longitude\":" + String(longStr) + "}";
SSEBroadcastTxt(str);
latLongValidTime = millis();
}
}
}

}
// else {
// if (latLongValid) {
// if (millis() - latLongValidTime > latLongValidTimeOut) {
// String str = "{\"latitude\":" + String(latStr) + ",\"longitude\":" + String(longStr) + "}";
// SSEBroadcastTxt(str);
// latLongValidTime = millis();
// }
// }
// }
}

// void GPS_UTIL::gpsSatelliteTracker() {
Expand Down
6 changes: 4 additions & 2 deletions gpsUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ const int PAGE_LENGTH = 40;
class GPS_UTIL
{
public:
char latStr[13];
char longStr[13];
// char latStr[13];
// char longStr[13];
float latitude;
float longitude;
unsigned int idx;
GPS_UTIL(unsigned int _idx, unsigned int _RXPin, unsigned int _TXPin);
void begin(unsigned int baudRate);
Expand Down
22 changes: 22 additions & 0 deletions gpsUtilsWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,26 @@ void gpsUtilsWrapper_loop(void) {
void gpsUtilsWrapper_toggle_debug_print(void) {
gps1.toggle_print_raw();
gps2.toggle_print_raw();
}

float gpsUtilsWrapper_get_latitude(int index) {
switch(index) {
case 1:
gps1.latitude;
break;
case 2:
gps2.latitude;
break;
}
}

float gpsUtilsWrapper_get_longitude(int index) {
switch(index) {
case 1:
gps1.longitude;
break;
case 2:
gps2.longitude;
break;
}
}
2 changes: 2 additions & 0 deletions gpsUtilsWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@
void gpsUtilsWrapper_begin();
void gpsUtilsWrapper_loop();
void gpsUtilsWrapper_toggle_debug_print();
float gpsUtilsWrapper_get_latitude(int index);
float gpsUtilsWrapper_get_longitude(int index);

#endif // def(__gps_Utils_h__)
15 changes: 11 additions & 4 deletions imuUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
#include "webUtils.h"
#include <LittleFS.h>
#include "fileUtils.h"
#include "gpsUtilsWrapper.h"

extern "C" {
#include "quaternion.h"
}

MPU9250_DMP imu;
static char imuTxtBuffer[250];
static char imuTxtBuffer[320];

float qw,qx,qy,qz;
float ax,ay,az, mx, my, mz;
Expand Down Expand Up @@ -49,8 +51,13 @@ void printIMUData(void)
{
if (millis() - printTime > printTimeLimit) {
if (print_flag) {
sprintf(imuTxtBuffer, "{\"dqw\":%.4f,\"dqx\":%.4f,\"dqy\":%.4f,\"dqz\":%.4f,\"qw\":%.4f,\"qx\":%.4f,\"qy\":%.4f,\"qz\":%.4f,\"r\":%.2f,\"p\":%.2f,\"y\":%.2f,\"ax\":%.4f,\"ay\":%.4f,\"az\":%.4f,\"mx\":%.4f,\"my\":%.4f,\"mz\":%.4f,\"mh\":%.4f,\"h\":%.4f}",
qw,qx,qy,qz,(float)fusedQuat[QUAT_W], (float)fusedQuat[QUAT_X], (float)fusedQuat[QUAT_Y], (float)fusedQuat[QUAT_Z], (float)dmpEuler[VEC3_X], (float)dmpEuler[VEC3_Y], (float)dmpEuler[VEC3_Z], ax, ay, az, mx, my, mz, (float)magYaw, fHeading[0]);
sprintf(imuTxtBuffer, "{\"lat1\":%.8f,\"lng1\":%.8f,\"lat2\":%.8f,\"lng2\":%.8f,\"dqw\":%.4f,\"dqx\":%.4f,\"dqy\":%.4f,\"dqz\":%.4f,\"qw\":%.4f,\"qx\":%.4f,\"qy\":%.4f,\"qz\":%.4f,\"r\":%.2f,\"p\":%.2f,\"y\":%.2f,\"ax\":%.4f,\"ay\":%.4f,\"az\":%.4f,\"mx\":%.4f,\"my\":%.4f,\"mz\":%.4f,\"mh\":%.4f,\"h\":%.4f}",
gpsUtilsWrapper_get_latitude(1),gpsUtilsWrapper_get_longitude(1),gpsUtilsWrapper_get_latitude(2),gpsUtilsWrapper_get_longitude(2),
qw,qx,qy,qz,
(float)fusedQuat[QUAT_W], (float)fusedQuat[QUAT_X], (float)fusedQuat[QUAT_Y], (float)fusedQuat[QUAT_Z],
(float)dmpEuler[VEC3_X], (float)dmpEuler[VEC3_Y], (float)dmpEuler[VEC3_Z],
ax, ay, az, mx, my, mz,
(float)magYaw, fHeading[0]);
SSEBroadcastTxt(imuTxtBuffer);
print_flag = false;
}
Expand Down Expand Up @@ -214,7 +221,7 @@ int imu_calcHeading(void) {
quaternionToEuler(dmpQuat, dmpEuler);

fusedEuler[VEC3_X] = dmpEuler[VEC3_X];
fusedEuler[VEC3_Y] = -dmpEuler[VEC3_Y]; // dmp pitch is going down + but the eulerToQuaternion requires the pitch is up +
fusedEuler[VEC3_Y] = -dmpEuler[VEC3_Y]; // dmp pitch is going down + but the eulerToQuaternion requires the pitch to be up +
fusedEuler[VEC3_Z] = 0; //-atan2(mx, my); // this good with calibration but very prone to tilt

// X axis = dmp X axis = mag Y axis
Expand Down

0 comments on commit 1cd7fa8

Please sign in to comment.