Ejemplo n.º 1
0
  public void teleopPeriodic() {
    Definitions.drivetrain.arcadeDrive(
        Definitions.xbox1.getRawAxis(1), Definitions.xbox1.getRawAxis(4), false);
    DriveShifter.checkGearShift();
    SparkyIntakeBar.loadingRoutine();
    Shooter.firingRoutine(5000);
    ArduinoComm.communicate();

    try {
      if (!backfailed && !frontfailed) {
        if (Definitions.buttonbox.getRawButton(2) && !lastbutton4) {
          if (currsession == front) {
            NIVision.IMAQdxStopAcquisition(currsession);
            currsession = back;
            NIVision.IMAQdxConfigureGrab(currsession);
          } else if (currsession == back) {
            NIVision.IMAQdxStopAcquisition(currsession);
            currsession = front;
            NIVision.IMAQdxConfigureGrab(currsession);
          }
        }
      }
      lastbutton4 = Definitions.buttonbox.getRawButton(2);
      NIVision.IMAQdxGrab(currsession, frame, 1);
      CameraServer.getInstance().setImage(frame);
    } catch (Exception e) {
      //    		System.out.println("Camera problem");
    }
    SmartDashboard.putNumber("Pressure", 250 * (Definitions.pressuretrans.getVoltage() / 5.0) - 25);
    SmartDashboard.putNumber("ballSeater", Definitions.ballholder.get() ? 1 : 0);
    SmartDashboard.putBoolean(
        "catapultReady", (250 * (Definitions.pressuretrans.getVoltage() / 5.0) - 25) > 40);

    if (Definitions.joystick.getRawButton(3) && !lastbutton3) {
      Definitions.flashlightrelay.set(
          Definitions.flashlightrelay.get() == Relay.Value.kOff
              ? Relay.Value.kForward
              : Relay.Value.kOff);
    }
    //    	System.out.println(Definitions.flashlightrelay.get());
    lastbutton3 = Definitions.joystick.getRawButton(3);
    System.out.println(Definitions.pdp.getCurrent(4));

    Timer.delay(0.01);
  }
Ejemplo n.º 2
0
  public synchronized void getImage(Image image) {
    /*if (m_needSettingsUpdate || m_useJpeg) {
      m_needSettingsUpdate = false;
      m_useJpeg = false;
      updateSettings();
    }*/

    NIVision.IMAQdxGrab(m_id, image, 1);
  }
Ejemplo n.º 3
0
  public synchronized void getImageData(ByteBuffer data) {
    if (m_needSettingsUpdate || !m_useJpeg) {
      m_needSettingsUpdate = false;
      m_useJpeg = true;
      updateSettings();
    }

    NIVision.IMAQdxGetImageData(
        m_id, data, NIVision.IMAQdxBufferNumberMode.BufferNumberModeLast, 0);
    data.limit(data.capacity() - 1);
    data.limit(getJpegSize(data));
  }
Ejemplo n.º 4
0
 public synchronized void openCamera() {
   if (m_id != -1) return; // Camera is already open
   for (int i = 0; i < 3; i++) {
     try {
       m_id =
           NIVision.IMAQdxOpenCamera(
               m_name, NIVision.IMAQdxCameraControlMode.CameraControlModeController);
     } catch (VisionException e) {
       if (i == 2) throw e;
       delay(2.0);
       continue;
     }
     break;
   }
 }
Ejemplo n.º 5
0
  public synchronized void updateSettings() {
    boolean wasActive = m_active;
    // Stop acquistion, close and reopen camera
    if (wasActive) stopCapture();
    if (m_id != -1) closeCamera();
    openCamera();

    // Video Mode
    NIVision.dxEnumerateVideoModesResult enumerated = NIVision.IMAQdxEnumerateVideoModes(m_id);
    NIVision.IMAQdxEnumItem foundMode = null;
    int foundFps = 1000;
    for (NIVision.IMAQdxEnumItem mode : enumerated.videoModeArray) {
      Matcher m = m_reMode.matcher(mode.Name);
      if (!m.matches()) continue;
      if (Integer.parseInt(m.group("width")) != m_width) continue;
      if (Integer.parseInt(m.group("height")) != m_height) continue;
      double fps = Double.parseDouble(m.group("fps"));
      if (fps < m_fps) continue;
      if (fps > foundFps) continue;
      String format = m.group("format");
      boolean isJpeg = format.equals("jpeg") || format.equals("JPEG");
      if ((m_useJpeg && !isJpeg) || (!m_useJpeg && isJpeg)) continue;
      foundMode = mode;
      foundFps = (int) fps;
    }
    if (foundMode != null) {
      System.out.println("found mode " + foundMode.Value + ": " + foundMode.Name);
      if (foundMode.Value != enumerated.currentMode)
        NIVision.IMAQdxSetAttributeU32(m_id, ATTR_VIDEO_MODE, foundMode.Value);
    }

    // White Balance
    if (m_whiteBalance == "auto") NIVision.IMAQdxSetAttributeString(m_id, ATTR_WB_MODE, "Auto");
    else {
      NIVision.IMAQdxSetAttributeString(m_id, ATTR_WB_MODE, "Manual");
      if (m_whiteBalanceValue != -1)
        NIVision.IMAQdxSetAttributeI64(m_id, ATTR_WB_VALUE, m_whiteBalanceValue);
    }

    // Exposure
    if (m_exposure == "auto")
      NIVision.IMAQdxSetAttributeString(m_id, ATTR_EX_MODE, "AutoAperaturePriority");
    else {
      NIVision.IMAQdxSetAttributeString(m_id, ATTR_EX_MODE, "Manual");
      if (m_exposureValue != -1) {
        long minv = NIVision.IMAQdxGetAttributeMinimumI64(m_id, ATTR_EX_VALUE);
        long maxv = NIVision.IMAQdxGetAttributeMaximumI64(m_id, ATTR_EX_VALUE);
        long val = minv + (long) (((double) (maxv - minv)) * (((double) m_exposureValue) / 100.0));
        // NIVision.IMAQdxSetAttributeI64(m_id, ATTR_EX_VALUE, val);
        NIVision.IMAQdxSetAttributeI64(m_id, ATTR_EX_VALUE, m_exposureValue);
      }
    }

    // Brightness
    NIVision.IMAQdxSetAttributeString(m_id, ATTR_BR_MODE, "Manual");
    long minv = NIVision.IMAQdxGetAttributeMinimumI64(m_id, ATTR_BR_VALUE);
    long maxv = NIVision.IMAQdxGetAttributeMaximumI64(m_id, ATTR_BR_VALUE);
    long val = minv + (long) (((double) (maxv - minv)) * (((double) m_brightness) / 100.0));
    NIVision.IMAQdxSetAttributeI64(m_id, ATTR_BR_VALUE, val);

    // Restart acquisition
    if (wasActive) startCapture();
  }
Ejemplo n.º 6
0
 public synchronized void stopCapture() {
   if (m_id == -1 || !m_active) return;
   NIVision.IMAQdxStopAcquisition(m_id);
   NIVision.IMAQdxUnconfigureAcquisition(m_id);
   m_active = false;
 }
Ejemplo n.º 7
0
 public synchronized void startCapture() {
   if (m_id == -1 || m_active) return;
   NIVision.IMAQdxConfigureGrab(m_id);
   NIVision.IMAQdxStartAcquisition(m_id);
   m_active = true;
 }
Ejemplo n.º 8
0
 public synchronized void closeCamera() {
   if (m_id == -1) return;
   NIVision.IMAQdxCloseCamera(m_id);
   m_id = -1;
 }