Java 类edu.wpi.first.wpilibj.can.CANJNI 实例源码

项目:Steamworks2017Robot    文件:CanDeviceFinder.java   
/**
 * Helper routine to get last received message for a given ID.
 */
private long checkMessage(int fullId, int deviceId) {
  try {
    targetId.clear();
    targetId.order(ByteOrder.LITTLE_ENDIAN);
    targetId.asIntBuffer().put(0, fullId | deviceId);

    timestamp.clear();
    timestamp.order(ByteOrder.LITTLE_ENDIAN);
    timestamp.asIntBuffer().put(0, 0x00000000);

    CANJNI.FRCNetCommCANSessionMuxReceiveMessage(targetId.asIntBuffer(), 0x1fffffff, timestamp);

    long retval = timestamp.getInt();
    retval &= 0xFFFFFFFF; /* undo sign-extension */
    return retval;
  } catch (Exception ex) {
    return -1;
  }
}
项目:2016-Stronghold    文件:CANProbe.java   
/** helper routine to get last received message for a given ID */
private long checkMessage(int fullId, int deviceID) {
    try {
        targetID.clear();
        targetID.order(ByteOrder.LITTLE_ENDIAN);
        targetID.asIntBuffer().put(0,fullId|deviceID);

        timeStamp.clear();
        timeStamp.order(ByteOrder.LITTLE_ENDIAN);
        timeStamp.asIntBuffer().put(0,0x00000000);

        CANJNI.FRCNetworkCommunicationCANSessionMuxReceiveMessage(targetID.asIntBuffer(), 0x1fffffff, timeStamp);

        long retval = timeStamp.getInt();
        retval &= 0xFFFFFFFF; /* undo sign-extension */ 
        return retval;
    } catch (Exception e) {
        return -1;
    }
}
项目:Frc2016FirstStronghold    文件:CANJaguar.java   
/**
 * Set the P constant for the closed loop modes.
 *
 * @param p The proportional gain of the Jaguar's PID controller.
 */
public void setP(double p) {
  byte[] data = new byte[8];
  byte dataSize = packFXP16_16(data, p);

  switch (m_controlMode) {
    case Speed:
      sendMessage(CANJNI.LM_API_SPD_PC, data, dataSize);
      break;

    case Position:
      sendMessage(CANJNI.LM_API_POS_PC, data, dataSize);
      break;

    case Current:
      sendMessage(CANJNI.LM_API_ICTRL_PC, data, dataSize);
      break;

    default:
      throw new IllegalStateException(
          "PID constants only apply in Speed, Position, and Current mode");
  }

  m_p = p;
  m_pVerified = false;
}
项目:Frc2016FirstStronghold    文件:CANJaguar.java   
/**
 * Set the I constant for the closed loop modes.
 *
 * @param i The integral gain of the Jaguar's PID controller.
 */
public void setI(double i) {
  byte[] data = new byte[8];
  byte dataSize = packFXP16_16(data, i);

  switch (m_controlMode) {
    case Speed:
      sendMessage(CANJNI.LM_API_SPD_IC, data, dataSize);
      break;

    case Position:
      sendMessage(CANJNI.LM_API_POS_IC, data, dataSize);
      break;

    case Current:
      sendMessage(CANJNI.LM_API_ICTRL_IC, data, dataSize);
      break;

    default:
      throw new IllegalStateException(
          "PID constants only apply in Speed, Position, and Current mode");
  }

  m_i = i;
  m_iVerified = false;
}
项目:Frc2016FirstStronghold    文件:CANJaguar.java   
/**
 * Set the D constant for the closed loop modes.
 *
 * @param d The derivative gain of the Jaguar's PID controller.
 */
public void setD(double d) {
  byte[] data = new byte[8];
  byte dataSize = packFXP16_16(data, d);

  switch (m_controlMode) {
    case Speed:
      sendMessage(CANJNI.LM_API_SPD_DC, data, dataSize);
      break;

    case Position:
      sendMessage(CANJNI.LM_API_POS_DC, data, dataSize);
      break;

    case Current:
      sendMessage(CANJNI.LM_API_ICTRL_DC, data, dataSize);
      break;

    default:
      throw new IllegalStateException(
          "PID constants only apply in Speed, Position, and Current mode");
  }

  m_d = d;
  m_dVerified = false;
}
项目:Frc2016FirstStronghold    文件:CANJaguar.java   
/**
 * Disable the closed loop controller.
 *
 * Stop driving the output based on the feedback.
 */
