Add encoder indexing support in C++

Java will be done tonight or tomorrow

Change-Id: I3a3287a197b6f071c261172eb8ec930693e8b3c7
This commit is contained in:
Thomas Clark
2015-01-06 16:39:24 -05:00
parent 87e1df068c
commit a2dfffeddc
5 changed files with 165 additions and 18 deletions

View File

@@ -507,6 +507,47 @@ double Encoder::PIDGet()
}
}
/**
* Set the index source for the encoder. When this source is activated, the encoder count automatically resets.
*
* @param channel A DIO channel to set as the encoder index
* @param type The state that will cause the encoder to reset
*/
void Encoder::SetIndexSource(uint32_t channel, Encoder::IndexingType type) {
int32_t status = 0;
bool activeHigh = (type == kResetWhileHigh) || (type == kResetOnRisingEdge);
bool edgeSensitive = (type == kResetOnFallingEdge) || (type == kResetOnRisingEdge);
setEncoderIndexSource(m_encoder, channel, false, activeHigh, edgeSensitive, &status);
wpi_setGlobalErrorWithContext(status, getHALErrorMessage(status));
}
/**
* Set the index source for the encoder. When this source is activated, the encoder count automatically resets.
*
* @param channel A digital source to set as the encoder index
* @param type The state that will cause the encoder to reset
*/
void Encoder::SetIndexSource(DigitalSource *source, Encoder::IndexingType type) {
int32_t status = 0;
bool activeHigh = (type == kResetWhileHigh) || (type == kResetOnRisingEdge);
bool edgeSensitive = (type == kResetOnFallingEdge) || (type == kResetOnRisingEdge);
setEncoderIndexSource(m_encoder, source->GetChannelForRouting(), source->GetAnalogTriggerForRouting(), activeHigh,
edgeSensitive, &status);
wpi_setGlobalErrorWithContext(status, getHALErrorMessage(status));
}
/**
* Set the index source for the encoder. When this source is activated, the encoder count automatically resets.
*
* @param channel A digital source to set as the encoder index
* @param type The state that will cause the encoder to reset
*/
void Encoder::SetIndexSource(DigitalSource &source, Encoder::IndexingType type) {
SetIndexSource(&source, type);
}
void Encoder::UpdateTable() {
if (m_table != NULL) {
m_table->PutNumber("Speed", GetRate());