forked from TUC-ProAut/libRSF
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBetweenPose2Factor.h
More file actions
106 lines (94 loc) · 4.11 KB
/
Copy pathBetweenPose2Factor.h
File metadata and controls
106 lines (94 loc) · 4.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/***************************************************************************
* libRSF - A Robust Sensor Fusion Library
*
* Copyright (C) 2018 Chair of Automation Technology / TU Chemnitz
* For more information see https://www.tu-chemnitz.de/etit/proaut/libRSF
*
* libRSF is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* libRSF is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with libRSF. If not, see <http://www.gnu.org/licenses/>.
*
* Author: Tim Pfeifer (tim.pfeifer@etit.tu-chemnitz.de)
***************************************************************************/
/**
* @file BetweenPose2Factor.h
* @author Tim Pfeifer
* @date 18.09.2018
* @brief A Factor that connects two 2D poses with a relative pose measurement.
* @copyright GNU Public License.
*
*/
#ifndef BETWEENPOSE2FACTOR_H
#define BETWEENPOSE2FACTOR_H
#include "BaseFactor.h"
#include "../Geometry.h"
#include "../geometric_models/RelativePoseModel.h"
namespace libRSF
{
template <typename ErrorType>
class BetweenPose2Factor : public BaseFactor<ErrorType, true, false, 2, 1, 2, 1>
{
public:
/** construct factor and store measurement */
BetweenPose2Factor(ErrorType &Error, const Data &PoseMeasurement)
{
this->_Error = Error;
this->_MeasurementVector.resize(3);
this->_MeasurementVector = PoseMeasurement.getMean();
}
/** geometric error model */
template <typename T>
VectorT<T, 3> Evaluate(const T* const Pos1, const T* const Yaw1,
const T* const Pos2, const T* const Yaw2,
const Vector3 &RelativePose) const
{
/** estimate measurements*/
VectorT<T,2> TransEst;
Rotation2DT<T> RotEst;
RelativePose2Model<T>::applyBackward(Pos1, Yaw1,
Pos2, Yaw2,
TransEst, RotEst);
/** error = estimated measurement - measurement */
VectorT<T, 3> Error;
Error.template head<2>() = TransEst - RelativePose.template head<2>().template cast<T>();
Error(2) = NormalizeAngle<T>(RotEst.angle() - RelativePose(2));
return Error;
}
/** combine probabilistic and geometric model */
template <typename T, typename... ParamsType>
bool operator()(const T* const Pos1, const T* const Yaw1,
const T* const Pos2, const T* const Yaw2,
ParamsType... Params) const
{
return this->_Error.template weight<T>(this->Evaluate(
Pos1, Yaw1,
Pos2, Yaw2,
this->_MeasurementVector),
Params...);
}
/** predict the next state for initialization, order is the same as for Evaluate() */
void predict(const std::vector<double*> &StatePointers) const
{
/** split pose measurement */
const Vector2 Trans = this->_MeasurementVector.head(2);
const Rotation2D Rot(this->_MeasurementVector(2));
/** apply forward model */
RelativePose2Model<double>::applyForward(StatePointers.at(0), StatePointers.at(1),
StatePointers.at(2), StatePointers.at(3),
Trans, Rot);
}
};
/** compile time mapping from factor type enum to corresponding factor class */
template<typename ErrorType>
struct FactorTypeTranslator<FactorType::BetweenPose2, ErrorType> {using Type = BetweenPose2Factor<ErrorType>;};
}
#endif // BETWEENPOSE2FACTOR_H