kopia lustrzana https://github.com/sq2ips/m20-custom-firmware
Changed ascent rate calculating in XM1110 module based on SysTick
rodzic
e9de2f4783
commit
e0be801de9
|
@ -41,7 +41,7 @@
|
|||
/*-----------------------*/
|
||||
|
||||
/* GPS configuration */
|
||||
#define AscentRateTime 10 // Time of ascent rate mesure
|
||||
#define AscentRateTime TIME_PERIOD/2 // Time of ascent rate mesure
|
||||
|
||||
// type 1
|
||||
#define DATA_SIZE 35 // Max number of NMEA sentences in one parsing
|
||||
|
@ -50,13 +50,13 @@
|
|||
#define SENTENCE_ELEMENT_LEN 12 // Max lenght of a sentence element
|
||||
|
||||
// type 2
|
||||
#define FrameLen 62 // Length of XM1110 frame
|
||||
#define GPS_FRAME_LEN 62 // Length of XM1110 frame
|
||||
|
||||
#if GPS_TYPE == 1
|
||||
#define GpsRxBuffer_SIZE 512
|
||||
|
||||
#elif GPS_TYPE == 2
|
||||
#define GpsRxBuffer_SIZE FrameLen * 2
|
||||
#define GpsRxBuffer_SIZE GPS_FRAME_LEN * 2
|
||||
#endif
|
||||
/*-------------------*/
|
||||
|
||||
|
|
|
@ -55,6 +55,8 @@ extern "C" {
|
|||
#include "config.h"
|
||||
#if GPS_TYPE == 1
|
||||
#include "nmea.h"
|
||||
#elif GPS_TYPE == 2
|
||||
#include "xm_gps.h"
|
||||
#endif
|
||||
/* USER CODE END Includes */
|
||||
|
||||
|
|
|
@ -27,6 +27,6 @@ typedef struct NMEA_DATA {
|
|||
|
||||
void ParseNMEA(NMEA *nmea_data, uint8_t *buffer);
|
||||
|
||||
void incTimeCount();
|
||||
void incTimeCountNmea();
|
||||
|
||||
#endif /* INC_NMEA_H_ */
|
||||
|
|
|
@ -19,4 +19,6 @@ typedef struct XM_DATA {
|
|||
|
||||
void parseXMframe(XMDATA *GpsData, uint8_t *buffer);
|
||||
|
||||
void incTimeCountGps();
|
||||
|
||||
#endif
|
|
@ -315,8 +315,6 @@ int main(void)
|
|||
LL_GPIO_SetOutputPin(RADIO_EN_GPIO_Port, RADIO_EN_Pin);
|
||||
adf_setup();
|
||||
|
||||
|
||||
LL_GPIO_SetOutputPin(LPS_CS_GPIO_Port, LPS_CS_Pin); // to be removed
|
||||
for (uint8_t i = 0; i < 5; i++)
|
||||
{
|
||||
lps_init = LPS22_Init();
|
||||
|
|
|
@ -125,9 +125,11 @@ void PendSV_Handler(void)
|
|||
void SysTick_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN SysTick_IRQn 0 */
|
||||
if(TickCounter == 999){
|
||||
if(TickCounter >= 999){
|
||||
#if GPS_TYPE == 1
|
||||
incTimeCount();
|
||||
incTimeCountNmea();
|
||||
#elif GPS_TYPE == 2
|
||||
incTimeCountGps();
|
||||
#endif
|
||||
TickCounter = 0;
|
||||
}
|
||||
|
|
|
@ -11,10 +11,13 @@
|
|||
|
||||
const uint8_t syncChain[] = {0xAA, 0xAA, 0xAA, 0x03};
|
||||
|
||||
uint32_t oldTime = 0;
|
||||
float oldAlt = 0;
|
||||
float oldLat = 0;
|
||||
float oldLon = 0;
|
||||
|
||||
uint16_t TimeCounterr = 0;
|
||||
|
||||
void incTimeCountGps(){
|
||||
TimeCounterr++;
|
||||
}
|
||||
|
||||
void ParseXM(XMDATA *GpsData, uint8_t *buffer, uint8_t position){
|
||||
GpsData->Fix = *(uint8_t *)(buffer+4+position);
|
||||
|
@ -47,22 +50,17 @@ void ParseXM(XMDATA *GpsData, uint8_t *buffer, uint8_t position){
|
|||
((GpsData->Time & 0x00FF0000) >> 8) |
|
||||
((GpsData->Time & 0x0000FF00) << 8);
|
||||
|
||||
if((GpsData->Time - oldTime) >= AscentRateTime){
|
||||
if(oldTime!=0){
|
||||
GpsData->AscentRate = (GpsData->Alt-oldAlt)/(GpsData->Time-oldTime);
|
||||
|
||||
//float a = pow(sin((fabs(GpsData->Lat - oldLat)*90)/M_PI), 2) + cos(((GpsData->Lat)*180)/M_PI) * cos((oldLat*180)/M_PI) * pow(sin((fabs(GpsData->Lon - oldLon)*90)/M_PI),2);
|
||||
//float d = 2*6371*atan2(sqrt(a), sqrt(1-a));
|
||||
//GpsData->GroundSpeed = d;
|
||||
//GpsData->GroundSpeed = sqrt(pow(d, 2) + pow(GpsData->Alt-oldAlt, 2))/(GpsData->Time-oldTime);
|
||||
}else{
|
||||
GpsData->AscentRate = 0;
|
||||
GpsData->GroundSpeed = 0;
|
||||
if(GpsData->Fix > 1 && GpsData->Alt != 0){
|
||||
if(oldAlt == 0){
|
||||
oldAlt = GpsData->Alt;
|
||||
TimeCounterr = 0;
|
||||
}else if(oldAlt != 0 && TimeCounterr>=AscentRateTime){
|
||||
GpsData->AscentRate = (float)(GpsData->Alt-oldAlt)/TimeCounterr;
|
||||
oldAlt = GpsData->Alt;
|
||||
TimeCounterr = 0;
|
||||
}
|
||||
oldTime = GpsData->Time;
|
||||
oldAlt = GpsData->Alt;
|
||||
oldLat = GpsData->Lat;
|
||||
oldLon = GpsData->Lon;
|
||||
}else{
|
||||
oldAlt = 0;
|
||||
}
|
||||
|
||||
GpsData->Hours = (GpsData->Time/3600)%24;
|
||||
|
@ -78,7 +76,7 @@ void ParseXM(XMDATA *GpsData, uint8_t *buffer, uint8_t position){
|
|||
}
|
||||
|
||||
int8_t getPosition(uint8_t *buffer){
|
||||
for(uint8_t pos = 0; pos<=FrameLen+1; pos++){
|
||||
for(uint8_t pos = 0; pos<=GPS_FRAME_LEN+1; pos++){
|
||||
bool sync = true;
|
||||
for(uint8_t syncCount = 0; syncCount<sizeof(syncChain)/sizeof(syncChain[0]); syncCount++){
|
||||
if(buffer[pos+syncCount] != syncChain[syncCount]){
|
||||
|
|
Ładowanie…
Reference in New Issue