Orbiter-Forum  

Go Back   Orbiter-Forum > Orbiter Addons > Orbiter Lua Scripting
Register Blogs Orbinauts List Social Groups FAQ Projects Mark Forums Read

Notices

Orbiter Lua Scripting Find support, share snippets and general discussion around using the Lua engine in Orbiter.

Reply
 
Thread Tools
Old 07-27-2019, 01:12 PM   #1
dmurley
Orbinaut
Default proc.wait_simdt() issue?

Sometimes when I use proc.wait_simdt() it will cause Orbiter to hang or freeze. I figure:
  1. I am doing something in other parts of the script causing this behavior or
  2. there might be some issue with this routine that I don't know about

I would appreciate any insight that anyone could offer. Thanks.
dmurley is offline   Reply With Quote
Old 07-27-2019, 02:34 PM   #2
dgatsoulis
ele2png user
 
dgatsoulis's Avatar
Default

Quote:
proc.wait_simdt(dt)
Wait for a given simulation time interval.

Parameters:
dt (number): simulation time interval [s]

Notes:
This function suspends the execution of the script for dt seconds (simulation time).

Implemented as a script in oapi_init.lua.

See also:
proc.wait_simtime, proc.wait_systime, proc.wait_sysdt
proc.wait_simdt(dt) is pretty straightforward as a process function. When you use it, it suspends the execution of the script for dt seconds.

Can you share the part of your script that causes problems for you? Is it inside a while...do loop?
dgatsoulis is offline   Reply With Quote
Old 07-27-2019, 04:05 PM   #3
dmurley
Orbinaut
Default

I have used proc.wait_simdt(dt) in the past without any problem. I am several hundred miles today from the script I am writing. The call is in a loop, but I can't remember if it is a while-do loop or a repeat-until loop (actually I think it is in repeat-until which is nested inside of a while-do loop). I will post the part of my script it is in when I get home. Thanks for getting back to me.
dmurley is offline   Reply With Quote
Old 07-28-2019, 03:54 PM   #4
dmurley
Orbinaut
Default

Ok. Back home again. Attached are two items:
  • control skeleton of attached Lua script file
  • entire Lua script file

Maybe the control skeleton will be enough to reveal the problem I am having. Maybe not.

If you look through the Lua script file, be aware that it still needs quite a bit of work. I have just learned that such things as PID control loops exiist (after I started this script) and want to go back and make some changes. I also intend to make it smaller.

Skeleton of control structure
Code:
term.out ('Start Script')
     .
     .
     code
     .
     .
hGLNT:set_thrustergrouplevel(THGROUP.HOVER,.6577)
proc.wait_simdt(0.313)     -- Works fine
hGLNT:set_thrustergrouplevel(THGROUP.HOVER,.2184)
     .
     .  
     code
     .
     .
continue = true
while continue do
  while alt > 20 do
    if adjMade then
        .
	.
      code 
        .
	.
    else
	.
	.
      hGLNT:set_thrustergrouplevel(THGROUP.HOVER, dwnLevel)
      proc.wait_simdt(1)  -- This causes the system to freeze up
      hGLNT:set_thrustergrouplevel(THGROUP.HOVER, hLevel)
        .
	.
    end
  end
    .
    .
    code
    .
    .
  while alt < 20 do
    if adjMade then
	 .
	 .
	 code
	 .
	 .
    else
	 .
	 .
	 code
	 .
	 .
      hGLNT:set_thrustergrouplevel(THGROUP.HOVER,upLevel
      proc.wait_simdt(1)  -- This also causes the system to freeze up
      hGLNT:set_thrustergrouplevel(THGROUP.HOVER,hLevel)
         .
	 .
	 code
	 .
	 .
    end
  end
  if alt==20 then
	.
	.
	code
	.
	.
  end
  proc.wait_simdt(.25)  -- This works fine.
end

term.out ('End Script')
Attached Files
File Type: zip hover.zip (1.3 KB, 3 views)

Last edited by dmurley; 07-28-2019 at 04:31 PM. Reason: Replaced hover.zip with a cleaner copy of hover.zip
dmurley is offline   Reply With Quote
Old 07-28-2019, 08:56 PM   #5
martins
Orbiter Founder
Default

One thing to remember is that the Lua script is not running in a separate thread from the Orbiter main process (the communication between Lua and the Orbiter core is not threadsafe). Therefore, Orbiter is suspended while Lua is executing its code.

Therefore it is important during a lengthy bit of Lua code execution (for example a loop) to regularly pass control back to Orbiter to allow it to process the next simulation step. This is done with the proc.skip function. The wait functions (proc.wait_simdt, etc.) do call proc.skip, so on first glance your code looks ok - as long as it is guaranteed to be called in each loop cycle.

In your code example however this actually isn't the case: if alt > 20 and adjMade == true while executing the loop, you are going to be trapped in the first .. code .. block of your loop. Unless this block contains a direct or indirect call to proc.skip, Orbiter will not have a chance to progress, and therefore the alt > 20 will remain true indefinitely. So you are never getting out of the loop, hence the freeze.
martins is offline   Reply With Quote
Thanked by:
Old 07-29-2019, 03:36 PM   #6
dmurley
Orbinaut
Default

Yes. Inserting a proc.skip() solved the problem I was having. Thanks.
dmurley is offline   Reply With Quote
Reply

  Orbiter-Forum > Orbiter Addons > Orbiter Lua Scripting


Thread Tools

Posting Rules
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Jump


All times are GMT. The time now is 10:50 AM.

Quick Links Need Help?


About Us | Rules & Guidelines | TOS Policy | Privacy Policy

Orbiter-Forum is hosted at Orbithangar.com
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.
Copyright 2007 - 2017, Orbiter-Forum.com. All rights reserved.