Skip to content

Commit

Permalink
Make drive motor encoders report positive count when moving forward (#29
Browse files Browse the repository at this point in the history
)
  • Loading branch information
zhiquanyeo authored Oct 16, 2023
1 parent 1c49281 commit 452d63b
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,18 @@ void sendData() {

// Encoders
for (int i = 0; i < 4; i++) {
ptr += wpilibudp::writeEncoderData(i, xrp::readEncoderRaw(i), buffer, ptr);
int encoderValue = xrp::readEncoderRaw(i);

// We want to flip the encoder 0 value (left motor encoder) so that this returns
// positive values when moving forward.
if (i == 0) {
encoderValue = -encoderValue;
}

ptr += wpilibudp::writeEncoderData(i, encoderValue, buffer, ptr);
} // 4x 7 bytes

// DIO (currently just the button)
// TODO: Line sensors too if they are configured
ptr += wpilibudp::writeDIOData(0, xrp::isUserButtonPressed(), buffer, ptr);
// 1x 4 bytes

Expand Down

0 comments on commit 452d63b

Please sign in to comment.