Need good workaround for simple double errors.

Pages: 12
closed account (Ezyq4iN6)
@Duthomhas

That's a good idea, I never thought about that. I'll keep track of the keypresses and that will avoid a lot of the error. One of the examples I was thinking about is driving a car around. If I use my up arrow to increase the speed, I can then count the number of loops I was at each speed, and then use that to determine where I am. I guess I would have to get a little more creative when it comes to turning the car, but your suggestion sounds like a solid solution, thanks.

@mbozzi

Thanks for the suggestion. I'll tie my epsilon to the last place unit in the future, as that makes more sense than me keeping a const like 0.0001, or whatever.
Last edited on
I'm sure some implementations will be better than others, but based on what you just said, I don't think this is worth the perfectionism. Let me explain -- I assume you'll want to let the user hold down the arrow keys or something of that nature, in real-time. The same inherent problem is there, but now you're measuring it in terms of frames held down or time held down, which has its own set of "noise" (mostly timing-based). And once you factor in turning, non-constant acceleration, and other things like that, there isn't going to be a constant-time way to calculate the position of the car; error accumulation will happen either way. But if this is a just a simulation (like Microsoft Flight Simulator), then small error accumulation simply shouldn't matter, as long as the car isn't jumping around on a short time scale.

Just like a speedometer in a car, it doesn't matter whether it's saying your speed is 42.00000001 vs 42.0000002 [speed units]. The instrument can't actually measure something that precisely anyway.

