mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2026-08-17 03:11:28 +00:00
Intermediate
This commit is contained in:
@@ -730,11 +730,14 @@ do -- FSM
|
|||||||
if not self._EventSchedules[EventName] then
|
if not self._EventSchedules[EventName] then
|
||||||
CallID = self.CallScheduler:Schedule( self, self._handler, { EventName, ... }, DelaySeconds or 1, nil, nil, nil, 4, true )
|
CallID = self.CallScheduler:Schedule( self, self._handler, { EventName, ... }, DelaySeconds or 1, nil, nil, nil, 4, true )
|
||||||
self._EventSchedules[EventName] = CallID
|
self._EventSchedules[EventName] = CallID
|
||||||
|
self:T2(string.format("NEGATIVE Event %s delayed by %.1f sec SCHEDULED with CallID=%s", EventName, DelaySeconds, tostring(CallID)))
|
||||||
else
|
else
|
||||||
|
self:T2(string.format("NEGATIVE Event %s delayed by %.1f sec CANCELLED as we already have such an event in the queue.", EventName, DelaySeconds))
|
||||||
-- reschedule
|
-- reschedule
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
CallID = self.CallScheduler:Schedule( self, self._handler, { EventName, ... }, DelaySeconds or 1, nil, nil, nil, 4, true )
|
CallID = self.CallScheduler:Schedule( self, self._handler, { EventName, ... }, DelaySeconds or 1, nil, nil, nil, 4, true )
|
||||||
|
self:T2(string.format("Event %s delayed by %.1f sec SCHEDULED with CallID=%s", EventName, DelaySeconds, tostring(CallID)))
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
error( "FSM: An asynchronous event trigger requires a DelaySeconds parameter!!! This can be positive or negative! Sorry, but will not process this." )
|
error( "FSM: An asynchronous event trigger requires a DelaySeconds parameter!!! This can be positive or negative! Sorry, but will not process this." )
|
||||||
|
|||||||
@@ -428,6 +428,10 @@ do -- Types
|
|||||||
-- @type TaskArray
|
-- @type TaskArray
|
||||||
-- @list <#Task>
|
-- @list <#Task>
|
||||||
|
|
||||||
|
---
|
||||||
|
--@type WaypointAir
|
||||||
|
--@field #boolean lateActivated
|
||||||
|
--@field #boolean uncontrolled
|
||||||
|
|
||||||
end --
|
end --
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -27,6 +27,7 @@
|
|||||||
-- @field #table waypoints Table of waypoints.
|
-- @field #table waypoints Table of waypoints.
|
||||||
-- @field #table waypoints0 Table of initial waypoints.
|
-- @field #table waypoints0 Table of initial waypoints.
|
||||||
-- @field #table coordinates Table of waypoint coordinates.
|
-- @field #table coordinates Table of waypoint coordinates.
|
||||||
|
-- @field #table currentwp Current waypoint.
|
||||||
-- @field #table taskqueue Queue of tasks.
|
-- @field #table taskqueue Queue of tasks.
|
||||||
-- @field #number taskcounter Running number of task ids.
|
-- @field #number taskcounter Running number of task ids.
|
||||||
-- @field #number taskcurrent ID of current task. If 0, there is no current task assigned.
|
-- @field #number taskcurrent ID of current task. If 0, there is no current task assigned.
|
||||||
@@ -145,6 +146,7 @@ FLIGHTGROUP = {
|
|||||||
waypoints = nil,
|
waypoints = nil,
|
||||||
waypoints0 = nil,
|
waypoints0 = nil,
|
||||||
coordinates = {},
|
coordinates = {},
|
||||||
|
currentwp = -100,
|
||||||
elements = {},
|
elements = {},
|
||||||
taskqueue = {},
|
taskqueue = {},
|
||||||
taskcounter = nil,
|
taskcounter = nil,
|
||||||
@@ -480,7 +482,6 @@ function FLIGHTGROUP:New(groupname)
|
|||||||
_DATABASE:AddFlightGroup(self)
|
_DATABASE:AddFlightGroup(self)
|
||||||
|
|
||||||
-- Autostart.
|
-- Autostart.
|
||||||
--self:__Start(0.1)
|
|
||||||
self:Start()
|
self:Start()
|
||||||
|
|
||||||
return self
|
return self
|
||||||
@@ -559,7 +560,7 @@ function FLIGHTGROUP:AddTaskWaypoint(task, waypointindex, description, prio, dur
|
|||||||
newtask.id=self.taskcounter
|
newtask.id=self.taskcounter
|
||||||
newtask.duration=duration
|
newtask.duration=duration
|
||||||
newtask.time=0
|
newtask.time=0
|
||||||
newtask.waypoint=waypointindex or self.currentwp+1
|
newtask.waypoint=waypointindex or (self.currentwp and self.currentwp+1 or 2)
|
||||||
newtask.type=FLIGHTGROUP.TaskType.WAYPOINT
|
newtask.type=FLIGHTGROUP.TaskType.WAYPOINT
|
||||||
|
|
||||||
self:T2({newtask=newtask})
|
self:T2({newtask=newtask})
|
||||||
@@ -567,6 +568,9 @@ function FLIGHTGROUP:AddTaskWaypoint(task, waypointindex, description, prio, dur
|
|||||||
-- Add to table.
|
-- Add to table.
|
||||||
table.insert(self.taskqueue, newtask)
|
table.insert(self.taskqueue, newtask)
|
||||||
|
|
||||||
|
-- Info.
|
||||||
|
self:I(self.lid..string.format("Adding WAYPOINT task %s at WP %d", newtask.description, newtask.waypoint))
|
||||||
|
|
||||||
-- Update route.
|
-- Update route.
|
||||||
self:__UpdateRoute(-1)
|
self:__UpdateRoute(-1)
|
||||||
|
|
||||||
@@ -909,6 +913,11 @@ function FLIGHTGROUP:onafterStart(From, Event, To)
|
|||||||
-- Debug info.
|
-- Debug info.
|
||||||
self:I(self.lid..string.format("FF Found alive group %s at start with %d units", group:GetName(), #units))
|
self:I(self.lid..string.format("FF Found alive group %s at start with %d units", group:GetName(), #units))
|
||||||
|
|
||||||
|
-- Init waypoints.
|
||||||
|
if not self.waypoints then
|
||||||
|
self:InitWaypoints()
|
||||||
|
end
|
||||||
|
|
||||||
-- Add elemets.
|
-- Add elemets.
|
||||||
for _,unit in pairs(units) do
|
for _,unit in pairs(units) do
|
||||||
local element=self:AddElementByName(unit:GetName())
|
local element=self:AddElementByName(unit:GetName())
|
||||||
@@ -937,7 +946,7 @@ function FLIGHTGROUP:onafterStart(From, Event, To)
|
|||||||
|
|
||||||
-- Start the status monitoring.
|
-- Start the status monitoring.
|
||||||
self:__CheckZone(-1)
|
self:__CheckZone(-1)
|
||||||
self:__FlightStatus(-1)
|
--self:__FlightStatus(-1)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- On after Start event. Starts the FLIGHTGROUP FSM and event handlers.
|
--- On after Start event. Starts the FLIGHTGROUP FSM and event handlers.
|
||||||
@@ -1084,7 +1093,7 @@ function FLIGHTGROUP:onafterFlightStatus(From, Event, To)
|
|||||||
|
|
||||||
|
|
||||||
-- Next check in ~30 seconds.
|
-- Next check in ~30 seconds.
|
||||||
self:__FlightStatus(-30)
|
--self:__FlightStatus(-30)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- On after "QueueUpdate" event.
|
--- On after "QueueUpdate" event.
|
||||||
@@ -1792,20 +1801,44 @@ end
|
|||||||
-- @param #number n Waypoint number.
|
-- @param #number n Waypoint number.
|
||||||
function FLIGHTGROUP:onbeforeUpdateRoute(From, Event, To, n)
|
function FLIGHTGROUP:onbeforeUpdateRoute(From, Event, To, n)
|
||||||
|
|
||||||
|
-- Is transition allowed? We assume yes until proven otherwise.
|
||||||
|
local allowed=true
|
||||||
|
|
||||||
if self.group and self.group:IsAlive() and self:IsAirborne() then
|
if self.group and self.group:IsAlive() and self:IsAirborne() then
|
||||||
-- Alive & Airborne ==> Update route possible.
|
-- Alive & Airborne ==> Update route possible.
|
||||||
self:T2(self.lid.."Update route allowed")
|
self:T2(self.lid.."Update route possible. Group is ALIVE and AIRBORNE")
|
||||||
return true
|
|
||||||
elseif self:IsDead() then
|
elseif self:IsDead() then
|
||||||
-- Group is dead! No more updates.
|
-- Group is dead! No more updates.
|
||||||
return false
|
self:T3(self.lid.."FF update route denied. Group is DEAD!")
|
||||||
|
allowed=false
|
||||||
else
|
else
|
||||||
-- Not airborne yet. Try again in 1 sec.
|
-- Not airborne yet. Try again in 1 sec.
|
||||||
self:T3(self.lid.."FF update route denied ==> checking back in 1 sec")
|
self:T3(self.lid.."FF update route denied ==> checking back in 1 sec")
|
||||||
self:__UpdateRoute(-1, n)
|
self:__UpdateRoute(-1, n)
|
||||||
return false
|
allowed=false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if n and n<1 then
|
||||||
|
self:T3(self.lid.."FF update route denied because n<1")
|
||||||
|
self:__UpdateRoute(-1, n)
|
||||||
|
allowed=false
|
||||||
|
end
|
||||||
|
|
||||||
|
if not self.currentwp then
|
||||||
|
self:T3(self.lid.."FF update route denied because self.currentwp=nil")
|
||||||
|
self:__UpdateRoute(-1, n)
|
||||||
|
allowed=false
|
||||||
|
end
|
||||||
|
|
||||||
|
local N=n or self.currentwp+1
|
||||||
|
if not N or N<1 then
|
||||||
|
self:T3(self.lid.."FF update route denied because N=nil or N<1")
|
||||||
|
self:__UpdateRoute(-1, n)
|
||||||
|
allowed=false
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
return allowed
|
||||||
end
|
end
|
||||||
|
|
||||||
--- On after "UpdateRoute" event.
|
--- On after "UpdateRoute" event.
|
||||||
@@ -1816,6 +1849,8 @@ end
|
|||||||
-- @param #number n Waypoint number.
|
-- @param #number n Waypoint number.
|
||||||
function FLIGHTGROUP:onafterUpdateRoute(From, Event, To, n)
|
function FLIGHTGROUP:onafterUpdateRoute(From, Event, To, n)
|
||||||
|
|
||||||
|
env.info(string.format("FF Update route n=%s current wp=%s", tostring(n), tostring(self.currentwp)))
|
||||||
|
|
||||||
-- TODO: what happens if currentwp=#waypoints
|
-- TODO: what happens if currentwp=#waypoints
|
||||||
n=n or self.currentwp+1
|
n=n or self.currentwp+1
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,10 @@
|
|||||||
-- @field #string ClassName Name of the class.
|
-- @field #string ClassName Name of the class.
|
||||||
-- @field #boolean Debug Debug mode. Messages to all about status.
|
-- @field #boolean Debug Debug mode. Messages to all about status.
|
||||||
-- @field #string lid Class id string for output to DCS log file.
|
-- @field #string lid Class id string for output to DCS log file.
|
||||||
|
-- @field #table Qmissions Mission queue.
|
||||||
|
-- @field #table Qclients Client queue.
|
||||||
|
-- @field #TANKERGROUP.Mission currentmission Currently assigned mission.
|
||||||
|
-- @field #number missioncounter Counter of total missions.
|
||||||
-- @extends Ops.FlightGroup#FLIGHTGROUP
|
-- @extends Ops.FlightGroup#FLIGHTGROUP
|
||||||
|
|
||||||
--- *To invent an airplane is nothing. To build one is something. To fly is everything.* -- Otto Lilienthal
|
--- *To invent an airplane is nothing. To build one is something. To fly is everything.* -- Otto Lilienthal
|
||||||
@@ -46,7 +50,6 @@ TANKERGROUP = {
|
|||||||
ClassName = "TANKERGROUP",
|
ClassName = "TANKERGROUP",
|
||||||
Debug = false,
|
Debug = false,
|
||||||
lid = nil,
|
lid = nil,
|
||||||
tankerzones = nil,
|
|
||||||
Qmissions = {},
|
Qmissions = {},
|
||||||
Qclients = {},
|
Qclients = {},
|
||||||
currentmission = nil,
|
currentmission = nil,
|
||||||
@@ -98,7 +101,6 @@ function TANKERGROUP:New(groupname)
|
|||||||
|
|
||||||
-- Add FSM transitions.
|
-- Add FSM transitions.
|
||||||
-- From State --> Event --> To State
|
-- From State --> Event --> To State
|
||||||
self:AddTransition("*", "TankerStatus", "*") -- Tanker is on station and ready to refuel.
|
|
||||||
self:AddTransition("*", "OnStation", "Ready2Refuel") -- Tanker is on station and ready to refuel.
|
self:AddTransition("*", "OnStation", "Ready2Refuel") -- Tanker is on station and ready to refuel.
|
||||||
self:AddTransition("*", "MissionStart", "*") -- Tanker is on station and ready to refuel.
|
self:AddTransition("*", "MissionStart", "*") -- Tanker is on station and ready to refuel.
|
||||||
|
|
||||||
@@ -106,13 +108,18 @@ function TANKERGROUP:New(groupname)
|
|||||||
|
|
||||||
self.lid=string.format("TANKERGROUP %s | ", groupname)
|
self.lid=string.format("TANKERGROUP %s | ", groupname)
|
||||||
|
|
||||||
|
--[[
|
||||||
BASE:TraceOn()
|
BASE:TraceOn()
|
||||||
BASE:TraceLevel(3)
|
BASE:TraceLevel(3)
|
||||||
BASE:TraceClass(self.ClassName)
|
BASE:TraceClass(self.ClassName)
|
||||||
|
]]
|
||||||
|
|
||||||
env.info("FF NEW Tanker!")
|
env.info("FF NEW Tanker!")
|
||||||
|
|
||||||
self:TankerStatus()
|
|
||||||
|
-- Call status update.
|
||||||
|
-- TODO: WARNING, if the call is delayed, it is NOT executed!
|
||||||
|
self:FlightStatus()
|
||||||
|
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
@@ -123,13 +130,18 @@ end
|
|||||||
|
|
||||||
--- Add mission for tanker.
|
--- Add mission for tanker.
|
||||||
-- @param #TANKERGROUP self
|
-- @param #TANKERGROUP self
|
||||||
-- @return #TANKERGROUP self
|
-- @param Core.Zone#ZONE Zone The mission zone. Orbit is picked at a random location.
|
||||||
|
-- @param #number Altitude Orbit altitude in feet.
|
||||||
|
-- @param #number Distance Length of the race-track pattern leg in NM.
|
||||||
|
-- @param #number Speed Orbit speed in knots.
|
||||||
|
-- @return #TANKERGROUP.Mission The mission table.
|
||||||
function TANKERGROUP:AddMission(Zone, Altitude, Distance, Speed)
|
function TANKERGROUP:AddMission(Zone, Altitude, Distance, Speed)
|
||||||
|
|
||||||
|
-- Increase mission counter.
|
||||||
self.missioncounter=self.missioncounter+1
|
self.missioncounter=self.missioncounter+1
|
||||||
|
|
||||||
|
-- Make mission table.
|
||||||
local mission={} --#TANKERGROUP.Mission
|
local mission={} --#TANKERGROUP.Mission
|
||||||
|
|
||||||
mission.zone=Zone
|
mission.zone=Zone
|
||||||
mission.mid=self.missioncounter
|
mission.mid=self.missioncounter
|
||||||
mission.altitude=UTILS.FeetToMeters(Altitude or 10000)
|
mission.altitude=UTILS.FeetToMeters(Altitude or 10000)
|
||||||
@@ -139,7 +151,12 @@ function TANKERGROUP:AddMission(Zone, Altitude, Distance, Speed)
|
|||||||
mission.heading=270
|
mission.heading=270
|
||||||
mission.tid=nil
|
mission.tid=nil
|
||||||
|
|
||||||
|
-- Add mission to queue.
|
||||||
table.insert(self.Qmissions, mission)
|
table.insert(self.Qmissions, mission)
|
||||||
|
|
||||||
|
self:I(self.lid..string.format("Added mission"))
|
||||||
|
|
||||||
|
return mission
|
||||||
end
|
end
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
@@ -151,32 +168,37 @@ end
|
|||||||
-- @param #string From From state.
|
-- @param #string From From state.
|
||||||
-- @param #string Event Event.
|
-- @param #string Event Event.
|
||||||
-- @param #string To To state.
|
-- @param #string To To state.
|
||||||
function TANKERGROUP:onafterTankerStatus(From, Event, To)
|
function TANKERGROUP:onafterFlightStatus(From, Event, To)
|
||||||
|
|
||||||
|
-- First call flight status.
|
||||||
|
self:GetParent(self).onafterFlightStatus(self, From, Event, To)
|
||||||
|
|
||||||
env.info("FF Tanker status!")
|
env.info("FF Tanker status!")
|
||||||
|
env.info(string.format("FF current wp=%s", tostring(self.currentwp)))
|
||||||
|
|
||||||
-- FSM state.
|
-- FSM state.
|
||||||
local fsmstate=self:GetState()
|
local fsmstate=self:GetState()
|
||||||
|
|
||||||
-- First check if group is alive?
|
-- First check if group is alive?
|
||||||
if self.group and self.group:IsAlive()==true then
|
if self.group and self.group:IsAlive()==true and not self.currentmission then
|
||||||
|
|
||||||
local mission=self:_GetNextMission()
|
local mission=self:_GetNextMission()
|
||||||
|
|
||||||
if mission then
|
if mission then
|
||||||
|
|
||||||
|
env.info("FF starting mission")
|
||||||
self:MissionStart(mission)
|
self:MissionStart(mission)
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Current mission name.
|
||||||
local mymission=self.currentmission and self.currentmission.name or "N/A"
|
local mymission=self.currentmission and self.currentmission.name or "N/A"
|
||||||
|
|
||||||
local text=string.format("Tanker Status %s: Mission=%s (%d)", fsmstate, mymission, #self.Qmissions)
|
local text=string.format("Tanker Status %s: Mission=%s (%d)", fsmstate, mymission, #self.Qmissions)
|
||||||
self:I(self.lid..text)
|
self:I(self.lid..text)
|
||||||
|
|
||||||
self:__TankerStatus(30)
|
self:__FlightStatus(-30)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- On after "MissionStart" event.
|
--- On after "MissionStart" event.
|
||||||
@@ -204,7 +226,10 @@ function TANKERGROUP:onafterMissionStart(From, Event, To, Mission)
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
self:RouteTo(Mission)
|
self.currentmission=Mission
|
||||||
|
|
||||||
|
--
|
||||||
|
self:RouteToMission(Mission)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -228,17 +253,17 @@ function TANKERGROUP:_GetNextMission()
|
|||||||
return mission
|
return mission
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Get next mission.
|
--- Route group to mission. Also sets the
|
||||||
-- @param #TANKERGROUP self
|
-- @param #TANKERGROUP self
|
||||||
-- @param #TANKERGROUP.Mission mission
|
-- @param #TANKERGROUP.Mission mission The mission table.
|
||||||
-- @return #TANKERGROUP.Mission Next mission or *nil*.
|
-- @return #TANKERGROUP.Mission Next mission or *nil*.
|
||||||
function TANKERGROUP:RouteTo(mission)
|
function TANKERGROUP:RouteToMission(mission)
|
||||||
|
|
||||||
local Coordinate=mission.zone:GetRandomCoordinate():SetAltitude(mission.altitude, true)
|
local Coordinate=mission.zone:GetRandomCoordinate():SetAltitude(mission.altitude, true)
|
||||||
|
|
||||||
local CoordRaceTrack=Coordinate:Translate(mission.distance, mission.heading, true)
|
local CoordRaceTrack=Coordinate:Translate(mission.distance, mission.heading, true)
|
||||||
|
|
||||||
self:AddWaypointAir(Coordinate, wpnumber, self.speedmax*0.8)
|
self:AddWaypointAir(Coordinate, nil, self.speedmax*0.8)
|
||||||
|
|
||||||
local taskorbit=self.group:TaskOrbit(Coordinate, mission.altitude, mission.speed, CoordRaceTrack)
|
local taskorbit=self.group:TaskOrbit(Coordinate, mission.altitude, mission.speed, CoordRaceTrack)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user