-
Notifications
You must be signed in to change notification settings - Fork 550
/
Copy pathceres_solver.hpp
83 lines (67 loc) · 2.36 KB
/
ceres_solver.hpp
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
/*
* Copyright 2018 Simbe Robotics, Inc.
* Author: Steve Macenski (stevenmacenski@gmail.com)
*/
#ifndef SOLVERS__CERES_SOLVER_HPP_
#define SOLVERS__CERES_SOLVER_HPP_
#include <math.h>
#include <ceres/local_parameterization.h>
#include <ceres/ceres.h>
#include <vector>
#include <unordered_map>
#include <utility>
#include <cmath>
#include "karto_sdk/Mapper.h"
#include "solvers/ceres_utils.h"
#include "rclcpp/rclcpp.hpp"
#include "std_srvs/srv/empty.hpp"
#include "slam_toolbox/toolbox_types.hpp"
namespace solver_plugins
{
using namespace ::toolbox_types; // NOLINT
class CeresSolver : public karto::ScanSolver
{
public:
CeresSolver();
virtual ~CeresSolver();
public:
// Get corrected poses after optimization
virtual const karto::ScanSolver::IdPoseVector & GetCorrections() const;
virtual void Compute(); // Solve
virtual void Clear(); // Resets the corrections
virtual void Reset(); // Resets the solver plugin clean
virtual void Configure(rclcpp::Node::SharedPtr node);
// Adds a node to the solver
virtual void AddNode(karto::Vertex<karto::LocalizedRangeScan> * pVertex);
// Adds a constraint to the solver
virtual void AddConstraint(karto::Edge<karto::LocalizedRangeScan> * pEdge);
// Get graph stored
virtual std::unordered_map<int, Eigen::Vector3d> * getGraph();
// Removes a node from the solver correction table
virtual void RemoveNode(kt_int32s id);
// Removes constraints from the optimization problem
virtual void RemoveConstraint(kt_int32s sourceId, kt_int32s targetId);
// change a node's pose
virtual void ModifyNode(const int & unique_id, Eigen::Vector3d pose);
// get a node's current pose yaw
virtual void GetNodeOrientation(const int & unique_id, double & pose);
private:
// karto
karto::ScanSolver::IdPoseVector corrections_;
// ceres
ceres::Solver::Options options_;
ceres::Problem::Options options_problem_;
ceres::LossFunction * loss_function_;
ceres::Problem * problem_;
ceres::LocalParameterization * angle_local_parameterization_;
bool was_constant_set_, debug_logging_;
// graph
std::unordered_map<int, Eigen::Vector3d> * nodes_;
std::unordered_map<size_t, ceres::ResidualBlockId> * blocks_;
std::unordered_map<int, Eigen::Vector3d>::iterator first_node_;
boost::mutex nodes_mutex_;
// ros
rclcpp::Node::SharedPtr node_;
};
} // namespace solver_plugins
#endif // SOLVERS__CERES_SOLVER_HPP_