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

Add extrapolated prediction to drift compensation #1184

Merged
merged 7 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions gui/public/i18n/en/translation.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,12 @@ settings-general-tracker_mechanics-drift_compensation-description =
Compensates IMU yaw drift by applying an inverse rotation.
Change amount of compensation and up to how many resets are taken into account.
settings-general-tracker_mechanics-drift_compensation-enabled-label = Drift compensation
settings-general-tracker_mechanics-drift_compensation-prediction = Drift compensation prediction
# This cares about multilines
settings-general-tracker_mechanics-drift_compensation-prediction-description =
Predicts yaw drift compensation beyond previously measured range.
Enable this if the tracker is continuously spinning on yaw axis.
settings-general-tracker_mechanics-drift_compensation-prediction-label = Drift compensation prediction
settings-general-tracker_mechanics-drift_compensation-amount-label = Compensation amount
settings-general-tracker_mechanics-drift_compensation-max_resets-label = Use up to x last resets
settings-general-tracker_mechanics-save_mounting_reset = Save automatic mounting reset calibration
Expand Down
30 changes: 30 additions & 0 deletions gui/src/components/settings/pages/GeneralSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ interface SettingsForm {
};
driftCompensation: {
enabled: boolean;
prediction: boolean;
amount: number;
maxResets: number;
};
Expand Down Expand Up @@ -138,6 +139,7 @@ const defaultValues: SettingsForm = {
filtering: { amount: 0.1, type: FilteringType.NONE },
driftCompensation: {
enabled: false,
prediction: false,
amount: 0.1,
maxResets: 1,
},
Expand Down Expand Up @@ -282,6 +284,7 @@ export function GeneralSettings() {

const driftCompensation = new DriftCompensationSettingsT();
driftCompensation.enabled = values.driftCompensation.enabled;
driftCompensation.prediction = values.driftCompensation.prediction;
driftCompensation.amount = values.driftCompensation.amount;
driftCompensation.maxResets = values.driftCompensation.maxResets;
settings.driftCompensation = driftCompensation;
Expand Down Expand Up @@ -698,6 +701,33 @@ export function GeneralSettings() {
'settings-general-tracker_mechanics-drift_compensation-enabled-label'
)}
/>
<div className="flex flex-col pt-2 pb-4"></div>
<Typography bold>
{l10n.getString(
'settings-general-tracker_mechanics-drift_compensation-prediction'
)}
</Typography>
<div className="flex flex-col pt-2 pb-4">
{l10n
.getString(
'settings-general-tracker_mechanics-drift_compensation-prediction-description'
)
.split('\n')
.map((line, i) => (
<Typography color="secondary" key={i}>
{line}
</Typography>
))}
</div>
<CheckBox
variant="toggle"
outlined
control={control}
name="driftCompensation.prediction"
label={l10n.getString(
'settings-general-tracker_mechanics-drift_compensation-prediction-label'
)}
/>
<div className="flex gap-5 pt-5 md:flex-row flex-col">
<NumberSelector
control={control}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ class DriftCompensationConfig {
// Is drift compensation enabled
var enabled = false

// Is drift prediction enabled
var prediction = false

// Amount of drift compensation applied
var amount = 0.8f

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ public static int createDriftCompensationSettings(
.createDriftCompensationSettings(
fbb,
driftCompensationConfig.getEnabled(),
driftCompensationConfig.getPrediction(),
driftCompensationConfig.getAmount(),
driftCompensationConfig.getMaxResets()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class RPCSettingsHandler(var rpcHandler: RPCHandler, var api: ProtocolAPI) {
.vrConfig
.driftCompensation
driftCompensationConfig.enabled = req.driftCompensation().enabled()
driftCompensationConfig.prediction = req.driftCompensation().prediction()
driftCompensationConfig.amount = req.driftCompensation().amount()
driftCompensationConfig.maxResets = req.driftCompensation().maxResets()
driftCompensationConfig.updateTrackersDriftCompensation()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class TrackerResetsHandler(val tracker: Tracker) {
private var driftSince: Long = 0
private var timeAtLastReset: Long = 0
private var compensateDrift = false
private var driftPrediction = false
private var driftCompensationEnabled = false
private var resetMountingFeet = false
private var armsResetMode = ArmsResetModes.BACK
Expand Down Expand Up @@ -78,6 +79,7 @@ class TrackerResetsHandler(val tracker: Tracker) {
*/
fun readDriftCompensationConfig(config: DriftCompensationConfig) {
compensateDrift = config.enabled
driftPrediction = config.prediction
driftAmount = config.amount
val maxResets = config.maxResets

Expand Down Expand Up @@ -186,11 +188,11 @@ class TrackerResetsHandler(val tracker: Tracker) {
*/
private fun adjustToDrift(rotation: Quaternion): Quaternion {
if (driftCompensationEnabled && totalDriftTime > 0) {
return rotation
.interpR(
averagedDriftQuat * rotation,
driftAmount * ((System.currentTimeMillis() - driftSince).toFloat() / totalDriftTime),
)
var driftTimeRatio = ((System.currentTimeMillis() - driftSince).toFloat() / totalDriftTime)
if (!driftPrediction) {
driftTimeRatio = min(1.0f, driftTimeRatio)
}
return averagedDriftQuat.pow(driftAmount * driftTimeRatio) * rotation
}
return rotation
}
Expand Down