Select to view content in your preferred language

GpsAveragingTool.GoodPositionAcquired Never Fires

529
2
05-27-2011 09:27 AM
JM3
by
Deactivated User
I am trying to use the GpsAveragingTool class, but even though my SerialPortGpsConnection is collecting coordinates, the averaging tool is not collecting any coordinates. Here is a small application that reproduces the problem. All it does is send some information to Debug when the events of the connection and the averaging tool fire. When the connection has a GPS change, it prints information on both the connection and the averaging tool, and it only prints information on the averaging tool when its event fires.

My results are that the connection's event fires frequently, but the averaging tool's event never fires. Worse, the number of coordinates the averaging tool picks up remains zero. I've ensured that the PDOP is well below the quality filter's max PDOP and that the FixStatus matches that of the quality filter.

Any ideas on the cause?

There's no code on the designer side. You can drop this into a new Smart Device project named "AveragingToolTest" targeting .NET CF 2.0.
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Text;
using System.Windows.Forms;
using ESRI.ArcGIS.Mobile.Geometries;
using ESRI.ArcGIS.Mobile.Gps;
using ESRI.ArcGIS.Mobile.SpatialReferences;

namespace AveragingToolTest
{
    public partial class Form1 : Form
    {
        #region Variables

        private SerialPortGpsConnection Connection { get; set; }
        private GpsQualityFilter QualityFilter { get; set; }
        private Point OutputPoint { get; set; }
        private GpsAveragingTool AveragingTool { get; set; }

        #endregion

        #region Constructor

        public Form1()
        {
            InitializeComponent();
            this.Closing += new CancelEventHandler(Form1_Closing);
            this.Load +=new EventHandler(Form1_Load);

            this.Connection = new SerialPortGpsConnection();
            this.Connection.PortName = "COM0";
            this.Connection.BaudRate = GpsBaudRate.BaudRate4800;
            this.Connection.GpsChanged += new EventHandler(Connection_GpsChanged);

            this.QualityFilter = new GpsQualityFilter();
            this.QualityFilter.FixStatus = GpsFixStatus.GpsFix;
            this.QualityFilter.MaximumPdop = 50;

            this.OutputPoint = new Point();
            this.AveragingTool = new GpsAveragingTool(this.QualityFilter, this.Connection,
                this.OutputPoint, SpatialReference.CreateWgs84SpatialReference());
            this.AveragingTool.GoodPositionAcquired += new EventHandler(AveragingTool_GoodPositionAcquired);
        }

        #endregion

        #region GPS Events

        private void Connection_GpsChanged(object sender, EventArgs e)
        {
            this.Output("Connection.GpsChanged:");
            this.Output(true,
                "FixStatus: " + this.Connection.FixStatus,
                "PDOP:" + this.Connection.PositionDilutionOfPrecision,
                "AveragingTool.IsConstructing: " + AveragingTool.IsConstructing,
                "AveragingTool.IsGpsQualityAcceptable: " + AveragingTool.IsGpsQualityAcceptable,
                "AveragingTool.GoodPositionsAcquired: " + AveragingTool.GoodPositionsAcquired);
        }

        private void AveragingTool_GoodPositionAcquired(object sender, EventArgs e)
        {
            this.Output("AveragingTool.GoodPositionAcquired");
            this.Output(true, "GoodPositionsAcquired: " + AveragingTool.GoodPositionsAcquired);

            if (this.AveragingTool.GoodPositionsAcquired >= 5)
            {
                this.AveragingTool.Stop();
                this.AveragingTool.AcceptCurrentVertex();
                this.Output(true, "Averaged Vertex: " + this.OutputPoint.Coordinate);
            }
        }

        #endregion

        #region Form Events

        private void Form1_Load(object sender, EventArgs e)
        {
            this.Connection.Open();
            this.AveragingTool.Start();
        }

        private void Form1_Closing(object sender, CancelEventArgs e)
        {
            if (this.AveragingTool.IsConstructing)
            {
                this.AveragingTool.Stop();
            }

            if (this.Connection.IsOpen)
            {
                this.Connection.Close();
            }

            this.AveragingTool.Dispose();
            this.Connection.Dispose();
        }

        #endregion

        #region Debug Output Methods

        private const String newline = "\r\n";
        private void Output(bool indent, params String[] lines)
        {
            StringBuilder output = new StringBuilder();
            foreach (String line in lines)
            {
                output.Append((indent ? "    " : String.Empty) + line + newline);
            }

            Debug.Write(output.ToString());
        }

        private void Output(params String[] lines)
        {
            this.Output(false, lines);
        }

        #endregion
    }
}
0 Kudos
2 Replies
JM3
by
Deactivated User
It appears that the problem was that I was using a GPS simulator (which sent output to a virtual COM port). Going to a clear area and taking a real GPS sample caused the averaging tool to work. I'm not exactly sure what the difference is between the two. Any thoughts? I did log some NMEA sentences from both the simulation and the real sample if anyone wants to see them.
0 Kudos
AkhilParujanwala
Regular Contributor
GoodPositionAcquired is trigger by PDOP, some GPS simulator (free ones) don't give you all the NMEA strings you need.

I had this issue when I set up my indoor GPS developing environment several months ago.

I had to use 2-3 Free GPS simulators to figure this out. Some GPS units don't give enough satellites, some don't give you PDOP and etc.

I ended up using one GPS program that ran for about 15 secs, took all the strings. Copy and Pasted those strings into a textfile and repeated those 15 secs of string about 100 times so now my GPS simulator will last 2-3 hours.

I found a second free GPS simulator program that will read textfiles, in particular .NMEA files, so I quickly renamed my .txt to a .nmea and open the file and it started to read my textfilem and output that information on COM1.

Using a Serial Cable from one Tablet PC to my Laptop I am now able to get simulated GPS in ArcGIS Mobile. Albeit the green blinking dot moves in the same diagonal pattern repeatedly, but atleast I can now test and program indoors without having to run outside even in the winter.
0 Kudos