![]() |
Faster loop scheduling
I've learned that some teams use a special (not in WPILib) way of scheduling their loop callbacks. I've seen the number 200Hz thrown around occasionally. I believe (at least for C++) that WPILib tries to schedule at ~50Hz. Obviously, tighter control loops would be nicer, but I have 2 questions about this:
|
Re: Faster loop scheduling
Code:
int rate = 200; // Hz- Dead reckoning. Integrating gyro angle with encoder distance for approximate field position. We run it at 60 Hz, the update rate of the NavX, for best accuracy - 775pro monitoring. If close to stall current is detected, it immediately shuts off the motors. This is an important safety control so we don't want it potentially hung up by main thread stuff. |
Re: Faster loop scheduling
While putting a thread.sleep in a while loop works, I prefer the more institutional method of using a scheduledExecutorService. It's good for when you're not certain how long some code will take exactly.
|
Re: Faster loop scheduling
Why is this thread in Rules/Strategy? I'm just curious.
|
Re: Faster loop scheduling
Quote:
The big benefit of this doesn't really come from the "200hz" part, but the "separate thread". Using IterativeRobot, the update rate is supposed to be "about" 50hz, but it's really inconsistent. The loop is synchronized to driver station packets, meaning that it's waiting on the network in between iterations. Things like writing to the console or sending CAN messages can mess up your timing as well. This can give very strange results, especially if you're relying on consistent timing in your control loops. That said, there is still a benefit to running loops at 200hz if you're relying on really tight controls (faster update rates will allow your code to respond more quickly to disturbances). I believe that WPILib gets around these timing issues by updating their built-in PID controller class in a separate thread. However, if you're rolling your own PID code or doing some sort of other logic, you'll want to manually create a new thread to run your control loops so that you can avoid timing issues. Fair warning - multithreading can be really tricky to get right, especially when communicating between threads. |
Re: Faster loop scheduling
Quote:
|
Re: Faster loop scheduling
Quote:
There's also a new callback mechanism in the C++/Java Libraries that allow you to run code (as long as it's very efficient) off of the navX IO thread: public interface ITimestampedDataSubscriber { public void timestampedDataReceived( long system_timestamp, long sensor_timestamp, AHRSUpdateBase sensor_data, Object context ); } |
Re: Faster loop scheduling
There is Teleop.Continuous if you want to be continuously called (rather than waiting for the next cycle).
|
Re: Faster loop scheduling
Quote:
|
Re: Faster loop scheduling
Quote:
|
Re: Faster loop scheduling
Quote:
|
Re: Faster loop scheduling
Quote:
|
| All times are GMT -5. The time now is 20:17. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi