NASA Astrobee Robot Software  0.19.1
Flight software for the Astrobee robots operating inside the International Space Station.
marginals_pose_covariance_interpolater.h
Go to the documentation of this file.
1 /* Copyright (c) 2017, United States Government, as represented by the
2  * Administrator of the National Aeronautics and Space Administration.
3  *
4  * All rights reserved.
5  *
6  * The Astrobee platform is licensed under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with the
8  * License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15  * License for the specific language governing permissions and limitations
16  * under the License.
17  */
18 
19 #ifndef LOCALIZATION_COMMON_MARGINALS_POSE_COVARIANCE_INTERPOLATER_H_
20 #define LOCALIZATION_COMMON_MARGINALS_POSE_COVARIANCE_INTERPOLATER_H_
21 
24 
25 #include <boost/optional.hpp>
26 #include <gtsam/nonlinear/Marginals.h>
27 
28 namespace localization_common {
29 template <typename NodesT>
31  public:
32  MarginalsPoseCovarianceInterpolater(const std::shared_ptr<const NodesT>& nodes,
33  const boost::optional<const gtsam::Marginals&>& marginals = boost::none);
34  PoseCovariance Interpolate(const PoseWithCovariance& a, const PoseWithCovariance& b, const Time& timestamp_a,
35  const Time& timestamp_b) final;
36 
37  private:
38  boost::optional<const gtsam::Marginals&> marginals_;
39  std::shared_ptr<const NodesT> nodes_;
40 };
41 
42 // Implementation
43 template <typename NodesT>
45  const std::shared_ptr<const NodesT>& nodes, const boost::optional<const gtsam::Marginals&>& marginals)
46  : nodes_(nodes), marginals_(marginals) {}
47 
48 template <typename NodesT>
50  const PoseWithCovariance& b,
51  const Time& timestamp_a,
52  const Time& timestamp_b) {
53  boost::optional<PoseCovariance> covariance_a_b;
54  // Set covariance_a_b if available
55  if (marginals_ && nodes_) {
56  const auto closest_t_a = nodes_->ClosestTimestamp(timestamp_a);
57  const auto closest_t_b = nodes_->ClosestTimestamp(timestamp_b);
58  if (!closest_t_a || !closest_t_b) {
59  LogError("Interpolate: Failed to get closest timestamps.");
60  } else {
61  // TODO(rsoussan): Add fallback covariance/relative covariance if gap too large
62  if (std::abs(*closest_t_a - timestamp_a) > 3.0 || std::abs(*closest_t_b - timestamp_b) > 3.0) {
63  LogWarning("Interpolate: Timestamps far from closest timestamps available.");
64  }
65  const auto keys_a = nodes_->Keys(*closest_t_a);
66  const auto keys_b = nodes_->Keys(*closest_t_b);
67  covariance_a_b = marginals_->jointMarginalCovariance({keys_a[0], keys_b[0]}).fullMatrix();
68  }
69  }
70  return RelativePoseCovariance(a, b, covariance_a_b);
71 }
72 } // namespace localization_common
73 
74 #endif // LOCALIZATION_COMMON_MARGINALS_POSE_COVARIANCE_INTERPOLATER_H_
localization_common
Definition: averager.h:33
pose_covariance_interpolater.h
LogError
#define LogError(msg)
Definition: logger.h:55
utilities.h
nodes
Definition: combined_nav_state_nodes.h:24
localization_common::PoseCovariance
Eigen::Matrix< double, 6, 6 > PoseCovariance
Definition: pose_with_covariance.h:27
localization_common::MarginalsPoseCovarianceInterpolater::Interpolate
PoseCovariance Interpolate(const PoseWithCovariance &a, const PoseWithCovariance &b, const Time &timestamp_a, const Time &timestamp_b) final
Definition: marginals_pose_covariance_interpolater.h:49
localization_common::PoseWithCovariance
Definition: pose_with_covariance.h:28
localization_common::RelativePoseCovariance
PoseCovariance RelativePoseCovariance(const PoseWithCovariance &a, const PoseWithCovariance &b, const boost::optional< PoseCovariance > covariance_a_b=boost::none)
Definition: utilities.cc:233
localization_common::MarginalsPoseCovarianceInterpolater::MarginalsPoseCovarianceInterpolater
MarginalsPoseCovarianceInterpolater(const std::shared_ptr< const NodesT > &nodes, const boost::optional< const gtsam::Marginals & > &marginals=boost::none)
Definition: marginals_pose_covariance_interpolater.h:44
localization_common::PoseCovarianceInterpolater
Definition: pose_covariance_interpolater.h:25
LogWarning
#define LogWarning(msg)
Definition: logger.h:48
localization_common::Time
double Time
Definition: time.h:23
localization_common::MarginalsPoseCovarianceInterpolater
Definition: marginals_pose_covariance_interpolater.h:30