Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix getRangingResult to properly account for signed numbers #1206

Merged
merged 1 commit into from
Sep 7, 2024

Conversation

Jorropo
Copy link
Contributor

@Jorropo Jorropo commented Sep 7, 2024

I got numbers like this as I approached the slave (raw values before converting to meters):

Ranged: 8
Ranged: 6
Ranged: 3
Ranged: 3
Ranged: 5
Ranged: 5
Ranged: 5
Ranged: 6
Ranged: 1
Ranged: 1
Ranged: 800000
Ranged: 800003
Ranged: 800003

This is because the ToF becomes smaller than the correction factor resulting in a negative number.

This patch performs Sign Extension from 24bits to 32bits. This result in returning a negative meter value which makes more sense than an impossibly big one.

I got numbers like this as I approached the slave (raw values before converting to meters):
```
Ranged: 8
Ranged: 6
Ranged: 3
Ranged: 3
Ranged: 5
Ranged: 5
Ranged: 5
Ranged: 6
Ranged: 1
Ranged: 1
Ranged: 800000
Ranged: 800003
Ranged: 800003
```

This is because the ToF becomes smaller than the correction factor resulting in a negative number.

This patch performs Sign Extension from 24bits to 32bits.
This result in returning a negative meter value which makes more sense than an impossibly big one.
@Jorropo Jorropo force-pushed the fix-signed-ranging-result branch from 893ba38 to 951bfc0 Compare September 7, 2024 04:25
@Jorropo
Copy link
Contributor Author

Jorropo commented Sep 7, 2024

This could also happen if your ToF beacon time travel from the future. Altho I lack the hardware to test this properly.

@jgromes jgromes merged commit 885a921 into jgromes:master Sep 7, 2024
30 checks passed
@jgromes
Copy link
Owner

jgromes commented Sep 7, 2024

Looks good - merged, thank you for the contribution!

This could also happen if your ToF beacon time travel from the future. Altho I lack the hardware to test this properly.

True, but I do not think we should we should be too worried about handling the presumably rare cases when the SX128x device doing the ranging is moving at superluminal speeds :)

@Jorropo Jorropo deleted the fix-signed-ranging-result branch September 7, 2024 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants