@@ -4,7 +4,7 @@ use nalgebra::{Isometry2, Translation2, UnitComplex, Vector2};
44use serde:: { Deserialize , Serialize } ;
55
66use crate :: {
7- behavior:: { behaviors :: Standup , engine:: in_behavior } ,
7+ behavior:: engine:: BehaviorState ,
88 kinematics:: {
99 Kinematics ,
1010 spaces:: { LeftSole , RightSole } ,
@@ -21,14 +21,15 @@ pub(super) struct OdometryPlugin;
2121
2222impl Plugin for OdometryPlugin {
2323 fn build ( & self , app : & mut App ) {
24- app. init_resource :: < Odometry > ( ) . add_systems (
25- PreUpdate ,
26- update_odometry
27- . run_if ( not ( in_behavior :: < Standup > ) )
28- . after ( crate :: kinematics:: update_kinematics)
29- . after ( crate :: sensor:: orientation:: update_orientation)
30- . after ( WalkingEngineSet :: Prepare ) ,
31- ) ;
24+ app. init_resource :: < Odometry > ( )
25+ . add_systems ( OnExit ( BehaviorState :: Standup ) , reset_odometry)
26+ . add_systems (
27+ PreUpdate ,
28+ update_odometry
29+ . after ( crate :: kinematics:: update_kinematics)
30+ . after ( crate :: sensor:: orientation:: update_orientation)
31+ . after ( WalkingEngineSet :: Prepare ) ,
32+ ) ;
3233 }
3334}
3435
@@ -47,8 +48,6 @@ pub fn update_odometry(
4748 return ;
4849 }
4950
50- // TODO: We should probably reset the odometry in some cases
51- // See: https://github.com/IntelligentRoboticsLab/yggdrasil/issues/400
5251 odometry. update (
5352 & localization_config. odometry ,
5453 & foot_support,
@@ -57,6 +56,16 @@ pub fn update_odometry(
5756 ) ;
5857}
5958
59+ fn reset_odometry (
60+ mut odometry : ResMut < Odometry > ,
61+ orientation : Res < RobotOrientation > ,
62+ kinematics : Res < Kinematics > ,
63+ ) {
64+ odometry. offset_to_last = Isometry2 :: default ( ) ;
65+ odometry. last_left_sole_to_right_sole = kinematics. vector :: < LeftSole , RightSole > ( ) . inner . xy ( ) ;
66+ odometry. reset_orientation ( & orientation) ;
67+ }
68+
6069/// Configuration for the odometry.
6170#[ derive( Resource , Debug , Clone , Serialize , Deserialize ) ]
6271pub struct OdometryConfig {
@@ -103,7 +112,6 @@ impl Odometry {
103112 Side :: Left => left_sole_to_right_sole - self . last_left_sole_to_right_sole ,
104113 Side :: Right => -left_sole_to_right_sole + self . last_left_sole_to_right_sole ,
105114 } / 2.0 ;
106-
107115 self . last_left_sole_to_right_sole = left_sole_to_right_sole;
108116 let scaled_offset = offset. component_mul ( & config. scale_factor ) ;
109117
0 commit comments