From 1a2ba41e1bae91c690d69f751dd957fb08f44354 Mon Sep 17 00:00:00 2001 From: Bob Larkin Date: Mon, 14 Nov 2022 10:49:16 -0800 Subject: [PATCH] Added azimuth calculation --- examples/FT8Receive/FT8Receive.ino | 13 ++++++++++--- examples/FT8Receive/decode_ft8R.ino | 7 +++++-- examples/FT8Receive/locatorR.ino | 22 ++++++++++++++++++++-- 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/examples/FT8Receive/FT8Receive.ino b/examples/FT8Receive/FT8Receive.ino index 7cfe373..11bc9c4 100644 --- a/examples/FT8Receive/FT8Receive.ino +++ b/examples/FT8Receive/FT8Receive.ino @@ -1,6 +1,7 @@ // FT8Receive.ino 13 Oct 2022 Bob Larkin, W7PUA // Simple command-line reception of WSJT FT8 signals for // amateur radio. +// Added azimuth calculation. Bob 14 Nov 2022 /* * Huge thanks to Charley Hill, W5BAA, for his Pocket FT8 work, much of which @@ -120,7 +121,9 @@ int master_decoded; #define FT8_RCV_IDLE 0 #define FT8_RCV_DATA_COLLECT 1 #define FT8_RCV_FIND_POWERS 2 -#define FT8_RCV_DECODE 3 +#define FT8_RCV_READY_DECODE 3 +#define FT8_RCV_DECODE 4 + int rcvFT8State = FT8_RCV_IDLE; int master_offset, offset_step; int Target_Flag = 0; @@ -304,13 +307,16 @@ void loop(void) { Serial.print("Extract Power, fft count = "); Serial.println( demod1.getFFTCount() ); #endif extract_power(master_offset); // Do FFT and log powers - rcvFT8State = FT8_RCV_DATA_COLLECT; + if(demod1.getFFTCount() >= 184) + rcvFT8State = FT8_RCV_READY_DECODE; + else + rcvFT8State = FT8_RCV_DATA_COLLECT; #ifdef DEBUG1 Serial.println("Power array updated"); #endif } - if(rcvFT8State!=FT8_RCV_IDLE && demod1.getFFTCount() >= 184) + if(rcvFT8State==FT8_RCV_READY_DECODE ) { rcvFT8State = FT8_RCV_DECODE; #ifdef DEBUG1 @@ -318,6 +324,7 @@ void loop(void) { #endif tu = micros(); num_decoded_msg = ft8_decode(); + printFT8Received(); rcvFT8State = FT8_RCV_IDLE; master_decoded = num_decoded_msg; #ifdef DEBUG1 diff --git a/examples/FT8Receive/decode_ft8R.ino b/examples/FT8Receive/decode_ft8R.ino index b43b56c..a8d2aa1 100644 --- a/examples/FT8Receive/decode_ft8R.ino +++ b/examples/FT8Receive/decode_ft8R.ino @@ -57,6 +57,7 @@ typedef struct int sync_score; int snr; int distance; + float32_t azimuth; // Added Nov 2022 } Decode; Decode new_decoded[20]; @@ -222,6 +223,7 @@ int ft8_decode(void) { { distance = Target_Distancef(Target_Locator); new_decoded[num_decoded].distance = (int)(0.5f + distance); + new_decoded[num_decoded].azimuth = Target_Azimuthf(Target_Locator); } else { @@ -233,7 +235,7 @@ int ft8_decode(void) { } // End, duplicate not found } //End of big decode loop noiseMeasured = false; // Global flag for Process_DSP_R - printFT8Received(); + //printFT8Received(); // Move to main INO return num_decoded; } @@ -254,7 +256,8 @@ void printFT8Received(void) { Serial.print(" snr="); Serial.print(new_decoded[kk].snr); if(new_decoded[kk].distance > 0) { - Serial.print(" km="); Serial.println(new_decoded[kk].distance); + Serial.print(" km="); Serial.print(new_decoded[kk].distance); + Serial.print(" az="); Serial.println(new_decoded[kk].azimuth, 1); } else Serial.println(""); diff --git a/examples/FT8Receive/locatorR.ino b/examples/FT8Receive/locatorR.ino index 1d0c03d..fbd048c 100644 --- a/examples/FT8Receive/locatorR.ino +++ b/examples/FT8Receive/locatorR.ino @@ -6,6 +6,7 @@ // locatorR.ino Bob Larkin 12 Nov 2022 // Built from the K. Goba double precision files. // Data types float precision, funtion unchanged, names have added 'f' +// Added azimuth calculations Bob 14 Nov 2022 const float32_t EARTH_RAD = 6371.0f; //radius in km float32_t Latitude, Longitude; @@ -21,11 +22,28 @@ float32_t Target_Distancef(char target[]) { process_locator(target); Target_Latitude = Latitude; Target_Longitude = Longitude; - targetDistance = distancef((float32_t)Station_Latitude, (float32_t)Station_Longitude, - (float32_t)Target_Latitude, (float32_t)Target_Longitude); + targetDistance = distancef(Station_Latitude, Station_Longitude, + Target_Latitude, Target_Longitude); return targetDistance; } +// Azimuth added 14 Nov 2022 - This duplicates some of the calculations in distance +// but the number of targets this is run on is small, so won't restructure. +float32_t Target_Azimuthf(char target[]) { + float32_t targetAz; + float d2r = 0.017453292f; + process_locator(target); + Target_Latitude = Latitude; + Target_Longitude = Longitude; + float32_t y = sinf(d2r*(Target_Longitude - Station_Longitude)) * cosf(Target_Latitude*d2r); + float32_t x = cosf(Station_Latitude*d2r) * sinf(Target_Latitude*d2r) - + sinf(Station_Latitude*d2r) * cosf(Target_Latitude*d2r) * cosf(d2r*(Target_Longitude - Station_Longitude)); + targetAz = 57.2957795f*atan2f(y, x); + if(targetAz<0.0f) + targetAz += 360.0f; + return targetAz; +} + void process_locator(char locator[]) { uint8_t A1, A2, N1, N2; uint8_t A1_value, A2_value, N1_value, N2_value;