NASA Astrobee Robot Software  0.19.1
Flight software for the Astrobee robots operating inside the International Space Station.
single_measurement_based_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 
19 #ifndef FACTOR_ADDERS_SINGLE_MEASUREMENT_BASED_FACTOR_ADDER_H_
20 #define FACTOR_ADDERS_SINGLE_MEASUREMENT_BASED_FACTOR_ADDER_H_
21 
23 
24 namespace factor_adders {
25 template <typename MeasurementType>
26 // MeasurementBasedFactorAdder that adds factors using single measurements at a time
27 // for measurements in a provided time range.
29  public:
31  virtual ~SingleMeasurementBasedFactorAdder() = default;
32 
33  private:
34  // Add factors for all measurements in valid time range to existing factor graph.
35  // Calls AddFactors(measurement) for each measurement in range.
36  // Subsequently removes measurements that are addable (for example, if a corresponding
37  // node adder can create a node at it's timestamp) as determined by CanAddFactor().
38  // Returns number of added factors.
39  int AddMeasurementBasedFactors(const localization_common::Time oldest_allowed_time,
40  const localization_common::Time newest_allowed_time,
41  gtsam::NonlinearFactorGraph& factors) final;
42 
43  // Add factors given a single measurement.
44  // Returns number of added factors.
45  virtual int AddFactorsForSingleMeasurement(const MeasurementType& measurement,
46  gtsam::NonlinearFactorGraph& factors) = 0;
47 
48  // Whether a factor can be added for the given measurement.
49  virtual bool CanAddFactor(const MeasurementType& measurement) const = 0;
50 
51  // Serialization function
52  friend class boost::serialization::access;
53  template <class Archive>
54  void serialize(Archive& ar, const unsigned int file_version) {
55  ar& BOOST_SERIALIZATION_BASE_OBJECT_NVP(MeasurementBasedFactorAdder<MeasurementType>);
56  }
57 };
58 
59 // Implementation
60 template <typename MeasurementType>
62  : MeasurementBasedFactorAdder<MeasurementType>(params) {}
63 
64 template <typename MeasurementType>
66  const localization_common::Time oldest_allowed_time, const localization_common::Time newest_allowed_time,
67  gtsam::NonlinearFactorGraph& factors) {
68  int num_added_factors = 0;
69  this->ProcessMeasurements(
70  oldest_allowed_time, newest_allowed_time,
71  [this, &num_added_factors](const MeasurementType& measurement, gtsam::NonlinearFactorGraph& factors) {
72  if (!CanAddFactor(measurement)) return false;
73  num_added_factors += AddFactorsForSingleMeasurement(measurement, factors);
74  return true;
75  },
76  factors);
77  return num_added_factors;
78 }
79 } // namespace factor_adders
80 
81 #endif // FACTOR_ADDERS_SINGLE_MEASUREMENT_BASED_FACTOR_ADDER_H_
factor_adders::SingleMeasurementBasedFactorAdder
Definition: single_measurement_based_factor_adder.h:28
factor_adders::SingleMeasurementBasedFactorAdder::SingleMeasurementBasedFactorAdder
SingleMeasurementBasedFactorAdder(const FactorAdderParams &params)
Definition: single_measurement_based_factor_adder.h:61
measurement_based_factor_adder.h
factor_adders::FactorAdderParams
Definition: factor_adder_params.h:23
factor_adders::SingleMeasurementBasedFactorAdder::~SingleMeasurementBasedFactorAdder
virtual ~SingleMeasurementBasedFactorAdder()=default
factor_adders::MeasurementBasedFactorAdder
Definition: measurement_based_factor_adder.h:29
factor_adders
Definition: depth_odometry_factor_adder.h:31
localization_common::Time
double Time
Definition: time.h:23