@@ -10,21 +10,18 @@ A simple 2D pose slam example with "GPS" measurements
10
10
*/
11
11
12
12
#![ allow( unused_imports) ]
13
+ // Our state will be represented by SE2 -> theta, x, y
14
+ // VectorVar2 is a newtype around Vector2 for optimization purposes
15
+ use factrs:: variables:: { VectorVar2 , SE2 } ;
13
16
use factrs:: {
14
17
assign_symbols,
15
- containers :: { Graph , Values } ,
18
+ core :: { BetweenResidual , GaussNewton , GaussianNoise , Graph , Values } ,
16
19
dtype, fac,
17
20
linalg:: { Const , ForwardProp , Numeric , NumericalDiff , VectorX } ,
18
- noise:: GaussianNoise ,
19
- optimizers:: GaussNewton ,
20
- residuals:: { BetweenResidual , Residual1 } ,
21
- traits:: { GraphOptimizer , Optimizer , Variable } ,
21
+ residuals:: Residual1 ,
22
+ traits:: * ,
22
23
} ;
23
24
24
- // Our state will be represented by SE2 -> theta, x, y
25
- // VectorVar2 is a newtype around Vector2 for optimization purposes
26
- use factrs:: variables:: { VectorVar2 , SE2 } ;
27
-
28
25
#[ derive( Clone , Debug ) ]
29
26
// Enable serialization if it's desired
30
27
#[ cfg_attr( feature = "serde" , derive( serde:: Serialize , serde:: Deserialize ) ) ]
@@ -45,10 +42,11 @@ impl GpsResidual {
45
42
impl Residual1 for GpsResidual {
46
43
// Use forward propagation for differentiation
47
44
type Differ = ForwardProp < <Self as Residual1 >:: DimIn > ;
48
- // Alternatively, could use numerical differentiation (6 => 10^-6 as denominator)
49
- // type Differ = NumericalDiff<6>;
45
+ // Alternatively, could use numerical differentiation (6 => 10^-6 as
46
+ // denominator) type Differ = NumericalDiff<6>;
50
47
51
- // The input variable type, input dimension of variable(s), and output dimension of residual
48
+ // The input variable type, input dimension of variable(s), and output dimension
49
+ // of residual
52
50
type V1 = SE2 ;
53
51
type DimIn = Const < 3 > ;
54
52
type DimOut = Const < 2 > ;
@@ -64,8 +62,8 @@ impl Residual1 for GpsResidual {
64
62
}
65
63
66
64
// You can also hand-code the jacobian by hand if extra efficiency is desired.
67
- // fn residual1_jacobian(&self, values: &Values, keys: &[Key]) -> DiffResult<VectorX, MatrixX> {
68
- // let p: &SE2 = values
65
+ // fn residual1_jacobian(&self, values: &Values, keys: &[Key]) ->
66
+ // DiffResult<VectorX, MatrixX> { let p: &SE2 = values
69
67
// .get_unchecked(keys[0])
70
68
// .expect("got wrong variable type");
71
69
// let s = p.theta().sin();
@@ -76,8 +74,9 @@ impl Residual1 for GpsResidual {
76
74
// diff,
77
75
// }
78
76
// }
79
- // As a note - the above jacobian is only valid if running with the "left" feature disabled
80
- // Switching to the left feature will change the jacobian used
77
+ // As a note - the above jacobian is only valid if running with the "left"
78
+ // feature disabled Switching to the left feature will change the jacobian
79
+ // used
81
80
}
82
81
83
82
// Here we assign X to always represent SE2 variables
@@ -111,11 +110,12 @@ fn main() {
111
110
112
111
// These will all compile-time error
113
112
// values.insert(X(5), VectorVar2::identity()); // wrong variable type
114
- // let f = fac![GpsResidual::new(0.0, 0.0), (X(0), X(1))]; // wrong number of keys
115
- // let n = GaussianNoise::<5>::from_scalar_sigma(0.1);
116
- // let f = fac![GpsResidual::new(0.0, 0.0), X(0), n]; // wrong noise-model dimension
117
- // assign_symbols!(Y : VectorVar2);
118
- // let f = fac![GpsResidual::new(0.0, 0.0), Y(0), 0.1 as std]; // wrong variable type
113
+ // let f = fac![GpsResidual::new(0.0, 0.0), (X(0), X(1))]; // wrong number of
114
+ // keys let n = GaussianNoise::<5>::from_scalar_sigma(0.1);
115
+ // let f = fac![GpsResidual::new(0.0, 0.0), X(0), n]; // wrong noise-model
116
+ // dimension assign_symbols!(Y : VectorVar2);
117
+ // let f = fac![GpsResidual::new(0.0, 0.0), Y(0), 0.1 as std]; // wrong variable
118
+ // type
119
119
120
120
// optimize
121
121
let mut opt: GaussNewton = GaussNewton :: new ( graph) ;
0 commit comments