NASA Astrobee Robot Software  0.19.1
Flight software for the Astrobee robots operating inside the International Space Station.
relative_pose_factor_adder.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 #ifndef FACTOR_ADDERS_RELATIVE_POSE_FACTOR_ADDER_H_
19 #define FACTOR_ADDERS_RELATIVE_POSE_FACTOR_ADDER_H_
20 
25 
26 #include <gtsam/linear/NoiseModel.h>
27 #include <gtsam/slam/BetweenFactor.h>
28 
29 namespace factor_adders {
30 // Adds GTSAM Pose Between factors for relative pose measurements.
31 // Adds pose nodes using PoseNodeAdder at the same timestamps as the measurements.
32 template <class PoseNodeAdderType>
34  : public SingleMeasurementBasedFactorAdder<localization_measurements::RelativePoseWithCovarianceMeasurement> {
35  public:
37  const std::shared_ptr<PoseNodeAdderType> node_adder);
38 
39  private:
40  // Creates a pose between factor and pose nodes for the given measurement.
41  int AddFactorsForSingleMeasurement(
43  gtsam::NonlinearFactorGraph& factors) final;
44 
45  bool CanAddFactor(const localization_measurements::RelativePoseWithCovarianceMeasurement& measurement) const final;
46 
47  std::shared_ptr<PoseNodeAdderType> node_adder_;
49 };
50 
51 template <class PoseNodeAdderType>
53  const std::shared_ptr<PoseNodeAdderType> node_adder)
54  : SingleMeasurementBasedFactorAdder<localization_measurements::RelativePoseWithCovarianceMeasurement>(params),
55  params_(params),
56  node_adder_(node_adder) {}
57 
58 template <class PoseNodeAdderType>
61  gtsam::NonlinearFactorGraph& factors) {
62  if (!node_adder_->AddNode(measurement.timestamp_a, factors) ||
63  !node_adder_->AddNode(measurement.timestamp_b, factors)) {
64  LogError("AddFactorsForSingleMeasurement: Failed to add nodes at respective times.");
65  return 0;
66  }
67 
68  const auto keys_a = node_adder_->Keys(measurement.timestamp_a);
69  // First key is pose key
70  const auto& pose_key_a = keys_a[0];
71  const auto keys_b = node_adder_->Keys(measurement.timestamp_b);
72  const auto& pose_key_b = keys_b[0];
73  const auto relative_pose_noise =
74  gtsam::noiseModel::Gaussian::Covariance(params_.covariance_scale * measurement.covariance);
75  const gtsam::BetweenFactor<gtsam::Pose3>::shared_ptr pose_between_factor(
76  new gtsam::BetweenFactor<gtsam::Pose3>(pose_key_a, pose_key_b, measurement.relative_pose, relative_pose_noise));
77  factors.push_back(pose_between_factor);
78  return 1;
79 }
80 
81 template <class PoseNodeAdderType>
82 bool RelativePoseFactorAdder<PoseNodeAdderType>::CanAddFactor(
84  return node_adder_->CanAddNode(measurement.timestamp_a) && node_adder_->CanAddNode(measurement.timestamp_b);
85 }
86 } // namespace factor_adders
87 
88 #endif // FACTOR_ADDERS_RELATIVE_POSE_FACTOR_ADDER_H_
factor_adders::SingleMeasurementBasedFactorAdder
Definition: single_measurement_based_factor_adder.h:28
node_adders::Covariance
gtsam::Matrix Covariance(const gtsam::SharedNoiseModel &robust_gaussian_noise)
Definition: utilities.cc:22
localization_measurements::RelativePoseWithCovarianceMeasurement
Definition: relative_pose_with_covariance_measurement.h:29
LogError
#define LogError(msg)
Definition: logger.h:55
factor_adders::RelativePoseFactorAdderParams
Definition: relative_pose_factor_adder_params.h:25
localization_measurements::RelativePoseWithCovarianceMeasurement::timestamp_a
localization_common::Time timestamp_a
Definition: relative_pose_with_covariance_measurement.h:40
time.h
localization_measurements
Definition: depth_correspondences.h:25
factor_adders::RelativePoseFactorAdder
Definition: relative_pose_factor_adder.h:33
relative_pose_factor_adder_params.h
factor_adders::RelativePoseFactorAdder::RelativePoseFactorAdder
RelativePoseFactorAdder(const RelativePoseFactorAdderParams &params, const std::shared_ptr< PoseNodeAdderType > node_adder)
Definition: relative_pose_factor_adder.h:52
single_measurement_based_factor_adder.h
factor_adders
Definition: depth_odometry_factor_adder.h:31
relative_pose_with_covariance_measurement.h
localization_measurements::RelativePoseWithCovarianceMeasurement::timestamp_b
localization_common::Time timestamp_b
Definition: relative_pose_with_covariance_measurement.h:41
localization_measurements::RelativePoseWithCovarianceMeasurement::relative_pose
gtsam::Pose3 relative_pose
Definition: relative_pose_with_covariance_measurement.h:38
localization_measurements::RelativePoseWithCovarianceMeasurement::covariance
PoseCovariance covariance
Definition: relative_pose_with_covariance_measurement.h:39