Intermediate

This commit is contained in:
Frank
2020-01-31 23:34:07 +01:00
parent 5fda8c1c1b
commit 30c21086ba
5 changed files with 91 additions and 1548 deletions
+4 -1
View File
@@ -727,14 +727,17 @@ do -- FSM
if DelaySeconds ~= nil then
if DelaySeconds < 0 then -- Only call the event ONCE!
DelaySeconds = math.abs( DelaySeconds )
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 )
self._EventSchedules[EventName] = CallID
self:T2(string.format("NEGATIVE Event %s delayed by %.1f sec SCHEDULED with CallID=%s", EventName, DelaySeconds, tostring(CallID)))
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
end
else
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
else
error( "FSM: An asynchronous event trigger requires a DelaySeconds parameter!!! This can be positive or negative! Sorry, but will not process this." )
+4
View File
@@ -428,6 +428,10 @@ do -- Types
-- @type TaskArray
-- @list <#Task>
---
--@type WaypointAir
--@field #boolean lateActivated
--@field #boolean uncontrolled
end --
File diff suppressed because it is too large Load Diff
+43 -8
View File
@@ -27,6 +27,7 @@
-- @field #table waypoints Table of waypoints.
-- @field #table waypoints0 Table of initial waypoints.
-- @field #table coordinates Table of waypoint coordinates.
-- @field #table currentwp Current waypoint.
-- @field #table taskqueue Queue of tasks.
-- @field #number taskcounter Running number of task ids.
-- @field #number taskcurrent ID of current task. If 0, there is no current task assigned.
@@ -145,6 +146,7 @@ FLIGHTGROUP = {
waypoints = nil,
waypoints0 = nil,
coordinates = {},
currentwp = -100,
elements = {},
taskqueue = {},
taskcounter = nil,
@@ -480,7 +482,6 @@ function FLIGHTGROUP:New(groupname)
_DATABASE:AddFlightGroup(self)
-- Autostart.
--self:__Start(0.1)
self:Start()
return self
@@ -559,7 +560,7 @@ function FLIGHTGROUP:AddTaskWaypoint(task, waypointindex, description, prio, dur
newtask.id=self.taskcounter
newtask.duration=duration
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
self:T2({newtask=newtask})
@@ -567,6 +568,9 @@ function FLIGHTGROUP:AddTaskWaypoint(task, waypointindex, description, prio, dur
-- Add to table.
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.
self:__UpdateRoute(-1)
@@ -908,6 +912,11 @@ function FLIGHTGROUP:onafterStart(From, Event, To)
-- Debug info.
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.
for _,unit in pairs(units) do
@@ -937,7 +946,7 @@ function FLIGHTGROUP:onafterStart(From, Event, To)
-- Start the status monitoring.
self:__CheckZone(-1)
self:__FlightStatus(-1)
--self:__FlightStatus(-1)
end
--- 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.
self:__FlightStatus(-30)
--self:__FlightStatus(-30)
end
--- On after "QueueUpdate" event.
@@ -1792,20 +1801,44 @@ end
-- @param #number n Waypoint number.
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
-- Alive & Airborne ==> Update route possible.
self:T2(self.lid.."Update route allowed")
return true
self:T2(self.lid.."Update route possible. Group is ALIVE and AIRBORNE")
elseif self:IsDead() then
-- Group is dead! No more updates.
return false
self:T3(self.lid.."FF update route denied. Group is DEAD!")
allowed=false
else
-- Not airborne yet. Try again in 1 sec.
self:T3(self.lid.."FF update route denied ==> checking back in 1 sec")
self:__UpdateRoute(-1, n)
return false
allowed=false
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
--- On after "UpdateRoute" event.
@@ -1816,6 +1849,8 @@ end
-- @param #number n Waypoint number.
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
n=n or self.currentwp+1
+40 -15
View File
@@ -19,6 +19,10 @@
-- @field #string ClassName Name of the class.
-- @field #boolean Debug Debug mode. Messages to all about status.
-- @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
--- *To invent an airplane is nothing. To build one is something. To fly is everything.* -- Otto Lilienthal
@@ -46,7 +50,6 @@ TANKERGROUP = {
ClassName = "TANKERGROUP",
Debug = false,
lid = nil,
tankerzones = nil,
Qmissions = {},
Qclients = {},
currentmission = nil,
@@ -98,7 +101,6 @@ function TANKERGROUP:New(groupname)
-- Add FSM transitions.
-- 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("*", "MissionStart", "*") -- Tanker is on station and ready to refuel.
@@ -106,13 +108,18 @@ function TANKERGROUP:New(groupname)
self.lid=string.format("TANKERGROUP %s | ", groupname)
--[[
BASE:TraceOn()
BASE:TraceLevel(3)
BASE:TraceClass(self.ClassName)
]]
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
end
@@ -123,13 +130,18 @@ end
--- Add mission for tanker.
-- @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)
-- Increase mission counter.
self.missioncounter=self.missioncounter+1
local mission={} --#TANKERGROUP.Mission
-- Make mission table.
local mission={} --#TANKERGROUP.Mission
mission.zone=Zone
mission.mid=self.missioncounter
mission.altitude=UTILS.FeetToMeters(Altitude or 10000)
@@ -139,7 +151,12 @@ function TANKERGROUP:AddMission(Zone, Altitude, Distance, Speed)
mission.heading=270
mission.tid=nil
-- Add mission to queue.
table.insert(self.Qmissions, mission)
self:I(self.lid..string.format("Added mission"))
return mission
end
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
@@ -151,32 +168,37 @@ end
-- @param #string From From state.
-- @param #string Event Event.
-- @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(string.format("FF current wp=%s", tostring(self.currentwp)))
-- FSM state.
local fsmstate=self:GetState()
-- 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()
if mission then
env.info("FF starting mission")
self:MissionStart(mission)
end
end
-- Current mission name.
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)
self:I(self.lid..text)
self:__TankerStatus(30)
self:__FlightStatus(-30)
end
--- On after "MissionStart" event.
@@ -203,8 +225,11 @@ function TANKERGROUP:onafterMissionStart(From, Event, To, Mission)
elseif self:IsParking() then
end
self.currentmission=Mission
self:RouteTo(Mission)
--
self:RouteToMission(Mission)
end
@@ -228,17 +253,17 @@ function TANKERGROUP:_GetNextMission()
return mission
end
--- Get next mission.
--- Route group to mission. Also sets the
-- @param #TANKERGROUP self
-- @param #TANKERGROUP.Mission mission
-- @param #TANKERGROUP.Mission mission The mission table.
-- @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 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)