1 /*
2  * Copyright (C) 2021 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"){}
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "PoseRateLimiter.h"
18 
19 namespace android {
20 namespace media {
21 
PoseRateLimiter(const Options & options)22 PoseRateLimiter::PoseRateLimiter(const Options& options) : mOptions(options), mLimiting(false) {}
23 
enable()24 void PoseRateLimiter::enable() {
25     mLimiting = true;
26 }
27 
reset(const Pose3f & target)28 void PoseRateLimiter::reset(const Pose3f& target) {
29     mLimiting = false;
30     mTargetPose = target;
31 }
32 
setTarget(const Pose3f & target)33 void PoseRateLimiter::setTarget(const Pose3f& target) {
34     mTargetPose = target;
35 }
36 
calculatePose(int64_t timestamp)37 Pose3f PoseRateLimiter::calculatePose(int64_t timestamp) {
38     assert(mTargetPose.has_value());
39     Pose3f pose;
40     if (mLimiting && mOutput.has_value()) {
41         std::tie(pose, mLimiting) = moveWithRateLimit(
42                 mOutput->pose, mTargetPose.value(), timestamp - mOutput->timestamp,
43                 mOptions.maxTranslationalVelocity, mOptions.maxRotationalVelocity);
44     } else {
45         pose = mTargetPose.value();
46     }
47     mOutput = Point{pose, timestamp};
48     return pose;
49 }
50 
51 }  // namespace media
52 }  // namespace android
53