NASA Astrobee Robot Software  0.19.1
Flight software for the Astrobee robots operating inside the International Space Station.
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_POSE_FACTOR_ADDER_H_
19 #define FACTOR_ADDERS_POSE_FACTOR_ADDER_H_
20 
25 
26 #include <gtsam/linear/NoiseModel.h>
27 #include <gtsam/slam/PriorFactor.h>
28 
29 namespace factor_adders {
31 
32 // Adds GTSAM Pose Prior factors for absolute pose measurements.
33 // Adds pose nodes using PoseNodeAdder at the same timestamps as the measurements.
34 template <class PoseNodeAdderType>
36  : public SingleMeasurementBasedFactorAdder<localization_measurements::PoseWithCovarianceMeasurement> {
37  public:
38  PoseFactorAdder(const PoseFactorAdderParams& params, const std::shared_ptr<PoseNodeAdderType> node_adder);
39 
40  private:
41  // Creates a pose factor and pose node for the given measurement.
42  int AddFactorsForSingleMeasurement(const localization_measurements::PoseWithCovarianceMeasurement& measurement,
43  gtsam::NonlinearFactorGraph& factors) final;
44 
45  // Able to add a factor if the node adder can create a node for the provided measurement.
46  bool CanAddFactor(const localization_measurements::PoseWithCovarianceMeasurement& measurement) const final;
47 
48  std::shared_ptr<PoseNodeAdderType> node_adder_;
49  PoseFactorAdderParams params_;
50 };
51 
52 template <class PoseNodeAdderType>
54  const std::shared_ptr<PoseNodeAdderType> node_adder)
55  : SingleMeasurementBasedFactorAdder<localization_measurements::PoseWithCovarianceMeasurement>(params),
56  params_(params),
57  node_adder_(node_adder) {}
58 
59 template <class PoseNodeAdderType>
61  const localization_measurements::PoseWithCovarianceMeasurement& measurement, gtsam::NonlinearFactorGraph& factors) {
62  node_adder_->AddNode(measurement.timestamp, factors);
63  const auto keys = node_adder_->Keys(measurement.timestamp);
64  // First key is pose key
65  const auto& pose_key = keys[0];
66  const auto pose_noise = gtsam::noiseModel::Gaussian::Covariance(measurement.covariance);
67  const gtsam::PriorFactor<gtsam::Pose3>::shared_ptr pose_prior_factor(
68  new gtsam::PriorFactor<gtsam::Pose3>(pose_key, measurement.pose, pose_noise));
69  factors.push_back(pose_prior_factor);
70  return 1;
71 }
72 
73 template <class PoseNodeAdderType>
74 bool PoseFactorAdder<PoseNodeAdderType>::CanAddFactor(
76  return node_adder_->CanAddNode(measurement.timestamp);
77 }
78 } // namespace factor_adders
79 
80 #endif // FACTOR_ADDERS_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::PoseWithCovarianceMeasurement::covariance
PoseCovariance covariance
Definition: pose_with_covariance_measurement.h:52
localization_measurements::Measurement::timestamp
localization_common::Time timestamp
Definition: measurement.h:29
factor_adders::PoseFactorAdder::PoseFactorAdder
PoseFactorAdder(const PoseFactorAdderParams &params, const std::shared_ptr< PoseNodeAdderType > node_adder)
Definition: pose_factor_adder.h:53
factor_adders::PoseFactorAdder
Definition: pose_factor_adder.h:35
factor_adders::FactorAdderParams
Definition: factor_adder_params.h:23
time.h
localization_measurements
Definition: depth_correspondences.h:25
localization_measurements::PoseWithCovarianceMeasurement::pose
gtsam::Pose3 pose
Definition: pose_with_covariance_measurement.h:51
single_measurement_based_factor_adder.h
factor_adders
Definition: depth_odometry_factor_adder.h:31
localization_measurements::PoseWithCovarianceMeasurement
Definition: pose_with_covariance_measurement.h:31
pose_node_adder.h
pose_with_covariance_measurement.h