public void disableControl() {
  // Disable all control modes.
  sendMessage(CANJNI.LM_API_VOLT_DIS, new byte[0], 0);
  sendMessage(CANJNI.LM_API_SPD_DIS, new byte[0], 0);
  sendMessage(CANJNI.LM_API_POS_DIS, new byte[0], 0);
  sendMessage(CANJNI.LM_API_ICTRL_DIS, new byte[0], 0);
  sendMessage(CANJNI.LM_API_VCOMP_DIS, new byte[0], 0);

  // Stop all periodic setpoints
  sendMessage(CANJNI.LM_API_VOLT_T_SET, new byte[0], 0, CANJNI.CAN_SEND_PERIOD_STOP_REPEATING);
  sendMessage(CANJNI.LM_API_SPD_T_SET, new byte[0], 0, CANJNI.CAN_SEND_PERIOD_STOP_REPEATING);
  sendMessage(CANJNI.LM_API_POS_T_SET, new byte[0], 0, CANJNI.CAN_SEND_PERIOD_STOP_REPEATING);
  sendMessage(CANJNI.LM_API_ICTRL_T_SET, new byte[0], 0, CANJNI.CAN_SEND_PERIOD_STOP_REPEATING);
  sendMessage(CANJNI.LM_API_VCOMP_T_SET, new byte[0], 0, CANJNI.CAN_SEND_PERIOD_STOP_REPEATING);

  m_controlEnabled = false;
}
项目:Frc2016FirstStronghold    文件:CANJaguar.java   
/**
 * set the maximum voltage change rate.
 *
 * When in PercentVbus or Voltage output mode, the rate at which the voltage
 * changes can be limited to reduce current spikes. set this to 0.0 to disable
 * rate limiting.
 *
 * @param rampRate The maximum rate of voltage change in Percent Voltage mode
 *        in V/s.
 */
public void setVoltageRampRate(double rampRate) {
  byte[] data = new byte[8];
  int dataSize;
  int message;

  switch (m_controlMode) {
    case PercentVbus:
      dataSize = packPercentage(data, rampRate / (m_maxOutputVoltage * kControllerRate));
      message = CANJNI.LM_API_VOLT_SET_RAMP;
      break;
    case Voltage:
      dataSize = packFXP8_8(data, rampRate / kControllerRate);
      message = CANJNI.LM_API_VCOMP_COMP_RAMP;
      break;
    default:
      throw new IllegalStateException(
          "Voltage ramp rate only applies in Percentage and Voltage modes");
  }

  sendMessage(message, data, dataSize);
}
项目:Frc2016FirstStronghold    文件:CANJaguar.java   
/**
 * Get a previously requested message.
 *
 * Jaguar always generates a message with the same message ID when replying.
 *
 * @param messageID The messageID to read from the CAN bus (device number is
 *        added internally)
 * @param data The up to 8 bytes of data that was received with the message
 *
 * @throws CANMessageNotFoundException if there's not new message available
 */
protected void getMessage(int messageID, int messageMask, byte[] data)
    throws CANMessageNotFoundException {
  messageID |= m_deviceNumber;
  messageID &= CANJNI.CAN_MSGID_FULL_M;

  ByteBuffer targetedMessageID = ByteBuffer.allocateDirect(4);
  targetedMessageID.order(ByteOrder.LITTLE_ENDIAN);
  targetedMessageID.asIntBuffer().put(0, messageID);

  ByteBuffer timeStamp = ByteBuffer.allocateDirect(4);

  // Get the data.
  ByteBuffer dataBuffer =
      CANJNI.FRCNetworkCommunicationCANSessionMuxReceiveMessage(targetedMessageID.asIntBuffer(),
          messageMask, timeStamp);

  if (data != null) {
    for (int i = 0; i < dataBuffer.capacity(); i++) {
      data[i] = dataBuffer.get(i);
    }
  }
}
项目:Frc2016FirstStronghold    文件:CANJaguar.java   
/**
 * Cancel periodic messages to the Jaguar, effectively disabling it. No other
 * methods should be called after this is called.
 */
public void free() {
  allocated.free(m_deviceNumber - 1);
  m_safetyHelper = null;

  int messageID;

  // Disable periodic setpoints
  switch (m_controlMode) {
    case PercentVbus:
      messageID = m_deviceNumber | CANJNI.LM_API_VOLT_T_SET;
      break;

    case Speed:
      messageID = m_deviceNumber | CANJNI.LM_API_SPD_T_SET;
      break;

    case Position:
      messageID = m_deviceNumber | CANJNI.LM_API_POS_T_SET;
      break;

    case Current:
      messageID = m_deviceNumber | CANJNI.LM_API_ICTRL_T_SET;
      break;

    case Voltage:
      messageID = m_deviceNumber | CANJNI.LM_API_VCOMP_T_SET;
      break;

    default:
      return;
  }

  CANJNI.FRCNetworkCommunicationCANSessionMuxSendMessage(messageID, null,
      CANJNI.CAN_SEND_PERIOD_STOP_REPEATING);

  configMaxOutputVoltage(kApproxBusVoltage);
}
项目:Frc2016FirstStronghold    文件:CANJaguar.java   
/**
 * Enable the closed loop controller.
 *
 * Start actually controlling the output based on the feedback. If starting a
 * position controller with an encoder reference, use the
 * encoderInitialPosition parameter to initialize the encoder state.
 *
 * @param encoderInitialPosition Encoder position to set if position with
 *        encoder reference. Ignored otherwise.
 */
