Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ba8f50eb authored by Ytai Ben-tsvi's avatar Ytai Ben-tsvi Committed by Android (Google) Code Review
Browse files

Merge changes I7dda8dd1,I50ad8f53

* changes:
  Small fix of parsing head tracker sensors
  Remove drift compensator
parents 0fe05c41 27bbea37
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@ cc_library {
      "HeadTrackingProcessor.cpp",
      "ModeSelector.cpp",
      "Pose.cpp",
      "PoseBias.cpp",
      "PoseDriftCompensator.cpp",
      "PoseRateLimiter.cpp",
      "QuaternionUtil.cpp",
@@ -67,6 +68,7 @@ cc_test_host {
        "HeadTrackingProcessor-test.cpp",
        "ModeSelector-test.cpp",
        "Pose-test.cpp",
        "PoseBias-test.cpp",
        "PoseDriftCompensator-test.cpp",
        "PoseRateLimiter-test.cpp",
        "QuaternionUtil-test.cpp",
+10 −18
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@
#include "media/HeadTrackingProcessor.h"

#include "ModeSelector.h"
#include "PoseDriftCompensator.h"
#include "PoseBias.h"
#include "QuaternionUtil.h"
#include "ScreenHeadFusion.h"
#include "StillnessDetector.h"
@@ -33,14 +33,6 @@ class HeadTrackingProcessorImpl : public HeadTrackingProcessor {
  public:
    HeadTrackingProcessorImpl(const Options& options, HeadTrackingMode initialMode)
        : mOptions(options),
          mHeadPoseDriftCompensator(PoseDriftCompensator::Options{
                  .translationalDriftTimeConstant = options.translationalDriftTimeConstant,
                  .rotationalDriftTimeConstant = options.rotationalDriftTimeConstant,
          }),
          mScreenPoseDriftCompensator(PoseDriftCompensator::Options{
                  .translationalDriftTimeConstant = options.translationalDriftTimeConstant,
                  .rotationalDriftTimeConstant = options.rotationalDriftTimeConstant,
          }),
          mHeadStillnessDetector(StillnessDetector::Options{
                  .defaultValue = false,
                  .windowDuration = options.autoRecenterWindowDuration,
@@ -65,7 +57,7 @@ class HeadTrackingProcessorImpl : public HeadTrackingProcessor {
                            const Twist3f& headTwist) override {
        Pose3f predictedWorldToHead =
                worldToHead * integrate(headTwist, mOptions.predictionDuration);
        mHeadPoseDriftCompensator.setInput(timestamp, predictedWorldToHead);
        mHeadPoseBias.setInput(predictedWorldToHead);
        mHeadStillnessDetector.setInput(timestamp, predictedWorldToHead);
        mWorldToHeadTimestamp = timestamp;
    }
@@ -78,7 +70,7 @@ class HeadTrackingProcessorImpl : public HeadTrackingProcessor {
        }

        Pose3f worldToLogicalScreen = worldToScreen * Pose3f(rotateY(-mPhysicalToLogicalAngle));
        mScreenPoseDriftCompensator.setInput(timestamp, worldToLogicalScreen);
        mScreenPoseBias.setInput(worldToLogicalScreen);
        mScreenStillnessDetector.setInput(timestamp, worldToLogicalScreen);
        mWorldToScreenTimestamp = timestamp;
    }
@@ -94,7 +86,7 @@ class HeadTrackingProcessorImpl : public HeadTrackingProcessor {
    void calculate(int64_t timestamp) override {
        // Handle the screen first, since it might trigger a recentering of the head.
        if (mWorldToScreenTimestamp.has_value()) {
            const Pose3f worldToLogicalScreen = mScreenPoseDriftCompensator.getOutput();
            const Pose3f worldToLogicalScreen = mScreenPoseBias.getOutput();
            bool screenStable = mScreenStillnessDetector.calculate(timestamp);
            mModeSelector.setScreenStable(mWorldToScreenTimestamp.value(), screenStable);
            // Whenever the screen is unstable, recenter the head pose.
@@ -107,11 +99,11 @@ class HeadTrackingProcessorImpl : public HeadTrackingProcessor {

        // Handle head.
        if (mWorldToHeadTimestamp.has_value()) {
            Pose3f worldToHead = mHeadPoseDriftCompensator.getOutput();
            Pose3f worldToHead = mHeadPoseBias.getOutput();
            // Auto-recenter.
            if (mHeadStillnessDetector.calculate(timestamp)) {
                recenter(true, false);
                worldToHead = mHeadPoseDriftCompensator.getOutput();
                worldToHead = mHeadPoseBias.getOutput();
            }

            mScreenHeadFusion.setWorldToHeadPose(mWorldToHeadTimestamp.value(), worldToHead);
@@ -142,11 +134,11 @@ class HeadTrackingProcessorImpl : public HeadTrackingProcessor {

    void recenter(bool recenterHead, bool recenterScreen) override {
        if (recenterHead) {
            mHeadPoseDriftCompensator.recenter();
            mHeadPoseBias.recenter();
            mHeadStillnessDetector.reset();
        }
        if (recenterScreen) {
            mScreenPoseDriftCompensator.recenter();
            mScreenPoseBias.recenter();
            mScreenStillnessDetector.reset();
        }

@@ -169,8 +161,8 @@ class HeadTrackingProcessorImpl : public HeadTrackingProcessor {
    std::optional<int64_t> mWorldToHeadTimestamp;
    std::optional<int64_t> mWorldToScreenTimestamp;
    Pose3f mHeadToStagePose;
    PoseDriftCompensator mHeadPoseDriftCompensator;
    PoseDriftCompensator mScreenPoseDriftCompensator;
    PoseBias mHeadPoseBias;
    PoseBias mScreenPoseBias;
    StillnessDetector mHeadStillnessDetector;
    StillnessDetector mScreenStillnessDetector;
    ScreenHeadFusion mScreenHeadFusion;
+52 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <gtest/gtest.h>

#include "PoseBias.h"
#include "QuaternionUtil.h"
#include "TestUtil.h"

namespace android {
namespace media {
namespace {

using Eigen::Quaternionf;
using Eigen::Vector3f;

TEST(PoseBias, Initial) {
    PoseBias bias;
    EXPECT_EQ(bias.getOutput(), Pose3f());
}

TEST(PoseBias, Basic) {
    Pose3f pose1({1, 2, 3}, Quaternionf::UnitRandom());
    Pose3f pose2({4, 5, 6}, Quaternionf::UnitRandom());

    PoseBias bias;
    bias.setInput(pose1);
    EXPECT_EQ(pose1, bias.getOutput());
    bias.recenter();
    EXPECT_EQ(bias.getOutput(), Pose3f());
    bias.setInput(pose2);
    EXPECT_EQ(bias.getOutput(), pose1.inverse() * pose2);
    bias.recenter();
    EXPECT_EQ(bias.getOutput(), Pose3f());
}

}  // namespace
}  // namespace media
}  // namespace android
+35 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License"){}
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "PoseBias.h"

namespace android {
namespace media {

void PoseBias::setInput(const Pose3f& input) {
    mLastWorldToInput = input;
}

void PoseBias::recenter() {
    mBiasToWorld = mLastWorldToInput.inverse();
}

Pose3f PoseBias::getOutput() const {
    return mBiasToWorld * mLastWorldToInput;
}

}  // namespace media
}  // namespace android
+60 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#pragma once

#include "media/Pose.h"

namespace android {
namespace media {

/**
 * Biasing for a stream of poses.
 *
 * This filter takes a stream of poses and at any time during the stream, can change the frame of
 * reference for the stream to be that of the last pose received, via the recenter() operation.
 *
 * Typical usage:
 * PoseBias bias;
 *
 * bias.setInput(...);
 * output = bias.getOutput();
 * bias.setInput(...);
 * output = bias.getOutput();
 * bias.setInput(...);
 * output = bias.getOutput();
 * bias.recenter();  // Reference frame is now equal to the last input.
 * output = bias.getOutput();  // This is now the identity pose.
 *
 * There doesn't need to be a 1:1 correspondence between setInput() and getOutput() calls.
 * The initial bias point is identity.
 *
 * This implementation is thread-compatible, but not thread-safe.
 */
class PoseBias {
  public:
    void setInput(const Pose3f& input);

    void recenter();

    Pose3f getOutput() const;

  private:
    Pose3f mLastWorldToInput;
    Pose3f mBiasToWorld;
};

}  // namespace media
}  // namespace android
Loading