mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
Java CANJaguar changes
Change-Id: Icb15b1b140816e44caec36cda2466a64e5cabf1d Change-Id: Idd6aebefe03acff5ab211a5e3e73a29563601515
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -13,7 +13,6 @@ import java.nio.ByteOrder;
|
||||
import edu.wpi.first.wpilibj.hal.PDPJNI;
|
||||
import edu.wpi.first.wpilibj.hal.HALUtil;
|
||||
import edu.wpi.first.wpilibj.livewindow.LiveWindowSendable;
|
||||
import edu.wpi.first.wpilibj.can.CANTimeoutException;
|
||||
|
||||
/**
|
||||
* Class for getting voltage, current, and temperature from the CAN PDP
|
||||
@@ -22,54 +21,42 @@ import edu.wpi.first.wpilibj.can.CANTimeoutException;
|
||||
public class PowerDistributionPanel extends SensorBase {
|
||||
public PowerDistributionPanel() {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return The voltage of the PDP
|
||||
*/
|
||||
public double getVoltage() throws CANTimeoutException {
|
||||
public double getVoltage() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
|
||||
double voltage = PDPJNI.getPDPVoltage(status.asIntBuffer());
|
||||
|
||||
if(status.asIntBuffer().get(0) != 0) {
|
||||
throw new CANTimeoutException();
|
||||
}
|
||||
|
||||
|
||||
return voltage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The temperature of the PDP in degrees Celsius
|
||||
*/
|
||||
public double getTemperature() throws CANTimeoutException {
|
||||
public double getTemperature() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
|
||||
double temperature = PDPJNI.getPDPTemperature(status.asIntBuffer());
|
||||
|
||||
if(status.asIntBuffer().get(0) != 0) {
|
||||
throw new CANTimeoutException();
|
||||
}
|
||||
|
||||
|
||||
return temperature;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return The current of one of the PDP channels (channels 1-16) in Amperes
|
||||
*/
|
||||
public double getCurrent(int channel) throws CANTimeoutException {
|
||||
public double getCurrent(int channel) {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
|
||||
double current = PDPJNI.getPDPChannelCurrent((byte)channel, status.asIntBuffer());
|
||||
|
||||
|
||||
checkPDPChannel(channel);
|
||||
|
||||
if(status.asIntBuffer().get(0) != 0) {
|
||||
throw new CANTimeoutException();
|
||||
}
|
||||
|
||||
|
||||
return current;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import edu.wpi.first.wpilibj.can.CANNotInitializedException;
|
||||
import edu.wpi.first.wpilibj.can.CANTimeoutException;
|
||||
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tInstances;
|
||||
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType;
|
||||
import edu.wpi.first.wpilibj.communication.UsageReporting;
|
||||
@@ -503,7 +502,7 @@ public class RobotDrive implements MotorSafety, IUtility {
|
||||
CANJaguar.updateSyncGroup(syncGroup);
|
||||
} catch (CANNotInitializedException e) {
|
||||
m_isCANInitialized = false;
|
||||
} catch (CANTimeoutException e) {}
|
||||
}
|
||||
}
|
||||
|
||||
if (m_safetyHelper != null) m_safetyHelper.feed();
|
||||
@@ -555,7 +554,7 @@ public class RobotDrive implements MotorSafety, IUtility {
|
||||
CANJaguar.updateSyncGroup(syncGroup);
|
||||
} catch (CANNotInitializedException e) {
|
||||
m_isCANInitialized = false;
|
||||
} catch (CANTimeoutException e) {}
|
||||
}
|
||||
}
|
||||
|
||||
if (m_safetyHelper != null) m_safetyHelper.feed();
|
||||
@@ -605,7 +604,7 @@ public class RobotDrive implements MotorSafety, IUtility {
|
||||
CANJaguar.updateSyncGroup(syncGroup);
|
||||
} catch (CANNotInitializedException e) {
|
||||
m_isCANInitialized = false;
|
||||
} catch (CANTimeoutException e) {}
|
||||
}
|
||||
}
|
||||
|
||||
if (m_safetyHelper != null) m_safetyHelper.feed();
|
||||
|
||||
@@ -10,35 +10,30 @@ package edu.wpi.first.wpilibj.can;
|
||||
import edu.wpi.first.wpilibj.communication.NIRioStatus;
|
||||
import edu.wpi.first.wpilibj.util.UncleanStatusException;
|
||||
|
||||
/**
|
||||
* Exception indicating that the Jaguar CAN Driver layer refused to send a
|
||||
* restricted message ID to the CAN bus.
|
||||
*/
|
||||
public class CANExceptionFactory {
|
||||
// FRC Error codes
|
||||
static final int ERR_JaguarCANDriver_InvalidBuffer = -44086;
|
||||
static final int ERR_JaguarCANDriver_TimedOut = -44087;
|
||||
static final int ERR_JaguarCANDriver_NotAllowed = -44088;
|
||||
static final int ERR_JaguarCANDriver_NotInitialized = -44089;
|
||||
static final int ERR_CANSessionMux_InvalidBuffer = -44086;
|
||||
static final int ERR_CANSessionMux_MessageNotFound = -44087;
|
||||
static final int ERR_CANSessionMux_NotAllowed = -44088;
|
||||
static final int ERR_CANSessionMux_NotInitialized = -44089;
|
||||
|
||||
public static void checkStatus(int status, int messageID) throws
|
||||
CANInvalidBufferException, CANTimeoutException,
|
||||
CANMessageNotAllowedException, CANNotInitializedException,
|
||||
UncleanStatusException {
|
||||
CANInvalidBufferException, CANMessageNotAllowedException,
|
||||
CANNotInitializedException, UncleanStatusException {
|
||||
switch (status) {
|
||||
case NIRioStatus.kRioStatusSuccess:
|
||||
// Everything is ok... don't throw.
|
||||
return;
|
||||
case ERR_JaguarCANDriver_InvalidBuffer:
|
||||
case ERR_CANSessionMux_InvalidBuffer:
|
||||
case NIRioStatus.kRIOStatusBufferInvalidSize:
|
||||
throw new CANInvalidBufferException();
|
||||
case ERR_JaguarCANDriver_TimedOut:
|
||||
case ERR_CANSessionMux_MessageNotFound:
|
||||
case NIRioStatus.kRIOStatusOperationTimedOut:
|
||||
throw new CANTimeoutException();
|
||||
case ERR_JaguarCANDriver_NotAllowed:
|
||||
throw new CANMessageNotFoundException();
|
||||
case ERR_CANSessionMux_NotAllowed:
|
||||
case NIRioStatus.kRIOStatusFeatureNotSupported:
|
||||
throw new CANMessageNotAllowedException("MessageID = " + Integer.toString(messageID));
|
||||
case ERR_JaguarCANDriver_NotInitialized:
|
||||
case ERR_CANSessionMux_NotInitialized:
|
||||
case NIRioStatus.kRIOStatusResourceNotInitialized:
|
||||
throw new CANNotInitializedException();
|
||||
default:
|
||||
|
||||
@@ -16,12 +16,6 @@ import java.nio.IntBuffer;
|
||||
* For help, please visit <a href="http://nativelibs4java.googlecode.com/">NativeLibs4Java</a> , <a href="http://rococoa.dev.java.net/">Rococoa</a>, or <a href="http://jna.dev.java.net/">JNA</a>.
|
||||
*/
|
||||
public class CANJNI extends JNIWrapper{
|
||||
//public static final String JNA_LIBRARY_NAME = LibraryExtractor.getLibraryPath("CAN", true, CANLibrary.class);
|
||||
//public static final NativeLibrary JNA_NATIVE_LIB = NativeLibrary.getInstance(CANLibrary.JNA_LIBRARY_NAME, MangledFunctionMapper.DEFAULT_OPTIONS);
|
||||
//static {
|
||||
// System.loadLibrary("JNIWrappers");
|
||||
//Native.register(CANLibrary.class, CANLibrary.JNA_NATIVE_LIB);
|
||||
//}
|
||||
/** <i>native declaration : src\main\include\CAN\can_proto.h</i> */
|
||||
public static final int LM_STATUS_LIMIT_REV = 0x02;
|
||||
/** <i>native declaration : src\main\include\CAN\can_proto.h</i> */
|
||||
@@ -452,6 +446,13 @@ public class CANJNI extends JNIWrapper{
|
||||
public static final int LM_API_VCOMP_T_EN = ((0x00020000 | 0x02000000 | 0x00000800) | (5 << 6));
|
||||
/** <i>native declaration : src\main\include\CAN\can_proto.h</i> */
|
||||
public static final int LM_STATUS_LIMIT_STKY_SFWD = 0x40;
|
||||
|
||||
public static final int CAN_SEND_PERIOD_NO_REPEAT = 0;
|
||||
public static final int CAN_SEND_PERIOD_STOP_REPEATING = -1;
|
||||
|
||||
/* Flags in the upper bits of the messageID */
|
||||
public static final int CAN_IS_FRAME_REMOTE = 0x80000000;
|
||||
public static final int CAN_IS_FRAME_11BIT = 0x40000000;
|
||||
|
||||
public static native void FRCNetworkCommunicationCANSessionMuxSendMessage(int messageID, ByteBuffer data, int periodMs, IntBuffer status);
|
||||
public static native ByteBuffer FRCNetworkCommunicationCANSessionMuxReceiveMessage(IntBuffer messageID, int messageIDMask, ByteBuffer timeStamp, IntBuffer status);
|
||||
|
||||
@@ -7,17 +7,13 @@
|
||||
|
||||
package edu.wpi.first.wpilibj.can;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Exception indicating that the CAN device did not respond
|
||||
* within the timeout period specified.
|
||||
* Exception indicating that a can message is not available from Network
|
||||
* Communications. This usually just means we already have the most recent
|
||||
* value cached locally.
|
||||
*/
|
||||
public class CANTimeoutException extends IOException {
|
||||
public CANTimeoutException() {
|
||||
public class CANMessageNotFoundException extends RuntimeException {
|
||||
public CANMessageNotFoundException() {
|
||||
super();
|
||||
}
|
||||
public CANTimeoutException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user