public void enableControl(double encoderInitialPosition) {
  switch (m_controlMode) {
    case PercentVbus:
      sendMessage(CANJNI.LM_API_VOLT_T_EN, new byte[0], 0);
      break;

    case Speed:
      sendMessage(CANJNI.LM_API_SPD_T_EN, new byte[0], 0);
      break;

    case Position:
      byte[] data = new byte[8];
      int dataSize = packFXP16_16(data, encoderInitialPosition);
      sendMessage(CANJNI.LM_API_POS_T_EN, data, dataSize);
      break;

    case Current:
      sendMessage(CANJNI.LM_API_ICTRL_T_EN, new byte[0], 0);
      break;

    case Voltage:
      sendMessage(CANJNI.LM_API_VCOMP_T_EN, new byte[0], 0);
      break;
  }

  m_controlEnabled = true;
}
项目:Frc2016FirstStronghold    文件:CANJaguar.java   
/**
 * Enable controlling the motor voltage with position feedback from a
 * potentiometer and no speed feedback.
 *
 * @param tag The constant {@link CANJaguar#kPotentiometer}
 */
public void setVoltageMode(PotentiometerTag tag) {
  changeControlMode(JaguarControlMode.Voltage);
  setPositionReference(CANJNI.LM_REF_POT);
  setSpeedReference(CANJNI.LM_REF_NONE);
  configPotentiometerTurns(1);
}
项目:Frc2016FirstStronghold    文件:CANJaguar.java   
/**
 * Configure how many codes per revolution are generated by your encoder.
 *
 * @param codesPerRev The number of counts per revolution in 1X mode.
 */
public void configEncoderCodesPerRev(int codesPerRev) {
  byte[] data = new byte[8];

  int dataSize = packINT16(data, (short) codesPerRev);
  sendMessage(CANJNI.LM_API_CFG_ENC_LINES, data, dataSize);

  m_encoderCodesPerRev = (short) codesPerRev;
  m_encoderCodesPerRevVerified = false;
}
项目:Frc2016FirstStronghold    文件:CANJaguar.java   
/**
 * Configure the number of turns on the potentiometer.
 *
 * There is no special support for continuous turn potentiometers. Only
 * integer numbers of turns are supported.
 *
 * @param turns The number of turns of the potentiometer
 */
public void configPotentiometerTurns(int turns) {
  byte[] data = new byte[8];

  int dataSize = packINT16(data, (short) turns);
  sendMessage(CANJNI.LM_API_CFG_POT_TURNS, data, dataSize);

  m_potentiometerTurns = (short) turns;
  m_potentiometerTurnsVerified = false;
}
项目:Frc2016FirstStronghold    文件:CANJaguar.java   
/**
 * Set the position that, if exceeded, will disable the forward direction.
 *
 * Use {@link #configSoftPositionLimits(double, double)} to set this and the
 * {@link LimitMode} automatically.
 *$
 * @param forwardLimitPosition The position that, if exceeded, will disable
 *        the forward direction.
 */
public void configForwardLimit(double forwardLimitPosition) {
  byte[] data = new byte[8];

  int dataSize = packFXP16_16(data, forwardLimitPosition);
  data[dataSize++] = 1;
  sendMessage(CANJNI.LM_API_CFG_LIMIT_FWD, data, dataSize);

  m_forwardLimit = forwardLimitPosition;
  m_forwardLimitVerified = false;
}
项目:Frc2016FirstStronghold    文件:CANJaguar.java   
/**
 * Set the position that, if exceeded, will disable the reverse direction.
 *
 * Use {@link #configSoftPositionLimits(double, double)} to set this and the
 * {@link LimitMode} automatically.
 *$
 * @param reverseLimitPosition The position that, if exceeded, will disable
 *        the reverse direction.
 */
public void configReverseLimit(double reverseLimitPosition) {
  byte[] data = new byte[8];

  int dataSize = packFXP16_16(data, reverseLimitPosition);
  data[dataSize++] = 1;
  sendMessage(CANJNI.LM_API_CFG_LIMIT_REV, data, dataSize);

  m_reverseLimit = reverseLimitPosition;
  m_reverseLimitVerified = false;
}
项目:Frc2016FirstStronghold    文件:CANJaguar.java   
/**
 * Configure the maximum voltage that the Jaguar will ever output.
 *
 * This can be used to limit the maximum output voltage in all modes so that
 * motors which cannot withstand full bus voltage can be used safely.
 *
 * @param voltage The maximum voltage output by the Jaguar.
 */
