blob: 380e22b35f703b8fd82bda1b7327902a31f22d7a [file] [log] [blame]
Ytai Ben-Tsvicbee7d42021-06-15 00:39:31 -07001/*
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
19namespace android {
20namespace media {
21
22PoseRateLimiter::PoseRateLimiter(const Options& options) : mOptions(options), mLimiting(false) {}
23
24void PoseRateLimiter::enable() {
25 mLimiting = true;
26}
27
28void PoseRateLimiter::reset(const Pose3f& target) {
29 mLimiting = false;
30 mTargetPose = target;
31}
32
33void PoseRateLimiter::setTarget(const Pose3f& target) {
34 mTargetPose = target;
35}
36
37Pose3f 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