NASA Astrobee Robot Software  0.19.1
Flight software for the Astrobee robots operating inside the International Space Station.
measurement_based_timestamped_node_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 NODE_ADDERS_MEASUREMENT_BASED_TIMESTAMPED_NODE_ADDER_H_
20 #define NODE_ADDERS_MEASUREMENT_BASED_TIMESTAMPED_NODE_ADDER_H_
21 
24 
25 namespace node_adders {
26 
27 // Timestamped node adder that uses provided measurements to create nodes.
28 template <typename MeasurementType, typename NodeType, typename TimestampedNodesType,
29  typename MeasurementBasedTimestampedNodeAdderModelType>
31  : public TimestampedNodeAdder<NodeType, TimestampedNodesType, MeasurementBasedTimestampedNodeAdderModelType> {
33 
34  public:
36  // Construct using nodes. Creates timestamped nodes interally.
38  const Params& params, const typename MeasurementBasedTimestampedNodeAdderModelType::Params& node_adder_model_params,
39  std::shared_ptr<nodes::Values> values);
40 
41  // Construct using already constructed timestamped nodes.
43  const Params& params, const typename MeasurementBasedTimestampedNodeAdderModelType::Params& node_adder_model_params,
44  std::shared_ptr<TimestampedNodesType> timestamped_nodes);
45 
46  void AddMeasurement(const MeasurementType& measurement);
47 
48  // Removes measurements using oldest_allowed_time. Depending on the measurement type,
49  // the lower bound <= oldest_allowed_time may be kept so it can be used to create
50  // relative factors in the future.
51  void RemoveMeasurements(const localization_common::Time oldest_allowed_time);
52 
53  // Slides window and removes old measurements
54  bool SlideWindow(const localization_common::Time oldest_allowed_timestamp,
55  const boost::optional<const gtsam::Marginals&>& marginals, const gtsam::KeyVector& old_keys,
56  const double huber_k, gtsam::NonlinearFactorGraph& factors) final;
57 
58  private:
59  // Serialization function
61  template <class Archive>
62  void serialize(Archive& ar, const unsigned int file_version) {
63  ar& BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
64  }
65 };
66 
67 // Implementation
68 template <typename MeasurementType, typename NodeType, typename TimestampedNodesType,
69  typename MeasurementBasedTimestampedNodeAdderModelType>
70 MeasurementBasedTimestampedNodeAdder<MeasurementType, NodeType, TimestampedNodesType,
71  MeasurementBasedTimestampedNodeAdderModelType>::
72  MeasurementBasedTimestampedNodeAdder(
73  const Params& params, const typename MeasurementBasedTimestampedNodeAdderModelType::Params& node_adder_model_params,
74  std::shared_ptr<nodes::Values> values)
75  : Base(params, node_adder_model_params, std::move(values)) {}
76 
77 template <typename MeasurementType, typename NodeType, typename TimestampedNodesType,
78  typename MeasurementBasedTimestampedNodeAdderModelType>
79 MeasurementBasedTimestampedNodeAdder<MeasurementType, NodeType, TimestampedNodesType,
80  MeasurementBasedTimestampedNodeAdderModelType>::
81  MeasurementBasedTimestampedNodeAdder(
82  const Params& params, const typename MeasurementBasedTimestampedNodeAdderModelType::Params& node_adder_model_params,
83  std::shared_ptr<TimestampedNodesType> timestamped_nodes)
84  : Base(params, node_adder_model_params, std::move(timestamped_nodes)) {}
85 
86 template <typename MeasurementType, typename NodeType, typename TimestampedNodesType,
87  typename MeasurementBasedTimestampedNodeAdderModelType>
89  MeasurementType, NodeType, TimestampedNodesType,
90  MeasurementBasedTimestampedNodeAdderModelType>::AddMeasurement(const MeasurementType& measurement) {
91  Base::node_adder_model().AddMeasurement(measurement);
92 }
93 
94 template <typename MeasurementType, typename NodeType, typename TimestampedNodesType,
95  typename MeasurementBasedTimestampedNodeAdderModelType>
96 void MeasurementBasedTimestampedNodeAdder<MeasurementType, NodeType, TimestampedNodesType,
97  MeasurementBasedTimestampedNodeAdderModelType>::
98  RemoveMeasurements(const localization_common::Time oldest_allowed_time) {
99  Base::node_adder_model().RemoveMeasurements(oldest_allowed_time);
100 }
101 
102 template <typename MeasurementType, typename NodeType, typename TimestampedNodesType,
103  typename MeasurementBasedTimestampedNodeAdderModelType>
105  MeasurementType, NodeType, TimestampedNodesType,
106  MeasurementBasedTimestampedNodeAdderModelType>::SlideWindow(const localization_common::Time oldest_allowed_timestamp,
107  const boost::optional<const gtsam::Marginals&>& marginals,
108  const gtsam::KeyVector& old_keys, const double huber_k,
109  gtsam::NonlinearFactorGraph& factors) {
110  if (!Base::SlideWindow(oldest_allowed_timestamp, marginals, old_keys, huber_k, factors)) {
111  LogError("Failed to slide window.");
112  return false;
113  }
114  RemoveMeasurements(oldest_allowed_timestamp);
115  return true;
116 }
117 } // namespace node_adders
118 
119 #endif // NODE_ADDERS_MEASUREMENT_BASED_TIMESTAMPED_NODE_ADDER_H_
node_adders::MeasurementBasedTimestampedNodeAdder::AddMeasurement
void AddMeasurement(const MeasurementType &measurement)
Definition: measurement_based_timestamped_node_adder.h:90
node_adders::MeasurementBasedTimestampedNodeAdder
Definition: measurement_based_timestamped_node_adder.h:30
node_adders::MeasurementBasedTimestampedNodeAdder::RemoveMeasurements
void RemoveMeasurements(const localization_common::Time oldest_allowed_time)
Definition: measurement_based_timestamped_node_adder.h:98
LogError
#define LogError(msg)
Definition: logger.h:55
node_adders
Definition: between_factor_node_adder_model.h:35
vive_localization::Params
Params
Definition: vive.h:58
node_adders::MeasurementBasedTimestampedNodeAdder::MeasurementBasedTimestampedNodeAdder
MeasurementBasedTimestampedNodeAdder(const Params &params, const typename MeasurementBasedTimestampedNodeAdderModelType::Params &node_adder_model_params, std::shared_ptr< nodes::Values > values)
Definition: measurement_based_timestamped_node_adder.h:72
std
Definition: tensor.h:39
node_adders::MeasurementBasedTimestampedNodeAdder::access
friend class boost::serialization::access
Definition: measurement_based_timestamped_node_adder.h:60
node_adders::MeasurementBasedTimestampedNodeAdder::SlideWindow
bool SlideWindow(const localization_common::Time oldest_allowed_timestamp, const boost::optional< const gtsam::Marginals & > &marginals, const gtsam::KeyVector &old_keys, const double huber_k, gtsam::NonlinearFactorGraph &factors) final
Definition: measurement_based_timestamped_node_adder.h:106
imu_integration::AddMeasurement
void AddMeasurement(const localization_measurements::ImuMeasurement &imu_measurement, localization_common::Time &last_added_imu_measurement_time, gtsam::PreintegratedCombinedMeasurements &pim)
Definition: utilities.cc:54
timestamped_node_adder.h
node_adders::TimestampedNodeAdderParams
Definition: timestamped_node_adder_params.h:32
localization_common::Time
double Time
Definition: time.h:23
timestamped_node_adder_params.h
node_adders::TimestampedNodeAdder
Definition: timestamped_node_adder.h:37