263 {
264 int maxIterations;
265 bool verbose;
266 bool robustKernel;
267 double lambdaInit;
269 bool fixSensor;
270 bool fixPlanes;
271 bool fixFirstPose;
272 bool fixTrajectory;
273 bool planarMotion;
274 bool listSolvers;
275 string strSolver;
276 cerr << "graph" << endl;
277 arg.
param(
"i", maxIterations, 5,
"perform n iterations");
278 arg.
param(
"v", verbose,
false,
"verbose output of the optimization process");
279 arg.
param(
"solver", strSolver,
"lm_var",
"select one specific solver");
280 arg.
param(
"lambdaInit", lambdaInit, 0,
281 "user specified lambda init for levenberg");
282 arg.
param(
"robustKernel", robustKernel,
false,
"use robust error functions");
283 arg.
param(
"fixSensor", fixSensor,
false,
284 "fix the sensor position on the robot");
285 arg.
param(
"fixTrajectory", fixTrajectory,
false,
"fix the trajectory");
286 arg.
param(
"fixFirstPose", fixFirstPose,
false,
"fix the first robot pose");
287 arg.
param(
"fixPlanes", fixPlanes,
false,
288 "fix the planes (do localization only)");
289 arg.
param(
"planarMotion", planarMotion,
false,
"robot moves on a plane");
290 arg.
param(
"listSolvers", listSolvers,
false,
"list the solvers");
292
295 odomOffset->
setId(0);
297
302 solverFactory->
construct(strSolver, solverProperty);
304 if (listSolvers) {
306 return 0;
307 }
308
310 cerr << "Error allocating solver. Allocating \"" << strSolver
311 << "\" failed!" << endl;
312 cerr << "available solvers: " << endl;
314 cerr << "--------------" << endl;
315 return 0;
316 }
317
318 cerr << "sim" << endl;
320
321 cerr << "robot" << endl;
323
324 cerr << "planeSensor" << endl;
325 Matrix3d R = Matrix3d::Identity();
326 R << 0, 0, 1, -1, 0, 0, 0, -1, 0;
327
328 Isometry3d sensorPose = Isometry3d::Identity();
329 sensorPose.matrix().block<3, 3>(0, 0) = R;
330 sensorPose.translation() = Vector3d(.3, 0.5, 1.2);
332 ps->
_nplane << 0.03, 0.03, 0.005;
335
336 cerr << "p1" << endl;
339 plane.
fromVector(Eigen::Vector4d(0., 0., 1., 5.));
343
344 plane.
fromVector(Eigen::Vector4d(1., 0., 0., 5.));
349
350 cerr << "p2" << endl;
352 plane.
fromVector(Eigen::Vector4d(0., 1., 0., 5.));
356
357 Quaterniond q, iq;
358 if (planarMotion) {
359 r->_planarMotion = true;
360 r->_nmovecov << 0.01, 0.0025, 1e-9, 0.001, 0.001, 0.025;
361 q = Quaterniond(AngleAxisd(0.2, Vector3d::UnitZ()).toRotationMatrix());
362 iq = Quaterniond(AngleAxisd(-0.2, Vector3d::UnitZ()).toRotationMatrix());
363 } else {
364 r->_planarMotion = false;
365
366 r->_nmovecov << 0.1, 0.005, 1e-9, 0.001, 0.001, 0.05;
367 q = Quaterniond((AngleAxisd(M_PI / 10, Vector3d::UnitZ()) *
368 AngleAxisd(0.1, Vector3d::UnitY()))
369 .toRotationMatrix());
370 iq = Quaterniond((AngleAxisd(-M_PI / 10, Vector3d::UnitZ()) *
371 AngleAxisd(0.1, Vector3d::UnitY()))
372 .toRotationMatrix());
373 }
374
375 Isometry3d delta = Isometry3d::Identity();
377
378 Isometry3d startPose = Isometry3d::Identity();
379 startPose.matrix().block<3, 3>(0, 0) =
380 AngleAxisd(-0.75 * M_PI, Vector3d::UnitZ()).toRotationMatrix();
381 sim->
move(0, startPose);
382
383 int k = 20;
384 int l = 2;
385 double delta_t = 0.2;
386 for (int j = 0; j < l; j++) {
387 Vector3d tr(1., 0., 0.);
388 delta.matrix().block<3, 3>(0, 0) = q.toRotationMatrix();
389 if (j == (l - 1)) {
390 delta.matrix().block<3, 3>(0, 0) = Matrix3d::Identity();
391 }
392 delta.translation() = tr * (delta_t * j);
393 Isometry3d iDelta = delta.inverse();
394 for (int a = 0; a < 2; a++) {
395 for (int i = 0; i < k; i++) {
396 cerr << "m";
397 if (a == 0)
399 else
401 cerr << "s";
403 }
404 }
405 }
406
407 for (int j = 0; j < l; j++) {
408 Vector3d tr(1., 0., 0.);
409 delta.matrix().block<3, 3>(0, 0) = iq.toRotationMatrix();
410 if (j == l - 1) {
411 delta.matrix().block<3, 3>(0, 0) = Matrix3d::Identity();
412 }
413 delta.translation() = tr * (delta_t * j);
414 Isometry3d iDelta = delta.inverse();
415 for (int a = 0; a < 2; a++) {
416 for (int i = 0; i < k; i++) {
417 cerr << "m";
418 if (a == 0)
420 else
422 cerr << "s";
424 }
425 }
426 }
427
428 ofstream os("test_gt.g2o");
430
431 if (fixSensor) {
433 } else {
435 noffcov << 0.1, 0.1, 0.1, 0.5, 0.5, 0.5;
439 }
440
441 if (fixFirstPose) {
444 }
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459 ofstream osp("test_preopt.g2o");
461
465 if (!fixSensor) {
467 std::pair<int, int> indexParams;
470 std::vector<std::pair<int, int> > blockIndices;
471 blockIndices.push_back(indexParams);
473 cerr << "error in computing the covariance" << endl;
474 } else {
477
478 cerr << "Param covariance" << endl;
479 cerr << m << endl;
480 cerr << "OffsetVertex: " << endl;
482 cerr << endl;
483 cerr << "rotationDeterminant: " << m.block<3, 3>(0, 0).determinant()
484 << endl;
485 cerr << "translationDeterminant: " << m.block<3, 3>(3, 3).determinant()
486 << endl;
487 cerr << endl;
488 }
489 }
490 ofstream os1("test_postOpt.g2o");
492}
std::set< BaseSensor * > _sensors
const EstimateType & estimate() const
return the current estimate of the vertex
void setEstimate(const EstimateType &et)
set the estimate for the vertex also calls updateCache()
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)
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 fromVector(const Vector4 &coeffs_)
Sparse matrix which uses blocks.
SparseMatrixBlock * block(int r, int c, bool alloc=false)
int optimize(int iterations, bool online=false)
void setVerbose(bool verbose)
virtual bool initializeOptimization(HyperGraph::EdgeSet &eset)
void setAlgorithm(OptimizationAlgorithm *algorithm)
OptimizationAlgorithm * solver()
bool computeMarginals(SparseBlockMatrix< MatrixX > &spinv, const std::vector< std::pair< int, int > > &blockIndices)
virtual bool write(std::ostream &os) const
write the vertex to a stream
Eigen::Isometry3d sample_noise_from_se3(const Vector6 &cov)
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