Ejemplo n.º 1
0
/**
 * Sets the maximum period for stopped detection.
 * Sets the value that represents the maximum period of the Encoder before it will assume
 * that the attached device is stopped. This timeout allows users to determine if the wheels or
 * other shaft has stopped rotating.
 * This method compensates for the decoding type.
 * 
 * @deprecated Use SetMinRate() in favor of this method.  This takes unscaled periods and SetMinRate() scales using value from SetDistancePerPulse().
 * 
 * @param maxPeriod The maximum time between rising and falling edges before the FPGA will
 * report the device stopped. This is expressed in seconds.
 */
void Encoder::SetMaxPeriod(double maxPeriod)
{
	if (m_counter)
	{
		m_counter->SetMaxPeriod(maxPeriod * DecodingScaleFactor());
	}
	else
	{
		m_encoder->writeTimerConfig_StallPeriod((UINT32)(maxPeriod * 1.0e6 * DecodingScaleFactor()), &status);
		wpi_assertCleanStatus(status);
	}
}
Ejemplo n.º 2
0
/**
 * Sets the maximum period for stopped detection.
 * Sets the value that represents the maximum period of the Encoder before it will assume
 * that the attached device is stopped. This timeout allows users to determine if the wheels or
 * other shaft has stopped rotating.
 * This method compensates for the decoding type.
 * 
 * @deprecated Use SetMinRate() in favor of this method.  This takes unscaled periods and SetMinRate() scales using value from SetDistancePerPulse().
 * 
 * @param maxPeriod The maximum time between rising and falling edges before the FPGA will
 * report the device stopped. This is expressed in seconds.
 */
void Encoder::SetMaxPeriod(double maxPeriod)
{
    if (StatusIsFatal()) return;
    if (m_counter)
    {
        m_counter->SetMaxPeriod(maxPeriod * DecodingScaleFactor());
    }
    else
    {
        tRioStatusCode localStatus = NiFpga_Status_Success;
        m_encoder->writeTimerConfig_StallPeriod((UINT32)(maxPeriod * 1.0e6 * DecodingScaleFactor()), &localStatus);
        wpi_setError(localStatus);
    }
}
Ejemplo n.º 3
0
/**
 * Returns the period of the most recent pulse.
 * Returns the period of the most recent Encoder pulse in seconds.
 * This method compenstates for the decoding type.
 * 
 * @deprecated Use GetRate() in favor of this method.  This returns unscaled periods and GetRate() scales using value from SetDistancePerPulse().
 *
 * @return Period in seconds of the most recent pulse.
 */
double Encoder::GetPeriod()
{
	double measuredPeriod;
	if (m_counter)
	{
		measuredPeriod = m_counter->GetPeriod();
	}
	else
	{
		tEncoder::tTimerOutput output = m_encoder->readTimerOutput(&status);
		double value;
		if (output.Stalled)
		{
			// Return infinity
			double zero = 0.0;
			value = 1.0 / zero;
		}
		else
		{
			// output.Period is a fixed point number that counts by 2 (24 bits, 25 integer bits)
			value = (double)(output.Period << 1) / (double)output.Count;
		}
		wpi_assertCleanStatus(status);
		measuredPeriod = value * 1.0e-6;
	}
	return measuredPeriod / DecodingScaleFactor();
}
Ejemplo n.º 4
0
/**
 * Returns the period of the most recent pulse.
 * Returns the period of the most recent Encoder pulse in seconds.
 * This method compenstates for the decoding type.
 * 
 * @deprecated Use GetRate() in favor of this method.  This returns unscaled periods and GetRate() scales using value from SetDistancePerPulse().
 *
 * @return Period in seconds of the most recent pulse.
 */
double Encoder::GetPeriod()
{
    if (StatusIsFatal()) return 0.0;
    double measuredPeriod;
    if (m_counter)
    {
        measuredPeriod = m_counter->GetPeriod();
    }
    else
    {
        tRioStatusCode localStatus = NiFpga_Status_Success;
        tEncoder::tTimerOutput output = m_encoder->readTimerOutput(&localStatus);
        double value;
        if (output.Stalled)
        {
            // Return infinity
            double zero = 0.0;
            value = 1.0 / zero;
        }
        else
        {
            // output.Period is a fixed point number that counts by 2 (24 bits, 25 integer bits)
            value = (double)(output.Period << 1) / (double)output.Count;
        }
        wpi_setError(localStatus);
        measuredPeriod = value * 1.0e-6;
    }
    return measuredPeriod / DecodingScaleFactor();
}
Ejemplo n.º 5
0
/**
 * Sets the maximum period for stopped detection.
 *
 * Sets the value that represents the maximum period of the Encoder before it
 * will assume that the attached device is stopped. This timeout allows users
 * to determine if the wheels or other shaft has stopped rotating.
 * This method compensates for the decoding type.
 *
 * @deprecated Use SetMinRate() in favor of this method.  This takes unscaled
 *             periods and SetMinRate() scales using value from
 *             SetDistancePerPulse().
 *
 * @param maxPeriod The maximum time between rising and falling edges before
 *                  the FPGA will report the device stopped. This is expressed
 *                  in seconds.
 */
