Huh / collar

Utilities for exploring telemetry data
Other
7 stars 9 forks source link

Fix status from Lotek #87

Open JessKLockhart opened 3 months ago

JessKLockhart commented 3 months ago

I'm wondering if it's possible to obtain the fix status (i.e. 2D, 3D, etc) from lotek's collar download metadata with this package? I've been using the fetch_lotek_positions function and noticed that the fix status is missing, but I think this is an important field to include.

Thanks!

ericnewkirk commented 3 months ago

Thanks @JessKLockhart for the suggestion, but I'm not sure that's possible. fetch_lotek_positions returns all the columns provided by Lotek's API, so if fix type is missing there it means Lotek didn't provide it in the response to the API call. Unfortunately that API isn't well documented, and we don't have any clear explanation of what the columns and values within them mean. I looked into whether RxStatus or FixType in the output correspond to 2D/3D briefly this morning, but I didn't get all that far. I'm a little concerned the values in those columns may depend on the model of collar and settings, too.

If you can figure out how to translate the integer values in either of those fields to their text equivalents I'd be happy to update the code. It looks like there's a bug in that function that needs to be fixed anyway.

JessKLockhart commented 3 months ago

Thanks @ericnewkirk. I'll see what I can find in terms of figuring out what the integer values for those fields actually mean. Will keep you posted.

JessKLockhart commented 3 months ago

Hi again,

I connected with Lotek and they informed me that the Fix status is actually encoded into the 'RxStatus' field using binary to decimal. They sent me the manual, attached, which explains the conversion. They also sent a function that does the conversion (see below). Are you able to include this in the collar package? Thanks!

parse_RxStatus <- Vectorize( function(x){ binary <- decimal2binary(x, length = 7)

Binary is read right to left. The fix strategy is stored in the last two digits.

fix_strategy <- binary2decimal(binary[5:7])

# satellites
satellites <- binary2decimal(binary[1:4])

fix_type <- case_when(
  fix_strategy == 0 ~ "No Fix", # 1 = no fix
  fix_strategy == 1 ~ "1 SV KF",
  fix_strategy == 2 ~ "2 SV KF",
  fix_strategy == 3 ~ "3 SV KF",
  fix_strategy == 4 ~ "4 or more SV KF",
  fix_strategy == 5 ~ "2-D least squares",
  fix_strategy == 6 ~ "3-D least squares",
  fix_strategy == 7 ~ "Dead Reckoning")

return(paste0(fix_type, ", ", satellites, "SVs"))}

)

Web-Service-API-User-Manual.pdf

ericnewkirk commented 3 months ago

Thanks @JessKLockhart! The manual is super helpful, and a lot better than what we had available when the Lotek functions were originally written. I will probably rewrite the conversion code to streamline it a bit and make sure it works for all Lotek devices, but that should be quick.

JessKLockhart commented 3 months ago

Great! Thanks @ericnewkirk!