How do i increase gps speed refresh rate with “interpolated” speed?

Continuing the discussion from Best GPS For Speedometer?:

Im building a speedometer where i want have fast/ accurate gps. At specific speeds between 10mph and 50mph i want to take actions but i dont want it to lag which its doing a bit today using tinygps++ and a neo6m module.

The attached post above references increasing frequency from 1 hz to 10hz by tracking acceleration/deceleration… “interpolated speed”

Does anyone know how to do this?

Doe most libraries update 1 per second and i do my own calcs in between and adjust the “truth” every 1000ms? Would love to improve the speedo response.

Its not the 'libraries' that update once per second, thats just the the default output rate for most all GPSs.

If you want faster updates check the datasheet of the GPS for the instruction to send it.

You would also likley need to increase the baud rate of the GPS from the 9600 default and turn off most all sentences leaving only GPGGA and GPRMC.

Doing a calculation every 100ms on Arduino is quite straightforward. In principle you either configure a hardware timer or you continuously check millis() to see if 100ms has elapsed since your last action.

Knowing the speed at the beginning of the second and knowing the acceleration you can calculate (guess) the speed at 100ms intervals until the beginning of the next second.

Can you also increase the frequency of data delivery by configuring you GPS receiver say using the equivalent of the ublox u-center?

Let's assume you get your speed at 1Hz

By comparing the speed at tn-1 and tn, you can see if you are running faster or slower or if you kept the same speed.

Assuming you have your Speedtn at instant tn in m/s, if there is a difference during the previous second, the acceleration is simply:

Atn = (Speedtn - Speedtn-1) / 1

The denominator 1 being 1 second, since this is your refresh rate (1Hz)

now that you know the current acceleration, you can infer speed before getting the new sample from the GPS :

at tn + 0.1s your speed is

Speedtn+0.1s = Speedtn + 0.1*Atn

and then similarly

Speedtn+0.2s = Speedtn+0.1s + 0.1*Atn

etc

(you could also decide that the acceleration is not constant and do the same thing by taking into account the acceleration of the acceleration...)

this is probably worth it only if the acceleration is significant enough to have an impact during 0.1s intervals

What, incidentally, is the display device. Some displays are slow and you may not benefit much from the improved resolution. E-Paper would definitely not, but liquid crystal displays can be quite sluggish.

There is no display device. My setup needs quick mph readings because it controls the beam pattern of an off-road light and needs to adjust quicker than 1 time per second.

In that case, @srnet gave you the answer in reply #2.

beam pattern of an off-road light

how do you control that? how fast does it react? how fast does speed change in your vehicle?

The light has a series of spot and floor leds that pass there 2 different lenses and im able to vary the brightness of each spot/flood group to change the over all beam pattern… 10 times a second seem good, if i need it faster i will increase my estimated refresh rate.

Now a 1 more question.

How do i know when i have a “stale” speed reading and should start my 10hz “estimated” speed if tiny gps always returns a speed when i call it? Should i just wait for the first gps speed number change and then just start a counter based on millis() ?

You can't interpolate into the future, because you are lacking a future data point. The best estimate of your current speed is the last reading. Position is different because the equations of motion do allow a good approximation because velocity = distance/time therefore an interpolated distance can be obtained from distance plus delta distance / delta time. If you know what I mean.

Velocity offers no clues, or trend, except that delta velocity is limited by mass. Even then, it is influenced by unpredictable factors, e.g. a car might be able to stop faster than it can accelerate. Also you can not predict when the brakes will be activated.

Given some velocity and inertia, you can approximate future velocity because it is an integral. But to improve on the accuracy of the last reading, you would need to know the forces of acceleration that are at work.

You can call if (gps.speed.isValid() ) {…}

It’s just a guess based on the previous 1s interval acceleration (the delta in speed over one second) of course you can’t predict when the driver will stop that current behavior (accelerating or slowing down).

You could supplement the output of the GPS module with an accelerometer, say MPU6050, which should be a bit more responsive.