Runtime Calibration Sync from Google3
Tip of G3 CL: 158580016
Bug: 30958130
Change-Id: I49a52f84a1c7661fc594e073e19f62e19ba5739d
diff --git a/firmware/os/algos/calibration/magnetometer/mag_sphere_fit.c b/firmware/os/algos/calibration/magnetometer/mag_sphere_fit.c
index 9d6591c..eb23b87 100644
--- a/firmware/os/algos/calibration/magnetometer/mag_sphere_fit.c
+++ b/firmware/os/algos/calibration/magnetometer/mag_sphere_fit.c
@@ -70,8 +70,8 @@
void magCalSphereOdrUpdate(struct MagCalSphere *mocs, float odr_in_hz) {
// Calculate the numbers of samples to be dropped, in order to fill up
// the data set.
- mocs->sample_drop =
- floor(odr_in_hz * mocs->batch_time_in_sec * mocs->inv_data_size);
+ float sample_drop = odr_in_hz * mocs->batch_time_in_sec * mocs->inv_data_size;
+ mocs->sample_drop = (uint32_t)floorf(sample_drop);
}
// Updates the sphere fit data set, by calculating the numbers
diff --git a/firmware/os/algos/common/math/mat.c b/firmware/os/algos/common/math/mat.c
index e137435..34aaa51 100644
--- a/firmware/os/algos/common/math/mat.c
+++ b/firmware/os/algos/common/math/mat.c
@@ -604,7 +604,7 @@
size_t i;
for (i = 0; i < nrows; ++i) {
const float *row = &A[i * ncols];
- out[i] = vecDot(row, v, (int)ncols);
+ out[i] = vecDot(row, v, ncols);
}
}
diff --git a/firmware/os/algos/common/math/vec.c b/firmware/os/algos/common/math/vec.c
index 62039bb..b55ea8e 100644
--- a/firmware/os/algos/common/math/vec.c
+++ b/firmware/os/algos/common/math/vec.c
@@ -50,67 +50,67 @@
*outZ = z * invMag;
}
-void vecAdd(float *u, const float *v, const float *w, int dim) {
+void vecAdd(float *u, const float *v, const float *w, size_t dim) {
ASSERT_NOT_NULL(u);
ASSERT_NOT_NULL(v);
ASSERT_NOT_NULL(w);
- int i;
+ size_t i;
for (i = 0; i < dim; i++) {
u[i] = v[i] + w[i];
}
}
-void vecAddInPlace(float *v, const float *w, int dim) {
+void vecAddInPlace(float *v, const float *w, size_t dim) {
ASSERT_NOT_NULL(v);
ASSERT_NOT_NULL(w);
- int i;
+ size_t i;
for (i = 0; i < dim; i++) {
v[i] += w[i];
}
}
-void vecSub(float *u, const float *v, const float *w, int dim) {
+void vecSub(float *u, const float *v, const float *w, size_t dim) {
ASSERT_NOT_NULL(u);
ASSERT_NOT_NULL(v);
ASSERT_NOT_NULL(w);
- int i;
+ size_t i;
for (i = 0; i < dim; i++) {
u[i] = v[i] - w[i];
}
}
-void vecScalarMul(float *u, const float *v, float c, int dim) {
+void vecScalarMul(float *u, const float *v, float c, size_t dim) {
ASSERT_NOT_NULL(u);
ASSERT_NOT_NULL(v);
- int i;
+ size_t i;
for (i = 0; i < dim; i++) {
u[i] = c * v[i];
}
}
-void vecScalarMulInPlace(float *u, float c, int dim) {
- ASSERT_NOT_NULL(u);
- int i;
+void vecScalarMulInPlace(float *v, float c, size_t dim) {
+ ASSERT_NOT_NULL(v);
+ size_t i;
for (i = 0; i < dim; i++) {
- u[i] *= c;
+ v[i] *= c;
}
}
-float vecNorm(const float *v, int dim) {
+float vecNorm(const float *v, size_t dim) {
ASSERT_NOT_NULL(v);
float norm_sq = vecNormSquared(v, dim);
return sqrtf(norm_sq);
}
-float vecNormSquared(const float *v, int dim) {
+float vecNormSquared(const float *v, size_t dim) {
ASSERT_NOT_NULL(v);
return vecDot(v, v, dim);
}
-float vecDot(const float *v, const float *w, int dim) {
+float vecDot(const float *v, const float *w, size_t dim) {
ASSERT_NOT_NULL(v);
ASSERT_NOT_NULL(w);
- int i;
+ size_t i;
float result = 0;
for (i = 0; i < dim; ++i) {
result += v[i] * w[i];
@@ -118,11 +118,11 @@
return result;
}
-float vecMaxAbsoluteValue(const float *v, int dim) {
+float vecMaxAbsoluteValue(const float *v, size_t dim) {
ASSERT_NOT_NULL(v);
float max = NANO_ABS(v[0]);
float tmp;
- int i;
+ size_t i;
for (i = 1; i < dim; ++i) {
tmp = NANO_ABS(v[i]);
if(tmp > max) {
diff --git a/firmware/os/algos/common/math/vec.h b/firmware/os/algos/common/math/vec.h
index 098c6d1..870e697 100644
--- a/firmware/os/algos/common/math/vec.h
+++ b/firmware/os/algos/common/math/vec.h
@@ -165,35 +165,35 @@
// Adds two vectors and returns the sum in the provided vector, i.e.
// u = v + w.
-void vecAdd(float *u, const float *v, const float *w, int dim);
+void vecAdd(float *u, const float *v, const float *w, size_t dim);
// Adds two vectors and returns the sum in the first vector, i.e.
// v = v + w.
-void vecAddInPlace(float *v, const float *w, int dim);
+void vecAddInPlace(float *v, const float *w, size_t dim);
// Subtracts two vectors and returns in the provided vector, i.e.
// u = v - w.
-void vecSub(float *u, const float *v, const float *w, int dim);
+void vecSub(float *u, const float *v, const float *w, size_t dim);
// Scales vector by a scalar and returns in the provided vector, i.e.
// u = c * v.
-void vecScalarMul(float *u, const float *v, float c, int dim);
+void vecScalarMul(float *u, const float *v, float c, size_t dim);
// Scales vector by a scalar and returns in the same vector, i.e.
// v = c * v.
-void vecScalarMulInPlace(float *v, float c, int dim);
+void vecScalarMulInPlace(float *v, float c, size_t dim);
// Returns the L2-norm of the given vector.
-float vecNorm(const float *v, int dim);
+float vecNorm(const float *v, size_t dim);
// Returns the square of the L2-norm of the given vector.
-float vecNormSquared(const float *v, int dim);
+float vecNormSquared(const float *v, size_t dim);
// Returns the dot product of v and w.
-float vecDot(const float *v, const float *w, int dim);
+float vecDot(const float *v, const float *w, size_t dim);
// Returns the maximum absolute value in vector.
-float vecMaxAbsoluteValue(const float *v, int dim);
+float vecMaxAbsoluteValue(const float *v, size_t dim);
#ifdef __cplusplus
}