248 {
249 bool verbose, robustKernel, fixLines, planarMotion, listSolvers;
250 int maxIterations;
251 double lambdaInit;
252 string strSolver;
254 arg.
param(
"i", maxIterations, 10,
"perform n iterations");
255 arg.
param(
"v", verbose,
false,
"verbose output of the optimization process");
256 arg.
param(
"solver", strSolver,
"lm_var",
"select one specific solver");
257 arg.
param(
"lambdaInit", lambdaInit, 0,
258 "user specified lambda init for levenberg");
259 arg.
param(
"robustKernel", robustKernel,
false,
"use robust error functions");
260 arg.
param(
"fixLines", fixLines,
false,
261 "fix the lines (do localization only)");
262 arg.
param(
"planarMotion", planarMotion,
false,
"robot moves on a plane");
263 arg.
param(
"listSolvers", listSolvers,
false,
"list the solvers");
265
268 odomOffset->
setId(0);
270
275 solverFactory->
construct(strSolver, solverProperty);
277 if (listSolvers) {
279 return 0;
280 }
281
283 std::cout << "Error allocating solver. Allocating \"" << strSolver
284 << "\" failed!" << std::endl;
285 std::cout << "Available solvers: " << std::endl;
287 std::cout << "--------------" << std::endl;
288 return 0;
289 }
290
291 std::cout << "Creating simulator" << std::endl;
293
294 std::cout << "Creating robot" << std::endl;
296
297 std::cout << "Creating line sensor" << std::endl;
298 Isometry3d sensorPose = Isometry3d::Identity();
300 ls->
_nline << 0.001, 0.001, 0.001, 0.0001;
301
304
306 std::cout << "Creating landmark line 1" << std::endl;
309 liv << 0.0, 0.0, 5.0, 0.0, 1.0, 0.0;
314
315 std::cout << "Creating landmark line 2" << std::endl;
316 liv << 5.0, 0.0, 0.0, 0.0, 0.0, 1.0;
322
323 std::cout << "Creating landmark line 3" << std::endl;
324 liv << 0.0, 5.0, 0.0, 1.0, 0.0, 0.0;
330
331 Quaterniond q, iq;
332 if (planarMotion) {
333 r->_planarMotion = true;
334 r->_nmovecov << 0.01, 0.0025, 1e-9, 0.001, 0.001, 0.025;
335 q = Quaterniond(AngleAxisd(0.2, Vector3d::UnitZ()).toRotationMatrix());
336 iq = Quaterniond(AngleAxisd(-0.2, Vector3d::UnitZ()).toRotationMatrix());
337 } else {
338 r->_planarMotion = false;
339 r->_nmovecov << 0.1, 0.005, 1e-9, 0.001, 0.001, 0.05;
340 q = Quaterniond((AngleAxisd(M_PI / 10, Vector3d::UnitZ()) *
341 AngleAxisd(0.1, Vector3d::UnitY()))
342 .toRotationMatrix());
343 iq = Quaterniond((AngleAxisd(-M_PI / 10, Vector3d::UnitZ()) *
344 AngleAxisd(0.1, Vector3d::UnitY()))
345 .toRotationMatrix());
346 }
347
348 Isometry3d delta = Isometry3d::Identity();
350
351 Isometry3d startPose = Isometry3d::Identity();
352 startPose.matrix().block<3, 3>(0, 0) =
353 AngleAxisd(-0.75 * M_PI, Vector3d::UnitZ()).toRotationMatrix();
354 sim->
move(0, startPose);
355
356 int k = 20;
357 int l = 2;
358 double delta_t = 0.2;
359 for (int j = 0; j < l; ++j) {
360 Vector3d tr(1.0, 0.0, 0.0);
361 delta.matrix().block<3, 3>(0, 0) = q.toRotationMatrix();
362 if (j == l - 1) {
363 delta.matrix().block<3, 3>(0, 0) = Matrix3d::Identity();
364 }
365 delta.translation() = tr * (delta_t * j);
366 Isometry3d iDelta = delta.inverse();
367 for (int a = 0; a < 2; ++a) {
368 for (int i = 0; i < k; ++i) {
369 std::cout << "m";
370 if (a == 0) {
372 } else {
374 }
375 std::cout << "s";
377 }
378 }
379 }
380 for (int j = 0; j < l; ++j) {
381 Vector3d tr(1.0, 0.0, 0.0);
382 delta.matrix().block<3, 3>(0, 0) = iq.toRotationMatrix();
383 if (j == l - 1) {
384 delta.matrix().block<3, 3>(0, 0) = Matrix3d::Identity();
385 }
386 delta.translation() = tr * (delta_t * j);
387 Isometry3d iDelta = delta.inverse();
388 for (int a = 0; a < 2; ++a) {
389 for (int i = 0; i < k; ++i) {
390 std::cout << "m";
391 if (a == 0) {
393 } else {
395 }
396 std::cout << "s";
398 }
399 }
400 }
401 std::cout << std::endl;
402
405 if (gauge) {
407 }
408
409 ofstream osp("line3d.g2o");
411 std::cout << "Saved graph on file line3d.g2o, use g2o_viewer to work with it."
412 << std::endl;
413
414 return 0;
415}
std::set< BaseSensor * > _sensors
Command line parsing of argc and argv.
bool parseArgs(int argc, char **argv, bool exitOnError=true)
void param(const std::string &name, bool &p, bool defValue, const std::string &desc)
static G2O_TYPES_SLAM3D_ADDONS_API Line3D fromCartesian(const Vector6 &cart)
A general case Vertex for optimization.
void setFixed(bool fixed)
true => this node should be considered fixed during the optimization
create solvers based on their short name
OptimizationAlgorithm * construct(const std::string &tag, OptimizationAlgorithmProperty &solverProperty) const
static OptimizationAlgorithmFactory * instance()
return the instance
void listSolvers(std::ostream &os) const
list the known solvers into a stream
Generic interface for a non-linear solver operating on a graph.
void setAlgorithm(OptimizationAlgorithm *algorithm)
OptimizationAlgorithm * solver()
VertexSE3 * _offsetVertex
void sense(int robotIndex)
void relativeMove(int robotIndex, const Isometry3d &delta)
void move(int robotIndex, const Isometry3d &newRobotPose)
OptimizableGraph::Vertex * vertex()
virtual bool save(std::ostream &os, int level=0) const
save the graph to a stream. Again uses the Factory system.
bool addParameter(Parameter *p)
Vertex * vertex(int id)
returns the vertex number id appropriately casted
describe the properties of a solver