Skip to content

Commit

Permalink
Add Error if geomagnetic field is invalid in EKF. Remove redundant no…
Browse files Browse the repository at this point in the history
…rmalization of magnetic measurement vector in FQA.
  • Loading branch information
Mayitzin committed May 19, 2021
1 parent bfe46ba commit a48210e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
7 changes: 4 additions & 3 deletions ahrs/filters/ekf.py
Original file line number Diff line number Diff line change
Expand Up @@ -1013,7 +1013,7 @@ def _set_measurement_noise_covariance(self, **kw) -> np.ndarray:

def _set_reference_frames(self, mref: float, frame: str = 'NED') -> None:
if frame.upper() not in ['NED', 'ENU']:
raise ValueError(f"Invalid frame '{frame}'. Try 'NED' or ENU'")
raise ValueError(f"Invalid frame '{frame}'. Try 'NED' or 'ENU'")
# Magnetic Reference Vector
if mref is None:
# Local magnetic reference of Munich, Germany
Expand Down Expand Up @@ -1310,8 +1310,9 @@ def update(self, q: np.ndarray, gyr: np.ndarray, acc: np.ndarray, mag: np.ndarra
self.z = np.copy(a)
if mag is not None:
m_norm = np.linalg.norm(mag)
if m_norm > 0:
self.z = np.r_[a, mag/m_norm]
if m_norm == 0:
raise ValueError(f"Invalid geomagnetic field. Its magnitude must be greater than zero.")
self.z = np.r_[a, mag/m_norm]
self.R = np.diag(np.repeat(self.noises[1:] if mag is not None else self.noises[1], 3))
# ----- Prediction -----
q_t = self.f(q, g) # Predicted State
Expand Down
1 change: 0 additions & 1 deletion ahrs/filters/fqa.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,6 @@ def estimate(self, acc: np.ndarray = None, mag: np.ndarray = None) -> np.ndarray
if not m_norm>0:
return q_er
q_a = np.array([1., 0., 0., 0.])
m_norm = np.linalg.norm(mag)
if m_norm>0:
m = mag/m_norm
bm = np.array([0.0, *m])
Expand Down

0 comments on commit a48210e

Please sign in to comment.