/** * 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); } }
public void startSimulation() throws InstantiationException, IllegalAccessException, ClassNotFoundException { RobotBase.initializeHardwareConfiguration(); loadConfig(sPROPERTIES_FILE); // Do all of the stuff that HAL.setWaitTime(.02); createSimulator(); createRobot(); Thread robotThread = new Thread(createRobotThread(), "RobotThread"); Runnable guiThread = createGuiThread(); robotThread.start(); SwingUtilities.invokeLater(guiThread); }
public VisionManager(IPositioner aPositioner, ISnobotActor aSnobotActor, IVisionJoystick aOperatorJoystick, RobotBase aSnobotState) { if (Properties2017.sENABLE_VISION.getValue()) { mVisionServer = new VisionAdbServer(PortMappings2017.sADB_BIND_PORT, PortMappings2017.sAPP_MJPEG_PORT, PortMappings2017.sAPP_MJPEG_PORT); } mPositioner = aPositioner; mSnobotActor = aSnobotActor; mOperatorJoystick = aOperatorJoystick; mSnobotState = aSnobotState; mStateManager = new StateManager(); mLatestTargetInformation = new ArrayList<>(); mTargetMessage = ""; MjpegForwarder forwarder = new MjpegForwarder(PortMappings2017.sAPP_MJPEG_FORWARDED_PORT); MjpegReceiver receiver = new MjpegReceiver(); receiver.addImageReceiver(forwarder); receiver.start("http://127.0.0.01:" + PortMappings2017.sAPP_MJPEG_PORT); }
public VisionAdbServer(int aAppBindPort, int aAppMjpegBindPort, int aAppForwardedMjpegBindPort) { super(aAppBindPort, sTIMEOUT_PERIOD); if(RobotBase.isSimulation()) { mAdb = new NativeAdbBridge(Properties2017.sADB_LOCATION.getValue(), sAPP_PACKAGE, sAPP_MAIN_ACTIVITY, Properties2017.sKILL_OLD_ADBS); } else { mAdb = new RioDroidAdbBridge(sAPP_PACKAGE, sAPP_MAIN_ACTIVITY); } mAdb.reversePortForward(aAppBindPort, aAppBindPort); mAdb.portForward(aAppMjpegBindPort, aAppForwardedMjpegBindPort); mFreshImage = false; }
/** * Initializes systems * @param robot the RobotBase to set */ public Environment(RobotBase robot) { this.robot = robot; this.input = new XboxInput(); this.accel = new AccelerometerSystem(); this.accel.init(this); this.gyro = new GyroSystem(); this.gyro.init(this); this.wheels = new WheelSystem(); this.wheels.init(this); this.shooter = new ShooterSystem(); this.shooter.init(this); this.intake = new IntakeSystem(); this.intake.init(this); this.compressor = new Compressor(2, 1); this.compressor.start(); }
@Override public void setRobot(RobotBase aRobot) { for (ISimulatorUpdater simulator : mSimulatorComponenets) { simulator.setRobot(aRobot); } }
private void createRobot() throws InstantiationException, IllegalAccessException, ClassNotFoundException { System.out.println("*************************************************************"); System.out.println("* Starting Robot Code *"); System.out.println("*************************************************************"); mRobot = (RobotBase) Class.forName(mClassName).newInstance(); }
@Override public void setRobot(RobotBase mRobot) { }
@Override public void setRobot(RobotBase aRobot) { mPositioner = ((Snobot2017) aRobot).getPositioner(); }
/** * 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(); } }
/** * Set the RobotBase * @param robot the RobotBase to set */ public RobotEnvironment(RobotBase robot) { this.setRobot(robot); }
/** * Accessor for robot * @return the robot */ protected synchronized RobotBase getRobot() { return robot; }
/** * Mutator for robot * @param robot the robot to set */ protected synchronized void setRobot(RobotBase robot) { this.robot = robot; }
public abstract void setRobot(RobotBase mRobot);