MissionPlanner.MagCalib.SaveOffsets C# (CSharp) Method

SaveOffsets() public static method

saves the offests to eeprom, os displays if cant
public static SaveOffsets ( double ofs ) : void
ofs double offsets
return void
        public static void SaveOffsets(double[] ofs)
        {
            if (MainV2.comPort.MAV.param.ContainsKey("COMPASS_OFS_X") && MainV2.comPort.BaseStream.IsOpen)
            {
                try
                {
                    // disable learning
                    MainV2.comPort.setParam("COMPASS_LEARN", 0);

                    if (
                        !MainV2.comPort.SetSensorOffsets(MAVLinkInterface.sensoroffsetsenum.magnetometer, (float) ofs[0],
                            (float) ofs[1], (float) ofs[2]))
                    {
                        // set values
                        MainV2.comPort.setParam("COMPASS_OFS_X", (float) ofs[0]);
                        MainV2.comPort.setParam("COMPASS_OFS_Y", (float) ofs[1]);
                        MainV2.comPort.setParam("COMPASS_OFS_Z", (float) ofs[2]);
                    }
                    else
                    {
                        // Need to reload these params into the param list if SetSensorOffsets() was used
                        MainV2.comPort.GetParam("COMPASS_OFS_X");
                        MainV2.comPort.GetParam("COMPASS_OFS_Y");
                        MainV2.comPort.GetParam("COMPASS_OFS_Z");
                    }

                    if (ofs.Length > 3)
                    {
                        // ellipsoid
                        MainV2.comPort.setParam("COMPASS_DIA_X", (float)ofs[3]);
                        MainV2.comPort.setParam("COMPASS_DIA_Y", (float)ofs[4]);
                        MainV2.comPort.setParam("COMPASS_DIA_Z", (float)ofs[5]);

                        MainV2.comPort.setParam("COMPASS_ODI_X", (float)ofs[6]);
                        MainV2.comPort.setParam("COMPASS_ODI_Y", (float)ofs[7]);
                        MainV2.comPort.setParam("COMPASS_ODI_Z", (float)ofs[8]);
                    }
                }
                catch
                {
                    CustomMessageBox.Show("Setting new offsets for compass #1 failed");
                    return;
                }

                CustomMessageBox.Show(
                    "New offsets for compass #1 are " + ofs[0].ToString("0") + " " + ofs[1].ToString("0") + " " +
                    ofs[2].ToString("0") + "\nThese have been saved for you.", "New Mag Offsets");
            }
            else
            {
                CustomMessageBox.Show(
                    "New offsets for compass #1 are " + ofs[0].ToString("0") + " " + ofs[1].ToString("0") + " " +
                    ofs[2].ToString("0") + "\n\nPlease write these down for manual entry", "New Mag Offsets");
            }
        }

Usage Example

Exemplo n.º 1
0
        public static void DoGUIMagCalib(bool dointro = true)
        {
            ans = null;
            filtercompass1.Clear();
            datacompass1.Clear();
            datacompass2.Clear();
            filtercompass2.Clear();

            if (dointro)
            {
                CustomMessageBox.Show("Please click ok and move the autopilot around all axises in a circular motion");
            }

            ProgressReporterSphere prd = new ProgressReporterSphere();

            prd.btnCancel.Text = "Done";

            Utilities.ThemeManager.ApplyThemeTo(prd);

            prd.DoWork += prd_DoWork;

            prd.RunBackgroundOperationAsync();

            if (ans != null)
            {
                MagCalib.SaveOffsets(ans);
            }

            if (ans2 != null)
            {
                MagCalib.SaveOffsets2(ans2);
            }
        }
All Usage Examples Of MissionPlanner.MagCalib::SaveOffsets