Jump to content

Detecting a helicopter landing


Wrecking Crew

Recommended Posts

Need to detect when a helicopter lands, anywhere.

 

I spent a lot of time on this today and have a working solution to share. If there is a better way I'd like to hear about it.

 

I tried a bunch of variations of 'return Unit.getByName('huey'):inAir()' but my result was toggling between 'flying' and 'landing' so much that I couldn't figure why or suppress the cycling. The result strengthened the notion that helicopters aren't really flying... :)

 

The Unit's Altitude Lower Than condition wasn't suitable because the height argument for it is 'above sea level' and the the helicopter could be in an area where the terrain is actually higher than the set value. This condition works fine if the helicopter is landing at a zone where the height is known.

 

 

To detect when a desired helicopter lands anywhere, I used three events:

1. Switched Condition, Unit's Speed Lower Than (unit name, 1), Flag On (1)

2. Switched Condition, Flag Is True (1) & Unit's Speed Higher Than (unit name, 1), Flag Off (1)

3. Switched Condition, Time Since Flag (1, 20), Message ("Helicopter has landed.")

..at less that 17 seconds in #3 there were false triggers as the helicopter prepared to land.

 

The test mission is attached -- look at events 8-10.

 

 

It would have been great if this could have worked:

if Unit.getByName('UH-1H 11'):inAir() == 1 then 
   trigger.action.setUserFlag(61105, 1) -- is flying
trigger.action.setUserFlag(61107, 0) -- not landed
else
trigger.action.setUserFlag(61105, 0) -- not flying
trigger.action.setUserFlag(61107, 1) -- is landed
end

 

WC

Visit the Hollo Pointe DCS World server -- an open server with a variety of COOP & H2H missions including Combined Arms. All released missions are available for free download, modification and public hosting, from my Wrecking Crew Projects site.

Link to comment
Share on other sites

I would use the event handler.

You can simply look for an event when a certain unit is landing.

 

local eHandler = {}

function eHandler:onEvent(e)
if e.id == world.event.S_EVENT_LAND then
if e.initiator then
 local gName = e.initiator:getname()
 if gName = 'whatever you want' then
  whatever you want
 end
end
end
end

world.addEventHandler(eHandler)

 

You can also use e.place to get the exact location of landing.


Edited by xcom
Link to comment
Share on other sites

Thanks, xcom!

 

I read about this function in the v37 Mist Guide. Can you point me to other references that list the different events and their returns?

 

WC

Visit the Hollo Pointe DCS World server -- an open server with a variety of COOP & H2H missions including Combined Arms. All released missions are available for free download, modification and public hosting, from my Wrecking Crew Projects site.

Link to comment
Share on other sites

I tried using this but I'm getting an error on mission load.

 

local eHandler = {}

function eHandler:onEvent(e)
if e.id == world.event.S_EVENT_LAND then
if e.initiator then
 local gName = e.initiator:getname()
 if gName = 'PEDRO 1' then
  trigger.action.setUserFlag(1,true)
  end
 end
end
end

world.addEventHandler(eHandler)

 

Here is the error...

 

[string

"c:\Users\username\AppData\Local\Temp\DCS\/~misc00000480"]:7:

'then' expected near '='

 

So it's telling me line 7, then expected near =, but that makes no sense to me.

 

Any help would be appreciated.

Link to comment
Share on other sites

Mission script error

 

[string "local eHandler = {}..."]:6: attempt to call method

'getname' (a nil value)

stack traceback:

[C]: in function 'getname'

[string "local eHandler = {}..."]:6: in function 'onEvent'

{string "Scripts/World/EventHandlers.lua"]:13: in

function <[string "Scripts/World/EventHandlers.lua"]:11>

 

...but I don't think it will work as I and the OP had hoped anyway. Landing events only happen at airfields. Landing off field doesn't count.

Link to comment
Share on other sites

My three-event method is working in this attached mission with regular events. Quite complicated to detect a landing, when this could be simplified with a change to the event condition of Unit's Altitude Lower Than (agl) -- see this post:

http://forums.eagle.ru/showthread.php?t=132956

 

WC


Edited by Wrecking Crew
using events

Visit the Hollo Pointe DCS World server -- an open server with a variety of COOP & H2H missions including Combined Arms. All released missions are available for free download, modification and public hosting, from my Wrecking Crew Projects site.

Link to comment
Share on other sites

I have an idea, but it may not work if the helicopter is hovering (very) still in the air. First, differentiate the unit's vertical position to attain it's vertical velocity. Might need to do this at a high rate, maybe 100 milliseconds per iteration, depending on how fast you'd want the landing event to register. Then add the unit's forward and lateral speeds (taken via differentiation again) to the result of the vertical. After doing this, you'll need to apply a peak following algorithm to the summed values, which is a function that will instantly increase in value if it goes above it's "decay", and the function will decay if the input value is lower. If you are familiar with electronics, it would look like the output of the bridge capacitor following the full wave rectifier in a power supply circuit, it just decays slowly after the input has ceased. And then maybe after that, use the InAir() function or whatever is used to report the aircraft is indeed flying, and if it returns true, add some large number to the derivatives' sum to offset any lack of motion in the air. Then compare the final sum to a small number and if it's below, most likely the thing has landed or crashed.

 

Rather difficult to explain completely, if you want some help with the math, send me a PM.

Link to comment
Share on other sites

These three events do the job --

To detect when a desired helicopter lands anywhere:

1. Switched Condition, Unit's Speed Lower Than (unit name, 1), Flag On (1)

2. Switched Condition, Flag Is True (1) & Unit's Speed Higher Than (unit name, 1), Flag Off (1)

3. Switched Condition, Time Since Flag (1, 20), Message ("Helicopter has landed.")

 

The InAir function kept returning false positives.

 

This week I did see a quite successful Embark and Disembark for a bunch of soldiers and an Mi-8T. The mission is by Toxocara in this post if you want to take a look.

http://forums.eagle.ru/showthread.php?p=2222442#post2222442

Whatever code is determining that the Mi-8T has landed works well for this feature.

 

WC

Visit the Hollo Pointe DCS World server -- an open server with a variety of COOP & H2H missions including Combined Arms. All released missions are available for free download, modification and public hosting, from my Wrecking Crew Projects site.

Link to comment
Share on other sites

I made a mission that embarked an "officer" (holding an AK47 :P) onto a helicopter. I used the altitude below trigger and vertical speed and unit in-zone. It works perfect but like you said, altitude is only above sea level.

Link to comment
Share on other sites

LOL

 

A friend suggested a new mission where a Huey could deliver Stingers around a Red airbase. So my issue was to be able to drop off a Stinger team anywhere on the map.

 

The Mission Editor has events to easily detect conditions for 'helicopter landed' when the helicopter lands in a zone, because the height of the zone is known. But to land anywhere and detect that condition required some investigation. The solution has to account for hovering, when the helicopter has zero speed.

 

Here is my mission --

WC's Bridge At Zugdidi 1210v2r

 

 

WC


Edited by Wrecking Crew

Visit the Hollo Pointe DCS World server -- an open server with a variety of COOP & H2H missions including Combined Arms. All released missions are available for free download, modification and public hosting, from my Wrecking Crew Projects site.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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