mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-23 01:21:42 +00:00
Implement DriverStation::GetBatteryVoltage
Make the GetBatteryVoltage method work using the new tPower header Change-Id: If504f8a46f3f7f737f0b729b72fc6b5da0d29ff9
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
#include "Interrupts.hpp"
|
||||
#include "Errors.hpp"
|
||||
#include "PDP.hpp"
|
||||
#include "Power.hpp"
|
||||
|
||||
#include "Utilities.hpp"
|
||||
#include "Semaphore.hpp"
|
||||
|
||||
15
hal/include/HAL/Power.hpp
Normal file
15
hal/include/HAL/Power.hpp
Normal file
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
extern "C"
|
||||
{
|
||||
float getVinVoltage(int32_t *status);
|
||||
float getVinCurrent(int32_t *status);
|
||||
float getUserVoltage6V(int32_t *status);
|
||||
float getUserCurrent6V(int32_t *status);
|
||||
float getUserVoltage5V(int32_t *status);
|
||||
float getUserCurrent5V(int32_t *status);
|
||||
float getUserVoltage3V3(int32_t *status);
|
||||
float getUserCurrent3V3(int32_t *status);
|
||||
}
|
||||
74
hal/lib/Athena/Power.cpp
Normal file
74
hal/lib/Athena/Power.cpp
Normal file
@@ -0,0 +1,74 @@
|
||||
#include "HAL/Power.hpp"
|
||||
#include "ChipObject.h"
|
||||
|
||||
static tPower *power = NULL;
|
||||
|
||||
static void initializePower(int32_t *status) {
|
||||
if(power == NULL) {
|
||||
power = tPower::create(status);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the roboRIO input voltage
|
||||
*/
|
||||
float getVinVoltage(int32_t *status) {
|
||||
initializePower(status);
|
||||
return power->readVinVoltage(status) / 4.096f * 0.025733f - 0.029f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the roboRIO input current
|
||||
*/
|
||||
float getVinCurrent(int32_t *status) {
|
||||
initializePower(status);
|
||||
return power->readVinCurrent(status) / 4.096f * 0.017042 - 0.071f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the 6V rail voltage
|
||||
*/
|
||||
float getUserVoltage6V(int32_t *status) {
|
||||
initializePower(status);
|
||||
return power->readUserVoltage6V(status) / 4.096f * 0.007019f - 0.014f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the 6V rail current
|
||||
*/
|
||||
float getUserCurrent6V(int32_t *status) {
|
||||
initializePower(status);
|
||||
return power->readUserCurrent6V(status) / 4.096f * 0.005566f - 0.009f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the 5V rail voltage
|
||||
*/
|
||||
float getUserVoltage5V(int32_t *status) {
|
||||
initializePower(status);
|
||||
return power->readUserVoltage5V(status) / 4.096f * 0.004962f - 0.013f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the 5V rail current
|
||||
*/
|
||||
float getUserCurrent5V(int32_t *status) {
|
||||
initializePower(status);
|
||||
return power->readUserCurrent5V(status) / 4.096f * 0.001996f - 0.002f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the 3.3V rail voltage
|
||||
*/
|
||||
float getUserVoltage3V3(int32_t *status) {
|
||||
initializePower(status);
|
||||
return power->readUserVoltage3V3(status) / 4.096f * 0.004902f - 0.01f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the 3.3V rail current
|
||||
*/
|
||||
float getUserCurrent3V3(int32_t *status) {
|
||||
initializePower(status);
|
||||
return power->readUserCurrent3V3(status) / 4.096f * 0.002486f - 0.003f;
|
||||
}
|
||||
@@ -162,7 +162,11 @@ void DriverStation::GetData()
|
||||
*/
|
||||
float DriverStation::GetBatteryVoltage()
|
||||
{
|
||||
return 0.0f; // TODO
|
||||
int32_t status = 0;
|
||||
float voltage = getVinVoltage(&status);
|
||||
wpi_setErrorWithContext(status, "getVinVoltage");
|
||||
|
||||
return voltage;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import java.nio.IntBuffer;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
@@ -13,6 +14,7 @@ import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary;
|
||||
import edu.wpi.first.wpilibj.communication.HALControlWord;
|
||||
import edu.wpi.first.wpilibj.communication.HALAllianceStationID;
|
||||
import edu.wpi.first.wpilibj.hal.HALUtil;
|
||||
import edu.wpi.first.wpilibj.hal.PowerJNI;
|
||||
import edu.wpi.first.wpilibj.Timer;
|
||||
|
||||
/**
|
||||
@@ -95,10 +97,7 @@ public class DriverStation implements RobotState.Interface {
|
||||
m_semaphore = new Object();
|
||||
m_dataSem = new Object();
|
||||
|
||||
m_packetDataAvailableSem = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
m_packetDataAvailableSem.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
m_packetDataAvailableSem = HALUtil.initializeMutexNormal();
|
||||
FRCNetworkCommunicationsLibrary.setNewDataSem(m_packetDataAvailableSem);
|
||||
|
||||
m_thread = new Thread(new DriverStationTask(this), "FRCDriverStation");
|
||||
@@ -209,7 +208,11 @@ public class DriverStation implements RobotState.Interface {
|
||||
* @return The battery voltage.
|
||||
*/
|
||||
public double getBatteryVoltage() {
|
||||
return 0.0; // TODO
|
||||
IntBuffer status = ByteBuffer.allocateDirect(4).asIntBuffer();
|
||||
float voltage = PowerJNI.getVinVoltage(status);
|
||||
HALUtil.checkStatus(status);
|
||||
|
||||
return voltage;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package edu.wpi.first.wpilibj.hal;
|
||||
|
||||
import java.nio.IntBuffer;
|
||||
|
||||
public class PowerJNI extends JNIWrapper {
|
||||
public static native float getVinVoltage(IntBuffer status);
|
||||
public static native float getVinCurrent(IntBuffer status);
|
||||
public static native float getUserVoltage6V(IntBuffer status);
|
||||
public static native float getUserCurrent6V(IntBuffer status);
|
||||
public static native float getUserVoltage5V(IntBuffer status);
|
||||
public static native float getUserCurrent5V(IntBuffer status);
|
||||
public static native float getUserVoltage3V3(IntBuffer status);
|
||||
public static native float getUserCurrent3V3(IntBuffer status);
|
||||
}
|
||||
99
wpilibj/wpilibJavaJNI/lib/PowerJNI.cpp
Normal file
99
wpilibj/wpilibJavaJNI/lib/PowerJNI.cpp
Normal file
@@ -0,0 +1,99 @@
|
||||
#include <jni.h>
|
||||
#include "edu_wpi_first_wpilibj_hal_PowerJNI.h"
|
||||
#include "HAL/Power.hpp"
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_hal_PowerJNI
|
||||
* Method: getVinVoltage
|
||||
* Signature: (Ljava/nio/IntBuffer;)F
|
||||
*/
|
||||
JNIEXPORT jfloat JNICALL Java_edu_wpi_first_wpilibj_hal_PowerJNI_getVinVoltage
|
||||
(JNIEnv * env, jclass, jobject status)
|
||||
{
|
||||
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
|
||||
return getVinVoltage(statusPtr);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_hal_PowerJNI
|
||||
* Method: getVinCurrent
|
||||
* Signature: (Ljava/nio/IntBuffer;)F
|
||||
*/
|
||||
JNIEXPORT jfloat JNICALL Java_edu_wpi_first_wpilibj_hal_PowerJNI_getVinCurrent
|
||||
(JNIEnv * env, jclass, jobject status)
|
||||
{
|
||||
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
|
||||
return getVinCurrent(statusPtr);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_hal_PowerJNI
|
||||
* Method: getUserVoltage6V
|
||||
* Signature: (Ljava/nio/IntBuffer;)F
|
||||
*/
|
||||
JNIEXPORT jfloat JNICALL Java_edu_wpi_first_wpilibj_hal_PowerJNI_getUserVoltage6V
|
||||
(JNIEnv * env, jclass, jobject status)
|
||||
{
|
||||
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
|
||||
return getUserVoltage6V(statusPtr);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_hal_PowerJNI
|
||||
* Method: getUserCurrent6V
|
||||
* Signature: (Ljava/nio/IntBuffer;)F
|
||||
*/
|
||||
JNIEXPORT jfloat JNICALL Java_edu_wpi_first_wpilibj_hal_PowerJNI_getUserCurrent6V
|
||||
(JNIEnv * env, jclass, jobject status)
|
||||
{
|
||||
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
|
||||
return getUserCurrent6V(statusPtr);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_hal_PowerJNI
|
||||
* Method: getUserVoltage5V
|
||||
* Signature: (Ljava/nio/IntBuffer;)F
|
||||
*/
|
||||
JNIEXPORT jfloat JNICALL Java_edu_wpi_first_wpilibj_hal_PowerJNI_getUserVoltage5V
|
||||
(JNIEnv * env, jclass, jobject status)
|
||||
{
|
||||
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
|
||||
return getUserVoltage5V(statusPtr);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_hal_PowerJNI
|
||||
* Method: getUserCurrent5V
|
||||
* Signature: (Ljava/nio/IntBuffer;)F
|
||||
*/
|
||||
JNIEXPORT jfloat JNICALL Java_edu_wpi_first_wpilibj_hal_PowerJNI_getUserCurrent5V
|
||||
(JNIEnv * env, jclass, jobject status)
|
||||
{
|
||||
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
|
||||
return getUserCurrent5V(statusPtr);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_hal_PowerJNI
|
||||
* Method: getUserVoltage3V3
|
||||
* Signature: (Ljava/nio/IntBuffer;)F
|
||||
*/
|
||||
JNIEXPORT jfloat JNICALL Java_edu_wpi_first_wpilibj_hal_PowerJNI_getUserVoltage3V3
|
||||
(JNIEnv * env, jclass, jobject status)
|
||||
{
|
||||
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
|
||||
return getUserVoltage3V3(statusPtr);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_hal_PowerJNI
|
||||
* Method: getUserCurrent3V3
|
||||
* Signature: (Ljava/nio/IntBuffer;)F
|
||||
*/
|
||||
JNIEXPORT jfloat JNICALL Java_edu_wpi_first_wpilibj_hal_PowerJNI_getUserCurrent3V3
|
||||
(JNIEnv * env, jclass, jobject status)
|
||||
{
|
||||
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
|
||||
return getUserCurrent3V3(statusPtr);
|
||||
}
|
||||
@@ -126,6 +126,7 @@ this default location, specify a value for the 'embeddedJDKHome' property at the
|
||||
<javahClassName>edu.wpi.first.wpilibj.hal.SolenoidJNI</javahClassName>
|
||||
<javahClassName>edu.wpi.first.wpilibj.hal.CompressorJNI</javahClassName>
|
||||
<javahClassName>edu.wpi.first.wpilibj.hal.PDPJNI</javahClassName>
|
||||
<javahClassName>edu.wpi.first.wpilibj.hal.PowerJNI</javahClassName>
|
||||
</javahClassNames>
|
||||
<!-- enable additional javah interface in dependencies list -->
|
||||
<!-- javahSearchJNIFromDependencies>true</javahSearchJNIFromDependencies -->
|
||||
|
||||
Reference in New Issue
Block a user