Jump to content

Recommended Posts

Posted (edited)

I have this executing every second on a trigger:

local SAM = "Ground-1-1"
local maxRange = 160000
local controller_unit = Unit.getController(Unit.getByName(SAM)) --sam
local tDetectedTargets = controller_unit:getDetectedTargets(Controller.Detection.RADAR)
trigger.action.outText("#tDetectedTargets: " .. tostring(#tDetectedTargets), 15)
if #tDetectedTargets > 0 then
    trigger.action.outText("Mayor a 0", 15)
    for objetivo = 1, #tDetectedTargets do
        local objName = Object.getName(tDetectedTargets[objetivo].object)
        trigger.action.outText("objName: " .. tostring(objName), 15)
        if Unit.getByName(objName) then
            local target = Unit.getByName(objName)
            local coal = Unit.getByName(objName):getCoalition()
            if coal == 2 then
                local distancia = Distancia(Unit.getByName(SAM), target)
                trigger.action.outText("Distancia: " .. tostring(distancia), 15)
                if distancia < maxRange then
                    a = 1
                else
                    a = 0
                end
            end
        end
    end
else
    trigger.action.outText("No detecta NADA", 15)
end

The problem is when it detects a target and the target goes beyond detection range, it still keep detecting it forever.

If the target gets destroyed getDetectedTargets, it gets fixed and it doesn't keep detecting it.

Edited by Ignition
Posted
11 hours ago, Ignition said:

The problem is when it detects a target and the target goes beyond detection range, it still keep detecting it forever.

That's indeed interesting. I've never use that function, but perhaps we are running up against a expectation issue.

I would assume (just like you seemingly do) that getDetectedTargets() returns all targets that a unit's detectors are currently detecting right now/within the last second or so, in other words that we are reading the current output from a detector.

Nothing in the description of the method, however says so explicitly, and we may simply assume this to be that way. Another reading of the documentation may well be 

"Returns a table of all currently alive units that have been detected in the past", i.e. the unit AI remembers all other units that it has detected before. In other words, we are not reading the detector's current state, but the AI pilot's mind, and the pilot also remembers units they detected before. Not what I would expect, but probably makes sense if/when you are trying to program an AI that doesn't immediately suffers amnesia when an engaged target disappears from the detector.

Posted
4 hours ago, cfrag said:

That's indeed interesting. I've never use that function, but perhaps we are running up against a expectation issue.

I would assume (just like you seemingly do) that getDetectedTargets() returns all targets that a unit's detectors are currently detecting right now/within the last second or so, in other words that we are reading the current output from a detector.

Nothing in the description of the method, however says so explicitly, and we may simply assume this to be that way. Another reading of the documentation may well be 

"Returns a table of all currently alive units that have been detected in the past", i.e. the unit AI remembers all other units that it has detected before. In other words, we are not reading the detector's current state, but the AI pilot's mind, and the pilot also remembers units they detected before. Not what I would expect, but probably makes sense if/when you are trying to program an AI that doesn't immediately suffers amnesia when an engaged target disappears from the detector.

Yes I thought about that. If that's the way it's supposed to work it would be really useful to have an option to reset it and force a check from 0.
As it is right now its only useful for the first time it sees the target. 😒
I'm going to couple this with isTargetDetected and see what happens. I guess it will check the table generated by getDetectedTargets and it will not be very useful.

Posted

I'm not seeing this behavior. I tested the function within my own script and the reporting always stops when the target far enough away. I use AWACS, EWR, and Patriot SAM as the detecting unit and the behavior was the same in all cases:

local pri = "T" -- priorirty target unit name
local outname = "ELINT aircraft" -- priority target text name (what AWACS will relay)

--Bullseye data
bullR = coalition.getMainRefPoint(1) -- Red Bulls
--trigger.action.outText("Red Bulls X: " ..bullR.x .." Y: " ..bullR.y .." Z: " ..bullR.z, 60, false)

bullB = coalition.getMainRefPoint(2) -- Blue Bulls
--trigger.action.outText("Blue Bulls X: " ..bullB.x .." Y: " ..bullB.y .." Z: " ..bullB.z, 60, false)

bullN = coalition.getMainRefPoint(0) -- Neut Bulls
--trigger.action.outText("Neut Bulls X: " ..bullN.x .." Y: " ..bullN.y .." Z: " ..bullN.z, 60, false)
--Surveillance Units
cmnd = Unit.getByName('E3') -- Command, AWACS unit
logi = Unit.getController(cmnd) -- Logic, Command Controller
list = logi:getDetectedTargets(Controller.Detection.RADAR) -- Table of detected target, is a table (list) of tables (DetectedTarget)
--Blue Side Detection



local magvar = -2.2

for _,DetectedTarget in pairs( list ) do
    if DetectedTarget ~= nil then
        obj = DetectedTarget.object  -- Get index Object from table Detected Target
        tgt = obj:getTypeName() --Get type of target
        tID = obj:getName()
        postab = obj:getPosition() --Get position table of target
        pospnt = postab.p --Get point position
        alt = (pospnt.y + 153 )/ 304.8 -- +500 ft for math.floor rounding
        xvec = pospnt.x - bullB.x -- X vector for target
        zvec = pospnt.z - bullB.z -- Z vector for target
        theta_r = math.atan2(zvec, xvec) -- angle calculation
        theta = theta_r * (180/math.pi) -- angle units
                theta = (theta_r * (180/math.pi)) + magvar -- angle units
            if theta < 0 then
                theta = 360 + theta
            end
            if tID == pri then
                magni = math.sqrt(xvec^2 + zvec^2) -- distance calculation
                range = (magni/1852) + 0.5 -- distance units
                trigger.action.outText("Detected " ..outname .."\nBulls: " ..math.floor(theta) .." for: " ..math.floor(range) .." Angels: " ..math.floor(alt), 10, false)
                --trigger.action.outText("Detected " ..tgt, 10, false) -- Output in text target type
                --trigger.action.outText("Bearing: " ..math.floor(theta) .." Range: " ..math.floor(range) .." Angels: " ..math.floor(alt), 10, false) -- Output in text target location
            end
    end
end

This script as written is looking for a specific target, but you can change that by commenting out the last if and choosing the appropriate outText at the end.

Awaiting: DCS F-15C

Win 10 i5-9600KF 4.6 GHz 64 GB RAM RTX2080Ti 11GB -- Win 7 64 i5-6600K 3.6 GHz 32 GB RAM GTX970 4GB -- A-10C, F-5E, Su-27, F-15C, F-14B, F-16C missions in User Files

 

  • 3 weeks later...
Posted (edited)
On 1/4/2024 at 1:22 AM, Exorcet said:

I'm not seeing this behavior. I tested the function within my own script and the reporting always stops when the target far enough away. I use AWACS, EWR, and Patriot SAM as the detecting unit and the behavior was the same in all cases:

local pri = "T" -- priorirty target unit name
local outname = "ELINT aircraft" -- priority target text name (what AWACS will relay)

--Bullseye data
bullR = coalition.getMainRefPoint(1) -- Red Bulls
--trigger.action.outText("Red Bulls X: " ..bullR.x .." Y: " ..bullR.y .." Z: " ..bullR.z, 60, false)

bullB = coalition.getMainRefPoint(2) -- Blue Bulls
--trigger.action.outText("Blue Bulls X: " ..bullB.x .." Y: " ..bullB.y .." Z: " ..bullB.z, 60, false)

bullN = coalition.getMainRefPoint(0) -- Neut Bulls
--trigger.action.outText("Neut Bulls X: " ..bullN.x .." Y: " ..bullN.y .." Z: " ..bullN.z, 60, false)
--Surveillance Units
cmnd = Unit.getByName('E3') -- Command, AWACS unit
logi = Unit.getController(cmnd) -- Logic, Command Controller
list = logi:getDetectedTargets(Controller.Detection.RADAR) -- Table of detected target, is a table (list) of tables (DetectedTarget)
--Blue Side Detection



local magvar = -2.2

for _,DetectedTarget in pairs( list ) do
    if DetectedTarget ~= nil then
        obj = DetectedTarget.object  -- Get index Object from table Detected Target
        tgt = obj:getTypeName() --Get type of target
        tID = obj:getName()
        postab = obj:getPosition() --Get position table of target
        pospnt = postab.p --Get point position
        alt = (pospnt.y + 153 )/ 304.8 -- +500 ft for math.floor rounding
        xvec = pospnt.x - bullB.x -- X vector for target
        zvec = pospnt.z - bullB.z -- Z vector for target
        theta_r = math.atan2(zvec, xvec) -- angle calculation
        theta = theta_r * (180/math.pi) -- angle units
                theta = (theta_r * (180/math.pi)) + magvar -- angle units
            if theta < 0 then
                theta = 360 + theta
            end
            if tID == pri then
                magni = math.sqrt(xvec^2 + zvec^2) -- distance calculation
                range = (magni/1852) + 0.5 -- distance units
                trigger.action.outText("Detected " ..outname .."\nBulls: " ..math.floor(theta) .." for: " ..math.floor(range) .." Angels: " ..math.floor(alt), 10, false)
                --trigger.action.outText("Detected " ..tgt, 10, false) -- Output in text target type
                --trigger.action.outText("Bearing: " ..math.floor(theta) .." Range: " ..math.floor(range) .." Angels: " ..math.floor(alt), 10, false) -- Output in text target location
            end
    end
end

This script as written is looking for a specific target, but you can change that by commenting out the last if and choosing the appropriate outText at the end.

Hi, I've used your script, it gets detected forever, even after landing and almost out the map 370nm from the EWR.

The F-16 gets detected correctly when entering the range of the EWR, then it still gets detected after landing.

The F-15E still gets detected way beyond detection range and it still gets detected after landing.

It's only not detected when the target doesn't exist.

getDetectedTargets.miz

Edited by Ignition
Posted

I might not be able to check the mission for a while, but I'll try to look at it when I can. Strange that results differ.

Awaiting: DCS F-15C

Win 10 i5-9600KF 4.6 GHz 64 GB RAM RTX2080Ti 11GB -- Win 7 64 i5-6600K 3.6 GHz 32 GB RAM GTX970 4GB -- A-10C, F-5E, Su-27, F-15C, F-14B, F-16C missions in User Files

 

Posted

I was able to look into it, the problem is related to 55G6 maybe. When using E-3, targets eventually get too far away. You can also see random detections at long range thanks to the new fluctuating RCS (I assume):

 

script2.miz

Awaiting: DCS F-15C

Win 10 i5-9600KF 4.6 GHz 64 GB RAM RTX2080Ti 11GB -- Win 7 64 i5-6600K 3.6 GHz 32 GB RAM GTX970 4GB -- A-10C, F-5E, Su-27, F-15C, F-14B, F-16C missions in User Files

 

Posted
10 minutes ago, Exorcet said:

I was able to look into it, the problem is related to 55G6 maybe. When using E-3, targets eventually get too far away. You can also see random detections at long range thanks to the new fluctuating RCS (I assume):

 

script2.miz 11.24 kB · 0 downloads

I have the same problem with both EWR 55 and 1L, I didn't test AWACS.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...