Page **1** of **1**

### Heading via lua

Posted: **Tue Jun 13, 2017 4:05 pm**

by **MrBlahh**

anyone worked out heading via lua?

not sure it's the best place to do it, due to jitter you would have to average out a few readings to calculate it reasonably

Posted: **Fri Sep 28, 2018 1:05 am**

by **burn4005**

came accross this post when looking to see if this bridge had been crossed..

I've created a function that will give heading angle in degrees.I haven't tested this yet but in theory it should work if Lua is fully implemented.

I got the function from:

https://www.igismap.com/formula-to-find ... longitude/
Code: Select all

```
function headingcalc(lat2,lon2,lat1,lon1)
rlat1 = math.rad(lat1)
rlon1 = math.rad(lon1)
rlat2 = math.rad(lat2)
rlon2 = math.rad(lon2)
dlon = rlon2-rlon1
x = math.cos(rlat2) * math.sin(dlon)
y = math.cos(rlat1) * math.sin (rlat2) - math.sin(rlat1) * math.cos(rlat2) * math.cos(dlon)
rhead = math.atan2(x,y)
return math.deg(rhead)
end
```

a lot of math functions to do, not sure how computationally expensive it will be. i'd operate it at a much lower tick rate than the GPS. maybe 10hz instead of 50?

### Re: Heading via lua

Posted: **Wed May 29, 2019 12:48 am**

by **thoraxe**

MrBlahh wrote:anyone worked out heading via lua?

not sure it's the best place to do it, due to jitter you would have to average out a few readings to calculate it reasonably

I'm curious why you wanted to implement this. I may have a similar need with integration with an AEM CD-7 dash.