当前位置: 首页>>代码示例>>Java>>正文


Java RobotBase.MAIN_THREAD_ID属性代码示例

本文整理汇总了Java中edu.wpi.first.wpilibj.RobotBase.MAIN_THREAD_ID属性的典型用法代码示例。如果您正苦于以下问题:Java RobotBase.MAIN_THREAD_ID属性的具体用法?Java RobotBase.MAIN_THREAD_ID怎么用?Java RobotBase.MAIN_THREAD_ID使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在edu.wpi.first.wpilibj.RobotBase的用法示例。


在下文中一共展示了RobotBase.MAIN_THREAD_ID属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: runOnce

/**
 * Runs the pipeline one time, giving it the next image from the video source specified
 * in the constructor. This will block until the source either has an image or throws an error.
 * If the source successfully supplied a frame, the pipeline's image input will be set,
 * the pipeline will run, and the listener specified in the constructor will be called to notify
 * it that the pipeline ran.
 *
 * <p>This method is exposed to allow teams to add additional functionality or have their own
 * ways to run the pipeline. Most teams, however, should just use {@link #runForever} in its own
 * thread using a {@link VisionThread}.</p>
 */
public void runOnce() {
  if (Thread.currentThread().getId() == RobotBase.MAIN_THREAD_ID) {
    throw new IllegalStateException(
        "VisionRunner.runOnce() cannot be called from the main robot thread");
  }
  long frameTime = m_cvSink.grabFrame(m_image);
  if (frameTime == 0) {
    // There was an error, report it
    String error = m_cvSink.getError();
    DriverStation.reportError(error, true);
  } else {
    // No errors, process the image
    m_pipeline.process(m_image);
    m_listener.copyPipelineOutputs(m_pipeline);
  }
}
 
开发者ID:ArcticWarriors,项目名称:snobot-2017,代码行数:27,代码来源:VisionRunner.java

示例2: runForever

/**
 * A convenience method that calls {@link #runOnce()} in an infinite loop. This must
 * be run in a dedicated thread, and cannot be used in the main robot thread because
 * it will freeze the robot program.
 *
 * <p><strong>Do not call this method directly from the main thread.</strong></p>
 *
 * @throws IllegalStateException if this is called from the main robot thread
 * @see VisionThread
 */
public void runForever() {
  if (Thread.currentThread().getId() == RobotBase.MAIN_THREAD_ID) {
    throw new IllegalStateException(
        "VisionRunner.runForever() cannot be called from the main robot thread");
  }
  while (!Thread.interrupted()) {
    runOnce();
  }
}
 
开发者ID:ArcticWarriors,项目名称:snobot-2017,代码行数:19,代码来源:VisionRunner.java


注:本文中的edu.wpi.first.wpilibj.RobotBase.MAIN_THREAD_ID属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。