MPU-9250-AHRS
MPU-9250-AHRS copied to clipboard
Kill a warning
I got this warning:
% make magneto
cc magneto.c -o magneto
magneto.c:58:13: warning: format specifies type 'char *' but the argument has type 'char (*)[64]' [-Wformat]
scanf("%s",&filename);
~~ ^~~~~~~~~
1 warning generated.
Since filename is already a char * buffer, it doesn't need to be a reference to a specific array type.
I also needed to change #include <malloc.h>
to #include <stdlib.h>
to compile on my Mac, but I didn't put that in the PR.
diff --git a/magneto/magneto.c b/magneto/magneto.c
index e1b6d62..e7bf01c 100644
--- a/magneto/magneto.c
+++ b/magneto/magneto.c
@@ -5,7 +5,8 @@
#include <stdio.h>
#include <math.h>
-#include <malloc.h>
+//#include <malloc.h>
+#include <stdlib.h>
#include <string.h>
#include <float.h>
@@ -54,7 +55,7 @@ int main()
FILE *fp;
printf("\r\nMagneto 1.2\r\n.csv input file name? ");
- scanf("%s",&filename);
+ scanf("%s",filename);
fp = fopen(filename, "r");
if (fp == NULL) {printf("file not found"); return 0;}
Downloading the MagCal data from https://github.com/hightower70/MagCal/blob/master/mag.txt and translating it into mag.csv with
awk '{print $1","$2","$3}' mag.txt > mag.csv
gives this truncated result:
Magneto 1.2
.csv input file name? mag.csv
0 0.0 -0.3 -0.4
1 -0.0 -0.2 -0.5
2 -0.0 -0.2 -0.6
3 -0.0 -0.2 -0.5
4 -0.0 -0.2 -0.5
5 -0.0 -0.2 -0.5
...
25596 0.4 0.2 -0.4
25597 0.4 0.2 -0.4
25598 0.4 0.2 -0.4
Average length of 25599 input vectors = 0.581882
Expected norm of local field vector? 1
Combined bias vector B:
-0.02 0.01 -0.03
Correction matrix Ainv, using Hm=1.000000:
1.68185 -0.03130 0.01154
-0.03130 1.69514 0.00581
0.01154 0.00581 1.82099
Where Hcalc = Ainv*(H-B)
Code initialization statements...
float B { -0.02, 0.01, -0.03};
float Ainv {{ 1.68185, -0.03130, 0.01154},
{ -0.03130, 1.69514, 0.00581},
{ 0.01154, 0.00581, 1.82099}};