Problem proc.wait_simdt() issue?

dmurley

New member
Joined
Dec 11, 2017
Messages
37
Reaction score
0
Points
0
Location
Hill country (near San Antonio
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.
 

dgatsoulis

ele2png user
Joined
Dec 2, 2009
Messages
1,774
Reaction score
8
Points
38
Location
Sparta
proc.wait_simdt(dt)
Wait for a given simulation time interval.

Parameters:
dt (number): simulation time interval

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?
 

dmurley

New member
Joined
Dec 11, 2017
Messages
37
Reaction score
0
Points
0
Location
Hill country (near San Antonio
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

New member
Joined
Dec 11, 2017
Messages
37
Reaction score
0
Points
0
Location
Hill country (near San Antonio
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')
 

Attachments

Last edited:

martins

Orbiter Founder
Orbiter Founder
Joined
Mar 31, 2008
Messages
2,352
Reaction score
8
Points
0
Website
orbit.medphys.ucl.ac.uk
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.
 
Top