void Encoder::SetMaxPeriod(double maxPeriod) {
  if (StatusIsFatal()) return;
  if (m_counter) {
    m_counter->SetMaxPeriod(maxPeriod * DecodingScaleFactor());
  } else {
    int32_t status = 0;
    setEncoderMaxPeriod(m_encoder, maxPeriod, &status);
    wpi_setErrorWithContext(status, getHALErrorMessage(status));
  }
}
Ejemplo n.º 6
0
/**
 * Returns the period of the most recent pulse.
 *
 * Returns the period of the most recent Encoder pulse in seconds.
 * This method compensates for the decoding type.
 *
 * @deprecated Use GetRate() in favor of this method.  This returns unscaled
 *             periods and GetRate() scales using value from
 *             SetDistancePerPulse().
 *
 * @return Period in seconds of the most recent pulse.
 */
double Encoder::GetPeriod() const {
  if (StatusIsFatal()) return 0.0;
  if (m_counter) {
    return m_counter->GetPeriod() / DecodingScaleFactor();
  } else {
    int32_t status = 0;
    double period = getEncoderPeriod(m_encoder, &status);
    wpi_setErrorWithContext(status, getHALErrorMessage(status));
    return period;
  }
}
Ejemplo n.º 7
0
/**
 * Returns the period of the most recent pulse.
 * Returns the period of the most recent Encoder pulse in seconds.
 * This method compenstates for the decoding type.
 * 
 * @deprecated Use GetRate() in favor of this method.  This returns unscaled periods and GetRate() scales using value from SetDistancePerPulse().
 *
 * @return Period in seconds of the most recent pulse.
 */
double Encoder::GetPeriod()
{
	if (m_counter)
	{
		return m_counter->GetPeriod() * DecodingScaleFactor();
	}
	else
	{
		tEncoder::tTimerOutput output = m_encoder->readTimerOutput(&status);
		double value;
		if (output.Stalled)
		{
			// Return infinity
			double zero = 0.0;
			value = 1.0 / zero;
		}
		else
		{
			value = (double)output.Period / (double)output.Count;
		}
		wpi_assertCleanStatus(status);
		return value * 1.0e-6  / (DecodingScaleFactor() * 4.0);
	}
}
Ejemplo n.º 8
0
/**
 * Get the distance the robot has driven since the last reset.
 *
 * @return The distance driven since the last reset as scaled by the value from
 *         SetDistancePerPulse().
 */
double Encoder::GetDistance() const {
  if (StatusIsFatal()) return 0.0;
  return GetRaw() * DecodingScaleFactor() * m_distancePerPulse;
}
Ejemplo n.º 9
0
/**
 * Gets the current count.
 *
 * Returns the current count on the Encoder. This method compensates for the
 * decoding type.
 *
 * @return Current count from the Encoder adjusted for the 1x, 2x, or 4x scale
 *         factor.
 */
int32_t Encoder::Get() const {
  if (StatusIsFatal()) return 0;
  return (int32_t)(GetRaw() * DecodingScaleFactor());
}
Ejemplo n.º 10
0
/**
 * Get the distance the robot has driven since the last reset.
 * 
 * @return The distance driven since the last reset as scaled by the value from SetDistancePerPulse().
 */
double Encoder::GetDistance()
{
	return GetRaw() * DecodingScaleFactor() * m_distancePerPulse;
}
Ejemplo n.º 11
0
/**
 * Gets the current count.
 * Returns the current count on the Encoder.
 * This method compensates for the decoding type.
 * 
 * @return Current count from the Encoder adjusted for the 1x, 2x, or 4x scale factor.
 */
INT32 Encoder::Get()
{
	return (INT32) (GetRaw() * DecodingScaleFactor());
}
Ejemplo n.º 12
0
/**
 * Gets the current count.
 * Returns the current count on the Encoder.
 * This method compensates for the decoding type.
 * 
 * @return Current count from the Encoder adjusted for the 1x, 2x, or 4x scale factor.
 */
INT32 Encoder::Get()
{
    if (StatusIsFatal()) return 0;
    return (INT32) (GetRaw() * DecodingScaleFactor());
}