Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make drive motor encoders report positive count when moving forward #29

Merged
merged 1 commit into from
Oct 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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