Added examples folder with simple rotation over one varialble - build script not finalized

release/4.3a0
Alex Cunningham 2010-08-26 18:46:48 +00:00
parent eed13e48d2
commit 9dd1d6bc10
2 changed files with 94 additions and 0 deletions

31
examples/Makefile.am Normal file
View File

@ -0,0 +1,31 @@
#----------------------------------------------------------------------------------------------------
# GTSAM Examples
#----------------------------------------------------------------------------------------------------
# use nostdinc to turn off -I. and -I.., we do not need them because
# header files are qualified so they can be included in external projects.
AUTOMAKE_OPTIONS = nostdinc
headers =
sources =
check_PROGRAMS =
noinst_PROGRAMS =
# Examples
noinst_PROGRAMS = SimpleRotation # Optimizes a single nonlinear rotation variable
#----------------------------------------------------------------------------------------------------
# rules to build local programs
#----------------------------------------------------------------------------------------------------
AM_LDFLAGS = $(BOOST_LDFLAGS)
LDADD = ../libgtsam.la
AM_DEFAULT_SOURCE_EXT = .cpp
if USE_LDL
LDADD += libldl.la
endif
# rule to run an executable
%.run: % $(LDADD)
./$^
#----------------------------------------------------------------------------------------------------

View File

@ -0,0 +1,63 @@
/*
* SimpleRotation.cpp
*
* This is a super-simple example of optimizing a single rotation according to a single prior
* yet it is quite painful (took 1.5 hours to code from scratch) and is overly complex
* An example like this should be very easy to do, so let's work at it.
*
* Created on: Jul 1, 2010
* @Author: Frank Dellaert
* @Author: Alex Cunningham
*/
#include <math.h>
#include <gtsam/inference/Key.h>
#include <gtsam/slam/PriorFactor.h>
#include <gtsam/geometry/Rot2.h>
#include <gtsam/linear/NoiseModel.h>
#include <gtsam/nonlinear/LieConfig-inl.h>
#include <gtsam/nonlinear/NonlinearFactorGraph-inl.h>
#include <gtsam/nonlinear/NonlinearOptimizer-inl.h>
/*
* TODO: make factors independent of Config
* TODO: get rid of excessive shared pointer stuff: mostly gone
* TODO: make toplevel documentation
* TODO: investigate whether we can just use ints as keys
*/
using namespace std;
using namespace gtsam;
typedef TypedSymbol<Rot2, 'x'> Key;
typedef LieConfig<Key> Config;
typedef NonlinearFactorGraph<Config> Graph;
typedef Factorization<Graph,Config> Solver;
typedef NonlinearOptimizer<Graph,Config> Optimizer;
const double degree = M_PI / 180;
int main() {
// optimize a unary factor on rotation 1
// Create a factor
Rot2 prior1 = Rot2::fromAngle(30 * degree);
SharedDiagonal model1 = noiseModel::Isotropic::Sigma(1, 1 * degree);
Key key1(1);
PriorFactor<Config, Key> factor1(key1, prior1, model1);
// Create a factor graph
Graph graph;
graph.add(factor1);
// and an initial estimate
Config initialEstimate;
initialEstimate.insert(1, Rot2::fromAngle(20 * degree));
// create an ordering
Optimizer::shared_config result = Optimizer::optimizeLM(graph, initialEstimate, Optimizer::LAMBDA);
GTSAM_PRINT(*result);
return 0;
}