public void configMaxOutputVoltage(double voltage) {
  byte[] data = new byte[8];

  int dataSize = packFXP8_8(data, voltage);
  sendMessage(CANJNI.LM_API_CFG_MAX_VOUT, data, dataSize);

  m_maxOutputVoltage = voltage;
  m_maxOutputVoltageVerified = false;
}
项目:Frc2016FirstStronghold    文件:CANJaguar.java   
/**
 * Configure how long the Jaguar waits in the case of a fault before resuming
 * operation.
 *
 * Faults include over temerature, over current, and bus under voltage. The
 * default is 3.0 seconds, but can be reduced to as low as 0.5 seconds.
 *
 * @param faultTime The time to wait before resuming operation, in seconds.
 */
public void configFaultTime(float faultTime) {
  byte[] data = new byte[8];

  if (faultTime < 0.5f)
    faultTime = 0.5f;
  else if (faultTime > 3.0f)
    faultTime = 3.0f;

  int dataSize = packINT16(data, (short) (faultTime * 1000.0));
  sendMessage(CANJNI.LM_API_CFG_FAULT_TIME, data, dataSize);

  m_faultTime = faultTime;
  m_faultTimeVerified = false;
}
项目:Frc2016FirstStronghold    文件:CANJaguar.java   
/**
 * Enables periodic status updates from the Jaguar
 */
