0% found this document useful (0 votes)
4 views3 pages

Target Tracking System Code

voial

Uploaded by

axel.lory12345
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

Target Tracking System Code

voial

Uploaded by

axel.lory12345
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

x = 0

y=0

max_tar = 7 -- Maximum target count


lastRange = 0
lastAz = 0
tarX = 0
tarY = 0
targetX=0
targetY=0
heading =0

tar = {}
tarD = {} -- Distance
tarAz = {} -- Azimuth
trackedTargets = {} -- Liste persistante des cibles

maxAge = 5000
-- 1 x /2 y / 3 age

function onTick()
zoom = [Link](31)
x = [Link](29)
y = [Link](30)
raw_compas = [Link](32)
heading = (raw_compas * 2 * [Link]) % (2 * [Link]) -- en radians 0 2p
for i=1,max_tar do
if([Link](i)==true) then
tar[i]=true -- Get the bool target data
tarD[i]=[Link](1 + (i - 1) * 4)
local relAz = [Link](2 + (i - 1) * 4) -- Azimut
relatif (-0.5 +0.5)
local relAzRad = relAz * 2 * [Link] -- En radians
tarAz[i] = (heading + relAzRad) % (2 * [Link]) -- Azimut absolu
en radians
end

end

[Link](3,tarX)
[Link](4,tarY )
end

function onDraw()

w = [Link]()
h = [Link]()

[Link](x, y, zoom)
myX, myY = [Link](x, y, zoom, w, h, x, y)

[Link](0,255,0)
[Link](myX, myY , 1)

lineX = x - 100 * [Link](heading)


lineY = y + 100 * [Link](heading)
toX, toY = [Link](x, y, zoom, w, h, lineX, lineY)
[Link](myX, myY,toX, toY)

targetCount = 0
for i=1,max_tar do
if tar[i] then
azRad = tarAz[i] --* (2 * [Link]) -- Degree to radians
tarX = x -tarD[i] * [Link](azRad)
tarY = y +tarD[i] * [Link](azRad) -- We subtract since Y axis is in
down direction

trackedTargetsUpdate(tarX,tarY)

end
end

for i=1,#trackedTargets do

targetX, targetY =[Link](x, y, zoom, w, h, trackedTargets[i]


[1], trackedTargets[i][2])

local r, g, b = getAgeColor( trackedTargets[i][3])


[Link](r, g, b)
[Link](targetX, targetY, 1)
end

end

function trackedTargetsUpdate(x1,y1)
local checked = false
if(#trackedTargets>0) then
print(#trackedTargets)
print(trackedTargets)

for i = #trackedTargets, 1, -1 do
-- 1 x /2 y / 3 age
if(distanceBetween(x1,y1,trackedTargets[i][1],trackedTargets[i]
[2])<200) then
checked = true;
trackedTargets[i][1] = x1
trackedTargets[i][2] = y1
trackedTargets[i][3] = 0;
else
trackedTargets[i][3] = trackedTargets[i][3]+1;
end

if(trackedTargets[i][3]>maxAge)then
--remove la cible ca fait longtemps que on la perdu
removeFromTableByIndex(trackedTargets,i)
end

end
end
if(checked==false)then
[Link](trackedTargets, {x1,y1,0})

end
end

function removeFromTableByIndex(tbl, index)


[Link](tbl, index)
end

function distanceBetween(x1, y1, xtarget, ytarget)


local dx = xtarget - x1
local dy = ytarget - y1
return [Link](dx * dx + dy * dy)
end

function getAgeColor(age)
local ratio = [Link](age / maxAge, 1)
local r = 255
local g = 0

if ratio < 0.5 then


-- Rouge → Orange
g = ratio * 2 * 127
else
-- Orange → Jaune
g = 127 + (ratio - 0.5) * 2 * 128
end

return [Link](r), [Link](g), 0


end

You might also like