• Correction to AGMagtest1

    The index values were corrected in the displayAg() function when set to display Accelerometer and Magnetometer values. AGMagtest2.js is attached.

    Adding the Rodrigues.js module to level the compass

    The background for this module is described here:
    http://forum.espruino.com/conversations/­298151/

    The basic idea is to take the accelerometer readings and determine the vector transformation needed to level the compass. This is done with the function A=FF.Setup(AA,[0,0,1]); where FF is an instance of Rodrigues. The tilt angle theta is then available and subsequent calls to the function BB=FF.RotVector(t) will transform other vectors (magnetometer) into level coordinates.
    The attached Rodrigues.js should be placed in the modules subdirectory of your WebIDE project.
    The attached program AGMagCompass1.js will then produce the following output when autocalc=2 and W.AGwrite(W.REGval.ODR_G,1);//do gyro and acceleration.

    M,0.0744,-0.1211,-0.1714,G,-0.1053,0.041­3,-0.0948,A,0.1575,0.3104,0.8621,
    Tilt,21.98781027298,Heading,306.68106708­380,Dip,72.16684715533
    M,0.0735,-0.1221,-0.1734,G,-0.1128,0.056­3,-0.1072,A,0.1559,0.3118,0.8613,
    Tilt,22.03654082060,Heading,306.02287887­278,Dip,72.48561573888
    M,0.0730,-0.1207,-0.1713,G,-0.1165,0.025­1,-0.0998,A,0.1551,0.3114,0.8618,
    Tilt,21.98386692289,Heading,306.35699288­042,Dip,72.36622200953
    M,0.0742,-0.1194,-0.1707,G,-0.0928,0.071­2,-0.0823,A,0.1538,0.3145,0.8604,
    Tilt,22.14296350951,Heading,308.33309975­404,Dip,72.42224117781
    M,0.0736,-0.1171,-0.1704,G,-0.0679,0.031­3,-0.0674,A,0.1558,0.3134,0.8606,
    Tilt,22.13447453002,Heading,308.75984729­535,Dip,72.83761339423
    >clearInterval();
    

    Changing W.AGwrite(W.REGval.ODR_G,0);//do acceleration only produces the following output:

    M,0.0747,-0.1202,-0.1713,A,0.1563,0.3096­,0.8569,
    Tilt,22.03355580117,Heading,307.43511787­449,Dip,72.28617992890
    M,0.0763,-0.1235,-0.1719,A,0.1563,0.3094­,0.8568,
    Tilt,22.02918941321,Heading,306.91511852­880,Dip,71.66990038608
    M,0.0741,-0.1204,-0.1721,A,0.1560,0.3093­,0.8569,
    Tilt,22.01028842165,Heading,306.98156662­314,Dip,72.44988041050
    M,0.0780,-0.1226,-0.1704,A,0.1559,0.3090­,0.8568,
    Tilt,22.00089649394,Heading,308.38042963­598,Dip,71.31936469986
    >clearInterval();
    

    ```


    3 Attachments

About