/* VectorNav HSI Calibration Library v1.0.0.2
 *
 * Copyright (c) 2018 VectorNav Technologies, LLC
 *
 * This source code is proprietary to and copyrighted by VectorNav Technologies, LLC and is
 * available solely under license from VectorNav. All rights reserved. If you do not have a
 * license to use this source code from VectorNav, any use hereof is strictly prohibited by
 * U.S. law and other applicable law. This source code is restricted for use solely with the
 * products of VectorNav and as otherwise set forth in any agreement with VectorNav. Any
 * disclosure of this source code to the public or to any third party is also prohibited.
 */
/** \file
*
* \section Description
* This header file contains declarations for using VectorNav HSI 3D tool.
*/
#ifndef VNHSI3D_H_INCLUDED
#define VNHSI3D_H_INCLUDED

#include "vnhsi.h"

#ifdef __cplusplus
extern "C" {
#endif

/** \brief Initialize the 3D HSI with the configuration parameters.
*
* \param[in] dipole The magnetic field dipole structure.
* \param[in] c  The configuration structure.
* \return None. */
void vnhsi_3d_init(VnHsiDipole dipole, VnHsiConfig* c);

/** \brief Determine if a YMR measurement should be kept for 3D HSI computation.
  *
  * Takes in YPR values from a sensor being tumbled in 3D.  
  * Calculates the change in magnetic direction in the body frame to threshold new
	measurements.
  
  * \param[in] dipole The magnetic field dipole structure.
  * \param[in] c The configuration structure.
  * \param[in] ypr The current YPR measurement vector (in degrees).
  * \return true to keep measurement, otherwise false. */
bool vnhsi_3d_keep(VnHsiDipole dipole, VnHsiConfig* c, union vn_vec3f ypr);

/** \brief Solve for the hard iron vector and the soft iron matrix for 3D measurement.
  *
  * Once certain number of measurements associated with the keep measurement criteria are selected
  * the 3D HSI calibration algorithm takes place in this function.
 
  * \param[in] dipole The magnetic field dipole structure. 
  * \param[in] c  The configuration structure.
  * \param[in] meas  The kept YMR measurement.
  * \param[in] hsisolnIN  HSI solution to apply to measurements prior to solving.  Used for calculating accurate FOM. Set to NULL for uncorrected solution.
  * \param[in] numMeas The number of kept measurements.
  * \param[out] hsisoln The HSI solution.
  * \param[out] FOM  The figures of merit.
  * \return Error code. */
enum VnError vnhsi_3d_solve(VnHsiDipole dipole, VnHsiConfig* c, VnHsiYmr* meas, VnHsiSol* hsisolnIN, size_t numMeas, VnHsiSol* hsisoln, VnHsiFom* FOM);

#endif /* VNHSI3D_H */
