32 _sample_buffer(nullptr)
55 start(fit_type, num_samples, sample_time,
Vector3f(0,0,0),
Vector3f(1,1,1),
Vector3f(0,0,0));
71 const float a = (4.0f *
M_PI / (3.0f * faces)) +
M_PI / 3.0f;
72 const float theta = 0.5f * acosf(cosf(a) / (1.0
f - cosf(a)));
332 float min_fitness = fitness;
334 uint8_t num_iterations = 0;
336 while(num_iterations < max_iterations) {
370 if (isnan(fitness) || isinf(fitness)) {
374 if (fitness < min_fitness) {
375 min_fitness = fitness;
429 diag.
x , offdiag.
x , offdiag.
y,
430 offdiag.
x , diag.
y , offdiag.
z,
431 offdiag.
y , offdiag.
z , diag.
z 434 float A = (diag.
x * (sample.
x + offset.
x)) + (offdiag.
x * (sample.
y + offset.
y)) + (offdiag.
y * (sample.
z + offset.
z));
435 float B = (offdiag.
x * (sample.
x + offset.
x)) + (diag.
y * (sample.
y + offset.
y)) + (offdiag.
z * (sample.
z + offset.
z));
436 float C = (offdiag.
y * (sample.
x + offset.
x)) + (offdiag.
z * (sample.
y + offset.
y)) + (diag.
z * (sample.
z + offset.
z));
437 float length = (M*(sample+offset)).length();
440 ret[0] = -1.0f * (((diag.
x * A) + (offdiag.
x * B) + (offdiag.
y * C))/length);
441 ret[1] = -1.0f * (((offdiag.
x * A) + (diag.
y * B) + (offdiag.
z * C))/length);
442 ret[2] = -1.0f * (((offdiag.
y * A) + (offdiag.
z * B) + (diag.
z * C))/length);
444 ret[3] = -1.0f * ((sample.
x + offset.
x) * A)/length;
445 ret[4] = -1.0f * ((sample.
y + offset.
y) * B)/length;
446 ret[5] = -1.0f * ((sample.
z + offset.
z) * C)/length;
448 ret[6] = -1.0f * (((sample.
y + offset.
y) * A) + ((sample.
x + offset.
x) * B))/length;
449 ret[7] = -1.0f * (((sample.
z + offset.
z) * A) + ((sample.
x + offset.
x) * C))/length;
450 ret[8] = -1.0f * (((sample.
z + offset.
z) * B) + ((sample.
y + offset.
y) * C))/length;
bool get_sample_corrected(uint8_t i, Vector3f &s) const
struct AccelSample * _sample_buffer
float calc_residual(const Vector3f &sample, const struct param_t ¶ms) const
Vector3< float > Vector3f
uint8_t get_num_params() const
uint32_t _last_samp_frag_collected_ms
void start(enum accel_cal_fit_type_t fit_type=ACCEL_CAL_AXIS_ALIGNED_ELLIPSOID, uint8_t num_samples=6, float sample_time=0.5f)
void calc_jacob(const Vector3f &sample, const struct param_t ¶ms, VectorP &ret) const
uint8_t _conf_num_samples
void * calloc(size_t nmemb, size_t size)
void get_calibration(Vector3f &offset) const
void set_status(enum accel_cal_status_t)
accel_cal_status_t _status
bool accept_sample(const Vector3f &sample)
bool accept_result() const
#define ACCEL_CAL_MAX_NUM_PARAMS
uint8_t _samples_collected
bool get_sample(uint8_t i, Vector3f &s) const
enum accel_cal_fit_type_t _conf_fit_type
VectorN< float, ACCEL_CAL_MAX_NUM_PARAMS > a
float calc_mean_squared_residuals() const
void new_sample(const Vector3f &delta_velocity, float dt)
bool inverse(float x[], float y[], uint16_t dim)
#define ACCEL_CAL_TOLERANCE
void run_fit(uint8_t max_iterations, float &fitness)