mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2026-07-16 22:22:25 +00:00
Compare commits
101 Commits
589e65963f
...
FF/OpsDev
| Author | SHA1 | Date | |
|---|---|---|---|
| 6eb1d78ecb | |||
| ff86cc9f11 | |||
| 1e78c6dea2 | |||
| 56d7638617 | |||
| 386be19b8b | |||
| 0e4eb9a263 | |||
| 1f20b830b7 | |||
| 0531b8f57e | |||
| 98e2997e26 | |||
| bdec6eb82d | |||
| 9bdacfbcf7 | |||
| be2eda25df | |||
| fa8e1d2a56 | |||
| 5242754c60 | |||
| 3dbafd7a19 | |||
| 56e751193a | |||
| b2b258cff0 | |||
| 75068a2a26 | |||
| d82df93eff | |||
| 5168380eac | |||
| a7ffbab850 | |||
| a238294079 | |||
| accb4b45fb | |||
| ba4ff5c9e9 | |||
| 171c450576 | |||
| f35078b426 | |||
| 8921007805 | |||
| 8fd3034503 | |||
| a20b6e8a62 | |||
| 4ce6cc7776 | |||
| 434296ab11 | |||
| a5232f49c0 | |||
| befc8207f5 | |||
| 23947b7c30 | |||
| da91b710a9 | |||
| d656bbc014 | |||
| ed23f11e4a | |||
| 068465a8f2 | |||
| 4e24a7bf80 | |||
| 1ece7238dc | |||
| db53f427e3 | |||
| d2e2c51275 | |||
| 691748082b | |||
| b294ef10c8 | |||
| 5d40091947 | |||
| 7453a6c55d | |||
| 153ef7cd08 | |||
| b6a550a247 | |||
| 3568f27150 | |||
| c46061466c | |||
| 9c7b5e8506 | |||
| b11df6b523 | |||
| 66dcd44fb8 | |||
| f35237f86f | |||
| f19c877a11 | |||
| 792a487eeb | |||
| f5e8bd0ffc | |||
| cbdbf36f32 | |||
| 1116b19b00 | |||
| edb490fa97 | |||
| 9fa16c6385 | |||
| a0ee957493 | |||
| f32c303c0a | |||
| 6febbbc8e6 | |||
| d5aa9eaf0f | |||
| 321b2d761d | |||
| 18581e4a78 | |||
| b03905154d | |||
| 2fda1709bc | |||
| 39f626390a | |||
| aa1e12163d | |||
| abb7f860ae | |||
| cffada1a1e | |||
| f8d91798e3 | |||
| 548aa8d5a9 | |||
| 1e929d1d19 | |||
| d5f215505e | |||
| 851660c793 | |||
| ee57b46c14 | |||
| 36eac9fccc | |||
| 1f630ab490 | |||
| 8f0c6948ac | |||
| eb2380c3f6 | |||
| df3e182de4 | |||
| bda7988118 | |||
| 72deb9ee17 | |||
| ced1f30f3f | |||
| 47c0006537 | |||
| 21e5c124c0 | |||
| 3ff374e1b9 | |||
| 02000be9af | |||
| 663c6cead0 | |||
| 6867df58c4 | |||
| 639625d3d5 | |||
| 0ace200e5a | |||
| e76c26ff59 | |||
| cb11de6f9c | |||
| cdd78e5163 | |||
| a8da02774a | |||
| 04258a69c4 | |||
| 49882f03d9 |
@@ -157,6 +157,8 @@ ASTAR = {
|
||||
-- @field #number surfacetype Surface type.
|
||||
-- @field #table valid Cached valid/invalid nodes.
|
||||
-- @field #table cost Cached cost.
|
||||
-- @field Core.Pathline#PATHLINE pathline Pathline that node is part of.
|
||||
-- @field Core.Pathline#PATHLINE.Point pathpoint Pathline point.
|
||||
|
||||
--- ASTAR infinity.
|
||||
-- @field #number INF
|
||||
@@ -164,7 +166,7 @@ ASTAR.INF=1/0
|
||||
|
||||
--- ASTAR class version.
|
||||
-- @field #string version
|
||||
ASTAR.version="0.4.0"
|
||||
ASTAR.version="0.5.0"
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- TODO list
|
||||
@@ -172,6 +174,7 @@ ASTAR.version="0.4.0"
|
||||
|
||||
-- TODO: Add more valid neighbour functions.
|
||||
-- TODO: Write docs.
|
||||
-- DONE: Add pathlines for seach/valid neighbours.
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- Constructor
|
||||
@@ -244,7 +247,10 @@ end
|
||||
function ASTAR:AddNode(Node)
|
||||
|
||||
self.nodes[Node.id]=Node
|
||||
self.Nnodes=self.Nnodes+1
|
||||
self.Nnodes=self.Nnodes+1
|
||||
|
||||
self:T3(self.lid..string.format("Adding node UID=%d", Node.id))
|
||||
--Node.coordinate:MarkToAll(string.format("Node ID=%d", Node.id))
|
||||
|
||||
return self
|
||||
end
|
||||
@@ -262,6 +268,47 @@ function ASTAR:AddNodeFromCoordinate(Coordinate)
|
||||
return node
|
||||
end
|
||||
|
||||
--- Adds nodes to the table of grid nodes from a PATHLINE.
|
||||
-- @param #ASTAR self
|
||||
-- @param Core.Pathline#PATHLINE Pathline Pathline or name of pathline. Has to exist.
|
||||
-- @return #ASTAR self
|
||||
function ASTAR:AddNodeFromPathlineName(Pathline)
|
||||
|
||||
if type(Pathline)=="string" then
|
||||
Pathline=PATHLINE:FindByName(Pathline)
|
||||
end
|
||||
|
||||
if Pathline then
|
||||
|
||||
for i,_point in pairs(Pathline.points) do
|
||||
local point=_point --Core.Pathline#PATHLINE.Point
|
||||
|
||||
-- Create node from point coordinate.
|
||||
local node=self:AddNodeFromCoordinate(COORDINATE:NewFromVec3(point.vec3))
|
||||
|
||||
-- Add pathline parameters.
|
||||
node.pathline=Pathline
|
||||
node.pathpoint=point
|
||||
|
||||
-- Debug.
|
||||
local name=node.pathline and node.pathline.name or "N/A"
|
||||
local idx=node.pathline and node.pathline:_GetPointIndex(node.pathpoint) or "N/A"
|
||||
|
||||
-- Debug message.
|
||||
self:T(self.lid..string.format("Adding node UID=%d pathline=%s [%s]", node.id, name, tostring(idx)))
|
||||
|
||||
-- Debug mark
|
||||
--node.coordinate:MarkToAll(string.format("Node ID=%d\npathline=%s [%s]", node.id, name, tostring(idx)))
|
||||
|
||||
end
|
||||
|
||||
else
|
||||
env.error("FF error pathline")
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Check if the coordinate of a node has is at a valid surface type.
|
||||
-- @param #ASTAR self
|
||||
-- @param #ASTAR.Node Node The node to be added.
|
||||
@@ -340,6 +387,18 @@ function ASTAR:SetValidNeighbourRoad(MaxDistance)
|
||||
return self
|
||||
end
|
||||
|
||||
--- Set valid neighbours to be on the same pathline or not further apart than 10 meters to jump from one pathline to another.
|
||||
-- @param #ASTAR self
|
||||
-- @param #number MaxDistance Max allowed distance between nodes of different pathlines in meters. Default is 10 m.
|
||||
-- @return #ASTAR self
|
||||
function ASTAR:SetValidNeighbourPathline(MaxDistance)
|
||||
|
||||
self:SetValidNeighbourFunction(ASTAR.Pathline, MaxDistance)
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
--- Set the function which calculates the "cost" to go from one to another node.
|
||||
-- The first to arguments of this function are always the two nodes under consideration. But you can add optional arguments.
|
||||
-- Very often the distance between nodes is a good measure for the cost.
|
||||
@@ -384,7 +443,7 @@ end
|
||||
-- @return #ASTAR self
|
||||
function ASTAR:SetCostRoad()
|
||||
|
||||
self:SetCostFunction(ASTAR)
|
||||
self:SetCostFunction(ASTAR.Road)
|
||||
|
||||
return self
|
||||
end
|
||||
@@ -544,6 +603,55 @@ function ASTAR.Road(nodeA, nodeB)
|
||||
|
||||
end
|
||||
|
||||
--- Function to check if two nodes are on the same pathline or if nodes are less than 10 meters apart.
|
||||
-- @param #ASTAR.Node nodeA First node.
|
||||
-- @param #ASTAR.Node nodeB Other node.
|
||||
-- @param #number distmax Max distance in meters. Default is 10 m.
|
||||
-- @return #boolean If true, two nodes are connected.
|
||||
function ASTAR.Pathline(nodeA, nodeB, distmax)
|
||||
|
||||
distmax=distmax or 10
|
||||
|
||||
if nodeA.pathline.name==nodeB.pathline.name then
|
||||
|
||||
-- Nodes are on the same pathline. We use the index to check if they are neighbours.
|
||||
|
||||
local pathline=nodeA.pathline
|
||||
|
||||
local idxA=pathline:_GetPointIndex(nodeA.pathpoint)
|
||||
local idxB=pathline:_GetPointIndex(nodeB.pathpoint)
|
||||
|
||||
if math.abs(idxA-idxB)<=1 then
|
||||
return true
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
-- Check if nodeB is close to pathline of nodeA.
|
||||
local c, dist, segA=nodeA.pathline:GetClosestPoint3D(nodeB.coordinate)
|
||||
local seg=segA --Core.Pathline#PATHLINE.Segment
|
||||
|
||||
if dist<distmax and (nodeA.pathpoint.uid==seg.p1.uid or nodeA.pathpoint.uid==seg.p2.uid) then
|
||||
--env.info(string.format("FF NodeB=%d [pathline=%s] is close to NodeA=%d [pathline=%s] ==> valid neighbour", nodeB.id, nodeB.pathline.name, nodeA.id, nodeA.pathline.name))
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
-- Check if nodeA is close to pathline of nodeB.
|
||||
local c, dist, segB=nodeB.pathline:GetClosestPoint3D(nodeA.coordinate)
|
||||
local seg=segB --Core.Pathline#PATHLINE.Segment
|
||||
|
||||
if dist<distmax and (nodeB.pathpoint.uid==seg.p1.uid or nodeB.pathpoint.uid==seg.p2.uid) then
|
||||
--env.info(string.format("FF NodeA=%d [pathline=%s] is close to NodeB=%d [pathline=%s] ==> valid neighbour", nodeA.id, nodeA.pathline.name, nodeB.id, nodeB.pathline.name))
|
||||
return true
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
|
||||
--- Function to check if distance between two nodes is less than a threshold distance.
|
||||
-- @param #ASTAR.Node nodeA First node.
|
||||
-- @param #ASTAR.Node nodeB Other node.
|
||||
@@ -567,7 +675,9 @@ end
|
||||
-- @param #ASTAR.Node nodeB Other node.
|
||||
-- @return #number Distance between the two nodes.
|
||||
function ASTAR.Dist2D(nodeA, nodeB)
|
||||
local dist=nodeA.coordinate:Get2DDistance(nodeB)
|
||||
local dist=nodeA.coordinate:Get2DDistance(nodeB.coordinate)
|
||||
--local text=string.format("FF Cost Dist2D NodeA=%d-->NodeB=%d = %.1f", nodeA.id, nodeB.id, dist)
|
||||
--env.info(text)
|
||||
return dist
|
||||
end
|
||||
|
||||
@@ -594,7 +704,7 @@ function ASTAR.DistRoad(nodeA, nodeB)
|
||||
local dist=0
|
||||
|
||||
for i=2,#path do
|
||||
local b=path[i] --DCS#Vec2
|
||||
local b=path[i] --DCS#Vec2
|
||||
local a=path[i-1] --DCS#Vec2
|
||||
|
||||
dist=dist+UTILS.VecDist2D(a,b)
|
||||
@@ -604,7 +714,6 @@ function ASTAR.DistRoad(nodeA, nodeB)
|
||||
return dist
|
||||
end
|
||||
|
||||
|
||||
return math.huge
|
||||
end
|
||||
|
||||
@@ -614,10 +723,11 @@ end
|
||||
|
||||
--- Find the closest node from a given coordinate.
|
||||
-- @param #ASTAR self
|
||||
-- @param Core.Point#COORDINATE Coordinate.
|
||||
-- @return #ASTAR.Node Cloest node to the coordinate.
|
||||
-- @param Core.Point#COORDINATE Coordinate Reference coordinate.
|
||||
-- @param #table ExcludeNodes Table of nodes that are excluded.
|
||||
-- @return #ASTAR.Node Closest node to the coordinate.
|
||||
-- @return #number Distance to closest node in meters.
|
||||
function ASTAR:FindClosestNode(Coordinate)
|
||||
function ASTAR:FindClosestNode(Coordinate, ExcludeNodes)
|
||||
|
||||
local distMin=math.huge
|
||||
local closeNode=nil
|
||||
@@ -625,11 +735,15 @@ function ASTAR:FindClosestNode(Coordinate)
|
||||
for _,_node in pairs(self.nodes) do
|
||||
local node=_node --#ASTAR.Node
|
||||
|
||||
local dist=node.coordinate:Get2DDistance(Coordinate)
|
||||
if ExcludeNodes==nil or self:_IsNodeNotInTable(ExcludeNodes, node) then
|
||||
|
||||
if dist<distMin then
|
||||
distMin=dist
|
||||
closeNode=node
|
||||
local dist=node.coordinate:Get2DDistance(Coordinate)
|
||||
|
||||
if dist<distMin then
|
||||
distMin=dist
|
||||
closeNode=node
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
@@ -637,38 +751,162 @@ function ASTAR:FindClosestNode(Coordinate)
|
||||
return closeNode, distMin
|
||||
end
|
||||
|
||||
--- Find the closest pathline to a given reference coordinate.
|
||||
-- @param #ASTAR self
|
||||
-- @param Core.Point#COORDINATE Coordinate Reference coordinate.
|
||||
-- @return Core.Pathline#PATHLINE Closest pathline
|
||||
-- @return #number Distance in meters.
|
||||
-- @return DCS#Vec3 Closest point on pathline to the ref coordinate.
|
||||
-- @return Core.Pathline#PATHLINE.Segment Segment.
|
||||
function ASTAR:FindClosestPathline(Coordinate)
|
||||
|
||||
local pathline=nil --Core.Pathline#PATHLINE
|
||||
local dist=math.huge
|
||||
local vec3=nil
|
||||
local S=nil
|
||||
|
||||
for _,_node in pairs(self.nodes) do
|
||||
local node=_node --#ASTAR.Node
|
||||
|
||||
if node.pathline then
|
||||
|
||||
local vec, d, s=node.pathline:GetClosestPoint3D(Coordinate)
|
||||
|
||||
if d<dist then
|
||||
pathline=node.pathline
|
||||
dist=d
|
||||
vec3=vec
|
||||
S=s
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
if pathline then
|
||||
-- Debug info.
|
||||
self:T(self.lid..string.format("Closest pathline %s: dist=%.1f", pathline.name, dist))
|
||||
end
|
||||
|
||||
return pathline, dist, vec3, S
|
||||
end
|
||||
|
||||
--- Find the closest node to the given coordinate.
|
||||
-- @param #ASTAR self
|
||||
-- @param Core.Point#COORDINATE Coord Reference coordinate.
|
||||
-- @param #table ExcludeNodes Nodes that are excluded.
|
||||
-- @return #ASTAR.Node The node that was fround
|
||||
function ASTAR:_FindClosestTerminalNode(Coord, ExcludeNodes)
|
||||
|
||||
-- Find the closest pathline to the ref coordinate.
|
||||
local pathline, dist, vec3, s=self:FindClosestPathline(Coord)
|
||||
|
||||
-- Find the closest node to the given start coordinate.
|
||||
local node, dist2=self:FindClosestNode(Coord)
|
||||
|
||||
if pathline and vec3 and dist and dist2>dist then
|
||||
|
||||
-- Create a node on the closest pathline so we first go straight there and then along the pathline.
|
||||
local node=self:AddNodeFromCoordinate(COORDINATE:NewFromVec3(vec3))
|
||||
|
||||
-- We also need the pathline point.
|
||||
local point=pathline:AddPointFromVec3(vec3, nil, s.p1)
|
||||
|
||||
node.pathline=pathline
|
||||
node.pathpoint=point
|
||||
|
||||
self:T2(self.lid..string.format("Added new node=%d, which is closest to start coord. dist=%.1f m", node.id, dist))
|
||||
end
|
||||
|
||||
-- Find the closest node to the given start coordinate.
|
||||
local Node, dist3=self:FindClosestNode(Coord, ExcludeNodes)
|
||||
|
||||
-- Debug info.
|
||||
self:T(self.lid..string.format("CLOSEST node ID=%d, distance=%.1f", Node.id, dist3))
|
||||
|
||||
return Node, dist3
|
||||
end
|
||||
|
||||
|
||||
--- Find the start node.
|
||||
-- @param #ASTAR self
|
||||
-- @param #ASTAR.Node Node The node to be added to the nodes table.
|
||||
-- @return #ASTAR self
|
||||
function ASTAR:FindStartNode()
|
||||
|
||||
-- Find the closest pathline to the
|
||||
local pathline, dist, vec3, s=self:FindClosestPathline(self.startCoord)
|
||||
|
||||
local node, dist=self:FindClosestNode(self.startCoord)
|
||||
-- Find the closest node to the given start coordinate.
|
||||
local node, dist2=self:FindClosestNode(self.startCoord)
|
||||
|
||||
self.startNode=node
|
||||
|
||||
if dist>1000 then
|
||||
self:T(self.lid.."Adding start node to node grid!")
|
||||
self:AddNode(node)
|
||||
if pathline and vec3 and dist and dist2>dist then
|
||||
|
||||
-- Create a node on the closest pathline so we first go straight there and then along the pathline.
|
||||
local node=self:AddNodeFromCoordinate(COORDINATE:NewFromVec3(vec3))
|
||||
|
||||
-- We also need the pathline point.
|
||||
local point=pathline:AddPointFromVec3(vec3, nil, s.p1)
|
||||
|
||||
node.pathline=pathline
|
||||
node.pathpoint=point
|
||||
|
||||
self:T2(self.lid..string.format("Added new node=%d, which is closest to start coord. dist=%.1f m", node.id, dist))
|
||||
end
|
||||
|
||||
-- Find the closest node to the given start coordinate.
|
||||
self.startNode, dist2=self:FindClosestNode(self.startCoord)
|
||||
|
||||
--self.startNode.coordinate:MarkToAll("Start Node")
|
||||
|
||||
-- Debug info.
|
||||
self:T(self.lid..string.format("START node ID=%d", self.startNode.id))
|
||||
|
||||
-- Not sure why I did this. The node does not need to be added again as it is already contained in self.nodes!
|
||||
-- if dist>1000 then
|
||||
-- self:T(self.lid.."Adding start node to node grid!")
|
||||
-- self:AddNode(node)
|
||||
-- end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Add a node.
|
||||
--- Find the end node.
|
||||
-- @param #ASTAR self
|
||||
-- @param #ASTAR.Node Node The node to be added to the nodes table.
|
||||
-- @return #ASTAR self
|
||||
function ASTAR:FindEndNode()
|
||||
|
||||
local node, dist=self:FindClosestNode(self.endCoord)
|
||||
|
||||
self.endNode=node
|
||||
|
||||
if dist>1000 then
|
||||
self:T(self.lid.."Adding end node to node grid!")
|
||||
self:AddNode(node)
|
||||
local pathline, dist, vec3, s=self:FindClosestPathline(self.endCoord)
|
||||
|
||||
-- Find the closest node to the given start coordinate.
|
||||
local node, dist2=self:FindClosestNode(self.endCoord)
|
||||
|
||||
if pathline and vec3 and dist and dist2>dist then
|
||||
|
||||
-- Create a node on the closest pathline so we first go straight there and then along the pathline.
|
||||
local node=self:AddNodeFromCoordinate(COORDINATE:NewFromVec3(vec3))
|
||||
|
||||
-- We also need the point.
|
||||
local point=pathline:AddPointFromVec3(vec3, nil, s.p1)
|
||||
|
||||
-- Add pathline parameters to node.
|
||||
node.pathline=pathline
|
||||
node.pathpoint=point
|
||||
|
||||
self:T2(self.lid..string.format("Added new node=%d, which is closest to END coord: dist=%.1f m", node.id, dist))
|
||||
end
|
||||
|
||||
-- Find closest node to the end coordinate (exclude the start coordinate.
|
||||
self.endNode, dist=self:FindClosestNode(self.endCoord, {self.startNode})
|
||||
|
||||
--self.endNode.coordinate:MarkToAll("End Node")
|
||||
|
||||
-- Debug info.
|
||||
self:T(self.lid..string.format("END node ID=%d", self.endNode.id))
|
||||
|
||||
-- Not sure why I did this. The node does not need to be added again as it is already contained in self.nodes!
|
||||
-- if dist>1000 then
|
||||
-- self:T(self.lid.."Adding end node to node grid!")
|
||||
-- self:AddNode(node)
|
||||
-- end
|
||||
|
||||
return self
|
||||
end
|
||||
@@ -684,12 +922,21 @@ end
|
||||
-- @return #table Table of nodes from start to finish.
|
||||
function ASTAR:GetPath(ExcludeStartNode, ExcludeEndNode)
|
||||
|
||||
self:FindStartNode()
|
||||
self:FindEndNode()
|
||||
-- self:FindStartNode()
|
||||
-- self:FindEndNode()
|
||||
|
||||
-- Find start Node (closest node to start coordinate).
|
||||
self.startNode=self:_FindClosestTerminalNode(self.startCoord)
|
||||
|
||||
-- Find end node, which is not the start node (excluded).
|
||||
self.endNode=self:_FindClosestTerminalNode(self.endCoord, {self.startNode})
|
||||
|
||||
local nodes=self.nodes
|
||||
local start=self.startNode
|
||||
local goal=self.endNode
|
||||
|
||||
-- Debug info.
|
||||
self:T(self.lid..string.format("GetPath Start Node=%d, End Node=%d", start.id, goal.id))
|
||||
|
||||
-- Sets.
|
||||
local openset = {}
|
||||
@@ -746,7 +993,12 @@ function ASTAR:GetPath(ExcludeStartNode, ExcludeEndNode)
|
||||
text=text..string.format(", OS Time %.6f sec", dT)
|
||||
end
|
||||
text=text..string.format(", Nvalid=%d [%d cached]", self.nvalid, self.nvalidcache)
|
||||
text=text..string.format(", Ncost=%d [%d cached]", self.ncost, self.ncostcache)
|
||||
text=text..string.format(", Ncost=%d [%d cached]", self.ncost, self.ncostcache)
|
||||
text=text..string.format("\nNodes:")
|
||||
for i,_node in ipairs(path) do
|
||||
local node=_node --#ASTAR.Node
|
||||
text=text..string.format("\n[%d] Node ID=%d", i, node.id)
|
||||
end
|
||||
self:T(self.lid..text)
|
||||
|
||||
return path
|
||||
@@ -759,13 +1011,16 @@ function ASTAR:GetPath(ExcludeStartNode, ExcludeEndNode)
|
||||
|
||||
-- Get neighbour nodes.
|
||||
local neighbors=self:_NeighbourNodes(current, nodes)
|
||||
|
||||
|
||||
-- Loop over neighbours.
|
||||
for _,neighbor in pairs(neighbors) do
|
||||
|
||||
-- Node is not in closed set.
|
||||
if self:_NotIn(closedset, neighbor.id) then
|
||||
|
||||
local tentative_g_score=g_score[current.id]+self:_DistNodes(current, neighbor)
|
||||
-- Calculate tentative_g_score.
|
||||
--local tentative_g_score=g_score[current.id] + self:_DistNodes(current, neighbor)
|
||||
local tentative_g_score=g_score[current.id] + self:_HeuristicCost(current, neighbor)
|
||||
|
||||
if self:_NotIn(openset, neighbor.id) or tentative_g_score < g_score[neighbor.id] then
|
||||
|
||||
@@ -793,6 +1048,73 @@ function ASTAR:GetPath(ExcludeStartNode, ExcludeEndNode)
|
||||
return nil -- no valid path
|
||||
end
|
||||
|
||||
--- A* pathfinding function. This seaches the path along nodes between start and end nodes/coordinates.
|
||||
-- It automatically creates a PATHLINE object that is returned in combination with the nodes of the optimal path.
|
||||
-- @param #ASTAR self
|
||||
-- @param #boolean ExcludeStartNode If *true*, do not include start node in found path. Default is to include it.
|
||||
-- @param #boolean ExcludeEndNode If *true*, do not include end node in found path. Default is to include it.
|
||||
-- @return Core.Pathline#PATHLINE Pathline.
|
||||
-- @return #table Nodes of path.
|
||||
function ASTAR:GetPathline(ExcludeStartNode, ExcludeEndNode)
|
||||
|
||||
local nodes=self:GetPath(ExcludeStartNode, ExcludeEndNode)
|
||||
|
||||
local pathline=nil --Core.Pathline#PATHLINE
|
||||
if nodes then
|
||||
|
||||
pathline=PATHLINE:New("Astar")
|
||||
|
||||
for _,_node in pairs(nodes) do
|
||||
local node=_node --#ASTAR.Node
|
||||
|
||||
local point=pathline:AddPointFromVec3(node.coordinate)
|
||||
point.name=node.pathline.name
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
return pathline, nodes
|
||||
end
|
||||
|
||||
--- Get pathlines from nodes.
|
||||
-- @param #ASTAR self
|
||||
-- @param #table Nodes Given nodes.
|
||||
-- @return #table Table of PATHLINES used in the path.
|
||||
function ASTAR:GetPathlinesFromNodes(Nodes)
|
||||
|
||||
local pathlines={}
|
||||
|
||||
--for _,_node in pairs(Nodes or {}) do
|
||||
for i=1,#Nodes do
|
||||
local node=Nodes[i] --#ASTAR.Node
|
||||
|
||||
-- Pathline.
|
||||
local pathline=node.pathline
|
||||
|
||||
if pathline and i>1 and i<#Nodes then
|
||||
|
||||
-- Previous and next nodes.
|
||||
local n=Nodes[i-1] --#ASTAR.Node
|
||||
local N=Nodes[i+1] --#ASTAR.Node
|
||||
|
||||
-- Check if previous and next nodes are on the same pathline.
|
||||
-- If only one point in beteen is of another pathline, this is a junction and we dont actually switch to the other pathline.
|
||||
if n.pathline and N.pathline and n.pathline.name==N.pathline.name and n.pathline.name~=pathline.name then
|
||||
pathline=n.pathline
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
-- We do not want to add the same pathline two times in a row.
|
||||
if #pathlines==0 or (#pathlines>0 and pathlines[#pathlines].name~=pathline.name) then
|
||||
table.insert(pathlines, pathline)
|
||||
end
|
||||
end
|
||||
|
||||
return pathlines
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- A* pathfinding helper functions
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
@@ -811,16 +1133,18 @@ function ASTAR:_HeuristicCost(nodeA, nodeB)
|
||||
local cost=nodeA.cost[nodeB.id]
|
||||
if cost~=nil then
|
||||
self.ncostcache=self.ncostcache+1
|
||||
self:T(self.lid..string.format("Cost nodeA=%d --> nodeB=%d = %.1f (Cashed!)", nodeA.id, nodeB.id, cost))
|
||||
return cost
|
||||
end
|
||||
|
||||
local cost=nil
|
||||
if self.CostFunc then
|
||||
cost=self.CostFunc(nodeA, nodeB, unpack(self.CostArg))
|
||||
else
|
||||
cost=self:_DistNodes(nodeA, nodeB)
|
||||
end
|
||||
|
||||
self:T(self.lid..string.format("Cost nodeA=%d --> nodeB=%d = %.1f", nodeA.id, nodeB.id, cost))
|
||||
|
||||
nodeA.cost[nodeB.id]=cost
|
||||
nodeB.cost[nodeA.id]=cost -- Symmetric problem.
|
||||
|
||||
@@ -834,9 +1158,10 @@ end
|
||||
-- @return #boolean If true, transition between nodes is possible.
|
||||
function ASTAR:_IsValidNeighbour(node, neighbor)
|
||||
|
||||
-- Counter.
|
||||
-- Counter of function calls.
|
||||
self.nvalid=self.nvalid+1
|
||||
|
||||
-- Check if neighbour is in cached set.
|
||||
local valid=node.valid[neighbor.id]
|
||||
if valid~=nil then
|
||||
--env.info(string.format("Node %d has valid=%s neighbour %d", node.id, tostring(valid), neighbor.id))
|
||||
@@ -844,13 +1169,16 @@ function ASTAR:_IsValidNeighbour(node, neighbor)
|
||||
return valid
|
||||
end
|
||||
|
||||
-- Check if this is a valid neighbour.
|
||||
local valid=nil
|
||||
if self.ValidNeighbourFunc then
|
||||
valid=self.ValidNeighbourFunc(node, neighbor, unpack(self.ValidNeighbourArg))
|
||||
else
|
||||
-- If no valid neighbour function is defined, we assume all nodes are valid neighbours.
|
||||
valid=true
|
||||
end
|
||||
|
||||
-- Cache valid neighbour.
|
||||
node.valid[neighbor.id]=valid
|
||||
neighbor.valid[node.id]=valid -- Symmetric problem.
|
||||
|
||||
@@ -884,6 +1212,9 @@ function ASTAR:_LowestFscore(set, f_score)
|
||||
end
|
||||
end
|
||||
|
||||
-- Debug info.
|
||||
self:T(self.lid..string.format("Lowest Fscore=%.1f, Node=%s", lowest, tostring(bestNode)))
|
||||
|
||||
return self.nodes[bestNode]
|
||||
end
|
||||
|
||||
@@ -928,16 +1259,46 @@ end
|
||||
-- @param #table map Map.
|
||||
-- @param #ASTAR.Node current_node The current node.
|
||||
-- @return #table Unwinded path.
|
||||
function ASTAR:_UnwindPath( flat_path, map, current_node )
|
||||
function ASTAR:_UnwindPath(flat_path, map, current_node)
|
||||
|
||||
if map [current_node] then
|
||||
table.insert (flat_path, 1, map[current_node])
|
||||
return self:_UnwindPath(flat_path, map, map[current_node])
|
||||
local previous_node=map[current_node]
|
||||
|
||||
if previous_node then
|
||||
table.insert(flat_path, 1, previous_node)
|
||||
return self:_UnwindPath(flat_path, map, previous_node)
|
||||
else
|
||||
-- No previous node ==> return path.
|
||||
return flat_path
|
||||
end
|
||||
end
|
||||
|
||||
--- Function to check if a certain node is in a given table.
|
||||
-- @param #ASTAR self
|
||||
-- @param #table Nodes Nodes table.
|
||||
-- @param #ASTAR.Node Node The node to check.
|
||||
-- @return #boolean If true, the node is not in the set.
|
||||
function ASTAR:_IsNodeInTable(Nodes, Node)
|
||||
|
||||
for _,_node in pairs(Nodes) do
|
||||
local node=_node --#ASTAR.Node
|
||||
if node.id==Node.id then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
--- Function to check if a certain node is **not** in a given table.
|
||||
-- @param #ASTAR self
|
||||
-- @param #table Nodes Nodes table.
|
||||
-- @param #ASTAR.Node Node The node to check.
|
||||
-- @return #boolean If true, the node is not in the set.
|
||||
function ASTAR:_IsNodeNotInTable(Nodes, Node)
|
||||
local is=self:_IsNodeInTable(Nodes, Node)
|
||||
return not is
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
@@ -5,11 +5,13 @@
|
||||
-- * Path from A to B
|
||||
-- * Arbitrary number of points
|
||||
-- * Automatically from lines drawtool
|
||||
-- * Draw line or mark points on F10 map
|
||||
-- * Find closest points to path
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- ### Author: **funkyfranky**
|
||||
--
|
||||
--
|
||||
-- ===
|
||||
-- @module Core.Pathline
|
||||
-- @image CORE_Pathline.png
|
||||
@@ -21,6 +23,7 @@
|
||||
-- @field #string lid Class id string for output to DCS log file.
|
||||
-- @field #string name Name of the path line.
|
||||
-- @field #table points List of 3D points defining the path.
|
||||
-- @field #number counter Running number counting the point IDs.
|
||||
-- @extends Core.Base#BASE
|
||||
|
||||
--- *The shortest distance between two points is a straight line.* -- Archimedes
|
||||
@@ -28,30 +31,30 @@
|
||||
-- ===
|
||||
--
|
||||
-- # The PATHLINE Concept
|
||||
--
|
||||
--
|
||||
-- List of points defining a path from A to B. The pathline can consist of multiple points. Each point holds the information of its position, the surface type, the land height
|
||||
-- and the water depth (if over sea).
|
||||
--
|
||||
--
|
||||
-- Line drawings created in the mission editor are automatically registered as pathlines and stored in the MOOSE database.
|
||||
-- They can be accessed with the @{#PATHLINE.FindByName) function.
|
||||
--
|
||||
--
|
||||
-- # Constructor
|
||||
--
|
||||
--
|
||||
-- The @{PATHLINE.New) function creates a new PATHLINE object. This does not hold any points. Points can be added with the @{#PATHLINE.AddPointFromVec2} and @{#PATHLINE.AddPointFromVec3}
|
||||
--
|
||||
--
|
||||
-- For a given table of 2D or 3D positions, a new PATHLINE object can be created with the @{#PATHLINE.NewFromVec2Array} or @{#PATHLINE.NewFromVec3Array}, respectively.
|
||||
--
|
||||
--
|
||||
-- # Line Drawings
|
||||
--
|
||||
--
|
||||
-- The most convenient way to create a pathline is the draw panel feature in the DCS mission editor. You can select "Line" and then "Segments", "Segment" or "Free" to draw your lines.
|
||||
-- These line drawings are then automatically added to the MOOSE database as PATHLINE objects and can be retrieved with the @{#PATHLINE.FindByName) function, where the name is the one
|
||||
-- you specify in the draw panel.
|
||||
--
|
||||
--
|
||||
-- # Mark on F10 map
|
||||
--
|
||||
-- The points of the PATHLINE can be marked on the F10 map with the @{#PATHLINE.MarkPoints}(`true`) function. The mark points contain information of the surface type, land height and
|
||||
-- water depth.
|
||||
--
|
||||
--
|
||||
-- To remove the marks, use @{#PATHLINE.MarkPoints}(`false`).
|
||||
--
|
||||
-- @field #PATHLINE
|
||||
@@ -59,10 +62,14 @@ PATHLINE = {
|
||||
ClassName = "PATHLINE",
|
||||
lid = nil,
|
||||
points = {},
|
||||
counter = 0,
|
||||
}
|
||||
|
||||
--- Point of line.
|
||||
-- @type PATHLINE.Point
|
||||
-- @field #number uid Unique ID of this point.
|
||||
-- @field #string mother Name of the pathline this point belongs to.
|
||||
-- @field #string name Name of this point.
|
||||
-- @field DCS#Vec3 vec3 3D position.
|
||||
-- @field DCS#Vec2 vec2 2D position.
|
||||
-- @field #number surfaceType Surface type.
|
||||
@@ -80,7 +87,9 @@ PATHLINE.version="0.2.0"
|
||||
-- TODO list
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
-- TODO: A lot...
|
||||
-- TODO: Read/write to JSON file
|
||||
-- TODO: Translate/rotate pathline
|
||||
-- TODO: Add color.
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- Constructor
|
||||
@@ -94,10 +103,10 @@ function PATHLINE:New(Name)
|
||||
|
||||
-- Inherit everything from INTEL class.
|
||||
local self=BASE:Inherit(self, BASE:New()) --#PATHLINE
|
||||
|
||||
|
||||
self.name=Name or "Unknown Path"
|
||||
|
||||
self.lid=string.format("PATHLINE %s | ", Name)
|
||||
self.lid=string.format("PATHLINE %s | ", self.name)
|
||||
|
||||
return self
|
||||
end
|
||||
@@ -152,41 +161,70 @@ end
|
||||
--- Add a point to the path from a given 2D position. The third dimension is determined from the land height.
|
||||
-- @param #PATHLINE self
|
||||
-- @param DCS#Vec2 Vec2 The 2D vector (x,y) to add.
|
||||
-- @param #number Index Index to add this point, *e.g.* 1 for first point or 2 for second point. Default is at the end.
|
||||
-- @param #PATHLINE.Point Point Add point after given point. Default is at the end or at given index.
|
||||
-- @return #PATHLINE self
|
||||
function PATHLINE:AddPointFromVec2(Vec2)
|
||||
function PATHLINE:AddPointFromVec2(Vec2, Index, Point)
|
||||
|
||||
if Vec2 then
|
||||
|
||||
|
||||
-- Create a new point.
|
||||
local point=self:_CreatePoint(Vec2)
|
||||
|
||||
table.insert(self.points, point)
|
||||
|
||||
if Index then
|
||||
-- Add at given index.
|
||||
table.insert(self.points, Index, point)
|
||||
else
|
||||
if Point then
|
||||
-- Get index of given point.
|
||||
local i=self:_GetPointIndex(Point)
|
||||
-- Add new point after given point.
|
||||
table.insert(self.points, i+1, point)
|
||||
else
|
||||
-- Add add the end.
|
||||
table.insert(self.points, point)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Add a point to the path from a given 3D position.
|
||||
-- @param #PATHLINE self
|
||||
-- @param DCS#Vec3 Vec3 The 3D vector (x,y) to add.
|
||||
-- @return #PATHLINE self
|
||||
function PATHLINE:AddPointFromVec3(Vec3)
|
||||
-- @param #number Index Index to add this point, *e.g.* 1 for first point or 2 for second point. Default is at the end.
|
||||
-- @param #PATHLINE.Point Point Add point after given point. Default is at the end or at given index.
|
||||
-- @return #PATHLINE.Point Point that was added.
|
||||
function PATHLINE:AddPointFromVec3(Vec3, Index, Point)
|
||||
|
||||
if Vec3 then
|
||||
|
||||
|
||||
local point=self:_CreatePoint(Vec3)
|
||||
|
||||
table.insert(self.points, point)
|
||||
|
||||
if Index then
|
||||
-- Add add given index.
|
||||
table.insert(self.points, Index, point)
|
||||
else
|
||||
if Point then
|
||||
local i=self:_GetPointIndex(Point)
|
||||
table.insert(self.points, i+1, point)
|
||||
else
|
||||
-- Add add the end.
|
||||
table.insert(self.points, point)
|
||||
end
|
||||
end
|
||||
|
||||
return point
|
||||
end
|
||||
|
||||
return self
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
--- Get name of pathline.
|
||||
-- @param #PATHLINE self
|
||||
-- @return #string Name of the pathline.
|
||||
function PATHLINE:GetName()
|
||||
function PATHLINE:GetName()
|
||||
return self.name
|
||||
end
|
||||
|
||||
@@ -200,18 +238,35 @@ end
|
||||
|
||||
--- Get points of pathline. Not that points are tables, that contain more information as just the 2D or 3D position but also the surface type etc.
|
||||
-- @param #PATHLINE self
|
||||
-- @return #list <#PATHLINE.Point> List of points.
|
||||
function PATHLINE:GetPoints()
|
||||
-- @return #list <Core.Pathline#PATHLINE.Point> List of points.
|
||||
function PATHLINE:GetPoints()
|
||||
return self.points
|
||||
end
|
||||
|
||||
--- Get segments of pathline.
|
||||
-- @param #PATHLINE self
|
||||
-- @return #list <Core.Pathline#PATHLINE.Segment> List of points.
|
||||
function PATHLINE:GetSetments()
|
||||
|
||||
local segments={}
|
||||
|
||||
for i=1,#self.points-1 do
|
||||
local segment={} --#PATHLINE.Segment
|
||||
segment.p1=self.points[i]
|
||||
segment.p2=self.points[i+1]
|
||||
table.insert(segments, segment)
|
||||
end
|
||||
|
||||
return segments
|
||||
end
|
||||
|
||||
--- Get 3D points of pathline.
|
||||
-- @param #PATHLINE self
|
||||
-- @return <DCS#Vec3> List of DCS#Vec3 points.
|
||||
-- @return #list <DCS#Vec3> List of DCS#Vec3 points.
|
||||
function PATHLINE:GetPoints3D()
|
||||
|
||||
local vecs={}
|
||||
|
||||
|
||||
for _,_point in pairs(self.points) do
|
||||
local point=_point --#PATHLINE.Point
|
||||
table.insert(vecs, point.vec3)
|
||||
@@ -222,11 +277,11 @@ end
|
||||
|
||||
--- Get 2D points of pathline.
|
||||
-- @param #PATHLINE self
|
||||
-- @return <DCS#Vec2> List of DCS#Vec2 points.
|
||||
-- @return #list <DCS#Vec2> List of DCS#Vec2 points.
|
||||
function PATHLINE:GetPoints2D()
|
||||
|
||||
local vecs={}
|
||||
|
||||
|
||||
for _,_point in pairs(self.points) do
|
||||
local point=_point --#PATHLINE.Point
|
||||
table.insert(vecs, point.vec2)
|
||||
@@ -241,11 +296,11 @@ end
|
||||
function PATHLINE:GetCoordinates()
|
||||
|
||||
local vecs={}
|
||||
|
||||
|
||||
for _,_point in pairs(self.points) do
|
||||
local point=_point --#PATHLINE.Point
|
||||
local coord=COORDINATE:NewFromVec3(point.vec3)
|
||||
table.insert(vecs,coord)
|
||||
table.insert(vecs, coord)
|
||||
end
|
||||
|
||||
return vecs
|
||||
@@ -258,11 +313,11 @@ end
|
||||
function PATHLINE:GetPointFromIndex(n)
|
||||
|
||||
local N=self:GetNumberOfPoints()
|
||||
|
||||
|
||||
n=n or 1
|
||||
|
||||
local point=nil --#PATHLINE.Point
|
||||
|
||||
|
||||
if n>=1 and n<=N then
|
||||
point=self.points[n]
|
||||
else
|
||||
@@ -279,11 +334,11 @@ end
|
||||
function PATHLINE:GetPoint3DFromIndex(n)
|
||||
|
||||
local point=self:GetPointFromIndex(n)
|
||||
|
||||
|
||||
if point then
|
||||
return point.vec3
|
||||
end
|
||||
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
@@ -294,11 +349,11 @@ end
|
||||
function PATHLINE:GetPoint2DFromIndex(n)
|
||||
|
||||
local point=self:GetPointFromIndex(n)
|
||||
|
||||
|
||||
if point then
|
||||
return point.vec2
|
||||
end
|
||||
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
@@ -332,8 +387,10 @@ end
|
||||
-- @param #boolean Switch If `true` or nil, set marks. If `false`, remove marks.
|
||||
-- @return #PATHLINE self
|
||||
function PATHLINE:MarkPoints(Switch)
|
||||
|
||||
for i,_point in pairs(self.points) do
|
||||
local point=_point --#PATHLINE.Point
|
||||
|
||||
if Switch==false then
|
||||
|
||||
if point.markerID then
|
||||
@@ -345,13 +402,19 @@ function PATHLINE:MarkPoints(Switch)
|
||||
if point.markerID then
|
||||
UTILS.RemoveMark(point.markerID)
|
||||
end
|
||||
|
||||
|
||||
else
|
||||
|
||||
if point.markerID then
|
||||
UTILS.RemoveMark(point.markerID)
|
||||
end
|
||||
|
||||
point.markerID=UTILS.GetMarkID()
|
||||
|
||||
local text=string.format("Pathline %s: Point #%d\nSurface Type=%d\nHeight=%.1f m\nDepth=%.1f m", self.name, i, point.surfaceType, point.landHeight, point.depth)
|
||||
|
||||
|
||||
local text=string.format("Pathline %s: Point #%d [UID=%d]\nSurface Type=%d\nHeight=%.1f m\nDepth=%.1f m", self.name, i, point.uid, point.surfaceType, point.landHeight, point.depth)
|
||||
|
||||
trigger.action.markToAll(point.markerID, text, point.vec3, "")
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
return self
|
||||
@@ -407,6 +470,283 @@ function PATHLINE:UnDrawLine(Delay)
|
||||
end
|
||||
|
||||
|
||||
--- Draw line on F10 map.
|
||||
-- @param #PATHLINE self
|
||||
-- @param #boolean Switch If `true` or nil, draw pathline. If `false`, remove drawing.
|
||||
-- @param #number Coalition Coalition side. Default -1 for all.
|
||||
-- @param #table Color RGB color and alpha `{r, g, b, a}`. Default {0, 1, 0, 0.5}.
|
||||
-- @param #number LineType Line type. Default 1=solid.
|
||||
-- @return #PATHLINE self
|
||||
function PATHLINE:Draw(Switch, Coalition, Color, LineType)
|
||||
|
||||
Coalition=Coalition or -1
|
||||
Color=Color or {0, 1, 0, 0.5}
|
||||
LineType=LineType or 1
|
||||
|
||||
if Switch==false then
|
||||
|
||||
for i,_point in pairs(self.points) do
|
||||
local point=_point --#PATHLINE.Point
|
||||
|
||||
if point.lineID then
|
||||
UTILS.RemoveMark(point.lineID)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
for i=2,#self.points do
|
||||
|
||||
local p1=self.points[i-1] --#PATHLINE.Point
|
||||
local p2=self.points[i] --#PATHLINE.Point
|
||||
|
||||
if p2.lineID then
|
||||
UTILS.RemoveMark(p2.lineID)
|
||||
end
|
||||
|
||||
p2.lineID=UTILS.GetMarkID()
|
||||
|
||||
trigger.action.lineToAll(Coalition, p2.lineID, p1.vec3, p2.vec3, Color, LineType)
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Get the closest point on the pathline for a given reference point.
|
||||
-- @param #PATHLINE self
|
||||
-- @param DCS#Vec2 Vec2 Reference Point in 2D.
|
||||
-- @return DCS#Vec2 Cloest point on pathline.
|
||||
-- @return #number Distance from closest point to ref point in meters.
|
||||
-- @return #PATHLINE.Segment Closest segment of ref point.
|
||||
function PATHLINE:GetClosestPoint2D(Vec2)
|
||||
|
||||
local P=nil --DCS#Vec2
|
||||
local D=math.huge
|
||||
local S={} --#PATHLINE.Segment
|
||||
|
||||
for i=2,#self.points do
|
||||
|
||||
local A=self.points[i-1] --#PATHLINE.Point
|
||||
local B=self.points[i] --#PATHLINE.Point
|
||||
|
||||
local a=A.vec2
|
||||
local b=B.vec2
|
||||
|
||||
local ab=UTILS.Vec2Substract(b, a)
|
||||
local ap=UTILS.Vec2Substract(Vec2, a)
|
||||
|
||||
local proj=UTILS.Vec2Dot(ap, ab)
|
||||
|
||||
local lab=UTILS.Vec2Norm(ab)
|
||||
|
||||
local f=proj/lab/lab
|
||||
|
||||
-- Debug info.
|
||||
local text=string.format("FF Proj=%.1f, |ab|=%.1f, f=%.1f", proj, lab, f)
|
||||
self:T(self.lid..text)
|
||||
|
||||
-- Cases for finite segment.
|
||||
local p=nil --DCS#Vec2
|
||||
if f<0 then
|
||||
p=a
|
||||
elseif f>1 then
|
||||
p=b
|
||||
else
|
||||
local r=UTILS.Vec2Mult(ab, f)
|
||||
p=UTILS.Vec2Add(a, r)
|
||||
end
|
||||
|
||||
-- Distance.
|
||||
local d=UTILS.VecDist2D(p, Vec2)
|
||||
|
||||
if d<=D then
|
||||
D=d
|
||||
P=p
|
||||
S.p1=A
|
||||
S.p2=B
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
return P, D, S
|
||||
end
|
||||
|
||||
--- Get the closest point on the pathline for a given reference point.
|
||||
-- This point does not necessarily is a node of the pathline. In general it will be somewhere in between the nodes defining the pathline.
|
||||
-- @param #PATHLINE self
|
||||
-- @param DCS#Vec3 Vec3 Reference Point in 3D. Can also be a `COORDINATE`.
|
||||
-- @return DCS#Vec3 Closest point on pathline.
|
||||
-- @return #number Distance from closest point to ref point in meters.
|
||||
-- @return #PATHLINE.Segment Closest segment of ref point.
|
||||
function PATHLINE:GetClosestPoint3D(Vec3)
|
||||
|
||||
local P=nil --DCS#Vec3
|
||||
local D=math.huge
|
||||
local S={} --#PATHLINE.Segment
|
||||
|
||||
if not Vec3 then
|
||||
self:E(self.lid.."ERROR: input Vec3 is nil!")
|
||||
return nil, nil, nil
|
||||
end
|
||||
|
||||
for i=2,#self.points do
|
||||
|
||||
local A=self.points[i-1] --#PATHLINE.Point
|
||||
local B=self.points[i] --#PATHLINE.Point
|
||||
|
||||
local a=A.vec3
|
||||
local b=B.vec3
|
||||
|
||||
local ab=UTILS.VecSubstract(b, a)
|
||||
local ap=UTILS.VecSubstract(Vec3, a)
|
||||
|
||||
local proj=UTILS.VecDot(ap, ab)
|
||||
|
||||
local lab=UTILS.VecNorm(ab)
|
||||
|
||||
local f=proj/lab/lab
|
||||
|
||||
-- Debug info.
|
||||
self:T(self.lid..string.format("Proj=%.1f, |ab|=%.1f, f=%.1f", proj, lab, f))
|
||||
|
||||
-- Cases for finite segment.
|
||||
local p=nil --DCS#Vec2
|
||||
if f<0 then
|
||||
p=a
|
||||
elseif f>1 then
|
||||
p=b
|
||||
else
|
||||
local r=UTILS.VecMult(ab, f)
|
||||
p=UTILS.VecAdd(a, r)
|
||||
end
|
||||
|
||||
-- Distance.
|
||||
local d=UTILS.VecDist3D(p, Vec3)
|
||||
|
||||
if d<=D then
|
||||
D=d
|
||||
P=p
|
||||
S.p1=A
|
||||
S.p2=B
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
return P, D, S
|
||||
end
|
||||
|
||||
|
||||
--- Write PATHLINE to JSON file.
|
||||
-- **NOTE**: Requires `io` and `lfs` to be de-sanitized!
|
||||
-- @param #PATHLINE self
|
||||
-- @param #string FileName Name of the file. Default is the name of the pathline.
|
||||
-- @return #PATHLINE self
|
||||
function PATHLINE:WriteJSON(FileName)
|
||||
|
||||
if io and lfs then
|
||||
|
||||
-- JSON script.
|
||||
local json=loadfile("Scripts\\JSON.lua")()
|
||||
|
||||
local data={}
|
||||
|
||||
-- We store the name and the points.
|
||||
data.name=self.name
|
||||
data.points=self.points
|
||||
for i,_point in pairs(self.points) do
|
||||
local point=_point --#PATHLINE.Point
|
||||
--point.markerID=nil
|
||||
end
|
||||
|
||||
-- Encode data to raw JSON. Encode converts a lua table into JSON string that can be written to file.
|
||||
local raw_json=json:encode(data)
|
||||
|
||||
-- Debug data.
|
||||
self:T(data)
|
||||
|
||||
-- Write in "User/Saved Games/" Folder.
|
||||
local filepath=lfs.writedir() .. FileName
|
||||
|
||||
-- Open file for writing.
|
||||
local f = io.open(filepath, "wb")
|
||||
if f then
|
||||
f:write(raw_json)
|
||||
f:close()
|
||||
self:T(self.lid .. string.format("Saving PATHLINE %s file %s", self.name, tostring(filepath)))
|
||||
else
|
||||
self:E(self.lid .. string.format( "ERROR: Could not save PATHLINE to file %s", tostring(filepath)))
|
||||
end
|
||||
|
||||
else
|
||||
self:E(self.lid .. string.format( "ERROR: Could not save results because IO and/or LFS are not de-sanitized!"))
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--- Read PATHLINE from JSON file.
|
||||
-- **NOTE**: Requires `io` and `lfs` to be de-sanitized!
|
||||
-- @param #PATHLINE self
|
||||
-- @param #string FileName Name of the file.
|
||||
-- @return #PATHLINE self
|
||||
function PATHLINE:NewFromJSON(FileName)
|
||||
|
||||
if io and lfs then
|
||||
|
||||
-- JSON script.
|
||||
local json=loadfile("Scripts\\JSON.lua")()
|
||||
|
||||
local data={}
|
||||
|
||||
-- Write in "User/Saved Games/" Folder.
|
||||
local filepath=lfs.writedir() .. FileName
|
||||
|
||||
--env.info(filepath)
|
||||
|
||||
-- Open file in binary mode for reading.
|
||||
local f = io.open(filepath, "rb")
|
||||
if f then
|
||||
data = f:read("*all")
|
||||
f:close()
|
||||
else
|
||||
env.info(string.format("WARNING: Could not load PATHLINE from file %s!", tostring(filepath)))
|
||||
return nil
|
||||
end
|
||||
|
||||
-- Decode JSON data to get a lua table.
|
||||
local data=json:decode(data)
|
||||
|
||||
if data and data.name then
|
||||
|
||||
-- Create a new pathline instance.
|
||||
local self=PATHLINE:New(data.name)
|
||||
|
||||
for i=1,#data.points do
|
||||
local point=data.points[i] --#PATHLINE.Point
|
||||
|
||||
-- Create new point from data.
|
||||
local p=self:AddPointFromVec3(point.vec3)
|
||||
|
||||
-- Set name.
|
||||
p.name=point.name
|
||||
|
||||
-- Remove marker ID.
|
||||
p.markerID=nil
|
||||
end
|
||||
|
||||
return self
|
||||
else
|
||||
BASE:E("ERROR: Cannot find pathline name in data from JSON file. File may be corrupted!")
|
||||
end
|
||||
else
|
||||
BASE:E("ERROR: IO and/or LFS not de-sanitized! Cannot read file.")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- Private functions
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
@@ -414,32 +754,56 @@ end
|
||||
--- Get 3D points of pathline.
|
||||
-- @param #PATHLINE self
|
||||
-- @param DCS#Vec3 Vec Position vector. Can also be a DCS#Vec2 in which case the altitude at landheight is taken.
|
||||
-- @return #PATHLINE.Point
|
||||
-- @return #PATHLINE.Point Pathline Point.
|
||||
function PATHLINE:_CreatePoint(Vec)
|
||||
|
||||
local point={} --#PATHLINE.Point
|
||||
|
||||
self.counter=self.counter+1
|
||||
|
||||
point.uid=self.counter
|
||||
point.mother=self.name
|
||||
|
||||
point.name=string.format("%s #%d", self.name, point.uid)
|
||||
|
||||
if Vec.z then
|
||||
-- Given vec is 3D
|
||||
point.vec3=UTILS.DeepCopy(Vec)
|
||||
point.vec2={x=Vec.x, y=Vec.z}
|
||||
else
|
||||
-- Given vec is 2D
|
||||
-- Given vec is 2D
|
||||
point.vec2=UTILS.DeepCopy(Vec)
|
||||
point.vec3={x=Vec.x, y=land.getHeight(Vec), z=Vec.y}
|
||||
end
|
||||
|
||||
-- Get surface type.
|
||||
point.surfaceType=land.getSurfaceType(point.vec2)
|
||||
|
||||
|
||||
-- Get land height and depth.
|
||||
point.landHeight, point.depth=land.getSurfaceHeightWithSeabed(point.vec2)
|
||||
|
||||
|
||||
point.markerID=nil
|
||||
|
||||
return point
|
||||
end
|
||||
|
||||
--- Get index of point in the lua table.
|
||||
-- @param #PATHLINE self
|
||||
-- @param #PATHLINE.Point Point Given point.
|
||||
-- @return #number index
|
||||
function PATHLINE:_GetPointIndex(Point)
|
||||
|
||||
for i,_point in pairs(self.points) do
|
||||
local point=_point --#PATHLINE.Point
|
||||
|
||||
if point.uid==Point.uid then
|
||||
return i
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -455,6 +455,23 @@ do -- COORDINATE
|
||||
end
|
||||
|
||||
|
||||
--- Returns the coordinate from the latitude and longitude given in degrees, minutes and seconds (DMS).
|
||||
-- @param #COORDINATE self
|
||||
-- @param #string Latitude Latitude in DMS as string, e.g. "`42° 24' 14.3"`". Not that the characters `°`, `'` and `"` are important.
|
||||
-- @param #string Longitude Longitude in DMS as string, e.g. "`42° 24' 14.3"`". Not that the characters `°`, `'` and `"` are important.
|
||||
-- @param #number Altitude (Optional) Altitude in meters. Default is the land height at the coordinate.
|
||||
-- @return #COORDINATE
|
||||
function COORDINATE:NewFromLLDMS(Latitude, Longitude, Altitude)
|
||||
|
||||
local lat=UTILS.LLDMSstringToDD(Latitude)
|
||||
local lon=UTILS.LLDMSstringToDD(Longitude)
|
||||
|
||||
self=COORDINATE:NewFromLLDD(lat, lon, Altitude)
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
--- Returns if the 2 coordinates are at the same 2D position.
|
||||
-- @param #COORDINATE self
|
||||
-- @param #COORDINATE Coordinate
|
||||
@@ -663,7 +680,7 @@ do -- COORDINATE
|
||||
local _,_,_,_,_,scenerys=self:ScanObjects(radius, false, false, true)
|
||||
|
||||
local set={}
|
||||
|
||||
|
||||
for _,_scenery in pairs(scenerys) do
|
||||
local scenery=_scenery --DCS#Object
|
||||
|
||||
|
||||
@@ -306,6 +306,20 @@ function ZONE_BASE:GetCoordinate( Height ) --R2.1
|
||||
return self.Coordinate
|
||||
end
|
||||
|
||||
--- Returns the @{Core.Vector#VECTOR} of the zone.
|
||||
-- @param #ZONE_BASE self
|
||||
-- @param DCS#Distance Height The height in meters to add to the land height where the center of the zone is located.
|
||||
-- @return Core.Vector#VECTOR The vector of the zone.
|
||||
function ZONE_BASE:GetVector( Height )
|
||||
self:F2(self.ZoneName)
|
||||
|
||||
local Vec3 = self:GetVec3( Height )
|
||||
|
||||
local vector=VECTOR:NewFromVec(Vec3)
|
||||
|
||||
return vector
|
||||
end
|
||||
|
||||
--- Get 2D distance to a coordinate.
|
||||
-- @param #ZONE_BASE self
|
||||
-- @param Core.Point#COORDINATE Coordinate Reference coordinate. Can also be a DCS#Vec2 or DCS#Vec3 object.
|
||||
|
||||
@@ -188,8 +188,10 @@ __Moose.Include( MOOSE_DEVELOPMENT_FOLDER..'/Moose/Tasking/Task_Cargo_Dispatcher
|
||||
__Moose.Include( MOOSE_DEVELOPMENT_FOLDER..'/Moose/Tasking/Task_Capture_Zone.lua' )
|
||||
__Moose.Include( MOOSE_DEVELOPMENT_FOLDER..'/Moose/Tasking/Task_Capture_Dispatcher.lua' )
|
||||
|
||||
__Moose.Include( MOOSE_DEVELOPMENT_FOLDER..'/Moose/Navigation/Point.lua' )
|
||||
__Moose.Include( MOOSE_DEVELOPMENT_FOLDER..'/Moose/Navigation/Beacons.lua' )
|
||||
__Moose.Include( MOOSE_DEVELOPMENT_FOLDER..'/Moose/Navigation/Point.lua' )
|
||||
__Moose.Include( MOOSE_DEVELOPMENT_FOLDER..'/Moose/Navigation/Procedure.lua' )
|
||||
__Moose.Include( MOOSE_DEVELOPMENT_FOLDER..'/Moose/Navigation/FlightPlan.lua' )
|
||||
__Moose.Include( MOOSE_DEVELOPMENT_FOLDER..'/Moose/Navigation/Radios.lua' )
|
||||
__Moose.Include( MOOSE_DEVELOPMENT_FOLDER..'/Moose/Navigation/Towns.lua' )
|
||||
|
||||
|
||||
@@ -0,0 +1,481 @@
|
||||
--- **NAVIGATION** - Flight Plan.
|
||||
--
|
||||
-- **Main Features:**
|
||||
--
|
||||
-- * Manage navigation aids
|
||||
-- * VOR, NDB
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- ## Example Missions:
|
||||
--
|
||||
-- Demo missions can be found on [github](https://github.com/FlightControl-Master/MOOSE_MISSIONS/tree/develop/Ops%20-%20FlightPlan).
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- ### Author: **funkyfranky**
|
||||
--
|
||||
-- ===
|
||||
-- @module Navigation.FlightPlan
|
||||
-- @image NAVIGATION_FlightPlan.png
|
||||
|
||||
|
||||
--- FLIGHTPLAN class.
|
||||
-- @type FLIGHTPLAN
|
||||
-- @field #string ClassName Name of the class.
|
||||
-- @field #number verbose Verbosity of output.
|
||||
-- @field #table fixes Navigation fixes.
|
||||
-- @field Core.Pathline#PATHLINE pathline Pathline of the plan.
|
||||
-- @field Wrapper.Airbase#AIRBASE departureAirbase Departure airbase.
|
||||
-- @field Wrapper.Airbase#AIRBASE destinationAirbase Destination airbase.
|
||||
-- @field #number altitudeCruiseMin Minimum cruise altitude in feet MSL.
|
||||
-- @field #number altitudeCruiseMax Maximum cruise altitude in feet MSL.
|
||||
-- @extends Core.Pathline#PATHLINE
|
||||
|
||||
--- *Life is what happens to us while we are making other plans.* -- Allen Saunders
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- # The FLIGHTPLAN Concept
|
||||
--
|
||||
-- This class has a great concept!
|
||||
--
|
||||
-- # Basic Setup
|
||||
--
|
||||
-- A new `FLIGHTPLAN` object can be created with the @{#FLIGHTPLAN.New}() function.
|
||||
--
|
||||
-- myFlightplan=FLIGHTPLAN:New("Plan A")
|
||||
-- myFleet:SetPortZone(ZonePort1stFleet)
|
||||
-- myFleet:Start()
|
||||
--
|
||||
-- A fleet needs a *port zone*, which is set via the @{#FLIGHTPLAN.SetPortZone}(`PortZone`) function. This is the zone where the naval assets are spawned and return to.
|
||||
--
|
||||
-- Finally, the fleet needs to be started using the @{#FLIGHTPLAN.Start}() function. If the fleet is not started, it will not process any requests.
|
||||
--
|
||||
-- @field #FLIGHTPLAN
|
||||
FLIGHTPLAN = {
|
||||
ClassName = "FLIGHTPLAN",
|
||||
verbose = 0,
|
||||
fixes = {}
|
||||
}
|
||||
|
||||
--- Type of flightplan.
|
||||
-- @type FLIGHTPLAN.Type
|
||||
-- @field #string IFRH Instrument Flying Rules High Altitude.
|
||||
-- @field #string IFRL Instrument Flying Rules Low Altitude.
|
||||
-- @field #string VFR Visual Flight Rules.
|
||||
FLIGHTPLAN.Type={
|
||||
IFRH = "IFR High",
|
||||
IFRL = "IFR Low",
|
||||
VFR = "VFR",
|
||||
}
|
||||
|
||||
|
||||
|
||||
--- FLIGHTPLAN class version.
|
||||
-- @field #string version
|
||||
FLIGHTPLAN.version="0.0.1"
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- ToDo list
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
-- TODO: How to connect SID, STAR, ENROUTE, TRANSITION, APPROACH. Typical flightplan SID --> ENROUTE --> STAR --> APPROACH
|
||||
-- TODO: Add approach.
|
||||
-- DONE: How to handle the FLIGHTGROUP:_LandAtAirBase
|
||||
-- TODO: Do we always need a holding pattern? https://www.faa.gov/air_traffic/publications/atpubs/aip_html/part2_enr_section_1.5.html#:~:text=If%20no%20holding%20pattern%20is,than%20that%20desired%20by%20ATC.
|
||||
-- DOEN: Read from MSFS file.
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- Constructor
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
--- Create a new FLIGHTPLAN instance.
|
||||
-- @param #FLIGHTPLAN self
|
||||
-- @param #string Name Name of this flight plan.
|
||||
-- @return #FLIGHTPLAN self
|
||||
function FLIGHTPLAN:New(Name)
|
||||
|
||||
-- Inherit everything from BASE class.
|
||||
self=BASE:Inherit(self, PATHLINE:New(Name)) -- #FLIGHTPLAN
|
||||
|
||||
-- Set alias.
|
||||
self.alias=tostring(Name)
|
||||
|
||||
-- Set some string id for output to DCS.log file.
|
||||
self.lid=string.format("FLIGHTPLAN %s | ", self.alias)
|
||||
|
||||
--self.pathline=PATHLINE:New(Name)
|
||||
|
||||
-- Debug info.
|
||||
self:I(self.lid..string.format("Created FLIGHTPLAN!"))
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Create a new FLIGHTPLAN instance from another FLIGHTPLAN acting as blue print.
|
||||
-- The newly created flight plan is deep copied from the given one.
|
||||
-- @param #FLIGHTPLAN self
|
||||
-- @param #FLIGHTPLAN FlightPlan Blue print of the flight plan to copy.
|
||||
-- @return #FLIGHTPLAN self
|
||||
function FLIGHTPLAN:NewFromFlightPlan(FlightPlan)
|
||||
self=UTILS.DeepCopy(FlightPlan)
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
--- Create a new FLIGHTPLAN instance from a given file.
|
||||
-- Currently, the file has to be an MSFS 2020 .pln file as, *e.g.*, exported from [Navigraph](https://navigraph.com/).
|
||||
--
|
||||
-- **Note** that the flight plan does only cover the departure, enroute and arrival portions but **not the approach** part!
|
||||
-- @param #FLIGHTPLAN self
|
||||
-- @param #string FileName Full path to file.
|
||||
-- @return #FLIGHTPLAN self
|
||||
function FLIGHTPLAN:NewFromFile(FileName)
|
||||
|
||||
if UTILS.FileExists(FileName) then
|
||||
|
||||
self=FLIGHTPLAN._ReadFileMSFS(FileName)
|
||||
|
||||
else
|
||||
error(string.format("ERROR: File not found! File name=%s", tostring(FileName)))
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- User Functions
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
--- Add navigation fix to the flight plan.
|
||||
-- @param #FLIGHTPLAN self
|
||||
-- @param Navigation.Point#NAVPOINT NavFix The nav fix.
|
||||
-- @return #FLIGHTPLAN self
|
||||
function FLIGHTPLAN:AddNavFix(NavFix)
|
||||
|
||||
table.insert(self.fixes, NavFix)
|
||||
|
||||
local point=self:AddPointFromVec3(NavFix.vector:GetVec3(true))
|
||||
|
||||
point.navpoint=NavFix
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
--- Set departure airbase.
|
||||
-- @param #FLIGHTPLAN self
|
||||
-- @param #string AirbaseName Name of the airbase or AIRBASE object.
|
||||
-- @return #FLIGHTPLAN self
|
||||
function FLIGHTPLAN:SetDepartureAirbase(AirbaseName)
|
||||
|
||||
self.departureAirbase=AIRBASE:FindByName(AirbaseName)
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Set destination airbase.
|
||||
-- @param #FLIGHTPLAN self
|
||||
-- @param #string AirbaseName Name of the airbase or AIRBASE object.
|
||||
-- @return #FLIGHTPLAN self
|
||||
function FLIGHTPLAN:SetDestinationAirbase(AirbaseName)
|
||||
|
||||
self.destinationAirbase=AIRBASE:FindByName(AirbaseName)
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
--- Set cruise altitude.
|
||||
-- @param #FLIGHTPLAN self
|
||||
-- @param #number AltMin Minimum altitude in feet MSL.
|
||||
-- @param #number AltMax Maximum altitude in feet MSL. Default is `AltMin`.
|
||||
-- @return #FLIGHTPLAN self
|
||||
function FLIGHTPLAN:SetCruiseAltitude(AltMin, AltMax)
|
||||
|
||||
self.altitudeCruiseMin=AltMin
|
||||
self.altitudeCruiseMax=AltMax or self.altitudeCruiseMin
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Set cruise speed.
|
||||
-- @param #FLIGHTPLAN self
|
||||
-- @param #number SpeedMin Minimum speed in knots.
|
||||
-- @param #number SpeedMax Maximum speed in knots. Default is `SpeedMin`.
|
||||
-- @return #FLIGHTPLAN self
|
||||
function FLIGHTPLAN:SetCruiseSpeed(SpeedMin, SpeedMax)
|
||||
|
||||
self.speedCruiseMin=SpeedMin
|
||||
self.speedCruiseMax=SpeedMax or self.speedCruiseMin
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
--- Get the name of this flight plan.
|
||||
-- @param #FLIGHTPLAN self
|
||||
-- @return #string The name.
|
||||
function FLIGHTPLAN:GetName()
|
||||
return self.alias
|
||||
end
|
||||
|
||||
|
||||
--- Get cruise altitude. This returns a random altitude between the set min/max cruise altitudes.
|
||||
-- @param #FLIGHTPLAN self
|
||||
-- @return #number Cruise altitude in feet MSL.
|
||||
function FLIGHTPLAN:GetCruiseAltitude()
|
||||
|
||||
local alt=10000
|
||||
if self.altitudeCruiseMin and self.altitudeCruiseMax then
|
||||
alt=math.random(self.altitudeCruiseMin, self.altitudeCruiseMax)
|
||||
elseif self.altitudeCruiseMin then
|
||||
alt=self.altitudeCruiseMin
|
||||
elseif self.altitudeCruiseMax then
|
||||
alt=self.altitudeCruiseMax
|
||||
end
|
||||
|
||||
return alt
|
||||
end
|
||||
|
||||
--- Get cruise speed. This returns a random speed between the set min/max cruise speeds.
|
||||
-- @param #FLIGHTPLAN self
|
||||
-- @return #number Cruise speed in knots.
|
||||
function FLIGHTPLAN:GetCruiseSpeed()
|
||||
|
||||
local speed=250
|
||||
|
||||
if self.speedCruiseMin and self.speedCruiseMax then
|
||||
speed=math.random(self.speedCruiseMin, self.speedCruiseMax)
|
||||
elseif self.speedCruiseMin then
|
||||
speed=self.speedCruiseMin
|
||||
elseif self.altitudeCruiseMax then
|
||||
speed=self.speedCruiseMax
|
||||
end
|
||||
|
||||
return speed
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- Private Functions
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
--- Read flight plan from a given MSFS 2020 .plt file.
|
||||
-- @param #string FileName Name of the file.
|
||||
-- @return #FLIGHTPLAN The flight plan.
|
||||
function FLIGHTPLAN._ReadFileMSFS(FileName)
|
||||
|
||||
local function readfile(filename)
|
||||
|
||||
local lines = {}
|
||||
|
||||
-- Open file in read binary mode.
|
||||
local file=assert(io.open(filename, "rb"), string.format("File not found! File name = %s", tostring(filename)))
|
||||
|
||||
for line in file:lines() do
|
||||
lines[#lines+1] = line
|
||||
end
|
||||
|
||||
-- Close file.
|
||||
file:close()
|
||||
|
||||
-- Return data
|
||||
return lines
|
||||
end
|
||||
|
||||
|
||||
--- This function returns an XML element, i.e. the string between <...> and </...>.
|
||||
local function getXMLelement(line)
|
||||
local element=string.match(line, ">(.+)<")
|
||||
return element
|
||||
end
|
||||
|
||||
--- This function returns Latitude and Longitude
|
||||
local function getLatLong(line)
|
||||
local latlong=getXMLelement(line)
|
||||
-- The format is "N41° 38' 20.00",E41° 33' 19.00",+000000.00" so we still need to process that.
|
||||
local lat,long=string.match(latlong, "(.+),(.+),")
|
||||
return lat,long
|
||||
end
|
||||
|
||||
-- Read data from file.
|
||||
local data=readfile(FileName)
|
||||
|
||||
local flightplan={}
|
||||
local waypoints={}
|
||||
local wp=nil
|
||||
|
||||
local gotwaypoint=false
|
||||
for i,line in pairs(data) do
|
||||
|
||||
|
||||
--print(line)
|
||||
|
||||
-- Title
|
||||
if string.find(line, "<Title>") then
|
||||
flightplan.title=getXMLelement(line)
|
||||
end
|
||||
|
||||
-- Departure ICAO
|
||||
if string.find(line, "<DepartureID>") then
|
||||
flightplan.departureICAO=getXMLelement(line)
|
||||
end
|
||||
|
||||
-- Destination ICAO
|
||||
if string.find(line, "<DestinationID>") then
|
||||
flightplan.destinationICAO=getXMLelement(line)
|
||||
end
|
||||
|
||||
-- FPType
|
||||
if string.find(line, "<FPType>") then
|
||||
flightplan.plantype=getXMLelement(line)
|
||||
end
|
||||
|
||||
-- Route type
|
||||
if string.find(line, "<RouteType>") then
|
||||
flightplan.routetype=getXMLelement(line)
|
||||
end
|
||||
|
||||
-- Cruise alt in feet
|
||||
if string.find(line, "<CruisingAlt>") then
|
||||
flightplan.altCruise=getXMLelement(line)
|
||||
end
|
||||
|
||||
-- Departure LLA
|
||||
if string.find(line, "<DepartureLLA>") then
|
||||
local lat,long=getLatLong(line)
|
||||
end
|
||||
|
||||
-- Destination LLA
|
||||
if string.find(line, "<DestinationLLA>") then
|
||||
local lat,long=getLatLong(line)
|
||||
end
|
||||
|
||||
-- Departure Name
|
||||
if string.find(line, "<DepartureName>") then
|
||||
local DepartureName=getXMLelement(line)
|
||||
end
|
||||
|
||||
-- DestinationName
|
||||
if string.find(line, "<DestinationName>") then
|
||||
local DestinationName=getXMLelement(line)
|
||||
end
|
||||
|
||||
---
|
||||
-- Waypoint stuff
|
||||
---
|
||||
|
||||
-- New waypoint starts.
|
||||
if string.find(line, "ATCWaypoint id") then
|
||||
|
||||
--Get string inside quotes " and ".
|
||||
local wpid=string.match(line, [["(.+)"]])
|
||||
|
||||
-- Create a new wp table.
|
||||
wp={}
|
||||
|
||||
-- Set waypoint name.
|
||||
wp.name=wpid
|
||||
end
|
||||
|
||||
-- Waypoint info ends.
|
||||
if string.find(line, "</ATCWaypoint>") then
|
||||
-- This is the end of the waypoint.
|
||||
|
||||
-- Add info to waypoints table.
|
||||
table.insert(waypoints, wp)
|
||||
|
||||
-- Set waypoint to nil. We create an empty table if the next wp starts.
|
||||
wp=nil
|
||||
end
|
||||
|
||||
-- Waypoint type (Airport, Intersection, NDB, VORTAC)
|
||||
if string.find(line, "<ATCWaypointType>") then
|
||||
local wptype=getXMLelement(line)
|
||||
wp.type=wptype
|
||||
end
|
||||
|
||||
-- Waypoint position.
|
||||
if string.find(line, "<WorldPosition>") then
|
||||
wp.lat, wp.long=getLatLong(line)
|
||||
end
|
||||
|
||||
-- Runway should exist for initial and final WP if it is an airport.
|
||||
if string.find(line, "RunwayNumberFP") then
|
||||
wp.runway=getXMLelement(line)
|
||||
end
|
||||
|
||||
-- Runway designator: LEFT, RIGHT, CENTER
|
||||
if string.find(line, "RunwayDesignatorFP") then
|
||||
wp.runwayDesignator=getXMLelement(line)
|
||||
end
|
||||
|
||||
-- Segment is Departure
|
||||
if string.find(line, "<DepartureFP>") then
|
||||
wp.segment="Departure"
|
||||
end
|
||||
|
||||
-- Segment is Arrival
|
||||
if string.find(line, "<ArrivalFP>") then
|
||||
wp.segment="Arrival"
|
||||
end
|
||||
|
||||
-- Segment is Enroute
|
||||
if string.find(line, "<ATCAirway>") then
|
||||
wp.segment="Enroute"
|
||||
end
|
||||
|
||||
-- Approach type: VORDME, LOCALIZER
|
||||
if string.find(line, "ApproachTypeFP") then
|
||||
flightplan.approachtype=getXMLelement(line)
|
||||
end
|
||||
|
||||
-- Approach type suffic: Z
|
||||
if string.find(line, "SuffixFP") then
|
||||
local SuffixFP=getXMLelement(line)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
for key, value in pairs(flightplan) do
|
||||
env.info(string.format("Flightplan %s=%s", key, tostring(value)))
|
||||
end
|
||||
|
||||
env.info(string.format("Number of waypoints=%d", #waypoints))
|
||||
for i,wp in pairs(waypoints) do
|
||||
env.info(string.format("Waypoint name=%s type=%s segment=%s runway=%s lat=%s long=%s", wp.name, wp.type, tostring(wp.segment), tostring(wp.runway)..tostring(wp.runwayDesignator or ""), wp.lat, wp.long))
|
||||
end
|
||||
|
||||
-- Create a new flightplan.
|
||||
local fp=FLIGHTPLAN:New(flightplan.title)
|
||||
|
||||
-- Set cruise altitude.
|
||||
fp:SetCruiseAltitude(flightplan.altCruise)
|
||||
|
||||
-- Set departure and destination airports.
|
||||
fp:SetDepartureAirbase(flightplan.departureICAO)
|
||||
fp:SetDestinationAirbase(flightplan.destinationICAO)
|
||||
|
||||
--TODO: Remove first and last waypoint if they are identical to the departure/destination airport!
|
||||
|
||||
for i,wp in pairs(waypoints) do
|
||||
|
||||
-- Create a navpoint.
|
||||
local navpoint=NAVPOINT:NewFromLLDMS(wp.name, wp.type, wp.lat, wp.long)
|
||||
|
||||
navpoint:SetAltMin(flightplan.altCruise)
|
||||
|
||||
-- Add point to flightplan.
|
||||
-- TODO: section departure, enroute, arrival.
|
||||
fp:AddNavFix(navpoint)
|
||||
end
|
||||
|
||||
|
||||
|
||||
return fp
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
@@ -0,0 +1,333 @@
|
||||
--- **NAVIGATION** - Prodedures for Departure (*e.g.* SID), Enroute, Arrival (*e.g.* STAR) and Approach.
|
||||
--
|
||||
-- **Main Features:**
|
||||
--
|
||||
-- * Stuff
|
||||
-- * More Stuff
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- ## Example Missions:
|
||||
--
|
||||
-- Demo missions can be found on [github](https://github.com/FlightControl-Master/MOOSE_MISSIONS/tree/develop/Navigation%20-%20Template).
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- ### Author: **funkyfranky**
|
||||
--
|
||||
-- ===
|
||||
-- @module Navigation.Procedure
|
||||
-- @image NAVIGATION_Procedure.png
|
||||
|
||||
|
||||
--- APPROACH class.
|
||||
-- @type APPROACH
|
||||
-- @field #string ClassName Name of the class.
|
||||
-- @field #number verbose Verbosity of output.
|
||||
-- @field #string apptype Approach type (ILS, VOR, LOC).
|
||||
-- @field Wrapper.Airbase#AIRBASE airbase Airbase of this approach.
|
||||
-- @field Wrapper.Airbase#AIRBASE.Runway runway Runway of this approach.
|
||||
-- @field Navigation.Point#NAVAID navaid Primary navigation aid.
|
||||
-- @field #number wpcounter Running number counting the waypoints to generate its UID.
|
||||
-- @list <#APPROACH.Waypoint> path Path of approach consisting of waypoints.
|
||||
-- @extends Core.Base#BASE
|
||||
|
||||
--- *A fleet of British ships at war are the best negotiators.* -- Horatio Nelson
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- # The APPROACH Concept
|
||||
--
|
||||
-- A typical approach has (up to) four segments. It starts with the initial approach segment, followed by the intermediate approach segment, followed
|
||||
-- by the final approach segment. In case something goes wrong during the final approach, the missed approach segment kicks in.
|
||||
--
|
||||
-- The initial approach segment starts at the initial approach fix (IAF). The segment can contain multiple other fixes, that need to be passed.
|
||||
-- Note, that an approach procedure can have more than one intitial approach segment and IAF.
|
||||
--
|
||||
-- The intermediate approach segment starts at the intermediate fix (IF). The intermediate approach segment blends the initial approach segment into the final approach segment.
|
||||
-- It is the segment in which aircraft configuration, speed, and positioning adjustments are made for entry into the final approach segment.
|
||||
--
|
||||
--
|
||||
-- https://en.wikipedia.org/wiki/Visual_approach
|
||||
-- https://en.wikipedia.org/wiki/Instrument_approach
|
||||
--
|
||||
-- # Basic Setup
|
||||
--
|
||||
-- A new `APPROACH` object can be created with the @{#APPROACH.New}() function.
|
||||
--
|
||||
-- myTemplate=APPROACH:New()
|
||||
-- myTemplate:SetXYZ(X, Y, Z)
|
||||
--
|
||||
-- This is how it works.
|
||||
--
|
||||
-- @field #APPROACH
|
||||
APPROACH = {
|
||||
ClassName = "APPROACH",
|
||||
verbose = 0,
|
||||
wpcounter = 0,
|
||||
}
|
||||
|
||||
--- Type of approach.
|
||||
-- @type APPROACH.Type
|
||||
-- @field #string VFR Visual Flight Rules.
|
||||
-- @field #string VOR VOR
|
||||
-- @field #string NDB NDB
|
||||
APPROACH.Type={
|
||||
VFR="VFR",
|
||||
VOR="VOR",
|
||||
ILS="ILS",
|
||||
}
|
||||
|
||||
|
||||
--- Setments of approach.
|
||||
-- @type APPROACH.Segment
|
||||
-- @field #string INITIAL Initial approach segment.
|
||||
-- @field #string INTERMEDIATE Intermediate approach segment.
|
||||
-- @field #string FINAL Final approach segment.
|
||||
-- @field #string MISSED Missed approach segment.
|
||||
APPROACH.Segment={
|
||||
INITIAL="Initial",
|
||||
INTERMEDIATE="Intermediate",
|
||||
FINAL="Final",
|
||||
MISSED="Missed",
|
||||
}
|
||||
|
||||
--- Waypoint of the approach.
|
||||
-- @type APPROACH.Waypoint
|
||||
-- @field #number uid Unique ID of the point.
|
||||
-- @field #string segment The segment this point belongs to.
|
||||
-- @field Navigation.Point#NAVFIX navfix The navigation fix that determines the coordinates of this point.
|
||||
|
||||
--- APPROACH class version.
|
||||
-- @field #string version
|
||||
APPROACH.version="0.0.1"
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- ToDo list
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
-- TODO: A lot...
|
||||
-- Initial approach segment --> Intermediate approach segment: starts at IF --> Final approach segment
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- Constructor
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
--- Create a new APPROACH class instance.
|
||||
-- @param #APPROACH self
|
||||
-- @param #string Type Type of approach (ILS, VOR, LOC).
|
||||
-- @param Wrapper.Airbase#AIRBASE Airbase The airbase or name of the airbase.
|
||||
-- @param Wrapper.Airbase#AIRBASE.Runway Runway The runway or name of the runway.
|
||||
-- @return #APPROACH self
|
||||
function APPROACH:New(Type, Airbase, Runway)
|
||||
|
||||
-- Inherit everything from BASE class.
|
||||
self=BASE:Inherit(self, BASE:New()) -- #APPROACH
|
||||
|
||||
-- Set approach type.
|
||||
-- TODO: Check if this is a valid/known approach type.
|
||||
self.apptype=Type
|
||||
|
||||
if type(Airbase)=="string" then
|
||||
self.airbase=AIRBASE:FindByName(Airbase)
|
||||
else
|
||||
self.airbase=Airbase
|
||||
end
|
||||
|
||||
if type(Runway)=="string" then
|
||||
self.runway=self.airbase:GetRunwayByName(Runway)
|
||||
else
|
||||
self.runway=Runway
|
||||
end
|
||||
|
||||
-- Debug info.
|
||||
self:I("Created new approach for airbase %s: type=%s, runway=%s", self.airbase:GetName(), self.apptype, self.runway.name)
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- User Functions
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
--- Set the primary navigation aid used in the approach.
|
||||
-- @param #APPROACH self
|
||||
-- @param Navigation.Point#NAVAID NavAid The NAVAID.
|
||||
-- @return #APPROACH self
|
||||
function APPROACH:SetNavAid(NavAid)
|
||||
|
||||
self.navaid=NavAid
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Add a waypoint to the path of the approach.
|
||||
-- @param #APPROACH self
|
||||
-- @param Navigation.Point#NAVFIX NavFix The navigation fix.
|
||||
-- @param #string Segment The approach segment this fix belongs to.
|
||||
-- @return #APPROACH.Waypoint The waypoint data table.
|
||||
function APPROACH:AddNavFix(NavFix, Segment)
|
||||
|
||||
self.wpcounter=self.wpcounter+1
|
||||
|
||||
local point={} --#APPROACH.Waypoint
|
||||
point.uid=self.wpcounter
|
||||
point.segment=Segment
|
||||
point.navfix=NavFix
|
||||
|
||||
table.insert(self.path, point)
|
||||
|
||||
return point
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- Private Functions
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
-- Add private functions here.
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
--- DEPARTURE class.
|
||||
-- @type DEPARTURE
|
||||
-- @field #string ClassName Name of the class.
|
||||
-- @field #number verbose Verbosity of output.
|
||||
-- @field #string apptype DEPARTURE type (ILS, VOR, LOC).
|
||||
-- @field Wrapper.Airbase#AIRBASE airbase Airbase of this DEPARTURE.
|
||||
-- @field Wrapper.Airbase#AIRBASE.Runway runway Runway of this DEPARTURE.
|
||||
-- @field Navigation.Point#NAVAID navaid Primary navigation aid.
|
||||
-- @field #number wpcounter Running number counting the waypoints to generate its UID.
|
||||
-- @list <#DEPARTURE.Waypoint> path Path of DEPARTURE consisting of waypoints.
|
||||
-- @extends Core.Base#BASE
|
||||
|
||||
--- *A fleet of British ships at war are the best negotiators.* -- Horatio Nelson
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- # The DEPARTURE Concept
|
||||
--
|
||||
-- Bla.
|
||||
--
|
||||
-- @field #DEPARTURE
|
||||
DEPARTURE = {
|
||||
ClassName = "DEPARTURE",
|
||||
verbose = 0,
|
||||
wpcounter = 0,
|
||||
}
|
||||
|
||||
--- Type of DEPARTURE.
|
||||
-- @type DEPARTURE.Type
|
||||
-- @field #string VOR VOR
|
||||
-- @field #string NDB NDB
|
||||
DEPARTURE.Type={
|
||||
VOR="VOR",
|
||||
ILS="ILS",
|
||||
}
|
||||
|
||||
|
||||
--- Setments of DEPARTURE.
|
||||
-- @type DEPARTURE.Segment
|
||||
-- @field #string INITIAL Initial DEPARTURE segment.
|
||||
-- @field #string INTERMEDIATE Intermediate DEPARTURE segment.
|
||||
-- @field #string FINAL Final DEPARTURE segment.
|
||||
-- @field #string MISSED Missed DEPARTURE segment.
|
||||
DEPARTURE.Segment={
|
||||
INITIAL="Initial",
|
||||
INTERMEDIATE="Intermediate",
|
||||
FINAL="Final",
|
||||
MISSED="Missed",
|
||||
}
|
||||
|
||||
--- Waypoint of the DEPARTURE.
|
||||
-- @type DEPARTURE.Waypoint
|
||||
-- @field #number uid Unique ID of the point.
|
||||
-- @field #string segment The segment this point belongs to.
|
||||
-- @field Navigation.Point#NAVFIX navfix The navigation fix that determines the coordinates of this point.
|
||||
|
||||
--- DEPARTURE class version.
|
||||
-- @field #string version
|
||||
DEPARTURE.version="0.0.1"
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- ToDo list
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
-- TODO: A lot...
|
||||
-- Initial DEPARTURE segment --> Intermediate DEPARTURE segment: starts at IF --> Final DEPARTURE segment
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- Constructor
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
--- Create a new DEPARTURE class instance.
|
||||
-- @param #DEPARTURE self
|
||||
-- @param Wrapper.Airbase#AIRBASE Airbase The airbase or name of the airbase.
|
||||
-- @param Wrapper.Airbase#AIRBASE.Runway Runway The runway or name of the runway.
|
||||
-- @param #string Type Type of DEPARTURE (ILS, VOR, LOC).
|
||||
-- @return #DEPARTURE self
|
||||
function DEPARTURE:New(Airbase, Runway)
|
||||
|
||||
-- Inherit everything from BASE class.
|
||||
self=BASE:Inherit(self, BASE:New()) -- #DEPARTURE
|
||||
|
||||
if type(Airbase)=="string" then
|
||||
self.airbase=AIRBASE:FindByName(Airbase)
|
||||
else
|
||||
self.airbase=Airbase
|
||||
end
|
||||
|
||||
if type(Runway)=="string" then
|
||||
self.runway=self.airbase:GetRunwayByName(Runway)
|
||||
else
|
||||
self.runway=Runway
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- User Functions
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
--- Set the primary navigation aid used in the DEPARTURE.
|
||||
-- @param #DEPARTURE self
|
||||
-- @param Navigation.Point#NAVAID NavAid The NAVAID.
|
||||
-- @return #DEPARTURE self
|
||||
function DEPARTURE:SetNavAid(NavAid)
|
||||
|
||||
self.navaid=NavAid
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Add a waypoint to the path of the DEPARTURE.
|
||||
-- @param #DEPARTURE self
|
||||
-- @param Navigation.Point#NAVFIX NavFix The navigation fix.
|
||||
-- @param #string Segment The DEPARTURE segment this fix belongs to.
|
||||
-- @return #DEPARTURE.Waypoint The waypoint data.
|
||||
function DEPARTURE:AddWaypoint(NavFix, Segment)
|
||||
|
||||
self.wpcounter=self.wpcounter+1
|
||||
|
||||
local point={} --#DEPARTURE.Waypoint
|
||||
point.uid=self.wpcounter
|
||||
point.segment=Segment
|
||||
point.navfix=NavFix
|
||||
|
||||
table.insert(self.path, point)
|
||||
|
||||
return point
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- Private Functions
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
-- Add DEPARTURE private functions here.
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
--- **NAVIGATION** - Template.
|
||||
--
|
||||
-- **Main Features:**
|
||||
--
|
||||
-- * Stuff
|
||||
-- * More Stuff
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- ## Example Missions:
|
||||
--
|
||||
-- Demo missions can be found on [github](https://github.com/FlightControl-Master/MOOSE_MISSIONS/tree/develop/Navigation%20-%20Template).
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- ### Author: **funkyfranky**
|
||||
--
|
||||
-- ===
|
||||
-- @module Navigation.Template
|
||||
-- @image NAVIGATION_Template.png
|
||||
|
||||
|
||||
--- TEMPLATE class.
|
||||
-- @type TEMPLATE
|
||||
-- @field #string ClassName Name of the class.
|
||||
-- @field #number verbose Verbosity of output.
|
||||
-- @extends Core.Base#BASE
|
||||
|
||||
--- *A fleet of British ships at war are the best negotiators.* -- Horatio Nelson
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- # The TEMPLATE Concept
|
||||
--
|
||||
-- The TEMPLATE class has a great concept!
|
||||
--
|
||||
-- # Basic Setup
|
||||
--
|
||||
-- A new `TEMPLATE` object can be created with the @{#TEMPLATE.New}() function.
|
||||
--
|
||||
-- myTemplate=TEMPLATE:New()
|
||||
-- myTemplate:SetXYZ(X, Y, Z)
|
||||
--
|
||||
-- This is how it works.
|
||||
--
|
||||
-- @field #TEMPLATE
|
||||
TEMPLATE = {
|
||||
ClassName = "TEMPLATE",
|
||||
verbose = 0,
|
||||
}
|
||||
|
||||
--- Type of navaid
|
||||
-- @type TEMPLATE.Type
|
||||
-- @field #string VOR VOR
|
||||
-- @field #string NDB NDB
|
||||
TEMPLATE.TYPE={
|
||||
VOR="VOR",
|
||||
NDB="NDB",
|
||||
}
|
||||
|
||||
--- TEMPLATE class version.
|
||||
-- @field #string version
|
||||
TEMPLATE.version="0.0.1"
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- ToDo list
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
-- TODO: A lot...
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- Constructor
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
--- Create a new TEMPLATE class instance.
|
||||
-- @param #TEMPLATE self
|
||||
-- @return #TEMPLATE self
|
||||
function TEMPLATE:New()
|
||||
|
||||
-- Inherit everything from SCENERY class.
|
||||
self=BASE:Inherit(self, BASE:New()) -- #TEMPLATE
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- User Functions
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
--- Set frequency.
|
||||
-- @param #TEMPLATE self
|
||||
-- @param #number Frequency Frequency in Hz.
|
||||
-- @return #TEMPLATE self
|
||||
function TEMPLATE:SetFrequency(Frequency)
|
||||
|
||||
self.frequency=Frequency
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- Private Functions
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
File diff suppressed because it is too large
Load Diff
@@ -60,6 +60,8 @@
|
||||
-- @field #boolean jettisonEmptyTanks Allow (true) or disallow (false) AI to jettison empty fuel tanks.
|
||||
-- @field #boolean jettisonWeapons Allow (true) or disallow (false) AI to jettison weapons if in danger.
|
||||
-- @field #number holdtime Time [s] flight is holding before going on final. Set to nil for indefinitely.
|
||||
-- @field #table flightplans Flight plans for this group.
|
||||
-- @field Navigation.FlightPlan#FLIGHTPLAN flightplan Currently active flight plan.
|
||||
--
|
||||
-- @extends Ops.OpsGroup#OPSGROUP
|
||||
|
||||
@@ -151,7 +153,8 @@ FLIGHTGROUP = {
|
||||
playerWarnings = {},
|
||||
prohibitAB = false,
|
||||
jettisonEmptyTanks = true,
|
||||
jettisonWeapons = true, -- that's actually a negative option like prohibitAB
|
||||
jettisonWeapons = true, -- that's actually a negative option like prohibitAB
|
||||
flightplans = {},
|
||||
}
|
||||
|
||||
|
||||
@@ -885,6 +888,17 @@ function FLIGHTGROUP:GetFlightControl()
|
||||
return self.flightcontrol
|
||||
end
|
||||
|
||||
--- Add flightplan.
|
||||
-- @param #FLIGHTGROUP self
|
||||
-- @param Navigation.FlightPlan#FLIGHTPLAN FlightPlan The flight plan.
|
||||
-- @return #FLIGHTGROUP self
|
||||
function FLIGHTGROUP:AddFlightPlan(FlightPlan)
|
||||
|
||||
self:T(self.lid..string.format("Adding flight plan %s", FlightPlan:GetName() ))
|
||||
table.insert(self.flightplans, FlightPlan)
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Set the homebase.
|
||||
-- @param #FLIGHTGROUP self
|
||||
@@ -1709,6 +1723,10 @@ function FLIGHTGROUP:Status()
|
||||
-- TODO: Not sure why I introduced this here.
|
||||
self:_CheckGroupDone()
|
||||
end
|
||||
|
||||
if not (self.cargoTransport or mission) then
|
||||
self:_CheckFlightPlans()
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -3799,6 +3817,56 @@ function FLIGHTGROUP:onafterFuelCritical(From, Event, To)
|
||||
end
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- Flightplan Functions
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
--- Check flightplans.
|
||||
-- @param #FLIGHTGROUP self
|
||||
-- @param Navigation.FlightPlan#FLIGHTPLAN FlightPlan Flight plan.
|
||||
-- @return #FLIGHTGROUP self
|
||||
function FLIGHTGROUP:_SetFlightPlan(FlightPlan)
|
||||
|
||||
self.flightplan=FlightPlan
|
||||
|
||||
for i,_fix in pairs(FlightPlan.fixes) do
|
||||
local fix=_fix --Navigation.NavFix#NAVFIX
|
||||
|
||||
--fix.coordinate
|
||||
|
||||
local speed=fix.altMin
|
||||
|
||||
local altitude=(fix.altMin or fix.altMax)~=nil and fix:GetAltitude() or FlightPlan:GetCruiseAltitude()
|
||||
|
||||
local wp=self:AddWaypoint(fix.coordinate, Speed, AfterWaypointWithID, altitude or 10000, false)
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--- Check flightplans.
|
||||
-- @param #FLIGHTGROUP self
|
||||
-- @return #FLIGHTGROUP self
|
||||
function FLIGHTGROUP:_CheckFlightPlans()
|
||||
|
||||
if self.flightplan then
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
for i,_flightplan in pairs(self.flightplans) do
|
||||
local flightplan=_flightplan --Navigation.FlightPlan#FLIGHTPLAN
|
||||
|
||||
if flightplan then
|
||||
|
||||
self:_SetFlightPlan(flightplan)
|
||||
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- Task functions
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -447,6 +447,7 @@ OPSGROUP.TaskType={
|
||||
-- @field Wrapper.Marker#MARKER marker Marker on the F10 map.
|
||||
-- @field #string formation Ground formation. Similar to action but on/off road.
|
||||
-- @field #number missionUID Mission UID (Auftragsnr) this waypoint belongs to.
|
||||
-- @field Navigation.FlightPlan#FLIGHTPLAN flightplan Flightplan this waypoint belongs to.
|
||||
|
||||
--- Cargo Carrier status.
|
||||
-- @type OPSGROUP.CarrierStatus
|
||||
@@ -575,6 +576,11 @@ function OPSGROUP:New(group)
|
||||
|
||||
-- Set DCS group and controller.
|
||||
self.dcsgroup=self:GetDCSGroup()
|
||||
|
||||
if not self.dcsgroup then
|
||||
return
|
||||
end
|
||||
|
||||
self.controller=self.dcsgroup:getController()
|
||||
|
||||
-- Category.
|
||||
@@ -11411,9 +11417,9 @@ function OPSGROUP:_SimpleTaskFunction(Function, uid)
|
||||
return DCSTask
|
||||
end
|
||||
|
||||
--- Enhance waypoint table.
|
||||
--- Enhanced waypoint table.
|
||||
-- @param #OPSGROUP self
|
||||
-- @param #OPSGROUP.Waypoint Waypoint data.
|
||||
-- @param #OPSGROUP.Waypoint waypoint Waypoint data.
|
||||
-- @return #OPSGROUP.Waypoint Modified waypoint data.
|
||||
function OPSGROUP:_CreateWaypoint(waypoint)
|
||||
|
||||
@@ -12841,7 +12847,7 @@ function OPSGROUP:_UpdatePosition()
|
||||
self.positionLast=self.position or self:GetVec3()
|
||||
self.headingLast=self.heading or self:GetHeading()
|
||||
self.orientXLast=self.orientX or self:GetOrientationX()
|
||||
self.velocityLast=self.velocity or self.group:GetVelocityMPS()
|
||||
self.velocityLast=self.velocity or self.group:GetVelocityMPS()
|
||||
|
||||
-- Current state.
|
||||
self.position=self:GetVec3()
|
||||
@@ -13687,20 +13693,24 @@ end
|
||||
-- @return Core.Point#COORDINATE The coordinate of the object.
|
||||
function OPSGROUP:_CoordinateFromObject(Object)
|
||||
|
||||
env.info("FF coordfrom object")
|
||||
if Object then
|
||||
if Object:IsInstanceOf("COORDINATE") then
|
||||
if VECTOR._IsVector(Object) then
|
||||
env.info("FF VECTOR")
|
||||
return Object:GetCoordinate()
|
||||
elseif Object:IsInstanceOf("COORDINATE") then
|
||||
return Object
|
||||
else
|
||||
if Object:IsInstanceOf("POSITIONABLE") or Object:IsInstanceOf("ZONE_BASE") then
|
||||
self:T(self.lid.."WARNING: Coordinate is not a COORDINATE but a POSITIONABLE or ZONE. Trying to get coordinate")
|
||||
self:E(self.lid.."WARNING: Coordinate is not a COORDINATE but a POSITIONABLE or ZONE. Trying to get coordinate")
|
||||
local coord=Object:GetCoordinate()
|
||||
return coord
|
||||
else
|
||||
self:T(self.lid.."ERROR: Coordinate is neither a COORDINATE nor any POSITIONABLE or ZONE!")
|
||||
self:E(self.lid.."ERROR: Coordinate is neither a COORDINATE nor any POSITIONABLE or ZONE!")
|
||||
end
|
||||
end
|
||||
else
|
||||
self:T(self.lid.."ERROR: Object passed is nil!")
|
||||
self:E(self.lid.."ERROR: Object passed is nil!")
|
||||
end
|
||||
|
||||
return nil
|
||||
|
||||
@@ -805,6 +805,33 @@ UTILS.kg2lbs = function( kg )
|
||||
return kg * 2.20462
|
||||
end
|
||||
|
||||
--- Convert latitude or longitude from degrees, minutes, seconds (DMS) to decimal degrees (DD).
|
||||
-- @param #number Degrees Degrees in grad.
|
||||
-- @param #number Minutes Minutes.
|
||||
-- @param #number Seconds Seconds.
|
||||
-- @return #number Latitude or Longitude in decimal degrees.
|
||||
UTILS.LLDMSToDD = function(Degrees, Minutes, Seconds)
|
||||
|
||||
local dd=tonumber(Degrees or 0) + tonumber(Minutes or 0)/60 + tonumber(Seconds or 0)/3600
|
||||
|
||||
return dd
|
||||
end
|
||||
|
||||
--- Convert latitude or longitude from degrees, minutes, seconds (DMS) given in text form to decimal degrees (DD).
|
||||
-- @param #string LatOrLongString Latitude or longitude passed as ttring in format `DD°MM'SS.SS"`.
|
||||
-- @return #number Latitude or Longitude in decimal degrees.
|
||||
UTILS.LLDMSstringToDD = function(LatOrLongString)
|
||||
|
||||
local hem=string.match(LatOrLongString, "(%a)")
|
||||
local Degrees=string.match(LatOrLongString, "(%d+)°")
|
||||
local Minutes=string.match(LatOrLongString, "(%d+)'")
|
||||
local Seconds=string.match(LatOrLongString, "([%d\.]+)\"")
|
||||
|
||||
local dd=UTILS.LLDMSToDD(Degrees, Minutes, Seconds)
|
||||
|
||||
return dd
|
||||
end
|
||||
|
||||
--[[acc:
|
||||
in DM: decimal point of minutes.
|
||||
In DMS: decimal point of seconds.
|
||||
@@ -1525,6 +1552,22 @@ function UTILS.Vec2Add(a, b)
|
||||
return {x=a.x+b.x, y=a.y+b.y}
|
||||
end
|
||||
|
||||
--- Multiply 2D vector by a scalar value.
|
||||
-- @param DCS#Vec2 a Vector in 2D with x, y components.
|
||||
-- @param #number c Scalar value.
|
||||
-- @return DCS#Vec2 Vector
|
||||
function UTILS.Vec2Mult(a, c)
|
||||
return {x=c*a.x, y=c*a.y}
|
||||
end
|
||||
|
||||
--- Multiply 3D vector by a scalar value.
|
||||
-- @param DCS#Vec3 a Vector in 3D with x, y, z components.
|
||||
-- @param #number c Scalar value.
|
||||
-- @return DCS#Vec3 Vector
|
||||
function UTILS.VecMult(a, c)
|
||||
return {x=c*a.x, y=c*a.y, z=c*a.z}
|
||||
end
|
||||
|
||||
--- Calculate the angle between two 3D vectors.
|
||||
-- @param DCS#Vec3 a Vector in 3D with x, y, z components.
|
||||
-- @param DCS#Vec3 b Vector in 3D with x, y, z components.
|
||||
@@ -1545,6 +1588,24 @@ function UTILS.VecAngle(a, b)
|
||||
return math.deg(alpha)
|
||||
end
|
||||
|
||||
--- Calculate the angle between two 3D vectors.
|
||||
-- @param DCS#Vec3 a Vector in 3D with x, y, z components.
|
||||
-- @param DCS#Vec3 b Vector in 3D with x, y, z components.
|
||||
-- @return #number Angle alpha between and b in degrees.
|
||||
function UTILS.VecAngleSigned(a, b)
|
||||
|
||||
local a=UTILS.VecSubstract(s1.p2.vec3, s1.p1.vec3)
|
||||
|
||||
local b=UTILS.VecSubstract(s2.p2.vec3, s2.p1.vec3)
|
||||
|
||||
local h1=UTILS.VecHdg(a)
|
||||
local h2=UTILS.VecHdg(b)
|
||||
|
||||
local angle=h1-h2 --UTILS.VecAngle(a, b)
|
||||
|
||||
|
||||
end
|
||||
|
||||
--- Calculate "heading" of a 3D vector in the X-Z plane.
|
||||
-- @param DCS#Vec3 a Vector in 3D with x, y, z components.
|
||||
-- @return #number Heading in degrees in [0,360).
|
||||
@@ -1567,6 +1628,20 @@ function UTILS.Vec2Hdg(a)
|
||||
return h
|
||||
end
|
||||
|
||||
--- Calculate the difference between two "heading", i.e. angles in [0,360) deg.
|
||||
-- @param DCS#Vec3 a Vector a.
|
||||
-- @param DCS#Vec3 a Vector b.
|
||||
-- @return #number Heading difference in degrees.
|
||||
function UTILS.VecHdgDiff(a, b)
|
||||
|
||||
local ha=math.deg(math.atan2(a.z, a.x))
|
||||
local hb=math.deg(math.atan2(b.z, b.x))
|
||||
|
||||
local angle=ha-hb
|
||||
|
||||
return angle
|
||||
end
|
||||
|
||||
--- Calculate the difference between two "heading", i.e. angles in [0,360) deg.
|
||||
-- @param #number h1 Heading one.
|
||||
-- @param #number h2 Heading two.
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
-- @field #AIRBASE.Runway runwayLanding Runway used for landing.
|
||||
-- @field #AIRBASE.Runway runwayTakeoff Runway used for takeoff.
|
||||
-- @field Wrapper.Storage#STORAGE storage The DCS warehouse storage.
|
||||
-- @field #table taxiways Taxiways stored as PATHLINEs.
|
||||
-- @extends Wrapper.Positionable#POSITIONABLE
|
||||
|
||||
--- Wrapper class to handle the DCS Airbase objects:
|
||||
@@ -78,6 +79,7 @@ AIRBASE = {
|
||||
[Airbase.Category.SHIP] = "Ship",
|
||||
},
|
||||
activerwyno = nil,
|
||||
taxiways = {},
|
||||
}
|
||||
|
||||
--- Airbases of the Caucasus map
|
||||
@@ -1549,6 +1551,32 @@ AIRBASE.SpotStatus = {
|
||||
RESERVED="Reserved",
|
||||
}
|
||||
|
||||
--- ICAO Codes.
|
||||
-- @type AIRBASE.ICAO
|
||||
AIRBASE.ICAO = {
|
||||
UGTB=AIRBASE.Caucasus.Tbilisi_Lochini,
|
||||
UGKO=AIRBASE.Caucasus.Kutaisi,
|
||||
UG5X=AIRBASE.Caucasus.Kobuleti,
|
||||
UG24=AIRBASE.Caucasus.Soganlug,
|
||||
UG27=AIRBASE.Caucasus.Vaziani,
|
||||
UGSS=AIRBASE.Caucasus.Sukhumi_Babushara,
|
||||
UG23=AIRBASE.Caucasus.Gudauta,
|
||||
URSS=AIRBASE.Caucasus.Sochi_Adler,
|
||||
URMO=AIRBASE.Caucasus.Beslan,
|
||||
URMN=AIRBASE.Caucasus.Nalchik,
|
||||
XRMF=AIRBASE.Caucasus.Mozdok,
|
||||
URMM=AIRBASE.Caucasus.Mineralnye_Vody,
|
||||
URKH=AIRBASE.Caucasus.Maykop_Khanskaya,
|
||||
URKK=AIRBASE.Caucasus.Krasnodar_Pashkovsky,
|
||||
URKL=AIRBASE.Caucasus.Krasnodar_Center,
|
||||
URKG=AIRBASE.Caucasus.Gelendzhik,
|
||||
URKN=AIRBASE.Caucasus.Novorossiysk,
|
||||
URKW=AIRBASE.Caucasus.Krymsk,
|
||||
URKA=AIRBASE.Caucasus.Anapa_Vityazevo,
|
||||
}
|
||||
|
||||
|
||||
|
||||
--- Runway data.
|
||||
-- @type AIRBASE.Runway
|
||||
-- @field #string name Runway name.
|
||||
@@ -1737,14 +1765,47 @@ end
|
||||
|
||||
--- Find a AIRBASE in the _DATABASE using the name of an existing DCS Airbase.
|
||||
-- @param #AIRBASE self
|
||||
-- @param #string AirbaseName The Airbase Name.
|
||||
-- @param #string AirbaseName The name of the airbase. Can also be the ICAO code or the airbase ID.
|
||||
-- @return #AIRBASE self
|
||||
function AIRBASE:FindByName( AirbaseName )
|
||||
|
||||
local AirbaseFound = _DATABASE:FindAirbase( AirbaseName )
|
||||
|
||||
if not AirbaseFound then
|
||||
AirbaseFound=self:FindByICAO(AirbaseName)
|
||||
end
|
||||
|
||||
if not AirbaseFound then
|
||||
AirbaseFound=self:FindByID(AirbaseName)
|
||||
end
|
||||
|
||||
return AirbaseFound
|
||||
end
|
||||
|
||||
|
||||
--- Find an AIRBASE in the _DATABASE using the [International Civil Aviation Organization](https://en.wikipedia.org/wiki/ICAO_airport_code) (ICAO) airport code.
|
||||
-- The code consists of four characters. Typically, the first one or two letters of the ICAO code indicate the country and the remaining letters identify the airport.
|
||||
--
|
||||
-- **NOTE** that the ICAO code cannot be retrieved via the DCS API and has to be hard coded into the MOOSE code. Therefore, it is a rare occasion where
|
||||
-- @param #AIRBASE self
|
||||
-- @param #string AirbaseICAO The Airbase ICAO code.
|
||||
-- @return #AIRBASE self
|
||||
function AIRBASE:FindByICAO( AirbaseICAO )
|
||||
|
||||
if AirbaseICAO then
|
||||
|
||||
local name=AIRBASE.ICAO[AirbaseICAO]
|
||||
|
||||
env.info(string.format("FF ICAO=%s, Name=%s", tostring(AirbaseICAO), tostring(name)))
|
||||
|
||||
local Airbase=self:FindByName(name)
|
||||
return Airbase
|
||||
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
--- Find a AIRBASE in the _DATABASE by its ID.
|
||||
-- @param #AIRBASE self
|
||||
-- @param #number id Airbase ID.
|
||||
@@ -2057,6 +2118,129 @@ function AIRBASE:IsShip()
|
||||
return self.isShip
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- Taxi ways
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
--- Add a taxiway from a given PATHLINE.
|
||||
-- @param #AIRBASE self
|
||||
-- @param Core.Pathline#PATHLINE TaxiPathline Pathline of the taxi way or name of pathline as #string.
|
||||
-- @param #string Name Name of the taxi way, *e.g.* "Alpha", or "Alpha-Kilo". Default is name of pathline.
|
||||
-- @return #AIRBASE self
|
||||
function AIRBASE:AddTaxiway(TaxiPathline, Name)
|
||||
|
||||
-- If passed as string, get pathline.
|
||||
if type(TaxiPathline)=="string" then
|
||||
TaxiPathline=PATHLINE:FindByName(TaxiPathline)
|
||||
end
|
||||
|
||||
-- Set name.
|
||||
Name=Name or TaxiPathline:GetName()
|
||||
|
||||
-- Create a deep copy.
|
||||
local taxiway=UTILS.DeepCopy(TaxiPathline) --Core.Pathline#PATHLINE
|
||||
|
||||
-- Set name.
|
||||
taxiway.name=Name
|
||||
|
||||
-- Add to taxiways.
|
||||
self.taxiways[Name]=taxiway
|
||||
|
||||
|
||||
--self:I(self.taxiways)
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
--- Find the shortest path using taxiways to get from given coodinates A to B on the airbase.
|
||||
-- Note that the taxi ways have to be manually added with the `AIRBASE:AddTaxiway()` function.
|
||||
-- @param #AIRBASE self
|
||||
-- @param Core.Point#COORDINATE StartCoord Start coordinate.
|
||||
-- @param Core.Point#COORDINATE EndCoord End coordinate.
|
||||
-- @return Core.Pathline#PATHLINE Shortest path on taxiways from `StartCoord` to `EndCoord`.
|
||||
-- @return #table Table of used taxi way pathlines.
|
||||
function AIRBASE:FindTaxiwaysFromAtoB(StartCoord, EndCoord)
|
||||
|
||||
-- Create A* pathfinding.
|
||||
local astar=ASTAR:New()
|
||||
|
||||
-- Add pathlines of taxiways of airport.
|
||||
for _,_taxiway in pairs(self.taxiways) do
|
||||
local taxiway=_taxiway --Core.Pathline#PATHLINE
|
||||
|
||||
astar:AddNodeFromPathlineName(taxiway)
|
||||
end
|
||||
|
||||
-- Set cost function.
|
||||
astar:SetCostDist2D()
|
||||
|
||||
-- Set valid neighbours to be on the same pathline or at most 10 meters between nodes to jump from one pathline/taxiway to another.
|
||||
astar:SetValidNeighbourPathline(10)
|
||||
|
||||
-- Set start and end coordinates.
|
||||
astar:SetStartCoordinate(StartCoord)
|
||||
astar:SetEndCoordinate(EndCoord)
|
||||
|
||||
-- Get pathline.
|
||||
local taxipath, nodes=astar:GetPathline()
|
||||
|
||||
local taxiways=astar:GetPathlinesFromNodes(nodes)
|
||||
|
||||
return taxipath, taxiways
|
||||
end
|
||||
|
||||
--- Get closest taxiway from a given reference coordinate.
|
||||
-- @param #AIRBASE self
|
||||
-- @param Core.Point#COORDINATE Coord Reference coordinate.
|
||||
-- @return Core.Pathline#PATHLINE Taxiway.
|
||||
-- @return #number Distance to taxiway in meters.
|
||||
-- @return Core.Point#COORDINATE Coordinate on taxiway closest to reference coordinate.
|
||||
-- @return Core.Pathline#PATHLINE.Segment Segment of the taxiway closest to the reference coordinate.
|
||||
function AIRBASE:GetClosestTaxiway(Coord)
|
||||
|
||||
local taxipath=nil
|
||||
local distmin=math.huge
|
||||
local coordmin=nil
|
||||
local segmin=nil
|
||||
|
||||
for name,_pathline in pairs(self.taxiways) do
|
||||
local pathline=_pathline --Core.Pathline#PATHLINE
|
||||
|
||||
local coord, dist, segment=pathline:GetClosestPoint3D(Coord)
|
||||
|
||||
if dist<distmin then
|
||||
taxipath=pathline
|
||||
coordmin=coord
|
||||
distmin=dist
|
||||
segmin=segment
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
return taxipath, distmin, coordmin, segmin
|
||||
end
|
||||
|
||||
|
||||
--- Find the shortest path using taxiways to get from given parking spot to the starting point of a runway.
|
||||
-- Note that the taxi ways have to be manually added with the `AIRBASE:AddTaxiway()` function.
|
||||
-- @param #AIRBASE self
|
||||
-- @param #AIRBASE.ParkingSpot ParkingSpot Parking spot.
|
||||
-- @param #AIRBASE.Runway Runway The runway. If none is given, we take the active runway for takeoff.
|
||||
-- @return Core.Pathline#PATHLINE Shortest path on taxiways from `StartCoord` to `EndCoord`.
|
||||
-- @return #table Table of used taxi way pathlines.
|
||||
function AIRBASE:FindTaxiwaysParkingToRunway(ParkingSpot, Runway)
|
||||
|
||||
Runway=Runway or self:GetActiveRunwayTakeoff()
|
||||
|
||||
local StartCoord=ParkingSpot.Coordinate
|
||||
local EndCoord=Runway.position
|
||||
|
||||
local taxipath, taxiways=self:FindTaxiwaysFromAtoB(StartCoord,EndCoord)
|
||||
|
||||
return taxipath, taxiways
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- Parking
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user