コード例 #1
0
ファイル: PWM.java プロジェクト: ArcticWarriors/snobot-2016
  /**
   * Initialize PWMs given a channel.
   *
   * <p>This method is private and is the common path for all the constructors for creating PWM
   * instances. Checks channel value ranges and allocates the appropriate channel. The allocation is
   * only done to help users ensure that they don't double assign channels. $
   *
   * @param channel The PWM channel number. 0-9 are on-board, 10-19 are on the MXP port
   */
  private void initPWM(final int channel) {
    checkPWMChannel(channel);
    m_channel = channel;

    m_port = DIOJNI.initializeDigitalPort(DIOJNI.getPort((byte) m_channel));

    if (!PWMJNI.allocatePWMChannel(m_port)) {
      throw new AllocationException("PWM channel " + channel + " is already allocated");
    }

    PWMJNI.setPWM(m_port, (short) 0);

    m_eliminateDeadband = false;

    UsageReporting.report(tResourceType.kResourceType_PWM, channel);
  }
コード例 #2
0
ファイル: DigitalInput.java プロジェクト: Team766/RRB4J
 /**
  * Get the value from a digital input channel. Retrieve the value of a single digital input
  * channel from the FPGA.
  *
  * @return the status of the digital input
  */
 public boolean get() {
   ByteBuffer status = ByteBuffer.allocateDirect(4);
   // set the byte order
   status.order(ByteOrder.LITTLE_ENDIAN);
   boolean value = DIOJNI.getDIO(m_port, status.asIntBuffer()) != 0;
   HALUtil.checkStatus(status.asIntBuffer());
   return value;
 }
コード例 #3
0
ファイル: PWM.java プロジェクト: ArcticWarriors/snobot-2016
 /**
  * Free the PWM channel.
  *
  * <p>Free the resource associated with the PWM channel and set the value to 0.
  */
 public void free() {
   if (m_port == 0) return;
   PWMJNI.setPWM(m_port, (short) 0);
   PWMJNI.freePWMChannel(m_port);
   PWMJNI.freeDIO(m_port);
   DIOJNI.freeDigitalPort(m_port);
   m_port = 0;
 }
コード例 #4
0
ファイル: PWM.java プロジェクト: ArcticWarriors/snobot-2016
  /**
   * Set the bounds on the PWM pulse widths. This sets the bounds on the PWM values for a particular
   * type of controller. The values determine the upper and lower speeds as well as the deadband
   * bracket. $
   *
   * @param max The max PWM pulse width in ms
   * @param deadbandMax The high end of the deadband range pulse width in ms
   * @param center The center (off) pulse width in ms
   * @param deadbandMin The low end of the deadband pulse width in ms
   * @param min The minimum pulse width in ms
   */
  protected void setBounds(
      double max, double deadbandMax, double center, double deadbandMin, double min) {
    double loopTime = DIOJNI.getLoopTiming() / (kSystemClockTicksPerMicrosecond * 1e3);

    m_maxPwm = (int) ((max - kDefaultPwmCenter) / loopTime + kDefaultPwmStepsDown - 1);
    m_deadbandMaxPwm =
        (int) ((deadbandMax - kDefaultPwmCenter) / loopTime + kDefaultPwmStepsDown - 1);
    m_centerPwm = (int) ((center - kDefaultPwmCenter) / loopTime + kDefaultPwmStepsDown - 1);
    m_deadbandMinPwm =
        (int) ((deadbandMin - kDefaultPwmCenter) / loopTime + kDefaultPwmStepsDown - 1);
    m_minPwm = (int) ((min - kDefaultPwmCenter) / loopTime + kDefaultPwmStepsDown - 1);
  }