protected void setupPeriodicStatus() {
  byte[] data = new byte[8];
  int dataSize;

  // Message 0 returns bus voltage, output voltage, output current, and
  // temperature.
  final byte[] kMessage0Data =
      new byte[] {CANJNI.LM_PSTAT_VOLTBUS_B0, CANJNI.LM_PSTAT_VOLTBUS_B1,
          CANJNI.LM_PSTAT_VOLTOUT_B0, CANJNI.LM_PSTAT_VOLTOUT_B1, CANJNI.LM_PSTAT_CURRENT_B0,
          CANJNI.LM_PSTAT_CURRENT_B1, CANJNI.LM_PSTAT_TEMP_B0, CANJNI.LM_PSTAT_TEMP_B1};

  // Message 1 returns position and speed
  final byte[] kMessage1Data =
      new byte[] {CANJNI.LM_PSTAT_POS_B0, CANJNI.LM_PSTAT_POS_B1, CANJNI.LM_PSTAT_POS_B2,
          CANJNI.LM_PSTAT_POS_B3, CANJNI.LM_PSTAT_SPD_B0, CANJNI.LM_PSTAT_SPD_B1,
          CANJNI.LM_PSTAT_SPD_B2, CANJNI.LM_PSTAT_SPD_B3};

  // Message 2 returns limits and faults
  final byte[] kMessage2Data =
      new byte[] {CANJNI.LM_PSTAT_LIMIT_CLR, CANJNI.LM_PSTAT_FAULT, CANJNI.LM_PSTAT_END,
          (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0,};

  dataSize = packINT16(data, (short) (kSendMessagePeriod));
  sendMessage(CANJNI.LM_API_PSTAT_PER_EN_S0, data, dataSize);
  sendMessage(CANJNI.LM_API_PSTAT_PER_EN_S1, data, dataSize);
  sendMessage(CANJNI.LM_API_PSTAT_PER_EN_S2, data, dataSize);

  dataSize = 8;
  sendMessage(CANJNI.LM_API_PSTAT_CFG_S0, kMessage0Data, dataSize);
  sendMessage(CANJNI.LM_API_PSTAT_CFG_S1, kMessage1Data, dataSize);
  sendMessage(CANJNI.LM_API_PSTAT_CFG_S2, kMessage2Data, dataSize);
}
项目:Frc2016FirstStronghold    文件:CANJaguar.java   
/**
 * Update all the motors that have pending sets in the syncGroup.
 *
 * @param syncGroup A bitmask of groups to generate synchronous output.
 */
public static void updateSyncGroup(byte syncGroup) {
  byte[] data = new byte[8];

  data[0] = syncGroup;

  sendMessageHelper(CANJNI.CAN_MSGID_API_SYNC, data, 1, CANJNI.CAN_SEND_PERIOD_NO_REPEAT);
}
项目:Robot_2016    文件:Robot.java   
void sendStateToLights(boolean isEnabled, boolean isAutonomous)
    {
 //     final int MSGID_FOR_LIGHTS = CANJNI.LM_API_ICTRL_T_SET | 0x30; // ID=59

        // LM_API_ICTRL_T_SET =((0x00020000 | 0x02000000 | 0x00001000) | (7 << 6));
        // Final ID: 0x020211FB
        // (7 < 6) => 111000000 => 0x1C0
        // Decoded on Ardinio as 0x1F02033B
        // Random: 0x2041441

        // DO NOT CHANGE THIS NUMBER
        // Doug and Justin worked for a long while to find an ID that works.
        // We are using CAN ID 16 (0x10) Bigger IDs don't seem to work.
        final int MSGID_FOR_LIGHTS = 0x02021451;

        timer = System.currentTimeMillis();
        if ( timer > lastRunTime + 100 ) // At least 100 ms difference.
        {
            lastRunTime = timer;

            CAN_data.put(0, (byte)(isAutonomous ? 0 : 1) );
            CAN_data.put(1, (byte)(isBlue ? 0 : 1) );
            CAN_data.put(2, (byte)(isEnabled ? 1 : 0) );
            CAN_data.put(3, (byte)(isSpinning ? 1 : 0) );
            //CAN_data.put(3, (byte)(rightTriggerPressed ? 1 : 0) );

            CAN_data.put(4, (byte)(isShooting ? 1 : 0) );
            CAN_data.put(5, (byte)(isExpelling ? 1 : 0) );
            CAN_data.put(6, (byte)(leftTriggerPressed ? 1: 0) );
//          CAN_data.put(6, (byte)(isIngesting ? 1 : 0) );
            CAN_data.put(7, (byte)0);

            try 
            {
                CANJNI.FRCNetworkCommunicationCANSessionMuxSendMessage(MSGID_FOR_LIGHTS, CAN_data, CANJNI.CAN_SEND_PERIOD_NO_REPEAT);
            } 
            catch (Exception e) 
            {
//              e.printStackTrace();
            }

        }
    }
项目:Frc2016FirstStronghold    文件:CANJaguar.java   
/**
 * Sets the output set-point value.
 *
 * The scale and the units depend on the mode the Jaguar is in.<br>
 * In percentVbus Mode, the outputValue is from -1.0 to 1.0 (same as PWM
 * Jaguar).<br>
 * In voltage Mode, the outputValue is in volts. <br>
 * In current Mode, the outputValue is in amps.<br>
 * In speed mode, the outputValue is in rotations/minute.<br>
 * In position Mode, the outputValue is in rotations.
 *
 * @param outputValue The set-point to sent to the motor controller.
 * @param syncGroup The update group to add this set() to, pending
 *        UpdateSyncGroup(). If 0, update immediately.
 */
@Override
public void set(double outputValue, byte syncGroup) {
  int messageID;
  byte[] data = new byte[8];
  byte dataSize;

  if (m_safetyHelper != null)
    m_safetyHelper.feed();

  if (m_stopped) {
    enableControl();
    m_stopped = false;
  }

  if (m_controlEnabled) {
    switch (m_controlMode) {
      case PercentVbus:
        messageID = CANJNI.LM_API_VOLT_T_SET;
        dataSize = packPercentage(data, isInverted ? -outputValue : outputValue);
        break;

      case Speed:
        messageID = CANJNI.LM_API_SPD_T_SET;
        dataSize = packFXP16_16(data, isInverted ? -outputValue : outputValue);
        break;

      case Position:
        messageID = CANJNI.LM_API_POS_T_SET;
        dataSize = packFXP16_16(data, outputValue);
        break;

      case Current:
        messageID = CANJNI.LM_API_ICTRL_T_SET;
        dataSize = packFXP8_8(data, outputValue);
        break;


      case Voltage:
        messageID = CANJNI.LM_API_VCOMP_T_SET;
        dataSize = packFXP8_8(data, isInverted ? -outputValue : outputValue);
        break;

      default:
        return;
    }

    if (syncGroup != 0) {
      data[dataSize++] = syncGroup;
    }

    sendMessage(messageID, data, dataSize, kSendMessagePeriod);
  }

  m_value = outputValue;

  verify();
}
项目:Frc2016FirstStronghold    文件:CANJaguar.java   
static void sendMessageHelper(int messageID, byte[] data, int dataSize, int period)
    throws CANMessageNotFoundException {
  final int[] kTrustedMessages =
      {CANJNI.LM_API_VOLT_T_EN, CANJNI.LM_API_VOLT_T_SET, CANJNI.LM_API_SPD_T_EN,
          CANJNI.LM_API_SPD_T_SET, CANJNI.LM_API_VCOMP_T_EN, CANJNI.LM_API_VCOMP_T_SET,
          CANJNI.LM_API_POS_T_EN, CANJNI.LM_API_POS_T_SET, CANJNI.LM_API_ICTRL_T_EN,
          CANJNI.LM_API_ICTRL_T_SET};

  for (byte i = 0; i < kTrustedMessages.length; i++) {
    if ((kFullMessageIDMask & messageID) == kTrustedMessages[i]) {
      // Make sure the data will still fit after adjusting for the token.
      if (dataSize > kMaxMessageDataSize - 2) {
        throw new RuntimeException("CAN message has too much data.");
      }

      ByteBuffer trustedBuffer = ByteBuffer.allocateDirect(dataSize + 2);
      trustedBuffer.put(0, (byte) 0);
      trustedBuffer.put(1, (byte) 0);

      for (byte j = 0; j < dataSize; j++) {
        trustedBuffer.put(j + 2, data[j]);
      }

      CANJNI.FRCNetworkCommunicationCANSessionMuxSendMessage(messageID, trustedBuffer, period);

      return;
    }
  }

  // Use a null pointer for the data buffer if the given array is null
  ByteBuffer buffer;
  if (data != null) {
    buffer = ByteBuffer.allocateDirect(dataSize);
    for (byte i = 0; i < dataSize; i++) {
      buffer.put(i, data[i]);
    }
  } else {
    buffer = null;
  }

  CANJNI.FRCNetworkCommunicationCANSessionMuxSendMessage(messageID, buffer, period);
}
项目:Frc2016FirstStronghold    文件:CANJaguar.java   
/**
 * Set the reference source device for speed controller mode.
 *
 * Choose encoder as the source of speed feedback when in speed control mode.
 *
 * @param reference Specify a speed reference.
 */
private void setSpeedReference(int reference) {
  sendMessage(CANJNI.LM_API_SPD_REF, new byte[] {(byte) reference}, 1);

  m_speedReference = reference;
  m_speedRefVerified = false;
}
项目:Frc2016FirstStronghold    文件:CANJaguar.java   
/**
 * Set the reference source device for position controller mode.
 *
 * Choose between using and encoder and using a potentiometer as the source of
 * position feedback when in position control mode.
 *
 * @param reference Specify a position reference.
 */
private void setPositionReference(int reference) {
  sendMessage(CANJNI.LM_API_POS_REF, new byte[] {(byte) reference}, 1);

  m_positionReference = reference;
  m_posRefVerified = false;
}
项目:Frc2016FirstStronghold    文件:CANJaguar.java   
/**
 * Enable controlling the motor voltage as a percentage of the bus voltage,
 * and enable speed sensing from a non-quadrature encoder.<br>
 * After calling this you must call {@link CANJaguar#enableControl()} or
 * {@link CANJaguar#enableControl(double)} to enable the device.
 *
 * @param tag The constant {@link CANJaguar#kEncoder}
 * @param codesPerRev The counts per revolution on the encoder
 */
public void setPercentMode(EncoderTag tag, int codesPerRev) {
  changeControlMode(JaguarControlMode.PercentVbus);
  setPositionReference(CANJNI.LM_REF_NONE);
  setSpeedReference(CANJNI.LM_REF_ENCODER);
  configEncoderCodesPerRev(codesPerRev);
}
项目:Frc2016FirstStronghold    文件:CANJaguar.java   
/**
 * Enable controlling the motor voltage as a percentage of the bus voltage,
 * and enable position and speed sensing from a quadrature encoder.<br>
 * After calling this you must call {@link CANJaguar#enableControl()} or
 * {@link CANJaguar#enableControl(double)} to enable the device.
 *
 * @param tag The constant {@link CANJaguar#kQuadEncoder}
 * @param codesPerRev The counts per revolution on the encoder
 */
public void setPercentMode(QuadEncoderTag tag, int codesPerRev) {
  changeControlMode(JaguarControlMode.PercentVbus);
  setPositionReference(CANJNI.LM_REF_ENCODER);
  setSpeedReference(CANJNI.LM_REF_QUAD_ENCODER);
  configEncoderCodesPerRev(codesPerRev);
}
项目:Frc2016FirstStronghold    文件:CANJaguar.java   
/**
 * Enable controlling the motor voltage as a percentage of the bus voltage,
 * and enable position sensing from a potentiometer and no speed feedback.<br>
 * After calling this you must call {@link CANJaguar#enableControl()} or
 * {@link CANJaguar#enableControl(double)} to enable the device.
 *
 * @param tag The constant {@link CANJaguar#kPotentiometer}
 */
public void setPercentMode(PotentiometerTag tag) {
  changeControlMode(JaguarControlMode.PercentVbus);
  setPositionReference(CANJNI.LM_REF_POT);
  setSpeedReference(CANJNI.LM_REF_NONE);
  configPotentiometerTurns(1);
}
项目:Frc2016FirstStronghold    文件:CANJaguar.java   
/**
 * Enable controlling the motor current with a PID loop.<br>
 * After calling this you must call {@link CANJaguar#enableControl()} or
 * {@link CANJaguar#enableControl(double)} to enable the device.
 *
 * @param p The proportional gain of the Jaguar's PID controller.
 * @param i The integral gain of the Jaguar's PID controller.
 * @param d The differential gain of the Jaguar's PID controller.
 */
public void setCurrentMode(double p, double i, double d) {
  changeControlMode(JaguarControlMode.Current);
  setPositionReference(CANJNI.LM_REF_NONE);
  setSpeedReference(CANJNI.LM_REF_NONE);
  setPID(p, i, d);
}
项目:Frc2016FirstStronghold    文件:CANJaguar.java   
/**
 * Enable controlling the motor current with a PID loop, and enable speed
 * sensing from a non-quadrature encoder.<br>
 * After calling this you must call {@link CANJaguar#enableControl()} or
 * {@link CANJaguar#enableControl(double)} to enable the device.
 *
 * @param tag The constant {@link CANJaguar#kEncoder}
 * @param p The proportional gain of the Jaguar's PID controller.
 * @param i The integral gain of the Jaguar's PID controller.
 * @param d The differential gain of the Jaguar's PID controller.
 */
public void setCurrentMode(EncoderTag tag, int codesPerRev, double p, double i, double d) {
  changeControlMode(JaguarControlMode.Current);
  setPositionReference(CANJNI.LM_REF_NONE);
  setSpeedReference(CANJNI.LM_REF_NONE);
  configEncoderCodesPerRev(codesPerRev);
  setPID(p, i, d);
}
项目:Frc2016FirstStronghold    文件:CANJaguar.java   
/**
 * Enable controlling the motor current with a PID loop, and enable speed and
 * position sensing from a quadrature encoder.<br>
 * After calling this you must call {@link CANJaguar#enableControl()} or
 * {@link CANJaguar#enableControl(double)} to enable the device.
 *
 * @param tag The constant {@link CANJaguar#kQuadEncoder}
 * @param p The proportional gain of the Jaguar's PID controller.
 * @param i The integral gain of the Jaguar's PID controller.
 * @param d The differential gain of the Jaguar's PID controller.
 */
public void setCurrentMode(QuadEncoderTag tag, int codesPerRev, double p, double i, double d) {
  changeControlMode(JaguarControlMode.Current);
  setPositionReference(CANJNI.LM_REF_ENCODER);
  setSpeedReference(CANJNI.LM_REF_QUAD_ENCODER);
  configEncoderCodesPerRev(codesPerRev);
  setPID(p, i, d);
}
项目:Frc2016FirstStronghold    文件:CANJaguar.java   
/**
 * Enable controlling the motor current with a PID loop, and enable position
 * sensing from a potentiometer.<br>
 * After calling this you must call {@link CANJaguar#enableControl()} or
 * {@link CANJaguar#enableControl(double)} to enable the device.
 *
 * @param tag The constant {@link CANJaguar#kPotentiometer}
 * @param p The proportional gain of the Jaguar's PID controller.
 * @param i The integral gain of the Jaguar's PID controller.
 * @param d The differential gain of the Jaguar's PID controller.
 */
public void setCurrentMode(PotentiometerTag tag, double p, double i, double d) {
  changeControlMode(JaguarControlMode.Current);
  setPositionReference(CANJNI.LM_REF_POT);
  setSpeedReference(CANJNI.LM_REF_NONE);
  configPotentiometerTurns(1);
  setPID(p, i, d);
}
项目:Frc2016FirstStronghold    文件:CANJaguar.java   
/**
 * Enable controlling the speed with a feedback loop from a non-quadrature
 * encoder.<br>
 * After calling this you must call {@link CANJaguar#enableControl()} or
 * {@link CANJaguar#enableControl(double)} to enable the device.
 *
 * @param tag The constant {@link CANJaguar#kEncoder}
 * @param codesPerRev The counts per revolution on the encoder
 * @param p The proportional gain of the Jaguar's PID controller.
 * @param i The integral gain of the Jaguar's PID controller.
 * @param d The differential gain of the Jaguar's PID controller.
 */
public void setSpeedMode(EncoderTag tag, int codesPerRev, double p, double i, double d) {
  changeControlMode(JaguarControlMode.Speed);
  setPositionReference(CANJNI.LM_REF_NONE);
  setSpeedReference(CANJNI.LM_REF_ENCODER);
  configEncoderCodesPerRev(codesPerRev);
  setPID(p, i, d);
}
项目:Frc2016FirstStronghold    文件:CANJaguar.java   
/**
 * Enable controlling the speed with a feedback loop from a quadrature
 * encoder.<br>
 * After calling this you must call {@link CANJaguar#enableControl()} or
 * {@link CANJaguar#enableControl(double)} to enable the device.
 *
 * @param tag The constant {@link CANJaguar#kQuadEncoder}
 * @param codesPerRev The counts per revolution on the encoder
 * @param p The proportional gain of the Jaguar's PID controller.
 * @param i The integral gain of the Jaguar's PID controller.
 * @param d The differential gain of the Jaguar's PID controller.
 */
public void setSpeedMode(QuadEncoderTag tag, int codesPerRev, double p, double i, double d) {
  changeControlMode(JaguarControlMode.Speed);
  setPositionReference(CANJNI.LM_REF_ENCODER);
  setSpeedReference(CANJNI.LM_REF_QUAD_ENCODER);
  configEncoderCodesPerRev(codesPerRev);
  setPID(p, i, d);
}
项目:Frc2016FirstStronghold    文件:CANJaguar.java   
/**
 * Enable controlling the position with a feedback loop using an encoder.<br>
 * After calling this you must call {@link CANJaguar#enableControl()} or
 * {@link CANJaguar#enableControl(double)} to enable the device.
 *
 * @param tag The constant {@link CANJaguar#kQuadEncoder}
 * @param codesPerRev The counts per revolution on the encoder
 * @param p The proportional gain of the Jaguar's PID controller.
 * @param i The integral gain of the Jaguar's PID controller.
 * @param d The differential gain of the Jaguar's PID controller.
 *
 */
public void setPositionMode(QuadEncoderTag tag, int codesPerRev, double p, double i, double d) {
  changeControlMode(JaguarControlMode.Position);
  setPositionReference(CANJNI.LM_REF_ENCODER);
  configEncoderCodesPerRev(codesPerRev);
  setPID(p, i, d);
}
项目:Frc2016FirstStronghold    文件:CANJaguar.java   
/**
 * Enable controlling the position with a feedback loop using a potentiometer.<br>
 * After calling this you must call {@link CANJaguar#enableControl()} or
 * {@link CANJaguar#enableControl(double)} to enable the device.
 *
 * @param tag The constant {@link CANJaguar#kPotentiometer}
 * @param p The proportional gain of the Jaguar's PID controller.
 * @param i The integral gain of the Jaguar's PID controller.
 * @param d The differential gain of the Jaguar's PID controller.
 */
public void setPositionMode(PotentiometerTag tag, double p, double i, double d) {
  changeControlMode(JaguarControlMode.Position);
  setPositionReference(CANJNI.LM_REF_POT);
  configPotentiometerTurns(1);
  setPID(p, i, d);
}
项目:Frc2016FirstStronghold    文件:CANJaguar.java   
/**
 * Enable controlling the motor voltage with speed feedback from a
 * non-quadrature encoder and no position feedback.<br>
 * After calling this you must call {@link CANJaguar#enableControl()} or
 * {@link CANJaguar#enableControl(double)} to enable the device.
 *
 * @param tag The constant {@link CANJaguar#kEncoder}
 * @param codesPerRev The counts per revolution on the encoder
 */
public void setVoltageMode(EncoderTag tag, int codesPerRev) {
  changeControlMode(JaguarControlMode.Voltage);
  setPositionReference(CANJNI.LM_REF_NONE);
  setSpeedReference(CANJNI.LM_REF_ENCODER);
  configEncoderCodesPerRev(codesPerRev);
}
项目:Frc2016FirstStronghold    文件:CANJaguar.java   
/**
 * Enable controlling the motor voltage with position and speed feedback from
 * a quadrature encoder.<br>
 * After calling this you must call {@link CANJaguar#enableControl()} or
 * {@link CANJaguar#enableControl(double)} to enable the device.
 *
 * @param tag The constant {@link CANJaguar#kQuadEncoder}
 * @param codesPerRev The counts per revolution on the encoder
 */
public void setVoltageMode(QuadEncoderTag tag, int codesPerRev) {
  changeControlMode(JaguarControlMode.Voltage);
  setPositionReference(CANJNI.LM_REF_ENCODER);
  setSpeedReference(CANJNI.LM_REF_QUAD_ENCODER);
  configEncoderCodesPerRev(codesPerRev);
}
项目:Frc2016FirstStronghold    文件:CANJaguar.java   
/**
 * Configure what the controller does to the H-Bridge when neutral (not
 * driving the output).
 *
 * This allows you to override the jumper configuration for brake or coast.
 *
 * @param mode Select to use the jumper setting or to override it to coast or
 *        brake.
 */
public void configNeutralMode(NeutralMode mode) {
  sendMessage(CANJNI.LM_API_CFG_BRAKE_COAST, new byte[] {mode.value}, 1);

  m_neutralMode = mode;
  m_neutralModeVerified = false;
}
项目:Frc2016FirstStronghold    文件:CANJaguar.java   
/**
 * Enable controlling the motor voltage as a percentage of the bus voltage
 * without any position or speed feedback.<br>
 * After calling this you must call {@link CANJaguar#enableControl()} or
 * {@link CANJaguar#enableControl(double)} to enable the device.
 */
public void setPercentMode() {
  changeControlMode(JaguarControlMode.PercentVbus);
  setPositionReference(CANJNI.LM_REF_NONE);
  setSpeedReference(CANJNI.LM_REF_NONE);
}
项目:Frc2016FirstStronghold    文件:CANJaguar.java   
/**
 * Enable controlling the motor voltage without any position or speed
 * feedback.<br>
 * After calling this you must call {@link CANJaguar#enableControl()} or
 * {@link CANJaguar#enableControl(double)} to enable the device.
 */
public void setVoltageMode() {
  changeControlMode(JaguarControlMode.Voltage);
  setPositionReference(CANJNI.LM_REF_NONE);
  setSpeedReference(CANJNI.LM_REF_NONE);
}