42int main(
int argc,
char** argv) {
48 std::vector<double> noiseTranslation;
49 std::vector<double> noiseRotation;
52 arg.
param(
"o", outFilename,
"-",
"output filename");
53 arg.
param(
"nodesPerLevel", nodesPerLevel, 50,
54 "how many nodes per lap on the sphere");
55 arg.
param(
"laps", numLaps, 50,
56 "how many times the robot travels around the sphere");
57 arg.
param(
"radius", radius, 100.,
"radius of the sphere");
58 arg.
param(
"noiseTranslation", noiseTranslation, std::vector<double>(),
59 "set the noise level for the translation, separated by semicolons "
60 "without spaces e.g: \"0.1;0.1;0.1\"");
61 arg.
param(
"noiseRotation", noiseRotation, std::vector<double>(),
62 "set the noise level for the rotation, separated by semicolons "
63 "without spaces e.g: \"0.001;0.001;0.001\"");
64 arg.
param(
"randomSeed", randomSeed,
false,
65 "use a randomized seed for generating the sphere");
68 if (noiseTranslation.size() == 0) {
69 cerr <<
"using default noise for the translation" << endl;
70 noiseTranslation.push_back(0.01);
71 noiseTranslation.push_back(0.01);
72 noiseTranslation.push_back(0.01);
74 cerr <<
"Noise for the translation:";
75 for (
size_t i = 0; i < noiseTranslation.size(); ++i)
76 cerr <<
" " << noiseTranslation[i];
78 if (noiseRotation.size() == 0) {
79 cerr <<
"using default noise for the rotation" << endl;
80 noiseRotation.push_back(0.005);
81 noiseRotation.push_back(0.005);
82 noiseRotation.push_back(0.005);
84 cerr <<
"Noise for the rotation:";
85 for (
size_t i = 0; i < noiseRotation.size(); ++i)
86 cerr <<
" " << noiseRotation[i];
89 Eigen::Matrix3d transNoise = Eigen::Matrix3d::Zero();
90 for (
int i = 0; i < 3; ++i)
91 transNoise(i, i) = std::pow(noiseTranslation[i], 2);
93 Eigen::Matrix3d rotNoise = Eigen::Matrix3d::Zero();
94 for (
int i = 0; i < 3; ++i) rotNoise(i, i) = std::pow(noiseRotation[i], 2);
96 Eigen::Matrix<double, 6, 6> information = Eigen::Matrix<double, 6, 6>::Zero();
97 information.block<3, 3>(0, 0) = transNoise.inverse();
98 information.block<3, 3>(3, 3) = rotNoise.inverse();
100 vector<VertexSE3*> vertices;
101 vector<EdgeSE3*> odometryEdges;
102 vector<EdgeSE3*> edges;
104 for (
int f = 0; f < numLaps; ++f) {
105 for (
int n = 0; n < nodesPerLevel; ++n) {
109 Eigen::AngleAxisd rotz(-M_PI + 2 * n * M_PI / nodesPerLevel,
110 Eigen::Vector3d::UnitZ());
111 Eigen::AngleAxisd roty(
112 -0.5 * M_PI +
id * M_PI / (numLaps * nodesPerLevel),
113 Eigen::Vector3d::UnitY());
114 Eigen::Matrix3d rot = (rotz * roty).toRotationMatrix();
118 t.translation() = t.linear() * Eigen::Vector3d(radius, 0, 0);
120 vertices.push_back(v);
125 for (
size_t i = 1; i < vertices.size(); ++i) {
134 odometryEdges.push_back(e);
139 for (
int f = 1; f < numLaps; ++f) {
140 for (
int nn = 0; nn < nodesPerLevel; ++nn) {
141 VertexSE3* from = vertices[(f - 1) * nodesPerLevel + nn];
142 for (
int n = -1; n <= 1; ++n) {
143 if (f == numLaps - 1 && n == 1)
continue;
144 VertexSE3* to = vertices[f * nodesPerLevel + nn + n];
162 std::random_device r;
163 std::seed_seq seedSeq{r(), r(), r(), r(), r()};
164 vector<int> seeds(2);
165 seedSeq.generate(seeds.begin(), seeds.end());
166 cerr <<
"using seeds:";
167 for (
size_t i = 0; i < seeds.size(); ++i) cerr <<
" " << seeds[i];
169 transSampler.
seed(seeds[0]);
170 rotSampler.
seed(seeds[1]);
174 for (
size_t i = 0; i < edges.size(); ++i) {
176 Eigen::Quaterniond gtQuat = (Eigen::Quaterniond)e->
measurement().linear();
177 Eigen::Vector3d gtTrans = e->
measurement().translation();
180 double qw = 1.0 - quatXYZ.norm();
185 Eigen::Quaterniond rot(qw, quatXYZ.x(), quatXYZ.y(), quatXYZ.z());
189 trans = gtTrans + trans;
191 Eigen::Isometry3d noisyMeasurement = (Eigen::Isometry3d)rot;
192 noisyMeasurement.translation() = trans;
197 for (
size_t i = 0; i < odometryEdges.size(); ++i) {
207 ofstream fileOutputStream;
208 if (outFilename !=
"-") {
209 cerr <<
"Writing into " << outFilename << endl;
210 fileOutputStream.open(outFilename.c_str());
212 cerr <<
"writing to stdout" << endl;
218 ostream& fout = outFilename !=
"-" ? fileOutputStream : cout;
219 for (
size_t i = 0; i < vertices.size(); ++i) {
221 fout << vertexTag <<
" " << v->
id() <<
" ";
226 for (
size_t i = 0; i < edges.size(); ++i) {
230 fout << edgeTag <<
" " << from->
id() <<
" " << to->
id() <<
" ";