SpaSolver.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2010 SRI International
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include "SpaSolver.h"
19 #include <open_karto/Karto.h>
20 
22 {
23 
24 }
25 
27 {
28 
29 }
30 
32 {
33  corrections.clear();
34 }
35 
37 {
38  return corrections;
39 }
40 
42 {
43  corrections.clear();
44 
45  typedef std::vector<sba::Node2d, Eigen::aligned_allocator<sba::Node2d> > NodeVector;
46 
47  printf("DO SPA BEGIN\n");
48  m_Spa.doSPA(40);
49  printf("DO SPA END\n");
50  NodeVector nodes = m_Spa.getNodes();
51  forEach(NodeVector, &nodes)
52  {
53  karto::Pose2 pose(iter->trans(0), iter->trans(1), iter->arot);
54  corrections.push_back(std::make_pair(iter->nodeId, pose));
55  }
56 }
57 
59 {
60  karto::Pose2 pose = pVertex->GetObject()->GetCorrectedPose();
61  Eigen::Vector3d vector(pose.GetX(), pose.GetY(), pose.GetHeading());
62  m_Spa.addNode(vector, pVertex->GetObject()->GetUniqueId());
63 }
64 
66 {
67  karto::LocalizedRangeScan* pSource = pEdge->GetSource()->GetObject();
68  karto::LocalizedRangeScan* pTarget = pEdge->GetTarget()->GetObject();
69  karto::LinkInfo* pLinkInfo = (karto::LinkInfo*)(pEdge->GetLabel());
70 
71  karto::Pose2 diff = pLinkInfo->GetPoseDifference();
72  Eigen::Vector3d mean(diff.GetX(), diff.GetY(), diff.GetHeading());
73 
74  karto::Matrix3 precisionMatrix = pLinkInfo->GetCovariance().Inverse();
75  Eigen::Matrix<double,3,3> m;
76  m(0,0) = precisionMatrix(0,0);
77  m(0,1) = m(1,0) = precisionMatrix(0,1);
78  m(0,2) = m(2,0) = precisionMatrix(0,2);
79  m(1,1) = precisionMatrix(1,1);
80  m(1,2) = m(2,1) = precisionMatrix(1,2);
81  m(2,2) = precisionMatrix(2,2);
82 
83  m_Spa.addConstraint(pSource->GetUniqueId(), pTarget->GetUniqueId(), mean, m);
84 }
sba::SysSPA2d::doSPA
int doSPA(int niter, double sLambda=1.0e-4, int useCSparse=SBA_SPARSE_CHOLESKY, double initTol=1.0e-8, int CGiters=50)
SpaSolver::GetCorrections
virtual const karto::ScanSolver::IdPoseVector & GetCorrections() const
Definition: SpaSolver.cpp:36
SpaSolver::m_Spa
sba::SysSPA2d m_Spa
Definition: SpaSolver.h:51
karto::Pose2::GetY
kt_double GetY() const
Definition: Karto.h:2028
sba::SysSPA2d::addNode
int addNode(const Vector3d &pos, int id)
sba::SysSPA2d::getNodes
std::vector< Node2d, Eigen::aligned_allocator< Node2d > > getNodes()
karto::LocalizedRangeScan
Definition: Karto.h:5185
karto::LinkInfo::GetCovariance
const Matrix3 & GetCovariance()
Definition: Mapper.h:186
sba::SysSPA2d::addConstraint
bool addConstraint(int nd0, int nd1, const Vector3d &mean, const Matrix3d &prec)
karto::Matrix3
Definition: Karto.h:2347
karto::ScanSolver::IdPoseVector
std::vector< std::pair< kt_int32s, Pose2 > > IdPoseVector
Definition: Mapper.h:830
SpaSolver::Compute
virtual void Compute()
Definition: SpaSolver.cpp:41
karto::Matrix3::Inverse
Matrix3 Inverse() const
Definition: Karto.h:2448
karto::Vertex::GetObject
T * GetObject() const
Definition: Mapper.h:243
Karto.h
karto::LinkInfo
Definition: Mapper.h:111
SpaSolver::Clear
virtual void Clear()
Definition: SpaSolver.cpp:31
SpaSolver.h
karto::Edge::GetLabel
EdgeLabel * GetLabel()
Definition: Mapper.h:352
karto::LocalizedRangeScan::GetCorrectedPose
const Pose2 & GetCorrectedPose() const
Definition: Karto.h:5239
SpaSolver::AddNode
virtual void AddNode(karto::Vertex< karto::LocalizedRangeScan > *pVertex)
Definition: SpaSolver.cpp:58
SpaSolver::SpaSolver
SpaSolver()
Definition: SpaSolver.cpp:21
SpaSolver::corrections
karto::ScanSolver::IdPoseVector corrections
Definition: SpaSolver.h:49
karto::Edge::GetTarget
Vertex< T > * GetTarget() const
Definition: Mapper.h:343
karto::SensorData::GetUniqueId
kt_int32s GetUniqueId() const
Definition: Karto.h:4875
karto::Pose2::GetX
kt_double GetX() const
Definition: Karto.h:2010
karto::Vertex
Definition: Mapper.h:209
SpaSolver::AddConstraint
virtual void AddConstraint(karto::Edge< karto::LocalizedRangeScan > *pEdge)
Definition: SpaSolver.cpp:65
SpaSolver::~SpaSolver
virtual ~SpaSolver()
Definition: SpaSolver.cpp:26
forEach
#define forEach(listtype, list)
Definition: Macros.h:66
karto::Pose2
Definition: Karto.h:1957
karto::Edge::GetSource
Vertex< T > * GetSource() const
Definition: Mapper.h:334
karto::Edge
Definition: Mapper.h:203
karto::Pose2::GetHeading
kt_double GetHeading() const
Definition: Karto.h:2064
karto::LinkInfo::GetPoseDifference
const Pose2 & GetPoseDifference()
Definition: Mapper.h:177


open_karto
Author(s):
autogenerated on Tue Jul 23 2024 02:26:00