(Edit: Just to clarify, if you're trying to "replay" a simulation or something of that nature, then recording the key presses/durations is probably the best thing you can do.)

[If this is some scientific, chaotic galaxy simulation, then I will not give advice there because that's well beyond me.]
Last edited on
I know that adding 0.1 a million times will give me 100,000. However, when I run code that does so in a loop versus multiplying 1,000,000 by 0.1, then I get the following results:

Addition: 100000.000001333

That's off by 1 part in 1011

It's like measuring 1 mile and being off by a 1.3 nanometers.
It's like measuring the circumference of the earth and being off by half a millimeter.

You have to evaluate the error and think about what it means. In this case, being off by 1 part of 1011 after a million calculations is pretty darned good.
For those who don't know this story -- An extreme case of round-off error occurred during a war, a grim summary is here: https://en.wikipedia.org/wiki/Round-off_error#Real_world_example:_Patriot_missile_failure_due_to_magnification_of_roundoff_error
Last edited on
closed account (Ezyq4iN6)
@Ganado
For right now it is a simulation, but I was hoping to one day apply it to a remote-controlled car with a GPS unit on it. I would guess that even then, the small amount of error isn't going to be an issue. It isn't like I would be driving long distances.

And you are right about the replay. I would like to eventually work with pathfinding and pre-plan a path, hence I would have to program in some kind of instructions for the car to follow, and assure that it always reached its goal.

No galactic simulations (though that sounds like fun), and definitely not missile interception... driving hobby-level robots or RC cars around is my eventual goal.

@dhayden
I see your point. The error number would be of little significance.

As an interesting side note, I actually did a test with large amounts of increments, and it seems like the error actually diminishes at a certain point and then simply bounces around.
The error peaked at about 671,000,000 loops before decreasing:

... error increasing ...
670,000,000 loops, count is 67,000,000.7042601
671,000,000 loops, count is 67,100,000.7057503
672,000,000 loops, count is 67,200,000.7004502
... error decreasing ...

I'm not sure exactly why this is occurring at that amount... maybe something inherent to the double. Here's the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
int main()
{
  uint count = 0;
  uint a = 1000000;
  double b = 0.0;

  while (true)
  {
    for (uint i = 0; i < a; i++)
      b += 0.1;
    count++;
    uint temp = count * a;
    std::cout << "Loops: " << temp << "\n";
    std::cout << "Number: " << b << "\n\n";
  }
  return 0;
}
In the specific case of using GPS, you would be periodically refreshing your position by pinging the GPS. The latest GPS devices are only accurate to about 30 centimeters, according IEEE spectrum.
closed account (Ezyq4iN6)
That's a good point. I would have a new place to start with every refresh, eliminating the accumulated error and allowing me to start again.

Thanks to everyone who helped me with this question. I feel I have learned a lot and do appreciate it.
If GPS were accurate to 30 cm that would be the primary control for all autonomous vehicles.

I think you meant 30 meters. Alas.
https://spectrum.ieee.org/tech-talk/semiconductors/design/superaccurate-gps-chips-coming-to-smartphones-in-2018
The article I was referring to was using the future tense. So now that it's 2019, I don't know if this has come true, or if the 30 cm estimate was exaggerated.
Yes, any relatively old one will be much less accurate than that (>5 meters).

https://www.gpsworld.com/swift-navigation-starling-gnss-engine-available-with-broadcom-bcm47755-chip/
October 2018:
According to the company, Starling features multi-band, multi-constellation support to provide centimeter-level accuracy


GPS, no matter how accurate, cannot be used (at least, completely) for self-driving cars because the signal could be lost. (That's my understanding, at least)

But the point I was making was, regardless of the specific number, is that any "noise" in the calculation of GPS would be greater than floating-point drift (referring to dhayden's post) unless something was seriously wrong.
Last edited on
Hi,

I am a surveyor, so I will explain a bit of what I know About GPS. This is a basic overview, there are all kinds of ways GPS can work.

A GPS unit in autonomous mode (as opposed to RTK, or Static mode) should give a position to about 1 metre; 2 metres on a bad day. This is the system that is usually employed by sat navs in cars boats and on phones. Although when there is an internet connection, it is possible to get corrections, which improves the accuracy a great deal, effectively becoming RTK. Autonomous mode means there is no base station to do corrections. The reason errors appear is because of atmospheric conditions, which can't be corrected mathematically with only one receiver.

The RTK (Real Time Kinematic) System employs a base station which is set up on a tripod, accurately over a known coordinate mark, and accurately levelled. The base station calcs a position from the satellites being used. Because it knows it's actual position, it can calculate a correction in real time which is broadcast to the roving GPS receiver via a radio connection. The Rover is doing the same thing, but now it has a correction to apply thereby achieving an accuracy of about 0.025 a metre or less.

With Static GPS, the base station continually records data at a specified interval of say 1 or 5 seconds. The Rover (or multiple rovers) are mounted on tripods, and also record data continuously. All the data is put into processing software, bad data is weeded out, and accuracy of about 0.003m or 0.005m can be achieved. Note that no GPS radio is required for these operations, so one can place the Rovers a long distance away - say 100km. The longer the distance the longer the observation time.

In the old days, Autonomous accuracy was about 100m - 200m. One of the last things President Clinton did, was to turn off the "Fuzzing" in the US GPS system. This allowed all the applications we take for granted today to be developed.

Edit:

Where the 30m distance comes from is probably because 1 second of latitude is about 30m, some people only publish data to that level because they mistakenly think it is already accurate enough. Surveyors GPS can normally output data to 5dp of a second of latitude, which is sub millimetre, but the accuracy is still 3mm at best. As mentioned before a sat nav is usually good for 1 or 2 metres.
Last edited on
@TheIdeasMan That was interesting, thanks :).
Yep, it was!
Last edited on
Some other comments:

Surveyors GPS have had the L5 signals for a long time now.

GPS using only 3 satellites is a bit misleading, ours use 15 to 19 routinely, 22 on a good day. if I was down to 8, I would pack up and go home :+). Our GPS can use multiple GNSS, including Galileo and Glosnass. One needs 4 satellites as a minimum to get a height, because that helps determine the clock error.

Augmentation has existed for a long time for some applications, notably for aircraft near airports, it does a similar thing to RTK. Basically they have base stations near the airport, the aircraft use them for corrections. It is interesting that this is becoming more mainstream.

The other thing that determines the quality of position data, is the quality of the GPS processing software in the device. Big Brands such as Leica, Trimble, Topcon et al do a better job of dealing with multipath and other problems, than do the cheaper equipment.
Topic archived. No new replies allowed.
Pages: 12