Processing Electronic Compass calibration (take MPU9250 as an example)

Source: Internet
Author: User

Using the processing software, through the Arduino input electronic compass data, through the PC side calibration, the program is as follows:

Import processing.serial.*; Serial MyPort; arraylist<float> xlist = new arraylist<float> (); arraylist<float> ylist = new arraylist<float> (); arraylist<float> zlist = new arraylist<float> (); Float minx,maxx;float miny,maxy;float minZ,maxZ;float MoX, Moy;float count;void Setup () {  size (+, p3d);  MyPort = new Serial (This, "COM5", 38400);  Myport.bufferuntil (10);} void Draw () {   background (+);   float Midx = (minx+maxx)/2;  float Midy = (miny+maxy)/2;  float Midz = (MINZ+MAXZ)/2;  if (mousepressed) {    mox= mousex;    moy= mousey;  }    Camera (Mox,moy, (HEIGHT/2)/tan (PI/5), Midx, Midy,midz, 0, 1, 0);  Camera (Mox,moy, (HEIGHT/2)/tan (PI/5), WIDTH/2, height/2,0, 0, 1, 0);  Translate (WIDTH/2, HEIGHT/2, -100);  Strokeweight (2);  Default   Stroke (255);  NoFill ();

//x
Line (Midx-100,midy,midz,midx+100,midy,midz);
  Y
Line (Midx,midy+100,midz,midx,midy-100,midz);
Z
Line (midx,midy,midz-100,midx,midy,midz+100);

    Box (200);  for (int i = 0;i<xlist.size (); i++) {Point (Xlist.get (i), ylist.get (i), zlist.get (i));  } println (count);  println ("Midx:" +midx+ "," + "Midy" +midy+ "," + "Midz:" +midz ");  }void serialevent (Serial myport) {float MX = 0;  float MY = 0;  float MZ = 0;   String instring = Myport.readstringuntil (10);   if (instring! = null) {instring = Trim (instring);   string[] List = Split (instring, ', ');     if (List.length ==4) {count = float (list[0]);     MX = float (list[1])/100;     MY = float (list[2])/100;          MZ = float (list[3])/100;     -------------------------if (MX < MinX) {MinX = mx;     } if (mx > MaxX) {maxX = mx;     }//----------------------------if (my < miny) {miny = my;     } if (My > Maxy) {maxy = my;     }//----------------------------if (Mz > MaxZ) {maxZ = MZ;     } if (Mz < MinZ) {MinZ = MZ;     } xlist.add (MX);     Ylist.add (MY); Zlist.add (MZ); }   }}

  

The Arduino code is as follows:

   int mx,my,mz;   :::  slightly    serial.print (count);      Serial.print (",");        Serial.print (MX);  Inclination X axis (as measured by accelerometer)    Serial.print (",");    Serial.print (my);  Inclination X axis (estimated/filtered)    serial.print (",");    Serial.print (MZ);  Inclination X axis (estimated/filtered)        serial.println ("");    count++;

  

PC-side access to the effects such as:

The final coordinate system completely falls inside the ball to indicate a successful calibration.

Video:

Processing Electronic Compass calibration (take MPU9250 as an example)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.