Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: Replacing ExecutorService to achieve more stable timing in the update loop #134

Open
ecmnet opened this issue Jul 5, 2022 · 3 comments

Comments

@ecmnet
Copy link

ecmnet commented Jul 5, 2022

The update loop is currently scheduled by an ExecutorService, which is known to be not very precise in its cyclic timing.

Therefore I would like to propose another solution for scheduling, which I currently use to avoid or at least reduce issues like polling errors or timeouts e.g. mentioned in this discussion.

Scheduling is implemented like this:

    long sleep_interval_ns;
    if (LOCKSTEP_ENABLED) {`
    	sleep_interval_ns = (long)(sleepInterval / speedFactor / checkFactor)*1000;
    } else {
    	sleep_interval_ns = sleepInterval*1000;
    }
    Thread loop = new Thread(() -> {
		long  wait;
		while(!shutdown) {
			wait = System.nanoTime();
			this.run();
			LockSupport.parkNanos(sleep_interval_ns - (System.nanoTime() - wait));    
		}
	});
    loop.setPriority(Thread.MAX_PRIORITY);
    loop.start();

On OSX this turned out to be much more stable although it is not solving the problem completely.

@dagar
Copy link
Member

dagar commented Jul 5, 2022

@ecmnet what actual requirements do you have for simulation? I'm wondering if it would be better to focus on using sih within PX4 (https://github.com/PX4/PX4-Autopilot/tree/main/src/modules/sih) for the this simple sim, then you can continue using jmavsim only for visualization.

For anything more sophisticated I'm hoping we can focus our efforts on new Gazebo (Ignition), including dealing with cross platform build (or packaging) issues if necessary.

@ecmnet
Copy link
Author

ecmnet commented Jul 5, 2022

@dagar: I use jMAVSim just for quick and basic functional tests of MAVCGL or the companion software (e.g. trajectory generation w. offboard) - usually without visualization. For more sophisticated tests, I currently use Gazebo but hadn't have a look into Ignition.

@dagar
Copy link
Member

dagar commented Jul 5, 2022

Makes sense. In the not too distant future I would like to consolidate a bit so we can focus on having 1 or 2 decent simulation options instead of 5-6 mediocre.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants