stable_flight/estimation/wind.rs
1//! Wind from the air's push on a rotor-borne vehicle: drag inverted to air velocity, one axis
2//! at a time, and filtered on world wind.
3//!
4//! Thrust acts along the thrust frame's `z`, so the specific force along its `x` and `y` is
5//! the air's push alone. Each axis's drag model, a bluff-body term `½ρv²/B` plus rotor
6//! momentum drag `μv` (ArduPilot's and PX4's drag fusion: `NavEKF3_core::FuseDragForces`,
7//! `Ekf::fuseDrag`), is inverted to the air velocity along it; the wind along it is
8//! the ground velocity's component less that. A two-state Kalman filter on wind (north, east)
9//! takes each axis as a scalar measurement whose noise is the force noise over the drag's
10//! slope there, so an axis with little drag (a tailsitter's span in hover) counts for little,
11//! and the wind across it is learned once a turn puts more drag on it. Both stacks fit the
12//! drag frame to the body with thrust along `z` and treat X and Y alike apart from their
13//! coefficients; per-axis noise is what lets a flat-plate airframe use it.
14//!
15//! The measurement is averaged over [`UPDATE_PERIOD_S`], as both stacks do, before each
16//! update. Allocation-free and fixed-size.
17
18use nalgebra::{Matrix2, UnitQuaternion};
19
20use crate::controllers::{InvalidConfig, check_limit, check_positive};
21use crate::math::neu_to_ned;
22use crate::{GRAVITY, Vec2, Vec3, VehicleState};
23
24#[cfg(test)]
25mod tests;
26
27/// Sea-level air density, in kg/m³ (ISA).
28pub const AIR_DENSITY_KGPM3: f32 = 1.225;
29
30/// Seconds the measurement is averaged over before each update: about 5 Hz, as both stacks
31/// average their specific force (`NavEKF3_core::SampleDragData`,
32/// `EstimatorInterface::setDragData`).
33pub const UPDATE_PERIOD_S: f32 = 0.2;
34
35/// Default [`WindConfig::force_noise_mps2`]: ArduPilot's `EK3_DRAG_M_NSE` (`AP_NavEKF3.cpp`).
36pub const DEFAULT_FORCE_NOISE_MPS2: f32 = 0.5;
37
38/// Default [`WindConfig::process_noise_mps_per_rt_s`]: lets a steady wind's estimate move about
39/// 0.1 m/s a second, slow beside a hover's drift.
40pub const DEFAULT_PROCESS_NOISE_MPS_PER_RT_S: f32 = 0.1;
41
42/// Default [`WindConfig::initial_sd_mps`], in m/s: past any wind a rotor-borne vehicle flies
43/// in, so the first measurements set the estimate.
44pub const DEFAULT_INITIAL_SD_MPS: f32 = 10.0;
45
46/// Default [`WindConfig::gate_sigma`]: both stacks gate drag at 5σ
47/// (`NavEKF3_core::FuseDragForces`, `Ekf::fuseDrag`).
48pub const DEFAULT_GATE_SIGMA: f32 = 5.0;
49
50/// Cosine of the most tilt, thrust axis from vertical, a tick is used at: 45°. The drag model
51/// is a hover's; tilted further (a tailsitter pitching over, a hard maneuver) the wing's lift
52/// and the thrust's own tilt dominate the push.
53const MIN_TILT_COSINE: f32 = core::f32::consts::FRAC_1_SQRT_2;
54
55/// Default [`WindConfig::max_axial_speed_mps`], in m/s: at 1 m/s a sim tailsitter's calm-air
56/// estimate is 0.14 m/s off 10 s after its takeoff, 0.22 m/s with no skip (#608).
57pub const DEFAULT_MAX_AXIAL_SPEED_MPS: f32 = 1.0;
58
59/// Least drag slope, in 1/s, an axis's noise is divided by: below it the axis tells almost
60/// nothing about the wind, and the noise stays finite.
61const MIN_DRAG_SLOPE_PER_S: f32 = 1e-3;
62
63/// The drag model, per thrust-frame axis (`x`, `y`), and the filter's noise.
64///
65/// With every coefficient 0 (the default, as both stacks ship drag fusion off) the estimator
66/// never updates.
67#[derive(Debug, Clone, Copy, PartialEq)]
68#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
69pub struct WindConfig {
70 /// Ballistic coefficient along `x` and `y`, in kg/m²: mass over drag coefficient times
71 /// area, so the bluff-body drag along the axis is `½ρ·v·|V|/B` per kg, `v` the air along
72 /// the axis and `|V|` the airspeed with the air along the thrust axis counted in (the
73 /// vehicle's climb or sink, the wind taken as horizontal), as PX4's `Ekf::fuseDrag`
74 /// predicts it (PX4 counts the other axis's air too, which inverting one axis at a time
75 /// can't). 0 leaves the term out. Must be non-negative and finite.
76 pub ballistic_kgpm2: Vec2,
77 /// Momentum drag along `x` and `y`, in 1/s: drag acceleration per m/s of air velocity.
78 /// 0 leaves the term out. Must be non-negative and finite.
79 pub momentum_per_s: Vec2,
80 /// Specific-force noise on each averaged measurement, in m/s². Must be positive and
81 /// finite. Defaults to [`DEFAULT_FORCE_NOISE_MPS2`].
82 pub force_noise_mps2: f32,
83 /// How fast the wind may wander, in m/s per √s (process noise). Must be non-negative and
84 /// finite. Defaults to [`DEFAULT_PROCESS_NOISE_MPS_PER_RT_S`].
85 pub process_noise_mps_per_rt_s: f32,
86 /// Standard deviation of each wind component, in m/s, before the first measurement; it
87 /// applies from the estimator's next [`reset`](WindEstimator::reset). Higher: the first
88 /// measurements move the estimate more. Must be positive and finite. Defaults to
89 /// [`DEFAULT_INITIAL_SD_MPS`].
90 pub initial_sd_mps: f32,
91 /// How many standard deviations an averaged measurement may be off the estimate before
92 /// it is rejected. Higher: takes in a sudden gust sooner, and a bad measurement with it.
93 /// Must be positive and finite. Defaults to [`DEFAULT_GATE_SIGMA`].
94 pub gate_sigma: f32,
95 /// Most ground speed along the thrust axis, in m/s, a tick is used at: the drag model is
96 /// a hover's, and climbing or sinking a cambered wing lifts toward its belly, which reads
97 /// as wind. Higher: uses more of a climb, and its lift; lower: holds the estimate through
98 /// gentler climbs and descents. Must be positive and finite. Defaults to
99 /// [`DEFAULT_MAX_AXIAL_SPEED_MPS`].
100 pub max_axial_speed_mps: f32,
101}
102
103impl Default for WindConfig {
104 /// No drag model (the estimator off), and the default noises.
105 fn default() -> Self {
106 WindConfig {
107 ballistic_kgpm2: Vec2::zeros(),
108 momentum_per_s: Vec2::zeros(),
109 force_noise_mps2: DEFAULT_FORCE_NOISE_MPS2,
110 process_noise_mps_per_rt_s: DEFAULT_PROCESS_NOISE_MPS_PER_RT_S,
111 initial_sd_mps: DEFAULT_INITIAL_SD_MPS,
112 gate_sigma: DEFAULT_GATE_SIGMA,
113 max_axial_speed_mps: DEFAULT_MAX_AXIAL_SPEED_MPS,
114 }
115 }
116}
117
118impl WindConfig {
119 /// Checks that the coefficients and `process_noise_mps_per_rt_s` are non-negative and
120 /// finite, and that `force_noise_mps2`, `initial_sd_mps`, `gate_sigma`, and
121 /// `max_axial_speed_mps` are positive and finite.
122 ///
123 /// # Examples
124 ///
125 /// ```
126 /// use stable_flight::estimation::wind::WindConfig;
127 ///
128 /// let mut config = WindConfig::default();
129 /// assert!(config.validate().is_ok());
130 /// config.force_noise_mps2 = 0.0;
131 /// assert!(config.validate().is_err());
132 /// ```
133 // Inlined so the firmware's checks of a constant config fold away at compile time:
134 // outlined, it takes 1.3 kB of flash (`just fw-size`).
135 #[inline(always)]
136 pub fn validate(&self) -> Result<(), InvalidConfig> {
137 check_limit("ballistic_kgpm2.x", self.ballistic_kgpm2.x)?;
138 check_limit("ballistic_kgpm2.y", self.ballistic_kgpm2.y)?;
139 check_limit("momentum_per_s.x", self.momentum_per_s.x)?;
140 check_limit("momentum_per_s.y", self.momentum_per_s.y)?;
141 check_positive("force_noise_mps2", self.force_noise_mps2)?;
142 check_limit(
143 "process_noise_mps_per_rt_s",
144 self.process_noise_mps_per_rt_s,
145 )?;
146 check_positive("initial_sd_mps", self.initial_sd_mps)?;
147 check_positive("gate_sigma", self.gate_sigma)?;
148 check_positive("max_axial_speed_mps", self.max_axial_speed_mps)
149 }
150
151 /// Whether any drag coefficient is set, so the estimator can update.
152 pub fn is_on(&self) -> bool {
153 self.ballistic_kgpm2
154 .iter()
155 .chain(&self.momentum_per_s)
156 .any(|c| *c > 0.0)
157 }
158
159 /// The drag per kg, in m/s² along the thrust frame's `x` and `y`, on a vehicle moving
160 /// through the air at `air_mps` along those axes (its velocity less the wind's), level:
161 /// `−(k|v| + μ)v` per axis, opposing the air velocity. Zero on an axis without a
162 /// coefficient.
163 ///
164 /// # Examples
165 ///
166 /// ```
167 /// use stable_flight::Vec2;
168 /// use stable_flight::estimation::wind::WindConfig;
169 ///
170 /// // Momentum drag 0.3/s: 2 m/s forward through the air is pushed back at 0.6 m/s².
171 /// let config = WindConfig { momentum_per_s: Vec2::new(0.3, 0.3), ..Default::default() };
172 /// let drag = config.drag_mps2(Vec2::new(2.0, 0.0));
173 /// assert!((drag - Vec2::new(-0.6, 0.0)).norm() < 1e-6);
174 /// ```
175 pub fn drag_mps2(&self, air_mps: Vec2) -> Vec2 {
176 let along =
177 |i: usize| -AxisDrag::new(self, i).push_mps2(air_mps[i], 0.0) * air_mps[i].signum();
178 Vec2::new(along(0), along(1))
179 }
180}
181
182/// The wind and its uncertainty.
183#[derive(Debug, Clone, Copy, PartialEq)]
184#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
185pub struct WindEstimate {
186 /// The air mass's velocity (north, east), in m/s: where the wind blows toward.
187 pub velocity_mps: Vec2,
188 /// Covariance of `velocity_mps`, in m²/s².
189 pub covariance_m2ps2: Matrix2<f32>,
190}
191
192impl WindEstimate {
193 /// Standard deviation of the wind along the horizontal unit vector `direction`, in m/s.
194 pub fn sd_along_mps(&self, direction: Vec2) -> f32 {
195 libm::sqrtf(
196 (direction.transpose() * self.covariance_m2ps2 * direction)
197 .x
198 .max(0.0),
199 )
200 }
201}
202
203/// Estimates the wind from the vehicle state while the caller says it is airborne on rotors.
204///
205/// The config is passed to each call rather than stored, so the owner's config stays the
206/// single source of truth.
207///
208/// # Examples
209///
210/// ```
211/// use stable_flight::estimation::wind::{WindConfig, WindEstimator};
212/// use stable_flight::{Vec2, Vec3, VehicleState};
213///
214/// // A level quad with momentum drag 0.3/s, not moving, pushed east at 0.6 m/s²: the air
215/// // moves east at 2 m/s.
216/// let config = WindConfig {
217/// momentum_per_s: Vec2::new(0.3, 0.3),
218/// ..Default::default()
219/// };
220/// let state = VehicleState {
221/// acceleration_mps2: Vec3::new(0.0, 0.6, 0.0),
222/// ..Default::default()
223/// };
224/// let mut estimator = WindEstimator::default();
225/// for _ in 0..2500 {
226/// estimator.update(0.004, &config, &state);
227/// }
228/// let wind = estimator.estimate().expect("updated").velocity_mps;
229/// assert!((wind - Vec2::new(0.0, 2.0)).norm() < 0.01);
230/// ```
231#[derive(Debug, Clone, Copy, Default, PartialEq)]
232pub struct WindEstimator {
233 /// The wind and its covariance; `None` until the first measurement, which seeds the
234 /// covariance from [`WindConfig::initial_sd_mps`].
235 filter: Option<WindEstimate>,
236 /// The measurement being averaged.
237 window: Window,
238}
239
240/// Sums over one averaging period.
241#[derive(Debug, Clone, Copy, Default, PartialEq)]
242struct Window {
243 elapsed_s: f32,
244 ticks: u32,
245 /// Specific force along the thrust frame's `x` and `y`, in m/s².
246 specific_force_mps2: Vec2,
247 /// Ground velocity along each axis, in m/s.
248 ground_along_mps: Vec2,
249 /// Each axis's horizontal part (north, east).
250 axis_x: Vec2,
251 axis_y: Vec2,
252 /// Ground velocity along the thrust axis, in m/s.
253 axial_mps: f32,
254}
255
256impl WindEstimator {
257 /// Adds this tick's state, `state.attitude` taken as the thrust frame (thrust along its
258 /// `z`), and once [`UPDATE_PERIOD_S`] has gathered, updates the wind from the period's
259 /// average. A tick with a non-finite attitude, velocity, or acceleration, with the thrust
260 /// axis tilted more than 45° from vertical, or moving along it faster than
261 /// [`max_axial_speed_mps`](WindConfig::max_axial_speed_mps), is skipped. Does nothing while
262 /// `config` has no drag coefficient.
263 ///
264 /// Each axis's measurement counts by the drag's slope at the air velocity the estimate
265 /// predicts, as both EKFs linearize their drag at the state (ArduPilot's
266 /// `NavEKF3_core::FuseDragForces`, PX4's `Ekf::fuseDrag`), or at the measured one where
267 /// that is steeper. Bluff-body drag has no slope in still air: taken at a measured push near
268 /// zero alone, the slope would leave a wrong estimate there for good, and taken at the
269 /// prediction alone, a fresh estimate of no wind would discount a real wind's push (#608).
270 pub fn update(&mut self, dt: f32, config: &WindConfig, state: &VehicleState) {
271 if !config.is_on() {
272 return;
273 }
274 let Some(sample) = Sample::from_state(state, config.max_axial_speed_mps) else {
275 return;
276 };
277 let window = &mut self.window;
278 window.elapsed_s += dt;
279 window.ticks += 1;
280 window.specific_force_mps2 += sample.specific_force_mps2;
281 window.ground_along_mps += sample.ground_along_mps;
282 window.axis_x += sample.axis_x;
283 window.axis_y += sample.axis_y;
284 window.axial_mps += sample.axial_mps;
285 if window.elapsed_s < UPDATE_PERIOD_S {
286 return;
287 }
288 let window = core::mem::take(&mut self.window);
289 let n = window.ticks as f32;
290 let initial_variance_m2ps2 = config.initial_sd_mps * config.initial_sd_mps;
291 let estimate = self.filter.get_or_insert(WindEstimate {
292 velocity_mps: Vec2::zeros(),
293 covariance_m2ps2: Matrix2::identity() * initial_variance_m2ps2,
294 });
295 estimate.predict(window.elapsed_s, config);
296 let force = window.specific_force_mps2 / n;
297 let ground = window.ground_along_mps / n;
298 let axes = [window.axis_x / n, window.axis_y / n];
299 let axial_mps = window.axial_mps / n;
300 for (i, axis) in axes.into_iter().enumerate() {
301 let drag = AxisDrag::new(config, i);
302 if let Some(air_mps) = drag.air_velocity(force[i], axial_mps) {
303 let predicted_air_mps = ground[i] - axis.dot(&estimate.velocity_mps);
304 let slope_per_s = drag
305 .slope_per_s(predicted_air_mps, axial_mps)
306 .max(drag.slope_per_s(air_mps, axial_mps));
307 let noise_mps = config.force_noise_mps2 / slope_per_s.max(MIN_DRAG_SLOPE_PER_S);
308 estimate.correct(
309 axis,
310 ground[i] - air_mps,
311 noise_mps * noise_mps,
312 config.gate_sigma,
313 );
314 }
315 }
316 }
317
318 /// The wind, once a measurement has been taken.
319 pub fn estimate(&self) -> Option<WindEstimate> {
320 self.filter
321 }
322
323 /// Forgets the wind and any partial average.
324 pub fn reset(&mut self) {
325 *self = Self::default();
326 }
327}
328
329/// The filter's steps, on the estimate it holds.
330impl WindEstimate {
331 /// Grows the covariance for `elapsed_s` of wandering wind.
332 fn predict(&mut self, elapsed_s: f32, config: &WindConfig) {
333 let q = config.process_noise_mps_per_rt_s;
334 self.covariance_m2ps2 += Matrix2::identity() * (q * q * elapsed_s);
335 }
336
337 /// Fuses `measured_mps`, the wind along `axis` (horizontal, not unit: a tilted axis
338 /// reaches less of it), with variance `variance_m2ps2`; rejected past `gate_sigma`
339 /// standard deviations.
340 fn correct(&mut self, axis: Vec2, measured_mps: f32, variance_m2ps2: f32, gate_sigma: f32) {
341 let p_h = self.covariance_m2ps2 * axis;
342 let innovation_variance = axis.dot(&p_h) + variance_m2ps2;
343 let innovation = measured_mps - axis.dot(&self.velocity_mps);
344 let gate = gate_sigma * gate_sigma * innovation_variance;
345 let within_gate = innovation * innovation <= gate;
346 // `<=` is false for a NaN innovation: rejected.
347 if !within_gate || !innovation_variance.is_finite() {
348 return;
349 }
350 let gain = p_h / innovation_variance;
351 self.velocity_mps += gain * innovation;
352 self.covariance_m2ps2 -= gain * p_h.transpose();
353 // Symmetric against rounding.
354 let off = 0.5 * (self.covariance_m2ps2[(0, 1)] + self.covariance_m2ps2[(1, 0)]);
355 self.covariance_m2ps2[(0, 1)] = off;
356 self.covariance_m2ps2[(1, 0)] = off;
357 }
358}
359
360/// The specific force on the vehicle (what an accelerometer reads: acceleration less gravity),
361/// in m/s², in NED, the frame `state.attitude` rotates the body into: `(0, 0, −g)` at rest.
362///
363/// # Examples
364///
365/// ```
366/// use stable_flight::estimation::wind::specific_force_ned;
367/// use stable_flight::{GRAVITY, Vec3, VehicleState};
368///
369/// let resting = specific_force_ned(&VehicleState::default());
370/// assert_eq!(resting, Vec3::new(0.0, 0.0, -GRAVITY));
371/// ```
372pub fn specific_force_ned(state: &VehicleState) -> Vec3 {
373 let a = state.acceleration_mps2;
374 Vec3::new(a.x, a.y, -a.z - GRAVITY)
375}
376
377/// One tick's measurement.
378struct Sample {
379 specific_force_mps2: Vec2,
380 ground_along_mps: Vec2,
381 axis_x: Vec2,
382 axis_y: Vec2,
383 axial_mps: f32,
384}
385
386impl Sample {
387 /// From `state`, its attitude taken as the thrust frame; `None` if anything used is
388 /// non-finite, or the thrust axis tilted past 45° or moving along it faster than
389 /// `max_axial_speed_mps`.
390 fn from_state(state: &VehicleState, max_axial_speed_mps: f32) -> Option<Self> {
391 let attitude: &UnitQuaternion<f32> = &state.attitude;
392 // NED, as the attitude rotates the FRD body into it.
393 let specific_force_ned = specific_force_ned(state);
394 let velocity_ned = neu_to_ned(state.velocity_mps);
395 // One matrix serves them all: its columns are the body axes in NED.
396 let rotation = attitude.to_rotation_matrix();
397 // `<` is false for NaN; the finiteness check below catches it.
398 if rotation.matrix()[(2, 2)] < MIN_TILT_COSINE {
399 return None;
400 }
401 let force = rotation.inverse_transform_vector(&specific_force_ned);
402 let axis_x: Vec3 = rotation.matrix().column(0).into();
403 let axis_y: Vec3 = rotation.matrix().column(1).into();
404 let axis_z: Vec3 = rotation.matrix().column(2).into();
405 let axial_mps = axis_z.dot(&velocity_ned);
406 // `>` is false for NaN; the finiteness check below catches it.
407 if axial_mps.abs() > max_axial_speed_mps {
408 return None;
409 }
410 let sample = Sample {
411 specific_force_mps2: force.xy(),
412 ground_along_mps: Vec2::new(axis_x.dot(&velocity_ned), axis_y.dot(&velocity_ned)),
413 axis_x: axis_x.xy(),
414 axis_y: axis_y.xy(),
415 axial_mps,
416 };
417 let finite = [
418 sample.specific_force_mps2,
419 sample.ground_along_mps,
420 sample.axis_x,
421 sample.axis_y,
422 ]
423 .iter()
424 .all(|v| v.iter().all(|c| c.is_finite()))
425 && sample.axial_mps.is_finite();
426 finite.then_some(sample)
427 }
428}
429
430/// One axis's drag per kg against air velocity `v` along it, with `w` m/s of air along the
431/// thrust axis: `−(k|V| + μ)v`, `|V| = √(v² + w²)`, `k = ½ρ/B`. A climb or sink adds to the
432/// bluff body's airspeed, so the same push reads as less air along the axis.
433struct AxisDrag {
434 /// Bluff-body term, in 1/m (0 without one).
435 k_per_m: f32,
436 /// Momentum term, in 1/s.
437 mu_per_s: f32,
438}
439
440/// Newton steps refining [`AxisDrag::air_velocity`]'s root: from the still-air root, above it,
441/// four land within 1e-4 of it across hover speeds and climbs (`axis_drag_round_trips`).
442const AIR_VELOCITY_STEPS: usize = 4;
443
444impl AxisDrag {
445 /// Axis `i` (0 `x`, 1 `y`) of `config`.
446 fn new(config: &WindConfig, i: usize) -> Self {
447 let ballistic = config.ballistic_kgpm2[i];
448 AxisDrag {
449 k_per_m: if ballistic > 0.0 {
450 0.5 * AIR_DENSITY_KGPM3 / ballistic
451 } else {
452 0.0
453 },
454 mu_per_s: config.momentum_per_s[i],
455 }
456 }
457
458 /// The air velocity, in m/s, along the axis that the drag `force_mps2` comes from, with
459 /// `axial_mps` of air along the thrust axis; `None` without a drag model on the axis.
460 fn air_velocity(&self, force_mps2: f32, axial_mps: f32) -> Option<f32> {
461 let (k, mu) = (self.k_per_m, self.mu_per_s);
462 let push = force_mps2.abs();
463 let speed = if k > 0.0 {
464 // k·s² + μ·s = |f|, the positive root: the speed without air along the thrust
465 // axis, at or above the root with it.
466 let still_air = (libm::sqrtf(mu * mu + 4.0 * k * push) - mu) / (2.0 * k);
467 // Drag rises and curves up with speed, so Newton's steps from above stay above the
468 // root and close on it.
469 (0..AIR_VELOCITY_STEPS).fold(still_air, |s, _| {
470 let excess = self.push_mps2(s, axial_mps) - push;
471 let slope = self.slope_per_s(s, axial_mps);
472 if slope > 0.0 { s - excess / slope } else { s }
473 })
474 } else if mu > 0.0 {
475 push / mu
476 } else {
477 return None;
478 };
479 // Drag opposes the air velocity.
480 Some(if force_mps2 > 0.0 { -speed } else { speed })
481 }
482
483 /// The drag's push per kg, in m/s², against `air_mps` of air along the axis and
484 /// `axial_mps` along the thrust axis: `(k|V| + μ)|v|`, its size without its sign.
485 fn push_mps2(&self, air_mps: f32, axial_mps: f32) -> f32 {
486 let airspeed_mps = libm::sqrtf(air_mps * air_mps + axial_mps * axial_mps);
487 (self.k_per_m * airspeed_mps + self.mu_per_s) * air_mps.abs()
488 }
489
490 /// The drag's slope against the air velocity along the axis, at `air_mps` along it and
491 /// `axial_mps` along the thrust axis, in 1/s: `k(|V| + v²/|V|) + μ`.
492 fn slope_per_s(&self, air_mps: f32, axial_mps: f32) -> f32 {
493 let airspeed_mps = libm::sqrtf(air_mps * air_mps + axial_mps * axial_mps);
494 let bluff = if airspeed_mps > 0.0 {
495 self.k_per_m * (airspeed_mps + air_mps * air_mps / airspeed_mps)
496 } else {
497 0.0
498 };
499 bluff + self.mu_per_s
500 }
501}