mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
Fixed the impossible bearing calculation problem
* Bearing is only known of a SET_UNIT, if all units of the set are heading +/- 5 degrees in the same direction.
This commit is contained in:
parent
df7ffc2a3f
commit
56813a800c
@ -488,9 +488,9 @@ do -- COORDINATE
|
|||||||
function COORDINATE:GetHeadingText( Settings )
|
function COORDINATE:GetHeadingText( Settings )
|
||||||
local Heading = self:GetHeading()
|
local Heading = self:GetHeading()
|
||||||
if Heading then
|
if Heading then
|
||||||
return string.format( " heading %3.2f °", Heading )
|
return string.format( " bearing %3d°", Heading )
|
||||||
else
|
else
|
||||||
return " heading cannot be determined"
|
return " bearing unknown"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -1883,7 +1883,7 @@ end
|
|||||||
-- @return #number Heading Heading in degrees and speed in mps in case of moving units.
|
-- @return #number Heading Heading in degrees and speed in mps in case of moving units.
|
||||||
function SET_UNIT:GetHeading()
|
function SET_UNIT:GetHeading()
|
||||||
|
|
||||||
local AvgHeading = nil
|
local HeadingSet = nil
|
||||||
local MovingCount = 0
|
local MovingCount = 0
|
||||||
|
|
||||||
for UnitName, UnitData in pairs( self:GetSet() ) do
|
for UnitName, UnitData in pairs( self:GetSet() ) do
|
||||||
@ -1894,15 +1894,20 @@ function SET_UNIT:GetHeading()
|
|||||||
local Velocity = Coordinate:GetVelocity()
|
local Velocity = Coordinate:GetVelocity()
|
||||||
if Velocity ~= 0 then
|
if Velocity ~= 0 then
|
||||||
local Heading = Coordinate:GetHeading()
|
local Heading = Coordinate:GetHeading()
|
||||||
AvgHeading = AvgHeading and ( AvgHeading + Heading ) or Heading
|
if HeadingSet == nil then
|
||||||
MovingCount = MovingCount + 1
|
HeadingSet = Heading
|
||||||
|
else
|
||||||
|
local HeadingDiff = ( HeadingSet - Heading + 180 + 360 ) % 360 - 180
|
||||||
|
HeadingDiff = math.abs( HeadingDiff )
|
||||||
|
if HeadingDiff > 5 then
|
||||||
|
HeadingSet = nil
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
AvgHeading = AvgHeading and ( AvgHeading / MovingCount )
|
return HeadingSet
|
||||||
|
|
||||||
self:F( { AvgHeading = AvgHeading } )
|
|
||||||
return AvgHeading
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user