| 1 | // g2o - General Graph Optimization |
| 2 | // Copyright (C) 2011 R. Kuemmerle, G. Grisetti, W. Burgard |
| 3 | // All rights reserved. |
| 4 | // |
| 5 | // Redistribution and use in source and binary forms, with or without |
| 6 | // modification, are permitted provided that the following conditions are |
| 7 | // met: |
| 8 | // |
| 9 | // * Redistributions of source code must retain the above copyright notice, |
| 10 | // this list of conditions and the following disclaimer. |
| 11 | // * Redistributions in binary form must reproduce the above copyright |
| 12 | // notice, this list of conditions and the following disclaimer in the |
| 13 | // documentation and/or other materials provided with the distribution. |
| 14 | // |
| 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS |
| 16 | // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
| 17 | // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
| 18 | // PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 19 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 20 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED |
| 21 | // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 22 | // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 23 | // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 24 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 25 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | |
| 27 | #include "g2o/stuff/os_specific.h" |
| 28 | #include "g2o/types/slam2d/edge_pointxy.h" |
| 29 | #include "g2o/types/slam2d/edge_se2.h" |
| 30 | #include "g2o/types/slam2d/edge_se2_pointxy.h" |
| 31 | #include "g2o/types/slam2d/edge_se2_pointxy_bearing.h" |
| 32 | #include "g2o/types/slam2d/edge_se2_prior.h" |
| 33 | #include "gtest/gtest.h" |
| 34 | #include "unit_test/test_helper/evaluate_jacobian.h" |
| 35 | |
| 36 | using namespace std; |
| 37 | using namespace g2o; |
| 38 | using namespace Eigen; |
| 39 | |
| 40 | static SE2 randomSE2() { return SE2(Vector3d::Random()); } |
| 41 | |
| 42 | TEST(Slam2D, EdgeSE2Jacobian) { |
| 43 | VertexSE2 v1; |
| 44 | v1.setId(0); |
| 45 | |
| 46 | VertexSE2 v2; |
| 47 | v2.setId(1); |
| 48 | |
| 49 | EdgeSE2 e; |
| 50 | e.setVertex(0, &v1); |
| 51 | e.setVertex(1, &v2); |
| 52 | e.setInformation(EdgeSE2::InformationType::Identity()); |
| 53 | |
| 54 | JacobianWorkspace jacobianWorkspace; |
| 55 | JacobianWorkspace numericJacobianWorkspace; |
| 56 | numericJacobianWorkspace.updateSize(&e); |
| 57 | numericJacobianWorkspace.allocate(); |
| 58 | |
| 59 | for (int k = 0; k < 10000; ++k) { |
| 60 | v1.setEstimate(randomSE2()); |
| 61 | v2.setEstimate(randomSE2()); |
| 62 | e.setMeasurement(randomSE2()); |
| 63 | |
| 64 | evaluateJacobian(e, jacobianWorkspace, numericJacobianWorkspace); |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | TEST(Slam2D, EdgeSE2PriorJacobian) { |
| 69 | VertexSE2 v1; |
| 70 | v1.setId(0); |
| 71 | |
| 72 | EdgeSE2Prior e; |
| 73 | e.setVertex(0, &v1); |
| 74 | e.setInformation(EdgeSE2::InformationType::Identity()); |
| 75 | |
| 76 | JacobianWorkspace jacobianWorkspace; |
| 77 | JacobianWorkspace numericJacobianWorkspace; |
| 78 | numericJacobianWorkspace.updateSize(&e); |
| 79 | numericJacobianWorkspace.allocate(); |
| 80 | |
| 81 | for (int k = 0; k < 10000; ++k) { |
| 82 | v1.setEstimate(randomSE2()); |
| 83 | e.setMeasurement(randomSE2()); |
| 84 | |
| 85 | evaluateJacobianUnary(e, jacobianWorkspace, numericJacobianWorkspace); |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | TEST(Slam2D, EdgePointXYJacobian) { |
| 90 | VertexPointXY v1; |
| 91 | v1.setId(0); |
| 92 | |
| 93 | VertexPointXY v2; |
| 94 | v2.setId(1); |
| 95 | |
| 96 | EdgePointXY e; |
| 97 | e.setVertex(0, &v1); |
| 98 | e.setVertex(1, &v2); |
| 99 | e.setInformation(EdgePointXY::InformationType::Identity()); |
| 100 | |
| 101 | JacobianWorkspace jacobianWorkspace; |
| 102 | JacobianWorkspace numericJacobianWorkspace; |
| 103 | numericJacobianWorkspace.updateSize(&e); |
| 104 | numericJacobianWorkspace.allocate(); |
| 105 | |
| 106 | for (int k = 0; k < 10000; ++k) { |
| 107 | v1.setEstimate(Eigen::Vector2d::Random()); |
| 108 | v2.setEstimate(Eigen::Vector2d::Random()); |
| 109 | e.setMeasurement(Eigen::Vector2d::Random()); |
| 110 | |
| 111 | evaluateJacobian(e, jacobianWorkspace, numericJacobianWorkspace); |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | TEST(Slam2D, EdgeSE2PointXYJacobian) { |
| 116 | VertexSE2 v1; |
| 117 | v1.setId(0); |
| 118 | |
| 119 | VertexPointXY v2; |
| 120 | v2.setId(1); |
| 121 | |
| 122 | EdgeSE2PointXY e; |
| 123 | e.setVertex(0, &v1); |
| 124 | e.setVertex(1, &v2); |
| 125 | e.setInformation(EdgeSE2PointXY::InformationType::Identity()); |
| 126 | |
| 127 | JacobianWorkspace jacobianWorkspace; |
| 128 | JacobianWorkspace numericJacobianWorkspace; |
| 129 | numericJacobianWorkspace.updateSize(&e); |
| 130 | numericJacobianWorkspace.allocate(); |
| 131 | |
| 132 | for (int k = 0; k < 10000; ++k) { |
| 133 | v1.setEstimate(randomSE2()); |
| 134 | v2.setEstimate(Eigen::Vector2d::Random()); |
| 135 | e.setMeasurement(Eigen::Vector2d::Random()); |
| 136 | |
| 137 | evaluateJacobian(e, jacobianWorkspace, numericJacobianWorkspace); |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | TEST(Slam2D, EdgeSE2PointXYBearingJacobian) { |
| 142 | VertexSE2 v1; |
| 143 | v1.setId(0); |
| 144 | |
| 145 | VertexPointXY v2; |
| 146 | v2.setId(1); |
| 147 | |
| 148 | EdgeSE2PointXYBearing e; |
| 149 | e.setVertex(0, &v1); |
| 150 | e.setVertex(1, &v2); |
| 151 | e.setInformation(EdgeSE2PointXYBearing::InformationType::Identity()); |
| 152 | |
| 153 | JacobianWorkspace jacobianWorkspace; |
| 154 | JacobianWorkspace numericJacobianWorkspace; |
| 155 | numericJacobianWorkspace.updateSize(&e); |
| 156 | numericJacobianWorkspace.allocate(); |
| 157 | |
| 158 | for (int k = 0; k < 10000; ++k) { |
| 159 | v1.setEstimate(randomSE2()); |
| 160 | v2.setEstimate(Eigen::Vector2d::Random()); |
| 161 | e.setMeasurement(drand48() * M_PI); |
| 162 | |
| 163 | evaluateJacobian(e, jacobianWorkspace, numericJacobianWorkspace); |
| 164 | } |
| 165 | } |