Go to the documentation of this file.00001
00034 #include <isam/isam.h>
00035 #include "isam/Anchor.h"
00036
00037 using namespace std;
00038 using namespace isam;
00039 using namespace Eigen;
00040
00041
00042 int main() {
00043
00044
00045
00046
00047
00048 Slam slam;
00049
00050 Noise noise = SqrtInformation(10. * eye(3));
00051
00052
00053 Pose2d prior_origin(0., 0., 0.);
00054 Pose2d_Node a0;
00055 slam.add_node(&a0);
00056 Pose2d_Factor p_a0(&a0, prior_origin, noise);
00057 slam.add_factor(&p_a0);
00058 Pose2d odo(1., 0., 0.);
00059 Pose2d_Node a1;
00060 slam.add_node(&a1);
00061 Pose2d_Pose2d_Factor o_a01(&a0, &a1, odo, noise);
00062 slam.add_factor(&o_a01);
00063
00064
00065 Pose2d_Node b0;
00066 slam.add_node(&b0);
00067 Pose2d_Factor p_b0(&b0, prior_origin, noise);
00068 slam.add_factor(&p_b0);
00069 Pose2d_Node b1;
00070 slam.add_node(&b1);
00071 Pose2d_Pose2d_Factor o_b01(&b0, &b1, odo, noise);
00072 slam.add_factor(&o_b01);
00073
00074 cout << "two independent pose graphs:" << endl;
00075 cout << "batch optimization... (nothing changes)" << endl;
00076 slam.batch_optimization();
00077 cout << "...done" << endl;
00078 cout << "a0: " << a0.value() << endl;
00079 cout << "a1: " << a1.value() << endl;
00080 cout << "b0: " << b0.value() << endl;
00081 cout << "b1: " << b1.value() << endl;
00082
00083
00084
00085
00086
00087 Anchor2d_Node anchor0(&slam);
00088 slam.add_node(&anchor0);
00089
00090
00091
00092
00093 Anchor2d_Node anchor1(&slam);
00094 slam.add_node(&anchor1);
00095
00096 Pose2d measure0(0., 1., 0.);
00097
00098
00099
00100
00101 Pose2d_Pose2d_Factor d_a1_b1(&a1, &b1, measure0, noise, &anchor0, &anchor1);
00102 slam.add_factor(&d_a1_b1);
00103
00104 cout << "\nfirst constraint added:" << endl;
00105
00106 cout << "batch optimization... (nothing changes)" << endl;
00107 slam.batch_optimization();
00108 cout << "...done" << endl;
00109
00110 cout << "a0: " << a0.value() << endl;
00111 cout << "a1: " << a1.value() << endl;
00112 cout << "b0: " << b0.value() << endl;
00113 cout << "b1: " << b1.value() << endl;
00114 cout << "anchor0: " << anchor0.value() << endl;
00115 cout << "anchor1: " << anchor1.value() << endl;
00116
00117 Pose2d measure1(0., 0.5, 0.);
00118 Pose2d_Pose2d_Factor d_a1_b1_2(&a1, &b1, measure1, noise, &anchor0, &anchor1);
00119 slam.add_factor(&d_a1_b1_2);
00120
00121 cout << "\nsecond conflicting constraint added (least squares is 0.75):" << endl;
00122
00123 cout << "batch optimization... (least squares solution)" << endl;
00124 slam.batch_optimization();
00125 cout << "...done" << endl;
00126
00127 cout.precision(2);
00128 cout << fixed;
00129 cout << "a0: " << a0.value() << endl;
00130 cout << "a1: " << a1.value() << endl;
00131 cout << "b0: " << b0.value() << endl;
00132 cout << "b1: " << b1.value() << endl;
00133 cout << "anchor0: " << anchor0.value() << endl;
00134 cout << "anchor1: " << anchor1.value() << endl;
00135
00136 slam.save("anchorNodes.graph");
00137
00138 return 0;
00139 }