Restructure WPILibJ to share code.

wpilibJavaDevices now contains RoboRIO specific code and wpilibJava has
shared high level information. The restructuring was mostly just copy
and paste. The three big exceptions are Timer, RobotState and
HLUsageReporting. Those require some dependencies injection since that
appears to be the cleanest way to share the code.

Change-Id: Ie7011e32bc95953a87801a9905b3bfec7f8de285
This commit is contained in:
Alex Henning
2014-07-23 14:04:33 -04:00
parent e84e0ebab8
commit 26d101caf9
174 changed files with 637 additions and 7173 deletions

View File

@@ -9,6 +9,7 @@
<modules>
<module>wpilibJava</module>
<module>wpilibJavaDevices</module>
<module>wpilibJavaSim</module>
<module>wpilibJavaJNI</module>
<module>wpilibJavaFinal</module>

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>edu.wpi.first.wpilibj</groupId>
<artifactId>wpilibJava</artifactId>
@@ -18,11 +18,11 @@
<profile>
<id>docline-java8-disable</id>
<activation>
<jdk>[1.8,</jdk>
<jdk>[1.8,</jdk>
</activation>
<build>
<plugins>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
@@ -30,47 +30,21 @@
<additionalparam>-Xdoclint:none</additionalparam>
</configuration>
</plugin>
</plugins>
</plugins>
</build>
</profile>
</profiles>
<repositories>
<!-- repository>
<id>sonatype</id>
<name>Sonatype OSS Snapshots Repository</name>
<url>http://oss.sonatype.org/content/groups/public</url>
</repository -->
<!-- For old snapshots, please use groupId `com.jnaerator` and the following repo -->
<!-- repository>
<id>nativelibs4java-repo</id>
<url>http://nativelibs4java.sourceforge.net/maven</url>
</repository -->
</repositories>
<dependencies>
<!-- dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<version>4.0.0</version>
</dependency -->
<!-- dependency>
<groupId>com.nativelibs4java</groupId>
<artifactId>jnaerator-runtime</artifactId>
<version>0.12-SNAPSHOT</version>
<scope>compile</scope>
</dependency -->
<dependency>
<groupId>edu.wpi.first.wpilib.networktables.java</groupId>
<artifactId>NetworkTables</artifactId>
<version>0.1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>
</dependencies>
@@ -83,68 +57,12 @@
<configuration>
<source>1.7</source>
<target>1.7</target>
<excludes>
<exclude>edu/wpi/first/wpilibj/image/</exclude>
<exclude>edu/wpi/first/wpilibj/camera/</exclude>
<exclude>edu/wpi/first/wpilibj/visa/</exclude>
<exclude>edu/wpi/first/wpilibj/SerialPort.java</exclude>
<exclude>edu/wpi/first/wpilibj/Kinect.java</exclude>
<exclude>edu/wpi/first/wpilibj/KinectStick.java</exclude>
<exclude>edu/wpi/first/wpilibj/DriverStationEnhancedIO.java</exclude>
<exclude>edu/wpi/first/wpilibj/buttons/DigitalIOButton.java</exclude>
<exclude>edu/wpi/first/wpilibj/buttons/AnalogIOButton.java</exclude>
</excludes>
</configuration>
</plugin>
<!-- plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<id>fetch-dependencies</id>
<phase>compile</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>edu.wpi.first.wpilib.hal</groupId>
<artifactId>libHALAthenaJava</artifactId>
<version>0.1.0-SNAPSHOT</version>
<type>so</type>
<destFileName>libHALAthenaJava.so</destFileName>
<outputDirectory>${project.build.directory}/classes/linux-arm</outputDirectory>
</artifactItem>
</artifactItems>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
</configuration>
</execution>
</executions>
</plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<sourceFileExcludes>
<exclude>edu/wpi/first/wpilibj/image/</exclude>
<exclude>edu/wpi/first/wpilibj/camera/</exclude>
<exclude>edu/wpi/first/wpilibj/visa/</exclude>
<exclude>edu/wpi/first/wpilibj/SerialPort.java</exclude>
<exclude>edu/wpi/first/wpilibj/Kinect.java</exclude>
<exclude>edu/wpi/first/wpilibj/KinectStick.java</exclude>
<exclude>edu/wpi/first/wpilibj/DriverStationEnhancedIO.java</exclude>
<exclude>edu/wpi/first/wpilibj/buttons/DigitalIOButton.java</exclude>
<exclude>edu/wpi/first/wpilibj/buttons/AnalogIOButton.java</exclude>
</sourceFileExcludes>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@@ -0,0 +1,31 @@
package edu.wpi.first.wpilibj;
/**
* Support for high level usage reporting.
*
* @author alex
*/
public class HLUsageReporting {
private static Interface impl;
public static void SetImplementation(Interface i) {
impl = i;
}
public static void reportScheduler() {
if (impl != null) {
impl.reportScheduler();
}
}
public static void reportPIDController(int num) {
if (impl != null) {
impl.reportPIDController(num);
}
}
public interface Interface {
void reportScheduler();
void reportPIDController(int num);
}
}

View File

@@ -1,456 +0,0 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008-2012. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj;
import com.sun.jna.Pointer;
import com.sun.jna.Structure;
import edu.wpi.first.wpilibj.communication.FRCControl;
import edu.wpi.first.wpilibj.communication.UsageReporting;
/**
* @author bradmiller
* Handles raw data input from the FRC Kinect Server
* when used with a Kinect device connected to the Driver Station.
* Each time a value is requested the most recent value is returned.
* See Getting Started with Microsoft Kinect for FRC and the Kinect
* for Windows SDK API reference for more information
*
*/
public class Kinect {
private static Kinect m_instance;
/**
* Gets an instance of the Kinect device
*
* @return The Kinect.
*/
public static synchronized Kinect getInstance() {
if(m_instance == null)
m_instance = new Kinect();
return m_instance;
}
/**
* A set of 4 coordinates (x,y,z,w) bundled into one object
*/
public class Point4 {
public float x, y, z, w;
public float getX() {
return x;
}
public float getY() {
return y;
}
public float getZ() {
return z;
}
public float getW() {
return w;
}
public int size() {
return 16;
}
}
static class header_t extends Structure {
byte[] version = new byte[11];
byte players;
int flags;
float[] floorClipPlane = new float[4];
float[] gravityNormalVector = new float[3];
final static int size = 44;
header_t(Pointer backingMemory) {
useMemory(backingMemory);
}
public void read() {
backingNativeMemory.getBytes(0, version, 0, version.length);
players = backingNativeMemory.getByte(11);
flags = backingNativeMemory.getInt(12);
backingNativeMemory.getFloats(16, floorClipPlane, 0, floorClipPlane.length);
backingNativeMemory.getFloats(32, gravityNormalVector, 0, gravityNormalVector.length);
}
public void write() {
backingNativeMemory.setBytes(0, version, 0, version.length);
backingNativeMemory.setByte(11, players);
backingNativeMemory.setInt(12, flags);
backingNativeMemory.setFloats(16, floorClipPlane, 0, floorClipPlane.length);
backingNativeMemory.setFloats(32, gravityNormalVector, 0, gravityNormalVector.length);
}
public int size() {
return size;
}
}
static class skeletonExtra_t extends Structure {
byte[] trackingState = new byte[20];
float[] position = new float[3];
int quality;
int trackState;
final static int size = 40;
skeletonExtra_t(Pointer backingMemory) {
useMemory(backingMemory);
}
public void read() {
backingNativeMemory.getBytes(0, trackingState, 0, trackingState.length);
backingNativeMemory.getFloats(20, position, 0, position.length);
quality = backingNativeMemory.getInt(32);
trackState = backingNativeMemory.getInt(36);
}
public void write() {
backingNativeMemory.setBytes(0, trackingState, 0, trackingState.length);
backingNativeMemory.setFloats(20, position, 0, position.length);
backingNativeMemory.setInt(32, quality);
backingNativeMemory.setInt(36, trackState);
}
public int size() {
return size;
}
}
static class skeleton_t extends Structure {
float[] vertices = new float[60];
final static int size = 240;
skeleton_t(Pointer backingMemory) {
useMemory(backingMemory);
}
public void read() {
backingNativeMemory.getFloats(0, vertices, 0, vertices.length);
}
public void write() {
backingNativeMemory.setFloats(0, vertices, 0, vertices.length);
}
public int size() {
return size;
}
}
class header_block_t extends FRCControl.DynamicControlData {
byte size = 45;
byte id = kHeaderBlockID;
header_t data;
{
allocateMemory();
data = new header_t(
new Pointer(backingNativeMemory.address().toUWord().toPrimitive() + 2,
header_t.size));
}
public void read() {
size = backingNativeMemory.getByte(0);
id = backingNativeMemory.getByte(1);
data.read();
}
public void write() {
backingNativeMemory.setByte(0, size);
backingNativeMemory.setByte(1, id);
data.write();
}
public int size() {
return 46;
}
public void copy(header_block_t dest) {
write();
Pointer.copyBytes(backingNativeMemory, 0, dest.backingNativeMemory, 0, size());
dest.read();
}
}
class skeletonExtra_block_t extends FRCControl.DynamicControlData {
byte size = 41;
byte id = kSkeletonExtraBlockID;
skeletonExtra_t data;
{
allocateMemory();
data = new skeletonExtra_t(
new Pointer(backingNativeMemory.address().toUWord().toPrimitive() + 2,
skeletonExtra_t.size));
}
public void read() {
size = backingNativeMemory.getByte(0);
id = backingNativeMemory.getByte(1);
data.read();
}
public void write() {
backingNativeMemory.setByte(0, size);
backingNativeMemory.setByte(1, id);
data.write();
}
public int size() {
return 42;
}
public void copy(skeletonExtra_block_t dest) {
write();
Pointer.copyBytes(backingNativeMemory, 0, dest.backingNativeMemory, 0, size());
dest.read();
}
}
class skeleton_block_t extends FRCControl.DynamicControlData {
byte size = -15; //temporary hack for 241
byte id = kSkeletonBlockID;
skeleton_t data;
{
allocateMemory();
data = new skeleton_t(
new Pointer(backingNativeMemory.address().toUWord().toPrimitive() + 2,
skeleton_t.size));
}
public void read() {
size = backingNativeMemory.getByte(0);
id = backingNativeMemory.getByte(1);
data.read();
}
public void write() {
backingNativeMemory.setByte(0, size);
backingNativeMemory.setByte(1, id);
data.write();
}
public int size() {
return 242;
}
public void copy(skeleton_block_t dest) {
write();
Pointer.copyBytes(backingNativeMemory, 0, dest.backingNativeMemory, 0, size());
dest.read();
}
}
static final byte kHeaderBlockID = 19;
static final byte kSkeletonExtraBlockID = 20;
static final byte kSkeletonBlockID = 21;
header_block_t m_headerData;
skeletonExtra_block_t m_skeletonExtraData;
skeleton_block_t m_skeletonData;
boolean m_headerValid = false;
boolean m_skeletonExtraValid = false;
boolean m_skeletonValid = false;
final Object m_headerDataSemaphore;
final Object m_skeletonExtraDataSemaphore;
final Object m_skeletonDataSemaphore;
int m_recentPacketNumber = 0;
/**
* Kinect constructor.
*
* This is only called once on the first call of getInstance()
*/
Kinect() {
m_headerData = new header_block_t();
m_skeletonExtraData = new skeletonExtra_block_t();
m_skeletonData = new skeleton_block_t();
m_headerDataSemaphore = new Object();
m_skeletonExtraDataSemaphore = new Object();
m_skeletonDataSemaphore = new Object();
UsageReporting.report(UsageReporting.kResourceType_Kinect, 0);
}
header_block_t tempHeaderData = new header_block_t();
skeletonExtra_block_t tempSkeletonExtraData = new skeletonExtra_block_t();
skeleton_block_t tempSkeletonData = new skeleton_block_t();
/**
* Called by the other Kinect functions to check for the latest data
* This function will update the internal data structures
* with the most recent Kinect input
*/
void updateData() {
int retVal;
if (m_recentPacketNumber != DriverStation.getInstance().getPacketNumber()) {
m_recentPacketNumber = DriverStation.getInstance().getPacketNumber();
synchronized (m_headerDataSemaphore) {
retVal = FRCControl.getDynamicControlData(kHeaderBlockID, tempHeaderData, tempHeaderData.size(), 5);
if (retVal == 0) {
tempHeaderData.copy(m_headerData);
m_headerValid = true;
} else {
m_headerValid = false;
}
}
synchronized (m_skeletonExtraDataSemaphore) {
retVal = FRCControl.getDynamicControlData(kSkeletonExtraBlockID, tempSkeletonExtraData, tempSkeletonExtraData.size(), 5);
if (retVal == 0) {
tempSkeletonExtraData.copy(m_skeletonExtraData);
m_skeletonExtraValid = true;
} else {
m_skeletonExtraValid = false;
}
}
synchronized (m_skeletonDataSemaphore) {
retVal = FRCControl.getDynamicControlData(kSkeletonBlockID, tempSkeletonData, tempSkeletonData.size(), 5);
if (retVal == 0) {
tempSkeletonData.copy(m_skeletonData);
m_skeletonValid = true;
} else {
m_skeletonValid = false;
}
}
}
}
/**
* Query the number of players detected by the Kinect
*
* @return The current number of players
*/
public int getNumberOfPlayers() {
updateData();
if (!m_headerValid) {
return 0;
}
synchronized (m_headerDataSemaphore) {
return (int)m_headerData.data.players;
}
}
/**
* Retrieve the FloorClipPlane from the Kinect device
*
* @return The FloorClipPlane
*/
public Point4 getFloorClipPlane() {
updateData();
Point4 tempClipPlane = new Point4();
if (!m_headerValid) {
return tempClipPlane;
}
synchronized(m_headerDataSemaphore) {
tempClipPlane.x = m_headerData.data.floorClipPlane[0];
tempClipPlane.y = m_headerData.data.floorClipPlane[1];
tempClipPlane.z = m_headerData.data.floorClipPlane[2];
tempClipPlane.w = m_headerData.data.floorClipPlane[3];
}
return tempClipPlane;
}
/**
* Retrieve the GravityNormal vector from the Kinect device
* The w value returned from this method is always 0
* @return The GravityNormal vector
*/
public Point4 getGravityNormal() {
updateData();
Point4 tempGravityNormal = new Point4();
if (!m_headerValid) {
return tempGravityNormal;
}
synchronized(m_headerDataSemaphore) {
tempGravityNormal.x = m_headerData.data.gravityNormalVector[0];
tempGravityNormal.y = m_headerData.data.gravityNormalVector[1];
tempGravityNormal.z = m_headerData.data.gravityNormalVector[2];
tempGravityNormal.w = 0;
}
return tempGravityNormal;
}
/**
* Query the position of the detected skeleton
* The w value returned from this method is always 1
* @return The position of the skeleton
*/
public Point4 getPosition() {
updateData();
Point4 tempPosition = new Point4();
if (!m_skeletonExtraValid) {
return tempPosition;
}
synchronized(m_headerDataSemaphore) {
tempPosition.x = m_skeletonExtraData.data.position[0];
tempPosition.y = m_skeletonExtraData.data.position[1];
tempPosition.z = m_skeletonExtraData.data.position[2];
tempPosition.w = 1;
}
return tempPosition;
}
/**
* Retrieve the detected skeleton from the Kinect device
*
* @return The skeleton
*/
public Skeleton getSkeleton() {
updateData();
Skeleton tempSkeleton = new Skeleton();
if (!m_skeletonValid) {
return tempSkeleton;
}
synchronized (m_skeletonDataSemaphore) {
for(int i=0; i<20; i++) {
tempSkeleton.skeleton[i].x = m_skeletonData.data.vertices[i*3];
tempSkeleton.skeleton[i].y = m_skeletonData.data.vertices[i*3+1];
tempSkeleton.skeleton[i].z = m_skeletonData.data.vertices[i*3+2];
}
}
synchronized (m_skeletonExtraDataSemaphore) {
for(int i=0; i<20; i++) {
tempSkeleton.skeleton[i].trackingState = m_skeletonExtraData.data.trackingState[i];
}
switch(m_skeletonExtraData.data.trackState) {
case 0:
tempSkeleton.trackState = Skeleton.tTrackState.kNotTracked;
break;
case 1:
tempSkeleton.trackState = Skeleton.tTrackState.kPositionOnly;
break;
case 2:
tempSkeleton.trackState = Skeleton.tTrackState.kTracked;
break;
}
}
return tempSkeleton;
}
}

View File

@@ -1,260 +0,0 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008-2012. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj;
import com.sun.jna.Pointer;
import com.sun.jna.Structure;
import edu.wpi.first.wpilibj.communication.FRCControl;
import edu.wpi.first.wpilibj.communication.UsageReporting;
/**
* @author bradmiller
* Handles input from the Joystick data sent by the FRC Kinect Server
* when used with a Kinect device connected to the Driver Station.
* Each time a value is requested the most recent value is returned.
* Default gestures embedded in the FRC Kinect Server are described
* in the document Getting Started with Microsoft Kinect for FRC.
*/
public class KinectStick extends GenericHID {
private final static byte kJoystickDataID = 24;
private final static byte kJoystickDataSize = 18;
private int m_recentPacketNumber;
private int m_id;
static class JoystickDataBlock extends Structure {
byte joystick1[] = new byte[6];
short button1;
byte joystick2[] = new byte[6];
short button2;
public static final int size = kJoystickDataSize - 2;
JoystickDataBlock(Pointer backingMemory) {
useMemory(backingMemory);
}
public void read() {
backingNativeMemory.getBytes(0, joystick1, 0, 6);
button1 = backingNativeMemory.getShort(6);
backingNativeMemory.getBytes(8, joystick2, 0, 6);
button2 = backingNativeMemory.getShort(14);
}
public void write() {
backingNativeMemory.setBytes(0, joystick1, 0, 6);
backingNativeMemory.setShort(6, button1);
backingNativeMemory.setBytes(8, joystick2, 0, 6);
backingNativeMemory.setShort(14, button2);
}
public int size() {
return size;
}
}
class JoystickData extends FRCControl.DynamicControlData {
JoystickDataBlock data;
{
allocateMemory();
data = new JoystickDataBlock(
new Pointer(backingNativeMemory.address().toUWord().toPrimitive() + 2,
JoystickDataBlock.size));
}
public void read() {
data.read();
}
public void write() {
data.write();
}
public int size() {
return kJoystickDataSize;
}
public void copy(JoystickData dest) {
write();
Pointer.copyBytes(backingNativeMemory, 0, dest.backingNativeMemory, 0, size());
dest.read();
}
}
JoystickData tempOutputData = new JoystickData();
/**
* Construct an instance of a KinectStick.
* @param id which KinectStick to read, in the default gestures
* an id of 1 corresponds to the left arm and 2 to the right arm.
*/
public KinectStick(int id) {
m_id = id;
UsageReporting.report(UsageReporting.kResourceType_KinectStick, id);
}
/**
* Update the data in this class with the latest data from the
* Driver Station.
*/
private void getData() {
if (m_recentPacketNumber != DriverStation.getInstance().getPacketNumber()) {
m_recentPacketNumber = DriverStation.getInstance().getPacketNumber();
int retVal = FRCControl.getDynamicControlData(kJoystickDataID, tempOutputData, tempOutputData.size(), 5);
if (retVal != 0) {
System.err.println("Bad retval: " + retVal);
}
}
}
/**
* Convert a value from a byte to a double in the
* -1 to 1 range
* @param rawValue the value to convert
* @return the normalized value
*/
private double normalize(byte rawValue) {
if(rawValue >= 0)
return rawValue / 127.0;
else
return rawValue / 128.0;
}
/**
* Get the X value of the KinectStick. This axis
* is unimplemented in the default gestures but can
* be populated by teams editing the Kinect Server.
* See (@link Joystick for axis number mapping)
* @param hand Unused
* @return The X value of the KinectStick
*/
public double getX(Hand hand) {
getData();
return getRawAxis(Joystick.kDefaultXAxis);
}
/**
* Get the Y value of the KinectStick. This axis
* represents arm angle in the default gestures
* See (@link Joystick for axis number mapping)
* @param hand Unused
* @return The Y value of the KinectStick
*/
public double getY(Hand hand) {
getData();
return getRawAxis(Joystick.kDefaultYAxis);
}
/**
* Get the Z value of the KinectStick. This axis
* is unimplemented in the default gestures but can
* be populated by teams editing the Kinect Server.
* See (@link Joystick for axis number mapping)
* @param hand Unused
* @return The Z value of the KinectStick
*/
public double getZ(Hand hand) {
getData();
return getRawAxis(Joystick.kDefaultZAxis);
}
/**
* Get the Twist value of the KinectStick. This axis
* is unimplemented in the default gestures but can
* be populated by teams editing the Kinect Server.
* See (@link Joystick for axis number mapping)
* @return The Twist value of the KinectStick
*/
public double getTwist() {
getData();
return getRawAxis(Joystick.kDefaultTwistAxis);
}
/**
* Get the Throttle value of the KinectStick. This axis
* is unimplemented in the default gestures but can
* be populated by teams editing the Kinect Server.
* See (@link Joystick for axis number mapping)
* @return The Throttle value of the KinectStick
*/
public double getThrottle() {
getData();
return getRawAxis(Joystick.kDefaultThrottleAxis);
}
/**
* Get the value of the KinectStick axis.
*
* @param axis The axis to read [1-6].
* @return The value of the axis
*/
public double getRawAxis(int axis) {
if (axis < 1 || axis > DriverStation.kJoystickAxes)
return 0.0;
getData();
if (m_id == 1) {
return normalize(tempOutputData.data.joystick1[axis-1]);
} else {
return normalize(tempOutputData.data.joystick2[axis-1]);
}
}
/**
* Get the button value for the button set as the default trigger in
* (@link Joystick)
*
* @param hand Unused
* @return The state of the button.
*/
public boolean getTrigger(Hand hand) {
getData();
return (tempOutputData.data.button1 & (short) Joystick.kDefaultTriggerButton) != 0;
}
/**
* Get the button value for the button set as the default top in
* (@link Joystick)
*
* @param hand Unused
* @return The state of the button.
*/
public boolean getTop(Hand hand) {
getData();
return (tempOutputData.data.button1 & (short) Joystick.kDefaultTopButton) != 0;
}
/**
* Get the button value for the button set as the default bumper in
* (@link Joystick)
*
* @param hand Unused
* @return The state of the button.
*/
public boolean getBumper(Hand hand) {
getData();
return (tempOutputData.data.button1 & (short) 4) != 0;
}
/**
* Get the button value for buttons 1 through 12. The default gestures
* implement only 9 buttons.
*
* The appropriate button is returned as a boolean value.
*
* @param button The button number to be read.
* @return The state of the button.
*/
public boolean getRawButton(int button) {
getData();
return (tempOutputData.data.button1 & (short) (1 << (button - 1))) != 0;
}
}

View File

@@ -7,6 +7,8 @@
package edu.wpi.first.wpilibj;
import edu.wpi.first.wpilibj.Timer;
/**
* The MotorSafetyHelper object is constructed for every object that wants to implement the Motor
* Safety protocol. The helper object has the code to actually do the timing and call the
@@ -82,8 +84,7 @@ public class MotorSafetyHelper {
* updated again.
*/
public void check() {
DriverStation ds = DriverStation.getInstance();
if (!m_enabled || ds.isDisabled() || ds.isTest())
if (!m_enabled || RobotState.isDisabled() || RobotState.isTest())
return;
if (m_stopTime < Timer.getFPGATimestamp()) {
System.err.println(m_safeObject.getDescription() + "... Output not updated often enough.");

View File

@@ -6,10 +6,7 @@
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj;
import java.util.TimerTask;
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType;
import edu.wpi.first.wpilibj.communication.UsageReporting;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.livewindow.LiveWindowSendable;
import edu.wpi.first.wpilibj.parsing.IUtility;
import edu.wpi.first.wpilibj.tables.ITable;
@@ -46,7 +43,6 @@ public class PIDController implements IUtility, LiveWindowSendable, Controller {
private double m_period = kDefaultPeriod;
PIDSource m_pidInput;
PIDOutput m_pidOutput;
java.util.Timer m_controlLoop;
private boolean m_freed = false;
private boolean m_usingPercentTolerance;
@@ -91,8 +87,7 @@ public class PIDController implements IUtility, LiveWindowSendable, Controller {
}
}
private class PIDTask extends TimerTask {
private class PIDTask implements Runnable {
private PIDController m_controller;
public PIDTask(PIDController controller) {
@@ -103,10 +98,9 @@ public class PIDController implements IUtility, LiveWindowSendable, Controller {
}
public void run() {
if(!m_freed){
while (!m_controller.m_freed) {
m_controller.calculate();
} else {
cancel();
Timer.delay(m_controller.m_period);
}
}
}
@@ -133,9 +127,6 @@ public class PIDController implements IUtility, LiveWindowSendable, Controller {
throw new NullPointerException("Null PIDOutput was given");
}
m_controlLoop = new java.util.Timer();
m_P = Kp;
m_I = Ki;
m_D = Kd;
@@ -145,10 +136,10 @@ public class PIDController implements IUtility, LiveWindowSendable, Controller {
m_pidOutput = output;
m_period = period;
m_controlLoop.schedule(new PIDTask(this), 0L, (long) (m_period * 1000));
new Thread(new PIDTask(this)).start();
instances++;
UsageReporting.report(tResourceType.kResourceType_PIDController, instances);
HLUsageReporting.reportPIDController(instances);
m_tolerance = new NullTolerance();
}
@@ -199,10 +190,8 @@ public class PIDController implements IUtility, LiveWindowSendable, Controller {
public void free() {
m_freed = true;
if(this.table!=null) table.removeTableListener(listener);
m_controlLoop.cancel();
m_pidInput = null;
m_pidOutput = null;
m_controlLoop = null;
}
/**

View File

@@ -0,0 +1,57 @@
package edu.wpi.first.wpilibj;
public class RobotState {
private static Interface impl;
public static void SetImplementation(Interface i) {
impl = i;
}
public static boolean isDisabled() {
if (impl != null) {
return impl.isDisabled();
} else {
return true;
}
}
public static boolean isEnabled() {
if (impl != null) {
return impl.isEnabled();
} else {
return false;
}
}
public static boolean isOperatorControl() {
if (impl != null) {
return impl.isOperatorControl();
} else {
return true;
}
}
public static boolean isAutonomous() {
if (impl != null) {
return impl.isAutonomous();
} else {
return false;
}
}
public static boolean isTest() {
if (impl != null) {
return impl.isTest();
} else {
return false;
}
}
interface Interface {
boolean isDisabled();
boolean isEnabled();
boolean isOperatorControl();
boolean isAutonomous();
boolean isTest();
}
}

View File

@@ -1,227 +0,0 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008-2012. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj;
/**
* A Skeleton object to be used with Kinect data from the
* FRC Kinect server on the DriverStation
* @author koconnor
*/
public class Skeleton {
/**
* The TrackState of the skeleton
*/
public static class tTrackState {
/** The integer value representing this enumeration. */
public final int value;
protected static final int kNotTracked_val = 0;
protected static final int kPositionOnly_val = 1;
protected static final int kTracked_val = 2;
/** TrackState: Not Tracked */
public static final tTrackState kNotTracked = new tTrackState(kNotTracked_val);
/** TrackState: Position Only */
public static final tTrackState kPositionOnly = new tTrackState(kPositionOnly_val);
/** TrackState: Tracked */
public static final tTrackState kTracked = new tTrackState(kTracked_val);
private tTrackState(int value) {
this.value = value;
}
}
/**
* The Joint TrackingState
*/
public static class tJointTrackingState {
/** The integer value representing this enumeration. */
public final int value;
protected static final int kNotTracked_val = 0;
protected static final int kInferred_val = 1;
protected static final int kTracked_val = 2;
/** Joint TrackingState: Not Tracked */
public static final tJointTrackingState kNotTracked = new tJointTrackingState(kNotTracked_val);
/** Joint TrackingState: Inferred */
public static final tJointTrackingState kInferred = new tJointTrackingState(kInferred_val);
/** Joint TrackingState: Tracked */
public static final tJointTrackingState kTracked = new tJointTrackingState(kTracked_val);
private tJointTrackingState(int value) {
this.value = value;
}
}
/**
* An individual Joint from Kinect data
*/
public class Joint {
protected float x, y, z;
protected byte trackingState;
Joint() {
x = y = z = 0;
}
public float getX() {
return x;
}
public float getY() {
return y;
}
public float getZ() {
return z;
}
public tJointTrackingState getTrackingState() {
switch(trackingState) {
case 1:
return tJointTrackingState.kInferred;
case 2:
return tJointTrackingState.kTracked;
default:
return tJointTrackingState.kNotTracked;
}
}
}
/**
* Helper class used to index the joints in a (@link Skeleton)
*/
public static class tJointTypes {
public final int value;
protected static final int kHipCenter_val = 0;
protected static final int kSpine_val = 1;
protected static final int kShoulderCenter_val = 2;
protected static final int kHead_val = 3;
protected static final int kShoulderLeft_val = 4;
protected static final int kElbowLeft_val = 5;
protected static final int kWristLeft_val = 6;
protected static final int kHandLeft_val = 7;
protected static final int kShoulderRight_val = 8;
protected static final int kElbowRight_val = 9;
protected static final int kWristRight_val = 10;
protected static final int kHandRight_val = 11;
protected static final int kHipLeft_val = 12;
protected static final int kKneeLeft_val = 13;
protected static final int kAnkleLeft_val = 14;
protected static final int kFootLeft_val = 15;
protected static final int kHipRight_val = 16;
protected static final int kKneeRight_val = 17;
protected static final int kAnkleRight_val = 18;
protected static final int kFootRight_val = 19;
protected static final int kCount_val = 20;
public static final tJointTypes kHipCenter = new tJointTypes(kHipCenter_val);
public static final tJointTypes kSpine = new tJointTypes(kSpine_val);
public static final tJointTypes kShoulderCenter = new tJointTypes(kShoulderCenter_val);
public static final tJointTypes kHead = new tJointTypes(kHead_val);
public static final tJointTypes kShoulderLeft = new tJointTypes(kShoulderLeft_val);
public static final tJointTypes kElbowLeft = new tJointTypes(kElbowLeft_val);
public static final tJointTypes kWristLeft = new tJointTypes(kWristLeft_val);
public static final tJointTypes kHandLeft = new tJointTypes(kHandLeft_val);
public static final tJointTypes kShoulderRight = new tJointTypes(kShoulderRight_val);
public static final tJointTypes kElbowRight = new tJointTypes(kElbowRight_val);
public static final tJointTypes kWristRight = new tJointTypes(kWristRight_val);
public static final tJointTypes kHandRight = new tJointTypes(kHandRight_val);
public static final tJointTypes kHipLeft = new tJointTypes(kHipLeft_val);
public static final tJointTypes kKneeLeft = new tJointTypes(kKneeLeft_val);
public static final tJointTypes kAnkleLeft = new tJointTypes(kAnkleLeft_val);
public static final tJointTypes kFootLeft = new tJointTypes(kFootLeft_val);
public static final tJointTypes kHipRight = new tJointTypes(kHipRight_val);
public static final tJointTypes kKneeRight = new tJointTypes(kKneeRight_val);
public static final tJointTypes kAnkleRight = new tJointTypes(kAnkleRight_val);
public static final tJointTypes kFootRight = new tJointTypes(kFootRight_val);
public static final tJointTypes kCount = new tJointTypes(kCount_val);
private tJointTypes(int value) {
this.value = value;
}
}
public Joint GetHandRight() {
return skeleton[tJointTypes.kHandRight.value];
}
public Joint GetHandLeft() {
return skeleton[tJointTypes.kHandLeft.value];
}
public Joint GetWristRight() {
return skeleton[tJointTypes.kWristRight.value];
}
public Joint GetWristLeft() {
return skeleton[tJointTypes.kWristLeft.value];
}
public Joint GetElbowLeft() {
return skeleton[tJointTypes.kElbowLeft.value];
}
public Joint GetElbowRight() {
return skeleton[tJointTypes.kElbowRight.value];
}
public Joint GetShoulderLeft() {
return skeleton[tJointTypes.kShoulderLeft.value];
}
public Joint GetShoulderRight() {
return skeleton[tJointTypes.kShoulderRight.value];
}
public Joint GetShoulderCenter() {
return skeleton[tJointTypes.kShoulderCenter.value];
}
public Joint GetHead() {
return skeleton[tJointTypes.kHead.value];
}
public Joint GetSpine() {
return skeleton[tJointTypes.kSpine.value];
}
public Joint GetHipCenter() {
return skeleton[tJointTypes.kHipCenter.value];
}
public Joint GetHipRight() {
return skeleton[tJointTypes.kHipRight.value];
}
public Joint GetHipLeft() {
return skeleton[tJointTypes.kHipLeft.value];
}
public Joint GetKneeLeft() {
return skeleton[tJointTypes.kKneeLeft.value];
}
public Joint GetKneeRight() {
return skeleton[tJointTypes.kKneeRight.value];
}
public Joint GetAnkleLeft() {
return skeleton[tJointTypes.kAnkleLeft.value];
}
public Joint GetAnkleRight() {
return skeleton[tJointTypes.kAnkleRight.value];
}
public Joint GetFootLeft() {
return skeleton[tJointTypes.kFootLeft.value];
}
public Joint GetFootRight() {
return skeleton[tJointTypes.kFootRight.value];
}
public Joint GetJoint(tJointTypes index) {
return skeleton[index.value];
}
public tTrackState GetTrackState() {
return trackState;
}
Skeleton() {
for(int i=0; i<20; i++) {
skeleton[i] = new Joint();
}
}
protected Joint[] skeleton = new Joint[20];
protected tTrackState trackState;
}

View File

@@ -1,27 +1,44 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008-2012. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj;
import edu.wpi.first.wpilibj.parsing.IUtility;
/**
* Timer objects measure accumulated time in milliseconds.
* The timer object functions like a stopwatch. It can be started, stopped, and cleared. When the
* timer is running its value counts up in milliseconds. When stopped, the timer holds the current
* value. The implementation simply records the time when started and subtracts the current time
* whenever the value is requested.
*/
public class Timer implements IUtility {
private long m_startTime;
private double m_accumulatedTime;
private boolean m_running;
public class Timer {
private static StaticInterface impl;
public static void SetImplementation(StaticInterface ti) {
impl = ti;
}
/**
* Return the system clock time in seconds. Return the time from the
* FPGA hardware clock in seconds since the FPGA started.
*
* @return Robot running time in seconds.
*/
public static double getFPGATimestamp() {
if (impl != null) {
return impl.getFPGATimestamp();
} else {
return 0; // TODO: Handle error
}
}
/**
* Return the approximate match time
* The FMS does not currently send the official match time to the robots
* This returns the time since the enable signal sent from the Driver Station
* At the beginning of autonomous, the time is reset to 0.0 seconds
* At the beginning of teleop, the time is reset to +15.0 seconds
* If the robot is disabled, this returns 0.0 seconds
* Warning: This is not an official time (so it cannot be used to argue with referees)
* @return Match time in seconds since the beginning of autonomous
*/
public static double getMatchTime() {
if (impl != null) {
return impl.getMatchTime();
} else {
return 0; // TODO: Handle error
}
}
/**
* Pause the thread for a specified time. Pause the execution of the
* thread for a specified period of time given in seconds. Motors will
@@ -32,51 +49,24 @@ public class Timer implements IUtility {
* @param seconds Length of time to pause
*/
public static void delay(final double seconds) {
try {
Thread.sleep((long) (seconds * 1e3));
} catch (final InterruptedException e) {
}
if (impl != null) {
impl.delay(seconds);
} else {
// TODO: Handle error
}
}
/**
* Return the system clock time in microseconds. Return the time from the
* FPGA hardware clock in microseconds since the FPGA started.
*
* @deprecated Use getFPGATimestamp instead.
* @return Robot running time in microseconds.
*/
public static long getUsClock() {
return Utility.getFPGATime();
public interface StaticInterface {
double getFPGATimestamp();
double getMatchTime();
void delay(final double seconds);
Interface newTimer();
}
/**
* Return the system clock time in milliseconds. Return the time from the
* FPGA hardware clock in milliseconds since the FPGA started.
*
* @deprecated Use getFPGATimestamp instead.
* @return Robot running time in milliseconds.
*/
static long getMsClock() {
return getUsClock() / 1000;
}
/**
* Return the system clock time in seconds. Return the time from the
* FPGA hardware clock in seconds since the FPGA started.
*
* @return Robot running time in seconds.
*/
public static double getFPGATimestamp() {
return Utility.getFPGATime() / 1000000.0;
}
/**
* Create a new timer object.
* Create a new timer object and reset the time to zero. The timer is initially not running and
* must be started.
*/
private Interface timer;
public Timer() {
reset();
timer = impl.newTimer();
}
/**
@@ -86,21 +76,16 @@ public class Timer implements IUtility {
*
* @return Current time value for this timer in seconds
*/
public synchronized double get() {
if (m_running) {
return ((double) ((getMsClock() - m_startTime) + m_accumulatedTime)) / 1000.0;
} else {
return m_accumulatedTime;
}
public double get() {
return timer.get();
}
/**
* Reset the timer by setting the time to 0.
* Make the timer startTime the current time so new requests will be relative now
*/
public synchronized void reset() {
m_accumulatedTime = 0;
m_startTime = getMsClock();
public void reset() {
timer.reset();
}
/**
@@ -108,9 +93,8 @@ public class Timer implements IUtility {
* Just set the running flag to true indicating that all time requests should be
* relative to the system clock.
*/
public synchronized void start() {
m_startTime = getMsClock();
m_running = true;
public void start() {
timer.start();
}
/**
@@ -119,9 +103,39 @@ public class Timer implements IUtility {
* subsequent time requests to be read from the accumulated time rather than
* looking at the system clock.
*/
public synchronized void stop() {
final double temp = get();
m_accumulatedTime = temp;
m_running = false;
public void stop() {
timer.stop();
}
public interface Interface {
/**
* Get the current time from the timer. If the clock is running it is derived from
* the current system clock the start time stored in the timer class. If the clock
* is not running, then return the time when it was last stopped.
*
* @return Current time value for this timer in seconds
*/
public double get();
/**
* Reset the timer by setting the time to 0.
* Make the timer startTime the current time so new requests will be relative now
*/
public void reset();
/**
* Start the timer running.
* Just set the running flag to true indicating that all time requests should be
* relative to the system clock.
*/
public void start();
/**
* Stop the timer.
* This computes the time as of now and clears the running flag, causing all
* subsequent time requests to be read from the accumulated time rather than
* looking at the system clock.
*/
public void stop();
}
}

View File

@@ -1,35 +0,0 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008-2012. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.buttons;
import edu.wpi.first.wpilibj.DriverStation;
import edu.wpi.first.wpilibj.DriverStationEnhancedIO.EnhancedIOException;
/**
*
* @author Greg
*/
public class AnalogIOButton extends Trigger {
public static double THRESHOLD = 0.5;
int port;
public AnalogIOButton(int port) {
this.port = port;
}
public boolean get() {
try {
return DriverStation.getInstance().getEnhancedIO().getAnalogIn(port) < THRESHOLD;
} catch (EnhancedIOException ex) {
return false;
}
}
}

View File

@@ -1,33 +0,0 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008-2012. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.buttons;
import edu.wpi.first.wpilibj.DriverStation;
import edu.wpi.first.wpilibj.DriverStationEnhancedIO.EnhancedIOException;
/**
*
* @author Greg
*/
public class DigitalIOButton extends Button {
public final static boolean ACTIVE_STATE = false;
int port;
public DigitalIOButton(int port) {
this.port = port;
}
public boolean get() {
try {
return DriverStation.getInstance().getEnhancedIO().getDigital(port) == ACTIVE_STATE;
} catch (EnhancedIOException ex) {
return false;
}
}
}

View File

@@ -7,8 +7,8 @@
package edu.wpi.first.wpilibj.command;
import edu.wpi.first.wpilibj.DriverStation;
import edu.wpi.first.wpilibj.NamedSendable;
import edu.wpi.first.wpilibj.RobotState;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.tables.ITable;
import edu.wpi.first.wpilibj.tables.ITableListener;
@@ -201,7 +201,7 @@ public abstract class Command implements NamedSendable {
* @return whether or not the command should stay within the {@link Scheduler}.
*/
synchronized boolean run() {
if (!m_runWhenDisabled && m_parent == null && DriverStation.getInstance().isDisabled()) {
if (!m_runWhenDisabled && m_parent == null && RobotState.isDisabled()) {
cancel();
}
if (isCanceled()) {

View File

@@ -10,11 +10,9 @@ import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Vector;
import edu.wpi.first.wpilibj.HLUsageReporting;
import edu.wpi.first.wpilibj.NamedSendable;
import edu.wpi.first.wpilibj.buttons.Trigger.ButtonScheduler;
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tInstances;
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType;
import edu.wpi.first.wpilibj.communication.UsageReporting;
import edu.wpi.first.wpilibj.networktables2.type.NumberArray;
import edu.wpi.first.wpilibj.networktables2.type.StringArray;
import edu.wpi.first.wpilibj.tables.ITable;
@@ -91,7 +89,7 @@ public class Scheduler implements NamedSendable {
* Instantiates a {@link Scheduler}.
*/
private Scheduler() {
UsageReporting.report(tResourceType.kResourceType_Command, tInstances.kCommand_Scheduler);
HLUsageReporting.reportScheduler();
}
/**

View File

@@ -7,7 +7,7 @@
package edu.wpi.first.wpilibj.command;
import edu.wpi.first.wpilibj.DriverStation;
import edu.wpi.first.wpilibj.Timer;
/**
* WaitUntilCommand - waits until an absolute game time.
@@ -34,7 +34,7 @@ public class WaitUntilCommand extends Command {
* Check if we've reached the actual finish time.
*/
public boolean isFinished() {
return DriverStation.getInstance().getMatchTime() >= m_time;
return Timer.getMatchTime() >= m_time;
}
public void end() {

View File

@@ -0,0 +1,91 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>edu.wpi.first.wpilibj</groupId>
<artifactId>wpilibJavaDevices</artifactId>
<packaging>jar</packaging>
<version>0.1.0-SNAPSHOT</version>
<parent>
<groupId>edu.wpi.first.wpilib.templates.athena</groupId>
<artifactId>library-jar</artifactId>
<version>0.1.0-SNAPSHOT</version>
<relativePath>../../maven-utilities/athena/library-jar</relativePath>
</parent>
<profiles>
<profile>
<id>docline-java8-disable</id>
<activation>
<jdk>[1.8,</jdk>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<additionalparam>-Xdoclint:none</additionalparam>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<dependencies>
<dependency>
<groupId>edu.wpi.first.wpilibj</groupId>
<artifactId>wpilibJava</artifactId>
<version>0.1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>edu.wpi.first.wpilib.networktables.java</groupId>
<artifactId>NetworkTables</artifactId>
<version>0.1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<excludes>
<exclude>edu/wpi/first/wpilibj/image/</exclude>
<exclude>edu/wpi/first/wpilibj/camera/</exclude>
<exclude>edu/wpi/first/wpilibj/visa/</exclude>
<exclude>edu/wpi/first/wpilibj/SerialPort.java</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<sourceFileExcludes>
<exclude>edu/wpi/first/wpilibj/image/</exclude>
<exclude>edu/wpi/first/wpilibj/camera/</exclude>
<exclude>edu/wpi/first/wpilibj/visa/</exclude>
<exclude>edu/wpi/first/wpilibj/SerialPort.java</exclude>
</sourceFileExcludes>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@@ -73,7 +73,6 @@ public class AnalogInput extends SensorBase implements PIDSource,
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
// XXX: Uncomment when Analog has been fixed
m_port = AnalogJNI.initializeAnalogInputPort(port_pointer, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());

View File

@@ -13,6 +13,7 @@ import java.nio.ByteOrder;
import edu.wpi.first.wpilibj.can.CANExceptionFactory;
import edu.wpi.first.wpilibj.can.CANJNI;
import edu.wpi.first.wpilibj.can.CANMessageNotFoundException;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.livewindow.LiveWindowSendable;
import edu.wpi.first.wpilibj.tables.ITable;
import edu.wpi.first.wpilibj.tables.ITableListener;

View File

@@ -13,12 +13,13 @@ import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary;
import edu.wpi.first.wpilibj.communication.FRCCommonControlData;
import edu.wpi.first.wpilibj.communication.FRCCommonControlMasks;
import edu.wpi.first.wpilibj.hal.HALUtil;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.parsing.IInputOutput;
/**
* Provide access to the network communication data to / from the Driver Station.
*/
public class DriverStation implements IInputOutput {
public class DriverStation implements IInputOutput, RobotState.Interface {
/**
* The size of the user status data
@@ -104,8 +105,6 @@ public class DriverStation implements IInputOutput {
private boolean m_userInTest = false;
private boolean m_newControlData;
private final ByteBuffer m_packetDataAvailableSem;
// XXX: Add DriverStationEnhancedIO back
// private DriverStationEnhancedIO m_enhancedIO = new DriverStationEnhancedIO();
/**
* Gets an instance of the DriverStation
@@ -164,8 +163,6 @@ public class DriverStation implements IInputOutput {
HALUtil.takeMutex(m_packetDataAvailableSem);
synchronized (this) {
getData();
// XXX: Add DriverStationEnhancedIO back
// m_enhancedIO.updateData();
setData();
}
synchronized (m_dataSem) {
@@ -597,16 +594,6 @@ public class DriverStation implements IInputOutput {
return (m_controlData.control & FRCCommonControlMasks.FMS_ATTATCHED) > 0;
}
/**
* Get the interface to the enhanced IO of the new driver station.
* @return An enhanced IO object for the advanced features of the driver
* station.
*/
// XXX: Add DriverStationEnhancedIO back
// public DriverStationEnhancedIO getEnhancedIO() {
// return m_enhancedIO;
// }
/**
* Return the approximate match time
* The FMS does not currently send the official match time to the robots

View File

@@ -8,6 +8,7 @@ package edu.wpi.first.wpilibj;
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType;
import edu.wpi.first.wpilibj.communication.UsageReporting;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
import edu.wpi.first.wpilibj.livewindow.LiveWindowSendable;
import edu.wpi.first.wpilibj.parsing.ISensor;

View File

@@ -10,6 +10,7 @@ import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary;
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tInstances;
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType;
import edu.wpi.first.wpilibj.communication.UsageReporting;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
/**

View File

@@ -19,6 +19,9 @@ import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tInst
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType;
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary;
import edu.wpi.first.wpilibj.communication.UsageReporting;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.internal.HardwareHLUsageReporting;
import edu.wpi.first.wpilibj.internal.HardwareTimer;
import edu.wpi.first.wpilibj.networktables.NetworkTable;
/**
@@ -156,102 +159,13 @@ public abstract class RobotBase {
* the robot.
* @throws javax.microedition.midlet.MIDletStateChangeException
*/
public static void main(String args[]) { // TODO: expose main to teams?
public static void main(String args[]) {
boolean errorOnExit = false;
// /* JNI Testing */
// boolean booleanTest = true;
// byte byteTest = (byte)0xa5;
// char charTest = 'X';
// short shortTest = 12346;
// int intTest = 2987654;
// long longTest = 897678665;
// float floatTest = 45.123456f;
// double doubleTest = 234E16;
// FRCNetworkCommunicationsLibrary.JNIValueParameterTest(booleanTest, byteTest, charTest, shortTest,
// intTest, longTest, floatTest, doubleTest);
// boolean booleanReturn = FRCNetworkCommunicationsLibrary.JNIValueReturnBooleanTest(booleanTest);
// System.out.println("Boolean Return: " + booleanReturn );
// byte byteReturn = FRCNetworkCommunicationsLibrary.JNIValueReturnByteTest(byteTest);
// System.out.println("Byte Return: " + byteReturn );
// char charReturn = FRCNetworkCommunicationsLibrary.JNIValueReturnCharTest(charTest);
// System.out.println("Char Return: " + charReturn );
// short shortReturn = FRCNetworkCommunicationsLibrary.JNIValueReturnShortTest(shortTest);
// System.out.println("Short Return: " + shortReturn );
// int intReturn = FRCNetworkCommunicationsLibrary.JNIValueReturnIntTest(intTest);
// System.out.println("Int Return: " + intReturn );
// long longReturn = FRCNetworkCommunicationsLibrary.JNIValueReturnLongTest(longTest);
// System.out.println("Long Return: " + longReturn );
// float floatReturn = FRCNetworkCommunicationsLibrary.JNIValueReturnFloatTest(floatTest);
// System.out.println("Float Return: " + floatReturn );
// double doubleReturn = FRCNetworkCommunicationsLibrary.JNIValueReturnDoubleTest(doubleTest);
// System.out.println("Double Return: " + doubleReturn );
// String testValue = "This is a test string";
// String returnValue = FRCNetworkCommunicationsLibrary.JNIObjectReturnStringTest(testValue);
// System.out.println("String Return:" + returnValue);
// ByteBuffer directBuffer = ByteBuffer.allocateDirect(4);
// directBuffer.put(0, (byte)0xFA);
// directBuffer.put(1, (byte)0xAB);
// directBuffer.put(2, (byte)0xB4);
// directBuffer.put(3, (byte)0xCD);
// ByteBuffer returnBuffer1 = FRCNetworkCommunicationsLibrary.JNIObjectReturnByteBufferTest(directBuffer);
// System.out.println("Return Buffer Capacity: " + returnBuffer1.capacity());
// System.out.println("ByteBuffer1 Return0: " + returnBuffer1.get(0) );
// System.out.println("ByteBuffer1 Return1: " + returnBuffer1.get(1) );
// System.out.println("ByteBuffer1 Return2: " + returnBuffer1.get(2) );
// System.out.println("ByteBuffer1 Return3: " + returnBuffer1.get(3) );
// ByteBuffer directByteBuffer = ByteBuffer.allocateDirect(4);
//set to little endian for C++
// directByteBuffer.order(ByteOrder.LITTLE_ENDIAN);
// directByteBuffer.putInt(0,2874933);
// System.out.println("Param In: " + directByteBuffer.getInt(0));
// System.out.println("Param In Byte0: " + directByteBuffer.get(0) );
// System.out.println("Param In Byte1: " + directByteBuffer.get(1) );
// System.out.println("Param In Byte2: " + directByteBuffer.get(2) );
// System.out.println("Param In Byte3: " + directByteBuffer.get(3) );
// ByteBuffer returnBuffer2 = FRCNetworkCommunicationsLibrary.JNIObjectAndParamReturnIntBufferTest(directByteBuffer.asIntBuffer());
// System.out.println("Param Out: " + directByteBuffer.getInt(0));
// System.out.println("Return Buffer Capacity: " + returnBuffer2.capacity());
// System.out.println("ByteBuffer2 Return0: " + returnBuffer2.get(0) );
// System.out.println("ByteBuffer2 Return1: " + returnBuffer2.get(1) );
// System.out.println("ByteBuffer2 Return2: " + returnBuffer2.get(2) );
// System.out.println("ByteBuffer2 Return3: " + returnBuffer2.get(3) );
// System.out.println("Byte Order from C++" + returnBuffer2.order().toString());
// System.out.println("ByteBuffer2 as Int" + returnBuffer2.getInt(0));
//change to little endian
// returnBuffer2.order(ByteOrder.LITTLE_ENDIAN);
// System.out.println("ByteBuffer2 as Int" + returnBuffer2.getInt(0));
/* End JNI Testing */
// Set some implementations so that the static methods work properly
Timer.SetImplementation(new HardwareTimer());
HLUsageReporting.SetImplementation(new HardwareHLUsageReporting());
RobotState.SetImplementation(DriverStation.getInstance());
FRCNetworkCommunicationsLibrary.FRCNetworkCommunicationReserve();
FRCNetworkCommunicationsLibrary.FRCNetworkCommunicationObserveUserProgramStarting();

View File

@@ -10,6 +10,7 @@ package edu.wpi.first.wpilibj;
import edu.wpi.first.wpilibj.communication.UsageReporting;
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tInstances;
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
/**

View File

@@ -9,6 +9,7 @@ package edu.wpi.first.wpilibj;
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType;
import edu.wpi.first.wpilibj.communication.UsageReporting;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
import edu.wpi.first.wpilibj.livewindow.LiveWindowSendable;
import edu.wpi.first.wpilibj.parsing.ISensor;

View File

@@ -80,13 +80,6 @@ public class Utility implements IUtility {
final String url = "dserror:edu.wpi.first.wpilibj.Utility"; // the path
// is just a
// comment.
/* XXX: Code Review!
Isolate isolate = VM.getCurrentIsolate();
if (enabled) {
isolate.addErr(url);
} else {
isolate.removeErr(url);
} */
}
}

View File

@@ -1,7 +1,6 @@
package edu.wpi.first.wpilibj.communication;
public class FRCCommonControlMasks {
// XXX: Verify these are right in FRCCommonControlData.field1
public static byte CHECK_VERSIONS = 1 << 0;
public static byte TEST = 1 << 1;
public static byte RESYNC = 1 << 2;

Some files were not shown because too many files have changed in this diff Show More