From 42fa235571b594fbdfd27fda123a97d7203cac72 Mon Sep 17 00:00:00 2001 From: Easton Potokar Date: Mon, 16 Dec 2024 20:48:36 -0500 Subject: [PATCH] Cleaned --- README.md | 72 ++++++++++++++++++++++------------------------ examples/readme.rs | 41 ++++++++++++++++++++++++++ examples/serde.rs | 9 ++---- src/lib.rs | 7 +++-- 4 files changed, 83 insertions(+), 46 deletions(-) create mode 100644 examples/readme.rs diff --git a/README.md b/README.md index e7d6fbd..8842c1d 100644 --- a/README.md +++ b/README.md @@ -42,48 +42,46 @@ Additionally, we recommend checking out the [tests](/tests/) folder for more exa ```rust use factrs::{ - assign_symbols, - fac, - containers::{FactorBuilder, Graph, Values}, - noise::GaussianNoise, - optimizers::GaussNewton, - residuals::{BetweenResidual, PriorResidual}, - robust::Huber, - traits::*, - variables::SO2, + core::{ + assign_symbols, fac, BetweenResidual, GaussNewton, Graph, Huber, PriorResidual, Values, SO2, + }, + traits::*, }; // Assign symbols to variable types assign_symbols!(X: SO2); -// Make all the values -let mut values = Values::new(); - -let x = SO2::from_theta(1.0); -let y = SO2::from_theta(2.0); -values.insert(X(0), SO2::identity()); -values.insert(X(1), SO2::identity()); - -// Make the factors & insert into graph -let mut graph = Graph::new(); -let res = PriorResidual::new(x.clone()); -let factor = fac![res, X(0)]; -graph.add_factor(factor); - -let res = BetweenResidual::new(y.minus(&x)); -let robust = Huber::default(); -let factor = fac![res, (X(0), X(1)), 0.1 as std, robust]; -// fac! is syntactic sugar for the following -// let noise = GaussianNoise::from_scalar_sigma(0.1); -// let factor = FactorBuilder::new2(res, X(0), X(1)) -// .noise(noise) -// .robust(robust) -// .build(); -graph.add_factor(factor); - -// Optimize! -let mut opt: GaussNewton = GaussNewton::new(graph); -let result = opt.optimize(values); +fn main() { + // Make all the values + let mut values = Values::new(); + + let x = SO2::from_theta(1.0); + let y = SO2::from_theta(2.0); + values.insert(X(0), SO2::identity()); + values.insert(X(1), SO2::identity()); + + // Make the factors & insert into graph + let mut graph = Graph::new(); + let res = PriorResidual::new(x.clone()); + let factor = fac![res, X(0)]; + graph.add_factor(factor); + + let res = BetweenResidual::new(y.minus(&x)); + let robust = Huber::default(); + let factor = fac![res, (X(0), X(1)), 0.1 as std, robust]; + // fac! is syntactic sugar for the following + // let noise = GaussianNoise::from_scalar_sigma(0.1); + // let factor = FactorBuilder::new2(res, X(0), X(1)) + // .noise(noise) + // .robust(robust) + // .build(); + graph.add_factor(factor); + + // Optimize! + let mut opt: GaussNewton = GaussNewton::new(graph); + let result = opt.optimize(values).unwrap(); + println!("Results {:#}", result); +} ``` # Installation diff --git a/examples/readme.rs b/examples/readme.rs new file mode 100644 index 0000000..619c6b3 --- /dev/null +++ b/examples/readme.rs @@ -0,0 +1,41 @@ +use factrs::{ + core::{ + assign_symbols, fac, BetweenResidual, GaussNewton, Graph, Huber, PriorResidual, Values, SO2, + }, + traits::*, +}; + +// Assign symbols to variable types +assign_symbols!(X: SO2); + +fn main() { + // Make all the values + let mut values = Values::new(); + + let x = SO2::from_theta(1.0); + let y = SO2::from_theta(2.0); + values.insert(X(0), SO2::identity()); + values.insert(X(1), SO2::identity()); + + // Make the factors & insert into graph + let mut graph = Graph::new(); + let res = PriorResidual::new(x.clone()); + let factor = fac![res, X(0)]; + graph.add_factor(factor); + + let res = BetweenResidual::new(y.minus(&x)); + let robust = Huber::default(); + let factor = fac![res, (X(0), X(1)), 0.1 as std, robust]; + // fac! is syntactic sugar for the following + // let noise = GaussianNoise::from_scalar_sigma(0.1); + // let factor = FactorBuilder::new2(res, X(0), X(1)) + // .noise(noise) + // .robust(robust) + // .build(); + graph.add_factor(factor); + + // Optimize! + let mut opt: GaussNewton = GaussNewton::new(graph); + let result = opt.optimize(values).unwrap(); + println!("Results {:#}", result); +} diff --git a/examples/serde.rs b/examples/serde.rs index 7cae953..3683ceb 100644 --- a/examples/serde.rs +++ b/examples/serde.rs @@ -1,10 +1,5 @@ -use factrs::{ - assign_symbols, - containers::{Graph, Values}, - fac, - residuals::{BetweenResidual, PriorResidual}, - robust::GemanMcClure, - variables::{SE2, SO2}, +use factrs::core::{ + assign_symbols, fac, BetweenResidual, GemanMcClure, Graph, PriorResidual, Values, SE2, SO2, }; assign_symbols!(X: SO2; Y: SE2); diff --git a/src/lib.rs b/src/lib.rs index 1cef9aa..e37f48a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -135,17 +135,20 @@ pub mod traits { /// Helper module to group together common types /// /// Specifically, this contains everything that would be needed to implement a -/// simple pose graph. While we recommend against it, it can be all imported -/// using +/// simple pose graph. While we recommend against it, for quick usage it can be +/// glob imported as /// ``` /// use factrs::core::*; /// ``` pub mod core { pub use crate::{ + assign_symbols, containers::{Factor, Graph, Values}, + fac, noise::{GaussianNoise, UnitNoise}, optimizers::{GaussNewton, LevenMarquardt}, residuals::{BetweenResidual, PriorResidual}, + robust::{GemanMcClure, Huber, L2}, variables::{VectorVar, VectorVar1, VectorVar2, VectorVar3, SE2, SE3, SO2, SO3}, }; }