void PWM::SetZeroLatch() { if (StatusIsFatal()) return; int32_t status = 0; latchPWMZero(m_pwm_ports[m_channel], &status); wpi_setErrorWithContext(status, getHALErrorMessage(status)); }
/** * Disable Interrupts without without deallocating structures. */ void InterruptableSensorBase::DisableInterrupts() { if (StatusIsFatal()) return; wpi_assert(m_interrupt != NULL); int32_t status = 0; disableInterrupts(m_interrupt, &status); wpi_setErrorWithContext(status, getHALErrorMessage(status)); }
/** * Returns the voltage coming in from the battery. * * @return The input voltage in volts. */ float CANTalon::GetBusVoltage() const { double voltage; CTR_Code status = m_impl->GetBatteryV(voltage); if (status != CTR_OKAY) { wpi_setErrorWithContext(status, getHALErrorMessage(status)); } return voltage; }
/** * Return the timestamp for the falling interrupt that occurred most recently. * This is in the same time domain as GetClock(). * The falling-edge interrupt should be enabled with * {@link #DigitalInput.SetUpSourceEdge} * @return Timestamp in seconds since boot. */ double InterruptableSensorBase::ReadFallingTimestamp() { if (StatusIsFatal()) return 0.0; wpi_assert(m_interrupt != nullptr); int32_t status = 0; double timestamp = readFallingTimestamp(m_interrupt, &status); wpi_setErrorWithContext(status, getHALErrorMessage(status)); return timestamp; }
/** * Sets the number of nanoseconds that the input must not change state for. * * @param nanoseconds The number of nanoseconds. */ void DigitalGlitchFilter::SetPeriodNanoSeconds(uint64_t nanoseconds) { int32_t status = 0; uint32_t fpga_cycles = nanoseconds * kSystemClockTicksPerMicrosecond / 4 / 1000; setFilterPeriod(m_channelIndex, fpga_cycles, &status); wpi_setErrorWithContext(status, getHALErrorMessage(status)); }
/** * Gets the number of cycles that the input must not change state for. * * @return The number of cycles. */ uint32_t DigitalGlitchFilter::GetPeriodCycles() { int32_t status = 0; uint32_t fpga_cycles = getFilterPeriod(m_channelIndex, &status); wpi_setErrorWithContext(status, getHALErrorMessage(status)); return fpga_cycles; }
/** * Read the battery voltage. * * @return The battery voltage in Volts. */ float DriverStation::GetBatteryVoltage() { int32_t status = 0; float voltage = getVinVoltage(&status); wpi_setErrorWithContext(status, "getVinVoltage"); return voltage; }
/** * Returns the current error in the controller. * * @return the difference between the setpoint and the sensor value. */ int CANTalon::GetClosedLoopError() { int error; CTR_Code status = m_impl->GetCloseLoopErr(error); if(status != CTR_OKAY) { wpi_setErrorWithContext(status, getHALErrorMessage(status)); } return error; }
/** * * @see SelectProfileSlot to choose between the two sets of gains. */ double CANTalon::GetF() { CanTalonSRX::param_t param = m_profile ? CanTalonSRX::eProfileParamSlot1_F : CanTalonSRX::eProfileParamSlot0_F; // Update the info in m_impl. CTR_Code status = m_impl->RequestParam(param); if(status != CTR_OKAY) { wpi_setErrorWithContext(status, getHALErrorMessage(status)); } usleep(kDelayForSolicitedSignalsUs); /* small yield for getting response */ double f; status = m_impl->GetFgain(m_profile, f); if(status != CTR_OKAY) { wpi_setErrorWithContext(status, getHALErrorMessage(status)); } return f; }
/** * @see SelectProfileSlot to choose between the two sets of gains. */ int CANTalon::GetIzone() { CanTalonSRX::param_t param = m_profile ? CanTalonSRX::eProfileParamSlot1_IZone: CanTalonSRX::eProfileParamSlot0_IZone; // Update the info in m_impl. CTR_Code status = m_impl->RequestParam(param); if(status != CTR_OKAY) { wpi_setErrorWithContext(status, getHALErrorMessage(status)); } usleep(kDelayForSolicitedSignalsUs); int iz; status = m_impl->GetIzone(m_profile, iz); if(status != CTR_OKAY) { wpi_setErrorWithContext(status, getHALErrorMessage(status)); } return iz; }
/** * TODO documentation (see CANJaguar.cpp) */ void CANTalon::ConfigReverseLimit(double reverseLimitPosition) { CTR_Code status; status = m_impl->SetReverseSoftLimit(reverseLimitPosition); if(status != CTR_OKAY) { wpi_setErrorWithContext(status, getHALErrorMessage(status)); } }
/** * SRX has two available slots for PID. * @param slotIdx one or zero depending on which slot caller wants. */ void CANTalon::SelectProfileSlot(int slotIdx) { m_profile = (slotIdx == 0) ? 0 : 1; /* only get two slots for now */ CTR_Code status = m_impl->SetProfileSlotSelect(m_profile); if(status != CTR_OKAY) { wpi_setErrorWithContext(status, getHALErrorMessage(status)); } }
/** * Get the position of whatever is in the analog pin of the Talon, regardless of * whether it is actually being used for feedback. * * @returns The value (0 - 1023) on the analog pin of the Talon. */ int CANTalon::GetEncPosition() const { int position; CTR_Code status = m_impl->GetEncPosition(position); if (status != CTR_OKAY) { wpi_setErrorWithContext(status, getHALErrorMessage(status)); } return position; }
/** * TODO documentation (see CANJaguar.cpp) */ void CANTalon::ConfigForwardLimit(double forwardLimitPosition) { CTR_Code status; status = m_impl->SetForwardSoftLimit(forwardLimitPosition); if(status != CTR_OKAY) { wpi_setErrorWithContext(status, getHALErrorMessage(status)); } }
/** * Change the rev limit switch setting to normally open or closed. * Talon will disable momentarilly if the Talon's current setting * is dissimilar to the caller's requested setting. * * Since Talon saves setting to flash this should only affect * a given Talon initially during robot install. * * @param normallyOpen true for normally open. false for normally closed. */ void CANTalon::ConfigRevLimitSwitchNormallyOpen(bool normallyOpen) { CTR_Code status = m_impl->SetParam(CanTalonSRX::eOnBoot_LimitSwitch_Reverse_NormallyClosed, normallyOpen ? 0 : 1); if (status != CTR_OKAY) { wpi_setErrorWithContext(status, getHALErrorMessage(status)); } }
/** * Return the TriggerState output of the analog trigger. * True if above upper limit. * False if below lower limit. * If in Hysteresis, maintain previous state. * @return True if above upper limit. False if below lower limit. If in Hysteresis, maintain previous state. */ bool AnalogTrigger::GetTriggerState() { if (StatusIsFatal()) return false; int32_t status = 0; bool result = getAnalogTriggerTriggerState(m_trigger, &status); wpi_setErrorWithContext(status, getHALErrorMessage(status)); return result; }
/** * @return nonzero if brake is enabled during neutral. Zero if coast is enabled * during neutral. */ int CANTalon::GetBrakeEnableDuringNeutral() const { int brakeEn = 0; CTR_Code status = m_impl->GetBrakeIsEnabled(brakeEn); if (status != CTR_OKAY) { wpi_setErrorWithContext(status, getHALErrorMessage(status)); } return brakeEn; }
void InterruptableSensorBase::AllocateInterrupts(bool watcher) { wpi_assert(m_interrupt == NULL); // Expects the calling leaf class to allocate an interrupt index. int32_t status = 0; m_interrupt = initializeInterrupts(m_interruptIndex, watcher, &status); wpi_setErrorWithContext(status, getHALErrorMessage(status)); }
/* * @param rises integral value to set into index-rises register. Great way to * zero the index count. */ void CANTalon::SetNumberOfQuadIdxRises(int rises) { CTR_Code status = m_impl->SetParam( CanTalonSRX::eEncIndexRiseEvents, rises); /* rename this func, '1' => open, '0' => closed */ if (status != CTR_OKAY) { wpi_setErrorWithContext(status, getHALErrorMessage(status)); } }
/** * @return IO level of QUAD Index pin. */ int CANTalon::GetPinStateQuadIdx() const { int retval; CTR_Code status = m_impl->GetQuadIdxpin(retval); if (status != CTR_OKAY) { wpi_setErrorWithContext(status, getHALErrorMessage(status)); } return retval; }
/** * Get the position of whatever is in the analog pin of the Talon, regardless of * whether it is actually being used for feedback. * * @returns The value (0 - 1023) on the analog pin of the Talon. */ int CANTalon::GetEncVel() const { int vel; CTR_Code status = m_impl->GetEncVel(vel); if (status != CTR_OKAY) { wpi_setErrorWithContext(status, getHALErrorMessage(status)); } return vel; }
/** * @return '1' iff reverse limit switch is closed, 0 iff switch is open. * This function works regardless if limit switch feature is enabled. */ int CANTalon::IsRevLimitSwitchClosed() { int retval; CTR_Code status = m_impl->GetLimitSwitchClosedRev(retval); /* rename this func, '1' => open, '0' => closed */ if(status != CTR_OKAY) { wpi_setErrorWithContext(status, getHALErrorMessage(status)); } return retval ? 0 : 1; }
/** * Returns temperature of Talon, in degrees Celsius. */ float CANTalon::GetTemperature() const { double temp; CTR_Code status = m_impl->GetTemp(temp); if (temp != CTR_OKAY) { wpi_setErrorWithContext(status, getHALErrorMessage(status)); } return temp; }
/* * Simple accessor for tracked rise eventso index pin. * @return number of rising edges on idx pin. */ int CANTalon::GetNumberOfQuadIdxRises() { int rises; CTR_Code status = m_impl->GetEncIndexRiseEvents(rises); /* rename this func, '1' => open, '0' => closed */ if(status != CTR_OKAY) { wpi_setErrorWithContext(status, getHALErrorMessage(status)); } return rises; }
/** * TODO documentation (see CANJaguar.cpp) * * @return The position of the sensor currently providing feedback. * When using analog sensors, 0 units corresponds to 0V, 1023 * units corresponds to 3.3V * When using an analog encoder (wrapping around 1023 => 0 is * possible) the units are still 3.3V per 1023 units. * When using quadrature, each unit is a quadrature edge (4X) * mode. */ double CANTalon::GetPosition() const { int postition; CTR_Code status = m_impl->GetSensorPosition(postition); if (status != CTR_OKAY) { wpi_setErrorWithContext(status, getHALErrorMessage(status)); } return (double)postition; }
/** * Gets the number of nanoseconds that the input must not change state for. * * @return The number of nanoseconds. */ uint64_t DigitalGlitchFilter::GetPeriodNanoSeconds() { int32_t status = 0; uint32_t fpga_cycles = getFilterPeriod(m_channelIndex, &status); wpi_setErrorWithContext(status, getHALErrorMessage(status)); return static_cast<uint64_t>(fpga_cycles) * 1000L / static_cast<uint64_t>(kSystemClockTicksPerMicrosecond / 4); }
/** * @return The voltage being output by the Talon, in Volts. */ float CANTalon::GetOutputVoltage() const { int throttle11; CTR_Code status = m_impl->GetAppliedThrottle(throttle11); float voltage = GetBusVoltage() * (float(throttle11) / 1023.0); if (status != CTR_OKAY) { wpi_setErrorWithContext(status, getHALErrorMessage(status)); } return voltage; }
/** * Get the PWM value directly from the hardware. * * Read a raw value from a PWM channel. * * @return Raw PWM control value. */ unsigned short PWM::GetRaw() const { if (StatusIsFatal()) return 0; int32_t status = 0; unsigned short value = getPWM(m_pwm_ports[m_channel], &status); wpi_setErrorWithContext(status, getHALErrorMessage(status)); return value; }
/** * Cancel interrupts on this device. * This deallocates all the chipobject structures and disables any interrupts. */ void InterruptableSensorBase::CancelInterrupts() { if (StatusIsFatal()) return; wpi_assert(m_interrupt != nullptr); int32_t status = 0; cleanInterrupts(m_interrupt, &status); wpi_setErrorWithContext(status, getHALErrorMessage(status)); m_interrupt = nullptr; m_interrupts->Free(m_interruptIndex); }
/** * Common initialization code for Encoders. * This code allocates resources for Encoders and is common to all constructors. * * The counter will start counting immediately. * * @param reverseDirection If true, counts down instead of up (this is all * relative) * @param encodingType either k1X, k2X, or k4X to indicate 1X, 2X or 4X * decoding. If 4X is * selected, then an encoder FPGA object is used and the returned counts will be * 4x the encoder * spec'd value since all rising and falling edges are counted. If 1X or 2X are * selected then * a counter object will be used and the returned value will either exactly * match the spec'd count * or be double (2x) the spec'd count. */ void Encoder::InitEncoder(bool reverseDirection, EncodingType encodingType) { m_encodingType = encodingType; switch (encodingType) { case k4X: { m_encodingScale = 4; if (m_aSource->StatusIsFatal()) { CloneError(*m_aSource); return; } if (m_bSource->StatusIsFatal()) { CloneError(*m_bSource); return; } int32_t status = 0; m_encoder = initializeEncoder( m_aSource->GetModuleForRouting(), m_aSource->GetChannelForRouting(), m_aSource->GetAnalogTriggerForRouting(), m_bSource->GetModuleForRouting(), m_bSource->GetChannelForRouting(), m_bSource->GetAnalogTriggerForRouting(), reverseDirection, &m_index, &status); wpi_setErrorWithContext(status, getHALErrorMessage(status)); m_counter = nullptr; SetMaxPeriod(.5); break; } case k1X: case k2X: { m_encodingScale = encodingType == k1X ? 1 : 2; m_counter = std::make_unique<Counter>(m_encodingType, m_aSource, m_bSource, reverseDirection); m_index = m_counter->GetFPGAIndex(); break; } default: wpi_setErrorWithContext(-1, "Invalid encodingType argument"); break; } HALReport(HALUsageReporting::kResourceType_Encoder, m_index, encodingType); #if FULL_WPILIB LiveWindow::GetInstance()->AddSensor("Encoder", m_aSource->GetChannelForRouting(), this); #endif }