PoseJPL.h
Go to the documentation of this file.
1 /*
2  * OpenVINS: An Open Platform for Visual-Inertial Research
3  * Copyright (C) 2018-2023 Patrick Geneva
4  * Copyright (C) 2018-2023 Guoquan Huang
5  * Copyright (C) 2018-2023 OpenVINS Contributors
6  * Copyright (C) 2018-2019 Kevin Eckenhoff
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <https://www.gnu.org/licenses/>.
20  */
21 
22 #ifndef OV_TYPE_TYPE_POSEJPL_H
23 #define OV_TYPE_TYPE_POSEJPL_H
24 
25 #include "JPLQuat.h"
26 #include "Vec.h"
27 #include "utils/quat_ops.h"
28 
29 namespace ov_type {
30 
37 class PoseJPL : public Type {
38 
39 public:
40  PoseJPL() : Type(6) {
41 
42  // Initialize subvariables
43  _q = std::shared_ptr<JPLQuat>(new JPLQuat());
44  _p = std::shared_ptr<Vec>(new Vec(3));
45 
46  // Set our default state value
47  Eigen::Matrix<double, 7, 1> pose0;
48  pose0.setZero();
49  pose0(3) = 1.0;
50  set_value_internal(pose0);
51  set_fej_internal(pose0);
52  }
53 
54  ~PoseJPL() {}
55 
63  void set_local_id(int new_id) override {
64  _id = new_id;
65  _q->set_local_id(new_id);
66  _p->set_local_id(new_id + ((new_id != -1) ? _q->size() : 0));
67  }
68 
74  void update(const Eigen::VectorXd &dx) override {
75 
76  assert(dx.rows() == _size);
77 
78  Eigen::Matrix<double, 7, 1> newX = _value;
79 
80  Eigen::Matrix<double, 4, 1> dq;
81  dq << .5 * dx.block(0, 0, 3, 1), 1.0;
82  dq = ov_core::quatnorm(dq);
83 
84  // Update orientation
85  newX.block(0, 0, 4, 1) = ov_core::quat_multiply(dq, quat());
86 
87  // Update position
88  newX.block(4, 0, 3, 1) += dx.block(3, 0, 3, 1);
89 
90  set_value(newX);
91  }
92 
97  void set_value(const Eigen::MatrixXd &new_value) override { set_value_internal(new_value); }
98 
103  void set_fej(const Eigen::MatrixXd &new_value) override { set_fej_internal(new_value); }
104 
105  std::shared_ptr<Type> clone() override {
106  auto Clone = std::shared_ptr<PoseJPL>(new PoseJPL());
107  Clone->set_value(value());
108  Clone->set_fej(fej());
109  return Clone;
110  }
111 
112  std::shared_ptr<Type> check_if_subvariable(const std::shared_ptr<Type> check) override {
113  if (check == _q) {
114  return _q;
115  } else if (check == _p) {
116  return _p;
117  }
118  return nullptr;
119  }
120 
122  Eigen::Matrix<double, 3, 3> Rot() const { return _q->Rot(); }
123 
125  Eigen::Matrix<double, 3, 3> Rot_fej() const { return _q->Rot_fej(); }
126 
128  Eigen::Matrix<double, 4, 1> quat() const { return _q->value(); }
129 
131  Eigen::Matrix<double, 4, 1> quat_fej() const { return _q->fej(); }
132 
134  Eigen::Matrix<double, 3, 1> pos() const { return _p->value(); }
135 
136  // FEJ position access
137  Eigen::Matrix<double, 3, 1> pos_fej() const { return _p->fej(); }
138 
139  // Quaternion type access
140  std::shared_ptr<JPLQuat> q() { return _q; }
141 
142  // Position type access
143  std::shared_ptr<Vec> p() { return _p; }
144 
145 protected:
147  std::shared_ptr<JPLQuat> _q;
148 
150  std::shared_ptr<Vec> _p;
151 
156  void set_value_internal(const Eigen::MatrixXd &new_value) {
157 
158  assert(new_value.rows() == 7);
159  assert(new_value.cols() == 1);
160 
161  // Set orientation value
162  _q->set_value(new_value.block(0, 0, 4, 1));
163 
164  // Set position value
165  _p->set_value(new_value.block(4, 0, 3, 1));
166 
167  _value = new_value;
168  }
169 
174  void set_fej_internal(const Eigen::MatrixXd &new_value) {
175 
176  assert(new_value.rows() == 7);
177  assert(new_value.cols() == 1);
178 
179  // Set orientation fej value
180  _q->set_fej(new_value.block(0, 0, 4, 1));
181 
182  // Set position fej value
183  _p->set_fej(new_value.block(4, 0, 3, 1));
184 
185  _fej = new_value;
186  }
187 };
188 
189 } // namespace ov_type
190 
191 #endif // OV_TYPE_TYPE_POSEJPL_H
check
ROSCPP_DECL bool check()
ov_type::PoseJPL::check_if_subvariable
std::shared_ptr< Type > check_if_subvariable(const std::shared_ptr< Type > check) override
Determine if pass variable is a sub-variable.
Definition: PoseJPL.h:112
ov_type::Type::_size
int _size
Dimension of error state.
Definition: Type.h:132
ov_core::quat_multiply
Eigen::Matrix< double, 4, 1 > quat_multiply(const Eigen::Matrix< double, 4, 1 > &q, const Eigen::Matrix< double, 4, 1 > &p)
Multiply two JPL quaternions.
Definition: quat_ops.h:180
ov_type::PoseJPL::clone
std::shared_ptr< Type > clone() override
Create a clone of this variable.
Definition: PoseJPL.h:105
ov_type::PoseJPL::update
void update(const Eigen::VectorXd &dx) override
Update q and p using a the JPLQuat update for orientation and vector update for position.
Definition: PoseJPL.h:74
ov_type::PoseJPL::pos_fej
Eigen::Matrix< double, 3, 1 > pos_fej() const
Definition: PoseJPL.h:137
ov_type::PoseJPL::~PoseJPL
~PoseJPL()
Definition: PoseJPL.h:54
ov_type::PoseJPL::set_fej_internal
void set_fej_internal(const Eigen::MatrixXd &new_value)
Sets the value of the first estimate.
Definition: PoseJPL.h:174
ov_type::PoseJPL::quat
Eigen::Matrix< double, 4, 1 > quat() const
Rotation access as quaternion.
Definition: PoseJPL.h:128
Vec.h
ov_type::PoseJPL::_p
std::shared_ptr< Vec > _p
Subvariable containing position.
Definition: PoseJPL.h:150
JPLQuat.h
ov_type::Type::_id
int _id
Location of error state in covariance.
Definition: Type.h:129
ov_type::Type::value
virtual const Eigen::MatrixXd & value() const
Access variable's estimate.
Definition: Type.h:79
ov_type::PoseJPL::set_local_id
void set_local_id(int new_id) override
Sets id used to track location of variable in the filter covariance.
Definition: PoseJPL.h:63
ov_type::JPLQuat
Derived Type class that implements JPL quaternion.
Definition: JPLQuat.h:92
ov_type::PoseJPL::set_value
void set_value(const Eigen::MatrixXd &new_value) override
Sets the value of the estimate.
Definition: PoseJPL.h:97
ov_type::PoseJPL::set_value_internal
void set_value_internal(const Eigen::MatrixXd &new_value)
Sets the value of the estimate.
Definition: PoseJPL.h:156
ov_type::PoseJPL::Rot_fej
Eigen::Matrix< double, 3, 3 > Rot_fej() const
FEJ Rotation access.
Definition: PoseJPL.h:125
ov_type::PoseJPL::Rot
Eigen::Matrix< double, 3, 3 > Rot() const
Rotation access.
Definition: PoseJPL.h:122
ov_type::PoseJPL::PoseJPL
PoseJPL()
Definition: PoseJPL.h:40
ov_type::PoseJPL::quat_fej
Eigen::Matrix< double, 4, 1 > quat_fej() const
FEJ Rotation access as quaternion.
Definition: PoseJPL.h:131
ov_type::PoseJPL::set_fej
void set_fej(const Eigen::MatrixXd &new_value) override
Sets the value of the first estimate.
Definition: PoseJPL.h:103
ov_type::PoseJPL::p
std::shared_ptr< Vec > p()
Definition: PoseJPL.h:143
ov_type
Dynamic type system types.
ov_core::quatnorm
Eigen::Matrix< double, 4, 1 > quatnorm(Eigen::Matrix< double, 4, 1 > q_t)
Normalizes a quaternion to make sure it is unit norm.
Definition: quat_ops.h:496
ov_type::PoseJPL::q
std::shared_ptr< JPLQuat > q()
Definition: PoseJPL.h:140
ov_type::PoseJPL
Derived Type class that implements a 6 d.o.f pose.
Definition: PoseJPL.h:37
ov_type::PoseJPL::pos
Eigen::Matrix< double, 3, 1 > pos() const
Position access.
Definition: PoseJPL.h:134
ov_type::Type::fej
virtual const Eigen::MatrixXd & fej() const
Access variable's first-estimate.
Definition: Type.h:84
ov_type::Type::_fej
Eigen::MatrixXd _fej
First-estimate.
Definition: Type.h:123
ov_type::Type::_value
Eigen::MatrixXd _value
Current best estimate.
Definition: Type.h:126
quat_ops.h
ov_type::PoseJPL::_q
std::shared_ptr< JPLQuat > _q
Subvariable containing orientation.
Definition: PoseJPL.h:147
ov_type::Vec
Derived Type class that implements vector variables.
Definition: Vec.h:32
ov_type::Type
Base class for estimated variables.
Definition: Type.h:37


ov_core
Author(s): Patrick Geneva , Kevin Eckenhoff , Guoquan Huang
autogenerated on Mon Jan 22 2024 03:08:17