Autoware.Auto
linear_measurement.hpp
Go to the documentation of this file.
1 // Copyright 2021 Apex.AI, Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //    http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 //
15 // Co-developed by Tier IV, Inc. and Apex.AI, Inc.
16 
17 
18 #ifndef STATE_ESTIMATION__MEASUREMENT__LINEAR_MEASUREMENT_HPP_
19 #define STATE_ESTIMATION__MEASUREMENT__LINEAR_MEASUREMENT_HPP_
20 
21 #include <common/type_traits.hpp>
23 
24 #include <Eigen/Core>
25 
26 #include <chrono>
27 #include <tuple>
28 
29 namespace autoware
30 {
31 namespace common
32 {
33 namespace state_estimation
34 {
35 
45 template<typename StateT>
46 class STATE_ESTIMATION_PUBLIC LinearMeasurement
47  : public MeasurementInterface<LinearMeasurement<StateT>>
48 {
49  template<typename OtherStateT>
50  using MappingMatrixFrom =
51  Eigen::Matrix<typename StateT::Scalar, StateT::size(), OtherStateT::size()>;
52 
53 public:
54  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
55  using State = StateT;
57  LinearMeasurement() = default;
65  const typename StateT::Vector & measurement,
66  const typename StateT::Matrix & covariance)
67  : m_measurement{measurement},
68  m_covariance{covariance} {}
81  const typename StateT::Vector & measurement,
82  const typename StateT::Vector & standard_deviation)
83  {
84  return LinearMeasurement{measurement,
85  standard_deviation.array().square().matrix().asDiagonal()};
86  }
87 
93  template<typename NewScalarT>
94  auto cast() const noexcept
95  {
96  using NewState = decltype(m_measurement.template cast<NewScalarT>());
98  m_measurement.vector().template cast<NewScalarT>(),
99  m_covariance.template cast<NewScalarT>()
100  };
101  }
102 
103 protected:
104  // Allow the CRTP interface to call private functions from this class.
106 
108  inline StateT & crtp_state() noexcept {return m_measurement;}
110  inline const StateT & crtp_state() const noexcept {return m_measurement;}
112  inline typename StateT::Matrix & crtp_covariance() noexcept {return m_covariance;}
114  inline const typename StateT::Matrix & crtp_covariance() const noexcept {return m_covariance;}
131  template<typename OtherStateT>
132  StateT crtp_create_new_instance_from(const OtherStateT & other_state) const
133  {
134  return other_state.template copy_into<StateT>();
135  }
147  template<typename OtherStateT>
148  OtherStateT crtp_map_into(const OtherStateT & other_state) const noexcept
149  {
150  return m_measurement.copy_into(other_state);
151  }
166  template<typename OtherStateT>
167  MappingMatrixFrom<OtherStateT> crtp_mapping_matrix_from(const OtherStateT &) const
168  {
169  MappingMatrixFrom<OtherStateT> m{MappingMatrixFrom<OtherStateT>::Zero()};
170  auto fill_mapping_matrix = [&m, this](auto variable) {
171  (void)this; // avoid warning -Wunused-lambda-capture
172  using VariableT = std::decay_t<decltype(variable)>;
173  constexpr auto index_in_this_state = StateT::template index_of<VariableT>();
174  constexpr auto index_in_other_state = OtherStateT::template index_of<VariableT>();
175  m(index_in_this_state, index_in_other_state) = 1;
176  };
177  using CommonVariablesTuple = typename autoware::common::type_traits::intersect<
178  typename StateT::Variables, typename OtherStateT::Variables>::type;
179  common::type_traits::visit(CommonVariablesTuple{}, fill_mapping_matrix);
180  return m;
181  }
182 
184  friend bool operator==(const LinearMeasurement & lhs, const LinearMeasurement & rhs)
185  {
186  return (lhs.state() == rhs.state()) &&
187  lhs.covariance().isApprox(rhs.covariance());
188  }
189 
190 private:
192  StateT m_measurement{};
194  typename StateT::Matrix m_covariance{StateT::Matrix::Zero()};
195 };
196 
197 } // namespace state_estimation
198 } // namespace common
199 } // namespace autoware
200 
201 #endif // STATE_ESTIMATION__MEASUREMENT__LINEAR_MEASUREMENT_HPP_
autoware::common::state_estimation::LinearMeasurement::crtp_map_into
OtherStateT crtp_map_into(const OtherStateT &other_state) const noexcept
Copy this measurement into another state space.
Definition: linear_measurement.hpp:148
autoware::common::state_estimation::MeasurementInterface::state
auto & state()
Get measurement as a state vector.
Definition: measurement_interface.hpp:42
autoware::common::state_estimation::LinearMeasurement::crtp_state
StateT & crtp_state() noexcept
Get state vector function that is to be called by the CRTP interface.
Definition: linear_measurement.hpp:108
type_traits.hpp
autoware::common::state_estimation::LinearMeasurement::crtp_mapping_matrix_from
MappingMatrixFrom< OtherStateT > crtp_mapping_matrix_from(const OtherStateT &) const
Get the mapping matrix between the two states called by the CRTP interface.
Definition: linear_measurement.hpp:167
autoware::common::state_estimation::LinearMeasurement::crtp_covariance
const StateT::Matrix & crtp_covariance() const noexcept
Get covariance function that is to be called by the CRTP interface.
Definition: linear_measurement.hpp:114
autoware::common::state_estimation::LinearMeasurement::crtp_create_new_instance_from
StateT crtp_create_new_instance_from(const OtherStateT &other_state) const
Create a new instance of the measurement from another state.
Definition: linear_measurement.hpp:132
autoware::common::state_estimation::LinearMeasurement::State
StateT State
Definition: linear_measurement.hpp:55
autoware::common::state_estimation::LinearMeasurement::operator==
friend bool operator==(const LinearMeasurement &lhs, const LinearMeasurement &rhs)
An equality operator.
Definition: linear_measurement.hpp:184
autoware::common::state_estimation::MeasurementInterface
A CRTP interface to any measurement.
Definition: measurement_interface.hpp:39
autoware::common::state_estimation::MeasurementInterface::covariance
auto & covariance()
Get covariance of the measurement as a matrix.
Definition: measurement_interface.hpp:61
autoware::common::state_estimation::LinearMeasurement
A class that represents a linear measurement.
Definition: linear_measurement.hpp:46
autoware
This file defines the lanelet2_map_provider_node class.
Definition: quick_sort.hpp:24
m
OnlineData m
Definition: linear_tire.snippet.hpp:36
autoware::common::state_estimation::LinearMeasurement::crtp_covariance
StateT::Matrix & crtp_covariance() noexcept
Get covariance function that is to be called by the CRTP interface.
Definition: linear_measurement.hpp:112
measurement_interface.hpp
autoware::common::state_estimation::LinearMeasurement::crtp_state
const StateT & crtp_state() const noexcept
Get state vector function that is to be called by the CRTP interface.
Definition: linear_measurement.hpp:110
autoware::common::state_estimation::LinearMeasurement::cast
auto cast() const noexcept
Cast to another scalar type.
Definition: linear_measurement.hpp:94
autoware::common::state_estimation::LinearMeasurement::LinearMeasurement
LinearMeasurement(const typename StateT::Vector &measurement, const typename StateT::Matrix &covariance)
Construct a new instance of the measurement from a state vector.
Definition: linear_measurement.hpp:64
autoware::common::state_estimation::LinearMeasurement::create_with_stddev
static LinearMeasurement create_with_stddev(const typename StateT::Vector &measurement, const typename StateT::Vector &standard_deviation)
Convenience factory function to construct a measurement from a vector of standard deviations.
Definition: linear_measurement.hpp:80
autoware::common::type_traits::intersect
A trait used to intersect types stored in tuples at compile time. The resulting typedef type will hol...
Definition: type_traits.hpp:180
autoware::common::type_traits::visit
constexpr COMMON_PUBLIC std::enable_if_t< I==sizeof...(TypesT)> visit(std::tuple< TypesT... > &, Callable) noexcept
Visit every element in a tuple.
Definition: type_traits.hpp:80