11use color_eyre:: Result ;
2+ use filtering:: low_pass_filter:: LowPassFilter ;
23use serde:: { Deserialize , Serialize } ;
34
45use context_attribute:: context;
5- use coordinate_systems:: { Field , Ground , Robot } ;
6+ use coordinate_systems:: { Ground , Robot } ;
67use framework:: MainOutput ;
7- use linear_algebra:: { vector, Isometry3 , Orientation3 } ;
8- use types:: { robot_kinematics:: RobotKinematics , support_foot:: Side } ;
8+ use linear_algebra:: { vector, Isometry3 , Orientation3 , Vector2 } ;
9+ use types:: { robot_kinematics:: RobotKinematics , sensor_data :: SensorData , support_foot:: Side } ;
910
1011#[ derive( Deserialize , Serialize ) ]
11- pub struct GroundProvider { }
12+ pub struct GroundProvider {
13+ roll_pitch_filter : LowPassFilter < Vector2 < Robot > > ,
14+ }
1215
1316#[ context]
14- pub struct CreationContext { }
17+ pub struct CreationContext {
18+ roll_pitch_smoothing_factor : Parameter < f32 , "ground_provider.roll_pitch_smoothing_factor" > ,
19+ }
1520
1621#[ context]
1722pub struct CycleContext {
1823 robot_kinematics : Input < RobotKinematics , "robot_kinematics" > ,
19- robot_orientation : RequiredInput < Option < Orientation3 < Field > > , "robot_orientation?" > ,
2024 support_side : RequiredInput < Option < Side > , "support_foot.support_side?" > ,
25+ sensor_data : Input < SensorData , "sensor_data" > ,
2126}
2227
2328#[ context]
@@ -28,16 +33,28 @@ pub struct MainOutputs {
2833}
2934
3035impl GroundProvider {
31- pub fn new ( _context : CreationContext ) -> Result < Self > {
32- Ok ( Self { } )
36+ pub fn new ( context : CreationContext ) -> Result < Self > {
37+ Ok ( Self {
38+ roll_pitch_filter : LowPassFilter :: with_smoothing_factor (
39+ vector ! [ 0.0 , 0.0 ] ,
40+ * context. roll_pitch_smoothing_factor ,
41+ ) ,
42+ } )
3343 }
3444
3545 pub fn cycle ( & mut self , context : CycleContext ) -> Result < MainOutputs > {
3646 struct LeftSoleHorizontal ;
3747 struct RightSoleHorizontal ;
3848
39- let ( roll, pitch, _) = context. robot_orientation . inner . euler_angles ( ) ;
40- let imu_orientation = Orientation3 :: from_euler_angles ( roll, pitch, 0.0 ) . mirror ( ) ;
49+ self . roll_pitch_filter
50+ . update ( context. sensor_data . inertial_measurement_unit . roll_pitch ) ;
51+
52+ let imu_orientation = Orientation3 :: from_euler_angles (
53+ self . roll_pitch_filter . state ( ) . x ( ) ,
54+ self . roll_pitch_filter . state ( ) . y ( ) ,
55+ 0.0 ,
56+ )
57+ . mirror ( ) ;
4158
4259 let left_sole_horizontal_to_robot = Isometry3 :: from_parts (
4360 context
0 commit comments