Skip to content

Commit

Permalink
Add the --suspend option to the JSBSim Python script.
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoconni committed Aug 20, 2022
1 parent b5ea872 commit a989104
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions python/JSBSim.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
help="specifies to run at lower CPU usage")
parser.add_argument("--nohighlight", default=False, action="store_true",
help="specifies that console output should be pure text only (no color)")
parser.add_argument("--suspend", default=False, action="store_true",
help="specifies to suspend the simulation after initialization")
parser.add_argument("--initfile", metavar="<filename>",
help="specifies an initialization file")
parser.add_argument("--catalog", default=False, action="store_true",
Expand Down Expand Up @@ -185,17 +187,31 @@ def CheckXMLFile(f):
current_seconds = initial_seconds = time.time()
result = fdm.run()

while result and fdm.get_sim_time() <= args.end:
if args.realtime:
current_seconds = time.time()
actual_elapsed_time = current_seconds - initial_seconds
sim_lag_time = actual_elapsed_time - fdm.get_sim_time()
if args.suspend:
fdm.hold()

for _ in range(int(sim_lag_time / frame_duration)):
result = fdm.run()
current_seconds = time.time()
else:
while result and fdm.get_sim_time() <= args.end:
fdm.check_incremental_hold()
if fdm.holding():
args.suspend = True
paused_seconds = time.time() - current_seconds
result = fdm.run()
else:
if args.realtime:
if args.suspend:
initial_seconds += paused_seconds
args.suspend = False
current_seconds = time.time()
actual_elapsed_time = current_seconds - initial_seconds
sim_lag_time = actual_elapsed_time - fdm.get_sim_time()

for _ in range(int(sim_lag_time / frame_duration)):
result = fdm.run()
current_seconds = time.time()
if fdm.holding():
break
else:
result = fdm.run()

if args.nice:
time.sleep(sleep_nseconds / 1000000.0)
if args.nice:
time.sleep(sleep_nseconds / 1000000.0)

0 comments on commit a989104

Please sign in to comment.