-
-
Save JoshuaGross/18ec9b0d10b858c352ef0651d5bd04a2 to your computer and use it in GitHub Desktop.
single diff measurement question (intersection of two structs via prns)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Compiles with gcc -O0 sdiff_empty.c | |
// After running your sdiff function once, it will run | |
// a second time on canned data and compare your results with | |
// known outputs. | |
#include <stdint.h> | |
#include <stdbool.h> | |
#include <string.h> | |
#include <stdio.h> | |
#include <inttypes.h> | |
#include <assert.h> | |
#include <stdlib.h> | |
// Note: this is a bad thing to do generally. | |
// http://stackoverflow.com/questions/3437404/min-and-max-in-c | |
#define MIN(X, Y) (((X) < (Y)) ? (X) : (Y)) | |
typedef uint8_t u8; | |
typedef uint16_t u16; | |
typedef struct { | |
double pseudorange; | |
double carrier_phase; | |
double doppler; | |
double snr; | |
u8 prn; | |
} navigation_measurement_t; | |
typedef struct { | |
double pseudorange; | |
double carrier_phase; | |
double doppler; | |
double snr; | |
u8 prn; | |
} sdiff_t; | |
/** Given given two lists of undifferenced input observations | |
* (navigation_measurement_t), nav_meas_1 and nav_meas_2, | |
* constructs the pseudorange, carrier_phase, and | |
* Doppler sdiffs (single difference observations) using the | |
* intersection of their PRNs. | |
* | |
* Also: | |
* 0. SNR in the output is the min of the SNRs of inputs 1 and 2. | |
* 1. `sat_pos` and `sat_vel` are taken from input 1. | |
* | |
* Returns the number of sdiffs in the intersection. | |
* | |
* \param nav_meas1_len Number of measurements in `nav_meas1` | |
* \oaram nav_meas1 Array of undifferenced observations | |
* \param nav_meas2_len Number of measurements in `nav_meas2` | |
* \oaram nav_meas2 Array of navigation measurements | |
* \param sdiff Single difference observations | |
* | |
* \return The number of observations written to `sdiff` | |
* | |
*/ | |
u8 single_diff(u8 nav_meas1_len, | |
navigation_measurement_t *nav_meas1, | |
u8 nav_meas2_len, | |
navigation_measurement_t *nav_meas2, | |
sdiff_t *sdiff) | |
{ | |
return 0; | |
} | |
int sdiff_test() { | |
// Canned measurements | |
navigation_measurement_t nm1_1 = {.pseudorange=21930242.933, .carrier_phase=115244233.296, .doppler=2641.315, .snr=48.0, .prn = 1}; | |
navigation_measurement_t nm2_1 = {.pseudorange=24028321.892, .carrier_phase=126269694.559, .doppler=2702.496, .snr=42.0, .prn = 2}; | |
navigation_measurement_t nm1_2 = {.pseudorange=21493600.745, .carrier_phase=127759979.261, .doppler=-3919.584, .snr=44.5, .prn = 1}; | |
navigation_measurement_t nm2_2 = {.pseudorange=28739156.033, .carrier_phase=1035750093.894, .doppler=-1162.682, .snr=41.5, .prn = 4}; | |
// Array of measurements. | |
navigation_measurement_t nms_no_match1[2]; | |
navigation_measurement_t nms_no_match2[2]; | |
// Single differences | |
sdiff_t sds_out[3]; | |
memcpy(&nms_no_match1[0], &nm1_1, sizeof(navigation_measurement_t)); | |
memcpy(&nms_no_match1[1], &nm2_1, sizeof(navigation_measurement_t)); | |
memcpy(&nms_no_match2[0], &nm1_2, sizeof(navigation_measurement_t)); | |
memcpy(&nms_no_match2[1], &nm2_2, sizeof(navigation_measurement_t)); | |
u8 num_match = single_diff(2, nms_no_match1, | |
2, nms_no_match2, | |
sds_out); | |
assert(num_match == 1); | |
assert(sds_out[0].prn == 1); | |
assert((sds_out[0].pseudorange - 436642.188000) < 0.00000001); | |
assert((sds_out[0].carrier_phase + 12515745.965000) < 0.00000001); | |
assert((sds_out[0].carrier_phase - 6560.899000) < 0.00000001); | |
return num_match; | |
} | |
int main() { | |
// Canned measurements | |
navigation_measurement_t nm1_1 = {.pseudorange=21930242.933, .carrier_phase=115244233.296, .doppler=2641.315, .snr=48.0, .prn = 1}; | |
navigation_measurement_t nm2_1 = {.pseudorange=24028321.892, .carrier_phase=126269694.559, .doppler=2702.496, .snr=42.0, .prn = 2}; | |
navigation_measurement_t nm1_2 = {.pseudorange=21493600.745, .carrier_phase=127759979.261, .doppler=-3919.584, .snr=44.5, .prn = 1}; | |
navigation_measurement_t nm2_2 = {.pseudorange=28739156.033, .carrier_phase=1035750093.894, .doppler=-1162.682, .snr=41.5, .prn = 4}; | |
// Array of measurements. | |
navigation_measurement_t nms_no_match1[2]; | |
navigation_measurement_t nms_no_match2[2]; | |
// Single differences | |
sdiff_t sds_out[3]; | |
memcpy(&nms_no_match1[0], &nm1_1, sizeof(navigation_measurement_t)); | |
memcpy(&nms_no_match1[1], &nm2_1, sizeof(navigation_measurement_t)); | |
memcpy(&nms_no_match2[0], &nm1_2, sizeof(navigation_measurement_t)); | |
memcpy(&nms_no_match2[1], &nm2_2, sizeof(navigation_measurement_t)); | |
u8 num_match = single_diff(2, nms_no_match1, | |
2, nms_no_match2, | |
sds_out); | |
printf("%d\n", num_match); | |
// Validate that it works | |
sdiff_test(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment