View Single Post
  #2   Spotlight this post!  
Unread 09-02-2017, 15:18
euhlmann's Avatar
euhlmann euhlmann is offline
CTO, Programmer
AKA: Erik Uhlmann
FRC #2877 (LigerBots)
Team Role: Leadership
 
Join Date: Dec 2015
Rookie Year: 2015
Location: United States
Posts: 417
euhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud of
Re: Faster loop scheduling

Code:
int rate = 200; // Hz

private void mySuperFastLoop() {
  while (true) {
    // do some fast stuff
    
    try {
      Thread.sleep(1000 / rate);
    } catch (InterruptedException ex) {}
  }
}

protected void robotInit() {
  Thread superFastLoopThread = new Thread(this::mySuperFastLoop);
  superFastLoopThread.setDaemon(true);
  superFastLoopThread.setName("Custom Super Fast Loop");
  superFastLoopThread.start();
}
What we use fast off-thread loops for:
- 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.
__________________
Creator of SmartDashboard.js, an extensible nodejs/webkit replacement for SmartDashboard


https://ligerbots.org

Last edited by euhlmann : 09-02-2017 at 15:22.
Reply With Quote