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

Add battery voltage read #44

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions include/robot.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,14 @@
#define XRP_DATA_AIO 0x04
#define XRP_DATA_GENERAL 0x08

#define XRP_VIN_MEAS 28

namespace xrp {

void robotInit();
bool robotInitialized();
uint8_t robotPeriodic();
float getVinMeasured();

// Robot control
void robotSetEnabled(bool enabled);
Expand Down
1 change: 1 addition & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ void sendData() {
if (xrp::rangefinderInitialized()) {
ptr += wpilibudp::writeAnalogData(2, xrp::getRangefinderDistance5V(), buffer, ptr);
}
ptr += wpilibudp::writeAnalogData(3, xrp::getVinMeasured(), buffer, ptr);

// ptr should now point to 1 past the last byte
size = ptr;
Expand Down
7 changes: 7 additions & 0 deletions src/robot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,13 @@ float getReflectanceRight5V() {
return _readAnalogPinScaled(REFLECT_RIGHT_PIN) * 5.0f;
}

float getVinMeasured() {
//ADC reads are 3.3V max
//R1 = 100k, R2 = 33k, voltage divider = R2/(R1+R2)
//reading * Vadc_max / volt divider
return _readAnalogPinScaled(XRP_VIN_MEAS) * 3.3f / (33.f/(100.f+33.f));
}

void rangefinderInit() {
pinMode(ULTRASONIC_TRIG_PIN, OUTPUT); // Trigger Pin
digitalWrite(ULTRASONIC_TRIG_PIN, LOW);
Expand Down