-
• #2
still puzzling as to why the markdown table above doesn't display correctly?
...autodetect of text of numbers does left and right alignment in table cell... :/ ...so much does autoXyz do any good...
-
• #3
@allObjects The Table appeared as markdown source text in the preview, but came out fine in the post.
I used the markdown editor at:
https://jbt.github.io/markdown-editor/#bVNBbtswELzzFVs4gO3GltpremqTpgkQA0WTnoICoUVSpC1yBXJlJyn69y4pw84hgAnJ5HBmd2Y1gdkPRzfDenndyR1GreawknGrcB/gu3KEUYhvMrkGhqTN0IHRkoaooXOJLoSAj3BJsTu/hxouveInISS500BWg3GdPkGsM3QCHv4xvLGISR8vynQqASPcPKzuMsdVlC3IoEBF7EEWbnCBb1kdy+0OpQJHGXydDxsMpAMlkHyeqfk0lLp+/7qDhPCCAzQyQLIZkQmTEOJ26iEgtIgKJME+OnKhZQLfM2mdcZ2OQPqZFpmlxYJhCfSabMYycUy6M5UQd4jbBZeb/fpQ/DKI+bGWcXy8CvGV28pdTFMh4cqV/gAX55/Z4aenp43cydRE15M4m5khNOQwzOZ/BcDZbKrcbjqvLPluNr0F6VmMt6rp/Iv4x4vvC/FgXQL+PWKAMfA/M0vUp4u6bh3ZYV016OvNmmp/8H6pS/zz3GKnCbisbcA9OAO3U45p/Slus6NUSt7n8rld8ZPTSTmNVazgCnFdMsvyj7krGFlHdRb3UTGmiPcRN7qhVGfcQb2eL8BE9LC3rrEiZ+dC6l2U2YIsw4anRdEozll+ewGXo/Kc/QjjTIhBjfS5xMlkAvc0GJNHWmUOL7e6EI0D/Xi0wNG7Nr05f/s+52jjaXZ7GRMPQ2G85JZWLsY3necufdmqgqZ6vJwblHtdWkkvXP/z0rrWdryIax1NKYzH7WqTjpwJDe15lr0MTjapwtiWvfqIrnU4SI30cDzJc8ufBw7UD1QmENYdNttU5DZpqbTpJOl3HVEybLGVrj7hRpX21fV9pkYDSpI82s1zY3ixIn+MSfwH
to create the document and the cheat sheet as a guide found at:
https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet -
• #4
Using a 3-Axis Magnetometer as a compass.
An example:
First Zero the magnetometer
For each axis X, Y and Z point the axis North and take a reading R1, then turn the magnetometer 180 degrees and take reading R2. Take the average of the two readings as the offset for that axis.
Your code will then take a reading and subtract the offset for each axis. X= Xraw- Xoffset, Y= Yraw- Yoffset, Z= Zraw- Zoffset.
Use the resulting Z, Y and Z values in all calculations that follow. If you repeat the North and then rotate proceedure then
Xn =-Xs, Yn=-Yz, and Zn=-Zs, where the subscripts s and n stanf for North and South.Example
- Assign the Z axis to the Yaw axis.
- Assign the X axis to the roll (heading) axis.
- Assign the Y axis to the pitch axis.
- With the X and Y axis level and the Z axis pointing in the position for use ( Think the model airplane is not inverted):
- Point the roll (X) axis North and note the sign of the X axis reading. If it is negative, you need to multiply X by -1 in the assignment statement of the code
- Point the roll (X) axis East and note the sign of the Y axis. The reading should be negative, if not you need to multiply Y by -1 in the assignment statement of the code
The yaw axis should be positive in the Northern hemisphere and negative in the Southern menisphere. If not negate it.
var X=1,Y=-1,Z=1; var X1,Y1,Z1; var Xoffset=0,Yoffset=0,Zoffset=0; //Read the magnetometer X,Y, and Z //Subtract the offsets X1=X-Xoffset; Y1=Y-Yoffset; Z1=Z-Zoffset; //Assign the XYZ to roll pitch and yaw axis var Sroll=1; var Spitch=-1; var Syaw=1; roll=Sroll*X1; pitch=Spitch*Y1; yaw=Syaw*Z1; heading=180/Math.PI * Math.atan2(pitch,roll); if(heading <0) heading+=360; console.log("Heading= ",heading); dip=180/Math.PI*Math.atan(Math.sqrt(roll*roll+pitch*pitch),yaw); console.log("Dip= ",dip); //add the declination to get true heading
Note the change in the argument order of the atan2 function from the orignal post.
- Try it out to see that 90 degree heading is East, 180 is South, 270 is West and 0 is North.
- Repeat using the Y axis as the roll axis and the X axis as pitch.
https://en.wikipedia.org/wiki/Magnetic_dip
- Assign the Z axis to the Yaw axis.
-
• #5
For dip try this instead:
dip=180/Math.PI*Math.atan(yaw/Math.sqrt(roll*roll+pitch*pitch));
dip is positive in Northern and negative in Southern hemispheres.
It ranges from -90 to +90. -
• #6
Thanks!
If we could think of a nice way of automatically doing calibration this could make a really interesting module
-
• #7
Thoughts on magnetometer calibrations.
Use a min/max program to find the minimum and maximum readings for each axis and then average the minimum and maximum to obtain the offset for each axis.
Point both ends of each axis towards the magnetic pole. Remember the pole is actually below the horizontal by the dip angle.//Cal_idea.js //5 Jan 2017 function minmax(){ this.min=[0,0,0]; this.max=[0,0,0]; this.avg=[0,0,0]; } minmax.prototype.process=function(A){ var i; for(i=0;i<3;i++){ if(A[i]>this.max[i])this.max[i]=A[i]; if(A[i]<this.min[i])this.min[i]=A[i]; this.avg[i]=(this.min[i]+this.max[i])/2; } console.log("max= ",this.max); console.log("min= ",this.min); console.log("avg= ",this.avg); }; var i; var reading=[0,0,0]; var T=new minmax(); for(i=-4;i<4;i++){ //take magnetometer readings here //fake some data for demo reading[0]=i; reading[1]=i*i; reading[2]=i*i*i; //process data while moving the magnetometer // until the max and min for each axis is at the limit //use the average as the offset value T.process(reading); }//next i
In the module MAG3110.js, does the Puck use this function?
http://www.espruino.com/modules/MAG3110.js/** * Performs a manual magnetic sensor reset (One-Shot). * Initiates a magnetic sensor reset cycle that will restore correct operation after exposure to an excessive magnetic * field wich exceeds the Full Scale Range of +/-1000µT, e.g. near a speaker magnet. */ MAG3110.prototype.magneticReset = function () { var value = this.read8(MAG3110.CTRL_REG2); value |= 0x10; // set Mag_RST this.write8(MAG3110.CTRL_REG2, value); };
Finding the best fit sphere regression using Solver in Excel
http://forum.espruino.com/conversations/297875/
1 Attachment
-
• #8
The Puck uses something very similar to that JS module, but it's written in C to try and get it running as fast as possible, without using up any JS code space.
Using a 3-Axis Magnetometer as a compass.
This leaves two remaining axis
57.29577951
*Magnetometer axis usually have an offset that needs to be corrected so that no field produces a zero value. x1= x - xoffset, y1= y-yoffset, z1= z-zoffset;
Use the attached trycompass.js file as a starting point. Attention Puck experimenters!
(still puzzling as to why the markdown table above doesn't display correctly?)
1 Attachment