spa_solver.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 "spa_solver.hpp"
19 #include <karto_sdk/Karto.h>
20 
21 #include "ros/console.h"
23 
25 
26 namespace solver_plugins
27 {
28 typedef std::vector<sba::Node2d, Eigen::aligned_allocator<sba::Node2d> > NodeVector;
29 
30 /*****************************************************************************/
32 /*****************************************************************************/
33 {
34 
35 }
36 
37 /*****************************************************************************/
39 /*****************************************************************************/
40 {
41 
42 }
43 
44 /*****************************************************************************/
46 /*****************************************************************************/
47 {
48  corrections.clear();
49 }
50 
52 {
53  return corrections;
54 }
55 
56 /*****************************************************************************/
58 /*****************************************************************************/
59 {
60  corrections.clear();
61 
62  const ros::Time start_time = ros::Time::now();
63  m_Spa.doSPA(40, 1.0e-4, 1);
64  ROS_INFO("Loop Closure Solve time: %f seconds",
65  (ros::Time::now() - start_time).toSec());
66 
67  NodeVector nodes = m_Spa.getNodes();
68  forEach(NodeVector, &nodes)
69  {
70  karto::Pose2 pose(iter->trans(0), iter->trans(1), iter->arot);
71  corrections.push_back(std::make_pair(iter->nodeId, pose));
72  }
73 }
74 
75 /*****************************************************************************/
77 /*****************************************************************************/
78 {
79  karto::Pose2 pose = pVertex->GetObject()->GetCorrectedPose();
80  Eigen::Vector3d vector(pose.GetX(), pose.GetY(), pose.GetHeading());
81  m_Spa.addNode(vector, pVertex->GetObject()->GetUniqueId());
82 }
83 
84 /*****************************************************************************/
86 /*****************************************************************************/
87 {
88  karto::LocalizedRangeScan* pSource = pEdge->GetSource()->GetObject();
89  karto::LocalizedRangeScan* pTarget = pEdge->GetTarget()->GetObject();
90  karto::LinkInfo* pLinkInfo = (karto::LinkInfo*)(pEdge->GetLabel());
91 
92  karto::Pose2 diff = pLinkInfo->GetPoseDifference();
93  Eigen::Vector3d mean(diff.GetX(), diff.GetY(), diff.GetHeading());
94 
95  karto::Matrix3 precisionMatrix = pLinkInfo->GetCovariance().Inverse();
96  Eigen::Matrix<double,3,3> m;
97  m(0,0) = precisionMatrix(0,0);
98  m(0,1) = m(1,0) = precisionMatrix(0,1);
99  m(0,2) = m(2,0) = precisionMatrix(0,2);
100  m(1,1) = precisionMatrix(1,1);
101  m(1,2) = m(2,1) = precisionMatrix(1,2);
102  m(2,2) = precisionMatrix(2,2);
103 
104  m_Spa.addConstraint(pSource->GetUniqueId(), pTarget->GetUniqueId(), mean, m);
105 }
106 
107 /*****************************************************************************/
108 void SpaSolver::getGraph(std::vector<Eigen::Vector2d>& g)
109 /*****************************************************************************/
110 {
111  std::vector<float> raw_graph;
112  m_Spa.getGraph(raw_graph);
113 
114  g.reserve(raw_graph.size()/4);
115 
116  Eigen::Vector2d pose;
117  for (size_t i=0; i!=raw_graph.size()/4; i++)
118  {
119  pose(0) = raw_graph[4*i];
120  pose(1) = raw_graph[4*i+1];
121  g.push_back(pose);
122  }
123 }
124 
125 
126 } // end namespace
solver_plugins::SpaSolver::Compute
virtual void Compute()
Definition: spa_solver.cpp:57
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)
karto::ScanSolver
Definition: Mapper.h:947
solver_plugins::SpaSolver
Definition: spa_solver.hpp:34
solver_plugins::SpaSolver::GetCorrections
virtual const karto::ScanSolver::IdPoseVector & GetCorrections() const
Definition: spa_solver.cpp:51
karto::Pose2::GetY
kt_double GetY() const
Definition: Karto.h:2117
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:5505
karto::LinkInfo::GetCovariance
const Matrix3 & GetCovariance()
Definition: Mapper.h:219
sba::SysSPA2d::addConstraint
bool addConstraint(int nd0, int nd1, const Vector3d &mean, const Matrix3d &prec)
solver_plugins::SpaSolver::AddNode
virtual void AddNode(karto::Vertex< karto::LocalizedRangeScan > *pVertex)
Definition: spa_solver.cpp:76
karto::Matrix3
Definition: Karto.h:2444
karto::ScanSolver::IdPoseVector
std::vector< std::pair< kt_int32s, Pose2 > > IdPoseVector
Definition: Mapper.h:953
class_list_macros.h
console.h
karto::Matrix3::Inverse
Matrix3 Inverse() const
Definition: Karto.h:2545
karto::Vertex::GetObject
T * GetObject() const
Definition: Mapper.h:319
solver_plugins::SpaSolver::~SpaSolver
virtual ~SpaSolver()
Definition: spa_solver.cpp:38
Karto.h
karto::LinkInfo
Definition: Mapper.h:141
PLUGINLIB_EXPORT_CLASS
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
karto::Edge::GetLabel
EdgeLabel * GetLabel()
Definition: Mapper.h:457
karto::LocalizedRangeScan::GetCorrectedPose
const Pose2 & GetCorrectedPose() const
Definition: Karto.h:5562
solver_plugins::SpaSolver::m_Spa
sba::SysSPA2d m_Spa
Definition: spa_solver.hpp:55
karto::Edge::GetTarget
Vertex< T > * GetTarget() const
Definition: Mapper.h:448
solver_plugins::SpaSolver::AddConstraint
virtual void AddConstraint(karto::Edge< karto::LocalizedRangeScan > *pEdge)
Definition: spa_solver.cpp:85
ros::Time
solver_plugins::NodeVector
std::vector< sba::Node2d, Eigen::aligned_allocator< sba::Node2d > > NodeVector
Definition: spa_solver.cpp:28
karto::SensorData::GetUniqueId
kt_int32s GetUniqueId() const
Definition: Karto.h:5163
karto::Pose2::GetX
kt_double GetX() const
Definition: Karto.h:2099
spa_solver.hpp
karto::Vertex< karto::LocalizedRangeScan >
solver_plugins::SpaSolver::corrections
karto::ScanSolver::IdPoseVector corrections
Definition: spa_solver.hpp:53
forEach
#define forEach(listtype, list)
Definition: Macros.h:66
karto::Pose2
Definition: Karto.h:2046
solver_plugins
Definition: ceres_solver.cpp:14
ROS_INFO
#define ROS_INFO(...)
karto::ScanSolver::getGraph
virtual std::unordered_map< int, Eigen::Vector3d > * getGraph()
Definition: Mapper.h:1026
karto::Edge::GetSource
Vertex< T > * GetSource() const
Definition: Mapper.h:439
solver_plugins::SpaSolver::SpaSolver
SpaSolver()
Definition: spa_solver.cpp:31
karto::Edge
Definition: Mapper.h:247
karto::Pose2::GetHeading
kt_double GetHeading() const
Definition: Karto.h:2153
ros::Time::now
static Time now()
sba::SysSPA2d::getGraph
void getGraph(std::vector< float > &graph)
solver_plugins::SpaSolver::Clear
virtual void Clear()
Definition: spa_solver.cpp:45
karto::LinkInfo::GetPoseDifference
const Pose2 & GetPoseDifference()
Definition: Mapper.h:210


slam_toolbox
Author(s): Steve Macenski
autogenerated on Thu Jan 11 2024 03:37:56