MCPcopy Create free account
hub / github.com/KumarRobotics/sloam / OptimizeXYYaw

Method OptimizeXYYaw

sloam/src/core/sloam.cpp:55–114  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

53 }
54
55 void sloam::OptimizeXYYaw(const SE3 &poseEstimate, const bool optimize, const std::vector<ObjectMatch<Cylinder>> &allTMatch, double* out)
56 {
57
58 auto t = poseEstimate.translation();
59 auto q = poseEstimate.unit_quaternion();
60 double quat[4] = {q.w(), q.x(), q.y(), q.z()};
61 double rpy[3];
62 ceres::QuaternionToAngleAxis(quat, rpy);
63 double params[6] = {t[0], t[1], t[2], rpy[0], rpy[1], rpy[2]};
64
65 bool success = true;
66 if(optimize)
67 {
68 ceres::LossFunction *loss = NULL;
69 loss = new ceres::HuberLoss(0.1);
70 ceres::Problem::Options problem_options;
71 ceres::Problem problem(problem_options);
72
73 problem.AddParameterBlock(params, 6);
74 // setting z, roll and pitch as constant
75 ceres::SubsetParameterization *subset_parameterization =
76 new ceres::SubsetParameterization(6, {2, 3, 4});
77 problem.SetParameterization(params, subset_parameterization);
78
79 for (auto tMatch : allTMatch)
80 {
81 Vector3 root = tMatch.object.model.root;
82 Vector3 ray = tMatch.object.model.ray;
83 double radius = (double)tMatch.object.model.radius;
84 double weight = 1.0;
85 ceres::CostFunction *cost =
86 new ceres::AutoDiffCostFunction<XYYawCylinderCost, 1, 6>(
87 new XYYawCylinderCost(tMatch.feature, root, ray, radius, weight));
88 problem.AddResidualBlock(cost, loss, params);
89 }
90
91 ceres::Solver::Options options;
92 options.max_num_iterations = 50;
93
94 options.linear_solver_type = ceres::DENSE_QR;
95 options.logging_type = ceres::SILENT;
96 ceres::Solver::Summary summary;
97 ceres::Solve(options, &problem, &summary);
98 success = summary.termination_type == 0;
99 }
100
101 // bool x_diff = abs(abs(params[0]) - abs(t[0])) < 0.5;
102 // bool y_diff = abs(abs(params[1]) - abs(t[1])) < 0.5;
103 if (optimize && success)
104 {
105 out[0] = params[0];
106 out[1] = params[1];
107 out[2] = params[5];
108 } else
109 {
110 out[0] = t[0];
111 out[1] = t[1];
112 out[2] = rpy[2];

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected