small update to types

This commit is contained in:
Vladyslav Usenko 2019-08-07 16:26:13 +02:00
parent 2d21860d5c
commit b3304884c6
1 changed files with 41 additions and 31 deletions

View File

@ -57,7 +57,9 @@ static const Eigen::Vector3d g(0, 0, -9.81);
static const Eigen::Vector3d g_dir(0, 0, -1); static const Eigen::Vector3d g_dir(0, 0, -1);
} // namespace constants } // namespace constants
struct PoseVelBiasStateWithLin : private PoseVelBiasState { struct PoseVelBiasStateWithLin {
using VecN = PoseVelBiasState::VecN;
PoseVelBiasStateWithLin() { PoseVelBiasStateWithLin() {
linearized = false; linearized = false;
delta.setZero(); delta.setZero();
@ -67,14 +69,14 @@ struct PoseVelBiasStateWithLin : private PoseVelBiasState {
const Eigen::Vector3d& vel_w_i, const Eigen::Vector3d& vel_w_i,
const Eigen::Vector3d& bias_gyro, const Eigen::Vector3d& bias_gyro,
const Eigen::Vector3d& bias_accel, bool linearized) const Eigen::Vector3d& bias_accel, bool linearized)
: PoseVelBiasState(t_ns, T_w_i, vel_w_i, bias_gyro, bias_accel), : linearized(linearized),
linearized(linearized) { state_linearized(t_ns, T_w_i, vel_w_i, bias_gyro, bias_accel) {
delta.setZero(); delta.setZero();
state_current = *this; state_current = state_linearized;
} }
PoseVelBiasStateWithLin(const PoseVelBiasState& other) PoseVelBiasStateWithLin(const PoseVelBiasState& other)
: PoseVelBiasState(other), linearized(false) { : linearized(false), state_linearized(other) {
delta.setZero(); delta.setZero();
state_current = other; state_current = other;
} }
@ -88,27 +90,29 @@ struct PoseVelBiasStateWithLin : private PoseVelBiasState {
void applyInc(const VecN& inc) { void applyInc(const VecN& inc) {
if (!linearized) { if (!linearized) {
PoseVelBiasState::applyInc(inc); state_linearized.applyInc(inc);
} else { } else {
delta += inc; delta += inc;
state_current = *this; state_current = state_linearized;
state_current.applyInc(delta); state_current.applyInc(delta);
} }
} }
inline const PoseVelBiasState& getState() const { inline const PoseVelBiasState& getState() const {
if (!linearized) { if (!linearized) {
return *this; return state_linearized;
} else { } else {
return state_current; return state_current;
} }
} }
inline const PoseVelBiasState& getStateLin() const { return *this; } inline const PoseVelBiasState& getStateLin() const {
return state_linearized;
}
inline bool isLinearized() const { return linearized; } inline bool isLinearized() const { return linearized; }
inline const VecN& getDelta() const { return delta; } inline const VecN& getDelta() const { return delta; }
inline int64_t getT_ns() const { return t_ns; } inline int64_t getT_ns() const { return state_linearized.t_ns; }
friend struct PoseStateWithLin; friend struct PoseStateWithLin;
@ -117,86 +121,92 @@ struct PoseVelBiasStateWithLin : private PoseVelBiasState {
bool linearized; bool linearized;
VecN delta; VecN delta;
PoseVelBiasState state_current; PoseVelBiasState state_linearized, state_current;
friend class cereal::access; friend class cereal::access;
template <class Archive> template <class Archive>
void serialize(Archive& ar) { void serialize(Archive& ar) {
ar(T_w_i); ar(state_linearized.T_w_i);
ar(vel_w_i); ar(state_linearized.vel_w_i);
ar(bias_gyro); ar(state_linearized.bias_gyro);
ar(bias_accel); ar(state_linearized.bias_accel);
ar(state_current.T_w_i); ar(state_current.T_w_i);
ar(state_current.vel_w_i); ar(state_current.vel_w_i);
ar(state_current.bias_gyro); ar(state_current.bias_gyro);
ar(state_current.bias_accel); ar(state_current.bias_accel);
ar(delta); ar(delta);
ar(linearized); ar(linearized);
ar(t_ns); ar(state_linearized.t_ns);
} }
}; };
struct PoseStateWithLin : private PoseState { struct PoseStateWithLin {
using VecN = PoseState::VecN;
PoseStateWithLin() { PoseStateWithLin() {
linearized = false; linearized = false;
delta.setZero(); delta.setZero();
}; };
PoseStateWithLin(int64_t t_ns, const Sophus::SE3d& T_w_i) PoseStateWithLin(int64_t t_ns, const Sophus::SE3d& T_w_i)
: PoseState(t_ns, T_w_i), linearized(false) { : linearized(false), pose_linearized(t_ns, T_w_i) {
delta.setZero(); delta.setZero();
T_w_i_current = T_w_i; T_w_i_current = T_w_i;
} }
PoseStateWithLin(const PoseVelBiasStateWithLin& other) PoseStateWithLin(const PoseVelBiasStateWithLin& other)
: PoseState(other.t_ns, other.T_w_i), : linearized(other.linearized),
linearized(other.linearized), delta(other.delta.head<6>()),
delta(other.delta.head<6>()) { pose_linearized(other.state_linearized.t_ns,
T_w_i_current = T_w_i; other.state_linearized.T_w_i) {
incPose(delta, T_w_i_current); T_w_i_current = pose_linearized.T_w_i;
PoseState::incPose(delta, T_w_i_current);
} }
inline const Sophus::SE3d& getPose() const { inline const Sophus::SE3d& getPose() const {
if (!linearized) { if (!linearized) {
return T_w_i; return pose_linearized.T_w_i;
} else { } else {
return T_w_i_current; return T_w_i_current;
} }
} }
inline const Sophus::SE3d& getPoseLin() const { return T_w_i; } inline const Sophus::SE3d& getPoseLin() const {
return pose_linearized.T_w_i;
}
inline void applyInc(const VecN& inc) { inline void applyInc(const VecN& inc) {
if (!linearized) { if (!linearized) {
incPose(inc, T_w_i); PoseState::incPose(inc, pose_linearized.T_w_i);
} else { } else {
delta += inc; delta += inc;
T_w_i_current = T_w_i; T_w_i_current = pose_linearized.T_w_i;
incPose(delta, T_w_i_current); PoseState::incPose(delta, T_w_i_current);
} }
} }
inline bool isLinearized() const { return linearized; } inline bool isLinearized() const { return linearized; }
inline const VecN& getDelta() const { return delta; } inline const VecN& getDelta() const { return delta; }
inline int64_t getT_ns() const { return t_ns; } inline int64_t getT_ns() const { return pose_linearized.t_ns; }
EIGEN_MAKE_ALIGNED_OPERATOR_NEW EIGEN_MAKE_ALIGNED_OPERATOR_NEW
private: private:
bool linearized; bool linearized;
VecN delta; VecN delta;
PoseState pose_linearized;
Sophus::SE3d T_w_i_current; Sophus::SE3d T_w_i_current;
friend class cereal::access; friend class cereal::access;
template <class Archive> template <class Archive>
void serialize(Archive& ar) { void serialize(Archive& ar) {
ar(T_w_i); ar(pose_linearized.T_w_i);
ar(T_w_i_current); ar(T_w_i_current);
ar(delta); ar(delta);
ar(linearized); ar(linearized);
ar(t_ns); ar(pose_linearized.t_ns);
} }
}; };