@@ -116,16 +116,10 @@ impl IMU {
116
116
117
117
pub fn update ( & mut self , dt : f32 ) {
118
118
let bias_drift = Normal :: new ( 0.0 , self . bias_instability * dt. sqrt ( ) ) . unwrap ( ) ;
119
- self . accel_bias += Vector3 :: new (
120
- bias_drift. sample ( & mut rand:: thread_rng ( ) ) ,
121
- bias_drift. sample ( & mut rand:: thread_rng ( ) ) ,
122
- bias_drift. sample ( & mut rand:: thread_rng ( ) ) ,
123
- ) ;
124
- self . gyro_bias += Vector3 :: new (
125
- bias_drift. sample ( & mut rand:: thread_rng ( ) ) ,
126
- bias_drift. sample ( & mut rand:: thread_rng ( ) ) ,
127
- bias_drift. sample ( & mut rand:: thread_rng ( ) ) ,
128
- ) ;
119
+ let drift_vector =
120
+ || Vector3 :: from_iterator ( ( 0 ..3 ) . map ( |_| bias_drift. sample ( & mut rand:: thread_rng ( ) ) ) ) ;
121
+ self . accel_bias += drift_vector ( ) ;
122
+ self . gyro_bias += drift_vector ( ) ;
129
123
}
130
124
131
125
pub fn read (
@@ -198,12 +192,10 @@ impl PIDController {
198
192
self . integral_att_error += error_angles * dt;
199
193
self . integral_att_error
200
194
. component_mul_assign ( & self . max_integral_att . map ( |x| x. signum ( ) ) ) ;
201
- for i in 0 ..3 {
202
- if self . integral_att_error [ i] . abs ( ) > self . max_integral_att [ i] {
203
- self . integral_att_error [ i] =
204
- self . integral_att_error [ i] . signum ( ) * self . max_integral_att [ i] ;
205
- }
206
- }
195
+ self . integral_att_error = self
196
+ . integral_att_error
197
+ . zip_map ( & self . max_integral_att , |int, max| int. clamp ( -max, max) ) ;
198
+
207
199
let error_angular_velocity = -current_angular_velocity;
208
200
209
201
self . kp_att . component_mul ( & error_angles)
0 commit comments