Compare commits

...

40 Commits

Author SHA1 Message Date
Patrick Plenefisch
46dc99a115 Adding SFX to tools zip
Change-Id: I09a04506682a5d0ccbe8e556285de587915f7383
2014-12-19 09:52:25 -08:00
Brad Miller (WPI)
91d714d2e9 Merge "Single line bug in CanTalonSRX::GetAnalogInVel(). return value was not being sign-extended." 2014-12-19 07:02:09 -08:00
Brad Miller (WPI)
9a28aaaa7c Merge "Change expected voltage on CAN tests" 2014-12-19 07:01:20 -08:00
Omar Zrien
96a76ba89e Single line bug in CanTalonSRX::GetAnalogInVel(). return value was not being sign-extended.
Change-Id: I44271726ece9aaa7b94f35e611f24a18dbb53825
2014-12-19 03:27:29 -05:00
Brad Miller
d26059a4fb Change expected voltage on CAN tests
Change-Id: I8c4533c7bcc81e7904d10792316382d4c01a840a
2014-12-18 21:22:31 -05:00
Brad Miller
ee0d835304 Remove an extra constructor from a bad merge
Change-Id: I0475eef143814ebf8ee4ec71a019872420442c4f
2014-12-18 18:28:15 -05:00
James Kuszmaul
6080a3b186 Duplicate of gerrit 739; changed method from public to private.
Change-Id: Ib15210ff0e5d8d99a649397499bab4737a1a489e
2014-12-18 16:08:46 -05:00
Omar Zrien
3d06a763a2 CanTalon : Adding config routines for limit switch normally open vs normally closed.
They already existed in Labview, so this will keep parity
New C++/Java funcs
ConfigFwdLimitSwitchNormallyOpen
ConfigRevLimitSwitchNormallyOpen

Change-Id: Ifd65ead827838e7158f7261c67adc3738c72eabf
2014-12-18 15:57:26 -05:00
Omar Zrien
e1480ec798 Noticed that if changeControlMode() is called every teleop loop, it causes motor to stutter as it enters and immediately leaves kDisabled.
A simple improvement was to only perform the disable-before-next-set strategy if the caller's request mode is not equal to the current mode.

To keep things simple, SetControlMode was renamed to private method ApplyControlMode so we can still invoke it from c'tor.
Then, the new impl'n of SetControlMode() just calls ApplyControlMode() when caller's request mode is different.  That takes care of direct-calls from team source, and indirect calls through enableControl().

Applied to both c++ and java.
Tested in java so far...

Change-Id: I934c06c5339d933918470659acd635e12eb4d113
2014-12-18 15:54:47 -05:00
Omar Zrien
a5d9ba412c Second pass through all the HAL functions and cpp/java API. Filled in some parity holes between java and cpp.
Java...
added setStatusFrameRateMs() to modify the frame rate for status frames
added missing func that already exists in c++
	isFwdLimitSwitchClosed()
	isRevLimitSwitchClosed()
	getNumberOfQuadIdxRises()
	getPinStateQuadA()
	getPinStateQuadB()
	getPinStateQuadIdx()
added getAnalogInRaw() that doesn't count overflows (for potentiometers).
added setStatusFrameRateMs() to modify the frame rate for status frames
added getBrakeEnableDuringNeutral()

C++...
added GetAnalogInRaw() that doesn't count overflows (for potentiometers).
added SetStatusFrameRateMs() to modify the frame rate for status frames
added GetBrakeEnableDuringNeutral()
added kLimitMode_SrxDisableSwitchInputs to CANSpeedController::LimitMode

Patch set 2: Joe Ross, fixed two javadoc errors

Change-Id: I0bf871e138953de60eeacb547dc359f2125b1327
2014-12-18 15:51:47 -05:00
Omar Zrien
2434515d41 artf3913
Increased wait delay to 4ms to cover worst case delays for solicted signal getters.
Specifically....
-Get firmware vers
-Get P,I,D,F gains
-Get IZone, Get CloseLoopRampRate
-Get IAccum (integral accumulator)

Change-Id: I313ea984832cce5182af8e5af5e775837fd54fdc
2014-12-18 15:49:29 -05:00
Brad Miller (WPI)
741618250b Merge "C++ CANTalon was missing SetIzone. Added SetIzone to match java, and made the set/get Izone integral." 2014-12-18 12:45:34 -08:00
Omar Zrien
8b8d7e77cd C++ CANTalon was missing SetIzone. Added SetIzone to match java, and made the set/get Izone integral.
Change-Id: I264ac8faaab0ebd208062923f6da2094e7e28b0a
2014-12-18 15:16:10 -05:00
Omar Zrien
c093a553ee changed variable type of closeLoopRampRate in setpid to double from int. It's represents V per sec since it calls setCloseLoopRampRate() underneath.
The other remaining closeloopramprate changes are also merged into this commit, so they may be redundant on gerrit.

Change-Id: Ic3108bb3669e487009b8f52412da3c2f44c42f6f
2014-12-18 15:11:39 -05:00
Fred Silberberg (WPI)
a1375e58cd Merge "Don't fail silently if DIO or PWM allocation fails" 2014-12-18 11:25:39 -08:00
Brad Miller (WPI)
15ff7f5038 Merge "Added the getButtons method back that reads all the buttons at the same time" 2014-12-18 10:33:11 -08:00
Brad Miller
c17ba98f72 Added the getButtons method back that reads all the buttons at the same time
Change-Id: I0f7f35b6a70f861911166de7be3802547ff4b2eb
2014-12-18 10:57:11 -05:00
Brad Miller (WPI)
dee755ab19 Merge "renamed param to match function name." 2014-12-18 07:06:20 -08:00
Brad Miller (WPI)
92c54f5f5d Merge "Image v23" 2014-12-17 15:10:36 -08:00
Fred Silberberg (WPI)
1fde00643f Merge "Fixed post4066 bug: Prestart() inaccessible." 2014-12-17 14:19:03 -08:00
Colby Skeggs
47443b4e1e Fixed post4066 bug: Prestart() inaccessible.
Change-Id: Ie179453b038458e77257c1b2d0acba7a4224f6c4
2014-12-17 13:39:54 -08:00
PetaroMitaro
f01e5b5570 fixed robotCommand in src
Change-Id: I591939301da4427e9139b824b016bb00d4b24485
2014-12-17 16:11:48 -05:00
Fredric Silberberg
22c4207553 Image v23
This updates the image version to version 23. It also moves the vision libraries
to follow the same conventions as the rest of the ni libraries.

Change-Id: I39e6fb3d8bbd2fd3141c2a43a5bae2fd15149003
2014-12-17 11:04:21 -05:00
Omar Zrien
bea9eb0efa renamed param to match function name.
Change-Id: I89c483691e0f99a6d20bed1271209a8141e71c0e
2014-12-16 20:05:30 -05:00
Brad Miller (WPI)
b72eb4b812 Merge "added Java vision example programs" 2014-12-16 11:43:02 -08:00
Dustin Spicuzza
0d8c454727 Don't fail silently if DIO or PWM allocation fails
Change-Id: I800c429507c3436c2d49561ba279700ad52569fe
2014-12-16 14:24:14 -05:00
PetaroMitaro
d61d491a02 added Java vision example programs
Change-Id: Icd99f53cc544c2609a333f0a86f4eac064d565bd
2014-12-16 11:14:37 -05:00
Brad Miller (WPI)
786e844a9f Merge "Fix ControllerPower 5v faults and add javadocs. Fixes artf3918." 2014-12-16 08:07:30 -08:00
Joe Ross
170b5860ee Fix javadoc compile errors that broke build.
Change-Id: Ie110743154f842dc3a2e756f7917e3aa131c87bd
2014-12-15 19:03:27 -08:00
PetaroMitaro
26c50ebe02 fixed java CameraServer
Change-Id: I34b8c1e2ff05199afdcab579f7ac7188fbe40fd7
2014-12-15 19:45:56 -05:00
Joe Ross
46c659d6b6 Enable Java 8 doclint checking (except for missing tags).
Change-Id: Iebfc7b99cbe43375f9cc067cca322244af44395b
2014-12-15 15:50:44 -08:00
Joe Ross
6fdd491081 Fix javadoc warnings.
Change-Id: I37049f234c6dfddc138121822525794d74e1b74c
2014-12-15 18:48:46 -05:00
Fred Silberberg (WPI)
fe4535dfa0 Merge "Resolved artf3579: robot can no longer be enabled until robotInit() finishes in IterativeRobot; similar options available by overriding prestart() for other base classes." 2014-12-15 15:39:21 -08:00
Brad Miller
636e2e13ad Wrong package declaration in camera server
Change-Id: Ia35d7f78d37aa0db51eb98901364fc228dabaa53
2014-12-15 13:40:25 -05:00
PetaroMitaro
d3f5b74668 added CameraServer.java
Change-Id: I4c41b560d879ffc6d8aa4681cad8f75297fe6cda

Fixed some issues with the camera server class

Change-Id: Ifda524b55f84053be004a404a2890905ded7b266
2014-12-15 11:00:49 -05:00
Brad Miller (WPI)
8116bbd15b Merge "Fix various bugs in nivision wrappers." 2014-12-15 05:42:07 -08:00
Peter Johnson
37052246a5 Fix various bugs in nivision wrappers.
- IMAQdx typedef overrides were being ignored, resulting in incorrect types
(e.g. IMAQdxSession was a long instead of an int).

- Allocated byte buffers byte order was not being set.

- imaqDispose was incorrectly named.

Change-Id: I5d038d45e82755615f0a5bb928defb98f557f93e
2014-12-15 02:44:07 -08:00
Joe Ross
a649d3b553 Fix ControllerPower 5v faults and add javadocs. Fixes artf3918.
5V faults was returning count of 3.3V faults. Copied javadocs from
C++.

Change-Id: I95b5c6ed1213ed235ecde11ef7e28ad05aabca6e
2014-12-14 16:55:22 -08:00
Omar Zrien
6a7e7cf611 Two param constructor added to C++/java CANTalon so caller can optionally specify the periodMs at which the talon control frame is sent.
The param is capped in the HAL C++ class to [1ms, 95ms] so that zero and negative periods are caped to 1ms, and so that caller can't pass an absurdly large value, which causes TALON is appear disabled.

Change-Id: I4207194be25a33bbd6ad281a75301ce6684659a5
2014-12-14 17:09:52 -05:00
Colby Skeggs
1c24096cc9 Resolved artf3579: robot can no longer be enabled until robotInit() finishes in IterativeRobot; similar options available by overriding prestart() for other base classes.
Change-Id: I07fde4b1bd2fae0c2e2a04336639b44ec715628a
2014-12-14 01:22:41 +00:00
52 changed files with 1566 additions and 662 deletions

View File

@@ -85,6 +85,14 @@
<outputDirectory>${tools-zip}</outputDirectory>
<destFileName>SmartDashboard.jar</destFileName>
</artifactItem>
<artifactItem>
<groupId>edu.wpi.first.wpilib</groupId>
<artifactId>sfx</artifactId>
<type>zip</type>
<classifier>zip</classifier>
<outputDirectory>${tools-zip}/../</outputDirectory>
<destFileName>sfx.zip</destFileName>
</artifactItem>
<artifactItem>
<groupId>edu.wpi.first.wpilib.networktables</groupId>
<artifactId>OutlineViewer</artifactId>
@@ -143,6 +151,7 @@
</goals>
<configuration>
<target>
<unzip src="${tools-zip}/../sfx.zip" dest="${tools-zip}"/>
<zip destfile="${project.build.directory}/classes/resources/tools.zip"
basedir="${tools-zip}"
update="true" />
@@ -208,6 +217,12 @@
<artifactId>SmartDashboard</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>edu.wpi.first.wpilib</groupId>
<artifactId>sfx</artifactId>
<type>zip</type>
<version>LATEST</version>
</dependency>
<dependency>
<groupId>edu.wpi.first.wpilib.networktables</groupId>
<artifactId>OutlineViewer</artifactId>

View File

@@ -8,7 +8,7 @@ command.dir=/home/lvuser/
# Libraries to use
wpilib=${user.home}/wpilib/cpp/${cpp-version}
wpilib.lib=${wpilib}/lib
roboRIOAllowedImages=22
roboRIOAllowedImages=23
# Ant support
wpilib.ant.dir=${wpilib}/ant

View File

@@ -0,0 +1,53 @@
package $package;
import com.ni.vision.NIVision;
import com.ni.vision.NIVision.DrawMode;
import com.ni.vision.NIVision.Image;
import com.ni.vision.NIVision.ShapeMode;
import edu.wpi.first.wpilibj.SampleRobot;
/**
* This is a demo program showing the use of the NIVision class to do vision processing.
* The image is acquired from the USB Webcam, then a circle is overlayed on it.
* The NIVision class supplies dozens of methods for different types of processing.
* The resulting image can then be sent to the FRC PC Dashboard with setImage()
*/
public class Robot extends SampleRobot {
int session;
Image frame;
public void robotInit() {
frame = NIVision.imaqCreateImage(NIVision.ImageType.IMAGE_RGB, 0);
/**
* the camera name (ex "cam1") can be found through the roborio web interface
*/
session = NIVision.IMAQdxOpenCamera("cam1",
NIVision.IMAQdxCameraControlMode.CameraControlModeController);
NIVision.IMAQdxConfigureGrab(session);
}
public void operatorControl() {
NIVision.IMAQdxStartAcquisition(session);
/**
* grab an image, draw the circle, and provide it for the camera server
* which will in turn send it to the dashboard.
*/
NIVision.Rect rect = new NIVision.Rect(10, 10, 100, 100);
while (isOperatorControl() && isEnabled()) {
NIVision.IMAQdxGrab(session, frame, 1);
NIVision.imaqDrawShapeOnImage(frame, frame, rect,
DrawMode.DRAW_VALUE, ShapeMode.SHAPE_OVAL, 0.0f);
CameraServer.getInstance().setImage(frame);
}
NIVision.IMAQdxStopAcquisition(session);
}
public void test() {
}
}

View File

@@ -0,0 +1,35 @@
package $package;
import edu.wpi.first.wpilibj.SampleRobot;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.Timer;
/**
* This is a demo program showing the use of the CameraServer class.
* With start automatic capture, there is no opertunity to process the image.
* Look at the AdvancedVision sample for how to process the image before sending it to the FRC PC Dashboard.
*/
public class Robot extends SampleRobot {
CameraServer server;
public Robot() {
server = CameraServer.getInstance();
server.setQuality(50);
}
/**
* start up automatic capture you should see the video stream from the
* webcam in your FRC PC Dashboard.
*/
public void operatorControl() {
server.startAutomaticCapture("cam1");
while (isOperatorControl() && isEnabled()) {
/** robot code here! **/
}
}
}

View File

@@ -81,6 +81,11 @@
<description>Example programs that demonstrate the use of the various commonly used sensors on FRC robots</description>
</tagDescription>
<tagDescription>
<name>Vision</name>
<description>Example programs that demonstrate the use of USB Cameras and image processing</description>
</tagDescription>
<example>
<name>Getting Started</name>
<description>An example program which demonstrates the simplest autonomous and
@@ -287,4 +292,35 @@
destination="src/$package-dir/triggers/DoubleButton.java"></file>
</files>
</example>
<example>
<name>Quick Vision</name>
<description>Demonstrate the use of the CameraServer class to stream from a USB Webcam without processing the images.</description>
<tags>
<tag>Vision</tag>
</tags>
<packages>
<package>src/$package-dir</package>
</packages>
<files>
<file source="examples/QuickVision/src/org/usfirst/frc/team190/robot/Robot.java"
destination="src/$package-dir/Robot.java"></file>
</files>
</example>
<example>
<name>Advanced Vision</name>
<description>Demonstrate the use of the NIVision class to capture image from a Webcam, process them, and then send them to the dashboard.</description>
<tags>
<tag>Vision</tag>
</tags>
<packages>
<package>src/$package-dir</package>
</packages>
<files>
<file source="examples/AdvancedVision/src/org/usfirst/frc/team190/robot/Robot.java"
destination="src/$package-dir/Robot.java"></file>
</files>
</example>
</examples>

View File

@@ -20,7 +20,7 @@ networktables.sources=${wpilib.lib}/NetworkTables-sources.jar
#jnaerator.jar=${wpilib.lib}/jnaerator-runtime.jar
#classpath=${wpilib.jar}:${networktables.jar}:${jna.jar}:${jnaerator.jar}
classpath=${wpilib.jar}:${networktables.jar}
roboRIOAllowedImages=22
roboRIOAllowedImages=23
# Ant support
wpilib.ant.dir=${wpilib}/ant

View File

@@ -1,2 +1,2 @@
/usr/local/frc/bin/netconsole-host /usr/local/frc/JRE/bin/java -jar /home/lvuser/FRCUserProgram.jar
env LD_PRELOAD=/lib/libstdc++.so.6.0.20 /usr/local/frc/bin/netconsole-host /usr/local/frc/JRE/bin/java -jar /home/lvuser/FRCUserProgram.jar

View File

@@ -1,2 +1,2 @@
/usr/local/frc/bin/netconsole-host /usr/local/frc/JRE/bin/java -XX:+UsePerfData -agentlib:jdwp=transport=dt_socket,address=8348,server=y,suspend=y -jar /home/lvuser/FRCUserProgram.jar
env LD_PRELOAD=/lib/libstdc++.so.6.0.20 /usr/local/frc/bin/netconsole-host /usr/local/frc/JRE/bin/java -XX:+UsePerfData -agentlib:jdwp=transport=dt_socket,address=8348,server=y,suspend=y -jar /home/lvuser/FRCUserProgram.jar

View File

@@ -47,6 +47,8 @@
#define ANALOG_TRIGGER_PULSE_OUTPUT_ERROR_MESSAGE "HAL: Attempted to read AnalogTrigger pulse output."
#define PARAMETER_OUT_OF_RANGE -1028
#define PARAMETER_OUT_OF_RANGE_MESSAGE "HAL: A parameter is out of range."
#define RESOURCE_IS_ALLOCATED -1029
#define RESOURCE_IS_ALLOCATED_MESSAGE "HAL: Resource already allocated"
#define VI_ERROR_SYSTEM_ERROR_MESSAGE "HAL - VISA: System Error";
#define VI_ERROR_INV_OBJECT_MESSAGE "HAL - VISA: Invalid Object"

View File

@@ -384,7 +384,11 @@ bool allocateDIO(void* digital_port_pointer, bool input, int32_t *status) {
DigitalPort* port = (DigitalPort*) digital_port_pointer;
char buf[64];
snprintf(buf, 64, "DIO %d", port->port.pin);
if (DIOChannels->Allocate(port->port.pin, buf) == ~0ul) return false;
if (DIOChannels->Allocate(port->port.pin, buf) == ~0ul) {
*status = RESOURCE_IS_ALLOCATED;
return false;
}
{
Synchronized sync(digitalDIOSemaphore);
@@ -420,7 +424,11 @@ bool allocatePWMChannel(void* digital_port_pointer, int32_t *status) {
DigitalPort* port = (DigitalPort*) digital_port_pointer;
char buf[64];
snprintf(buf, 64, "PWM %d", port->port.pin);
if (PWMChannels->Allocate(port->port.pin, buf) == ~0ul) return false;
if (PWMChannels->Allocate(port->port.pin, buf) == ~0ul) {
*status = RESOURCE_IS_ALLOCATED;
return false;
}
if (port->port.pin > tPWM::kNumHdrRegisters-1) {
snprintf(buf, 64, "PWM %d and DIO %d", port->port.pin, remapMXPPWMChannel(port->port.pin) + 10);
if (DIOChannels->Allocate(remapMXPPWMChannel(port->port.pin) + 10, buf) == ~0ul) return false;

View File

@@ -242,6 +242,11 @@ typedef struct _TALON_Param_Response_t {
CanTalonSRX::CanTalonSRX(int deviceNumber,int controlPeriodMs): CtreCanNode(deviceNumber), _can_h(0), _can_stat(0)
{
/* bound period to be within [1 ms,95 ms] */
if(controlPeriodMs < 1)
controlPeriodMs = 1;
else if(controlPeriodMs > 95)
controlPeriodMs = 95;
RegisterRx(STATUS_1 | (UINT8)deviceNumber );
RegisterRx(STATUS_2 | (UINT8)deviceNumber );
RegisterRx(STATUS_3 | (UINT8)deviceNumber );
@@ -566,6 +571,11 @@ CTR_Code CanTalonSRX::GetReverseSoftEnable(int & enable)
CTR_Code CanTalonSRX::SetStatusFrameRate(unsigned frameEnum, unsigned periodMs)
{
int32_t status = 0;
/* bounds check the period */
if(periodMs < 1)
periodMs = 1;
else if (periodMs > 255)
periodMs = 255;
uint8_t period = (uint8_t)periodMs;
/* tweak just the status messsage rate the caller cares about */
switch(frameEnum){
@@ -866,9 +876,9 @@ CTR_Code CanTalonSRX::GetAnalogInVel(int &param)
raw |= rx->AnalogInVelH;
raw <<= 8;
raw |= rx->AnalogInVelL;
param = (int)raw;
raw <<= (32-16); /* sign extend */
raw >>= (32-16); /* sign extend */
param = (int)raw;
return rx.err;
}
CTR_Code CanTalonSRX::GetTemp(double &param)

BIN
ni-libraries/libniimaqdx.so Executable file → Normal file

Binary file not shown.

View File

@@ -0,0 +1,2 @@
OUTPUT_FORMAT(elf32-littlearm)
GROUP ( libniimaqdx.so.14.0 )

View File

@@ -0,0 +1,2 @@
OUTPUT_FORMAT(elf32-littlearm)
GROUP ( libniimaqdx.so.14.0.0 )

Binary file not shown.

BIN
ni-libraries/libnivision.so Executable file → Normal file

Binary file not shown.

View File

@@ -0,0 +1,2 @@
OUTPUT_FORMAT(elf32-littlearm)
GROUP ( libnivision.so.14.0 )

View File

@@ -0,0 +1,2 @@
OUTPUT_FORMAT(elf32-littlearm)
GROUP ( libnivision.so.14.0.0 )

Binary file not shown.

BIN
ni-libraries/libnivissvc.so Executable file → Normal file

Binary file not shown.

View File

@@ -0,0 +1,2 @@
OUTPUT_FORMAT(elf32-littlearm)
GROUP ( libnivissvc.so.14.0 )

View File

@@ -0,0 +1,2 @@
OUTPUT_FORMAT(elf32-littlearm)
GROUP ( libnivissvc.so.14.0.0 )

Binary file not shown.

View File

@@ -54,7 +54,10 @@ public:
/** Only use switches for limits */
kLimitMode_SwitchInputsOnly = 0,
/** Use both switches and soft limits */
kLimitMode_SoftPositionLimits = 1
kLimitMode_SoftPositionLimits = 1,
/* SRX extensions */
/** Disable switches and disable soft limits */
kLimitMode_SrxDisableSwitchInputs = 2,
};
virtual float Get() = 0;

View File

@@ -26,8 +26,15 @@ public:
AnalogEncoder=3,
EncRising=4,
EncFalling=5
};
enum StatusFrameRate {
StatusFrameRateGeneral=0,
StatusFrameRateFeedback=1,
StatusFrameRateQuadEncoder=2,
StatusFrameRateAnalogTempVbat=3,
};
explicit CANTalon(int deviceNumber);
explicit CANTalon(int deviceNumber,int controlPeriodMs);
virtual ~CANTalon();
// PIDController interface
@@ -51,6 +58,7 @@ public:
virtual void SetI(double i) override;
virtual void SetD(double d) override;
void SetF(double f);
void SetIzone(unsigned iz);
virtual void SetPID(double p, double i, double d) override;
void SetPID(double p, double i, double d, double f);
virtual double GetP() override;
@@ -66,6 +74,7 @@ public:
virtual double GetSpeed() override;
virtual int GetClosedLoopError();
virtual int GetAnalogIn();
virtual int GetAnalogInRaw();
virtual int GetAnalogInVel();
virtual int GetEncPosition();
virtual int GetEncVel();
@@ -91,17 +100,41 @@ public:
virtual void ConfigLimitMode(LimitMode mode) override;
virtual void ConfigForwardLimit(double forwardLimitPosition) override;
virtual void ConfigReverseLimit(double reverseLimitPosition) override;
/**
* Change the fwd limit switch setting to normally open or closed.
* Talon will disable momentarilly if the Talon's current setting
* is dissimilar to the caller's requested setting.
*
* Since Talon saves setting to flash this should only affect
* a given Talon initially during robot install.
*
* @param normallyOpen true for normally open. false for normally closed.
*/
void ConfigFwdLimitSwitchNormallyOpen(bool normallyOpen);
/**
* Change the rev limit switch setting to normally open or closed.
* Talon will disable momentarilly if the Talon's current setting
* is dissimilar to the caller's requested setting.
*
* Since Talon saves setting to flash this should only affect
* a given Talon initially during robot install.
*
* @param normallyOpen true for normally open. false for normally closed.
*/
void ConfigRevLimitSwitchNormallyOpen(bool normallyOpen);
virtual void ConfigMaxOutputVoltage(double voltage) override;
virtual void ConfigFaultTime(float faultTime) override;
virtual void SetControlMode(ControlMode mode);
void SetFeedbackDevice(FeedbackDevice device);
void SetStatusFrameRateMs(StatusFrameRate stateFrame, int periodMs);
virtual ControlMode GetControlMode();
void SetSensorDirection(bool reverseSensor);
void SetCloseLoopRampRate(double rampRate);
void SelectProfileSlot(int slotIdx);
double GetIzone();
int GetIzone();
int GetIaccum();
void ClearIaccum();
int GetBrakeEnableDuringNeutral();
bool IsControlEnabled();
double GetSetpoint();
@@ -127,4 +160,12 @@ private:
TalonControlMode m_sendMode;
double m_setPoint;
static const unsigned int kDelayForSolicitedSignalsUs = 4000;
/**
* Fixup the sendMode so Set() serializes the correct demand value.
* Also fills the modeSelecet in the control frame to disabled.
* @param mode Control mode to ultimately enter once user calls Set().
* @see Set()
*/
void ApplyControlMode(CANSpeedController::ControlMode mode);
};

View File

@@ -34,6 +34,7 @@ public:
float GetStickAxis(uint32_t stick, uint32_t axis);
int GetStickPOV(uint32_t stick, uint32_t pov);
uint32_t GetStickButtons(uint32_t stick);
bool GetStickButton(uint32_t stick, uint8_t button);
int GetStickAxisCount(uint32_t stick);

View File

@@ -60,6 +60,8 @@ public:
virtual void TestPeriodic();
protected:
virtual void Prestart();
virtual ~IterativeRobot();
IterativeRobot();

View File

@@ -14,9 +14,9 @@ class DriverStation;
int main() \
{ \
if (!HALInitialize()){std::cerr<<"FATAL ERROR: HAL could not be initialized"<<std::endl;return -1;} \
HALNetworkCommunicationObserveUserProgramStarting(); \
HALReport(HALUsageReporting::kResourceType_Language, HALUsageReporting::kLanguage_CPlusPlus); \
(new _ClassName_())->StartCompetition(); \
_ClassName_ *robot = new _ClassName_(); \
RobotBase::robotSetup(robot); \
return 0; \
}
@@ -44,11 +44,15 @@ public:
static void startRobotTask(FUNCPTR factory);
static void robotTask(FUNCPTR factory, Task *task);
virtual void StartCompetition() = 0;
static void robotSetup(RobotBase *robot);
protected:
virtual ~RobotBase();
RobotBase();
virtual void Prestart();
Task *m_task;
DriverStation *m_ds;

View File

@@ -21,10 +21,27 @@ CANTalon::CANTalon(int deviceNumber)
, m_controlMode(kPercentVbus)
, m_setPoint(0)
{
SetControlMode(m_controlMode);
ApplyControlMode(m_controlMode);
m_impl->SetProfileSlotSelect(m_profile);
}
/**
* Constructor for the CANTalon device.
* @param deviceNumber The CAN ID of the Talon SRX
* @param controlPeriodMs The period in ms to send the CAN control frame.
* Period is bounded to [1ms, 95ms].
*/
CANTalon::CANTalon(int deviceNumber,int controlPeriodMs)
: m_deviceNumber(deviceNumber)
, m_impl(new CanTalonSRX(deviceNumber,controlPeriodMs)) /* bounded underneath to be within [1 ms,95 ms] */
, m_safetyHelper(new MotorSafetyHelper(this))
, m_profile(0)
, m_controlEnabled(true)
, m_controlMode(kPercentVbus)
, m_setPoint(0)
{
ApplyControlMode(m_controlMode);
m_impl->SetProfileSlotSelect(m_profile);
}
CANTalon::~CANTalon() {
delete m_impl;
delete m_safetyHelper;
@@ -203,6 +220,19 @@ void CANTalon::SetF(double f)
wpi_setErrorWithContext(status, getHALErrorMessage(status));
}
}
/**
* Set the Izone to a nonzero value to auto clear the integral accumulator
* when the absolute value of CloseLoopError exceeds Izone.
*
* @see SelectProfileSlot to choose between the two sets of gains.
*/
void CANTalon::SetIzone(unsigned iz)
{
CTR_Code status = m_impl->SetIzone(m_profile, iz);
if(status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
}
}
/**
* SRX has two available slots for PID.
* @param slotIdx one or zero depending on which slot caller wants.
@@ -243,6 +273,16 @@ void CANTalon::SetFeedbackDevice(FeedbackDevice device)
wpi_setErrorWithContext(status, getHALErrorMessage(status));
}
}
/**
* Select the feedback device to use in closed-loop
*/
void CANTalon::SetStatusFrameRateMs(StatusFrameRate stateFrame, int periodMs)
{
CTR_Code status = m_impl->SetStatusFrameRate((int)stateFrame,periodMs);
if(status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
}
}
/**
* TODO documentation (see CANJaguar.cpp)
@@ -256,7 +296,7 @@ double CANTalon::GetP()
if(status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
}
usleep(1000); /* small yield for getting response */
usleep(kDelayForSolicitedSignalsUs); /* small yield for getting response */
double p;
status = m_impl->GetPgain(m_profile, p);
if(status != CTR_OKAY) {
@@ -277,7 +317,7 @@ double CANTalon::GetI()
if(status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
}
usleep(1000); /* small yield for getting response */
usleep(kDelayForSolicitedSignalsUs); /* small yield for getting response */
double i;
status = m_impl->GetIgain(m_profile, i);
@@ -299,7 +339,7 @@ double CANTalon::GetD()
if(status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
}
usleep(1000); /* small yield for getting response */
usleep(kDelayForSolicitedSignalsUs); /* small yield for getting response */
double d;
status = m_impl->GetDgain(m_profile, d);
@@ -321,7 +361,7 @@ double CANTalon::GetF()
wpi_setErrorWithContext(status, getHALErrorMessage(status));
}
usleep(1000); /* small yield for getting response */
usleep(kDelayForSolicitedSignalsUs); /* small yield for getting response */
double f;
status = m_impl->GetFgain(m_profile, f);
if(status != CTR_OKAY) {
@@ -332,7 +372,7 @@ double CANTalon::GetF()
/**
* @see SelectProfileSlot to choose between the two sets of gains.
*/
double CANTalon::GetIzone()
int CANTalon::GetIzone()
{
CanTalonSRX::param_t param = m_profile ? CanTalonSRX::eProfileParamSlot1_IZone: CanTalonSRX::eProfileParamSlot0_IZone;
// Update the info in m_impl.
@@ -340,14 +380,14 @@ double CANTalon::GetIzone()
if(status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
}
usleep(1000);
usleep(kDelayForSolicitedSignalsUs);
int iz;
status = m_impl->GetIzone(m_profile, iz);
if(status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
}
return (double)iz;
return iz;
}
/**
@@ -499,7 +539,9 @@ double CANTalon::GetSpeed()
* Get the position of whatever is in the analog pin of the Talon, regardless of
* whether it is actually being used for feedback.
*
* @returns The value (0 - 1023) on the analog pin of the Talon.
* @returns The 24bit analog value. The bottom ten bits is the ADC (0 - 1023) on
* the analog pin of the Talon. The upper 14 bits
* tracks the overflows and underflows (continuous sensor).
*/
int CANTalon::GetAnalogIn()
{
@@ -510,7 +552,16 @@ int CANTalon::GetAnalogIn()
}
return position;
}
/**
* Get the position of whatever is in the analog pin of the Talon, regardless of
* whether it is actually being used for feedback.
*
* @returns The ADC (0 - 1023) on analog pin of the Talon.
*/
int CANTalon::GetAnalogInRaw()
{
return GetAnalogIn() & 0x3FF;
}
/**
* Get the position of whatever is in the analog pin of the Talon, regardless of
* whether it is actually being used for feedback.
@@ -835,7 +886,7 @@ uint32_t CANTalon::GetFirmwareVersion()
if(status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
}
usleep(1000);
usleep(kDelayForSolicitedSignalsUs);
status = m_impl->GetParamResponseInt32(CanTalonSRX::eFirmVers,firmwareVersion);
if(status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
@@ -858,7 +909,7 @@ int CANTalon::GetIaccum()
if(status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
}
usleep(1000); /* small yield for getting response */
usleep(kDelayForSolicitedSignalsUs); /* small yield for getting response */
int iaccum;
status = m_impl->GetParamResponseInt32(CanTalonSRX::ePidIaccum,iaccum);
if(status != CTR_OKAY) {
@@ -899,7 +950,18 @@ void CANTalon::ConfigNeutralMode(NeutralMode mode)
wpi_setErrorWithContext(status, getHALErrorMessage(status));
}
}
/**
* @return nonzero if brake is enabled during neutral. Zero if coast is enabled during neutral.
*/
int CANTalon::GetBrakeEnableDuringNeutral()
{
int brakeEn = 0;
CTR_Code status = m_impl->GetBrakeIsEnabled(brakeEn);
if(status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
}
return brakeEn;
}
/**
* TODO documentation (see CANJaguar.cpp)
*/
@@ -975,6 +1037,23 @@ void CANTalon::ConfigLimitMode(LimitMode mode)
wpi_setErrorWithContext(status, getHALErrorMessage(status));
}
break;
case kLimitMode_SrxDisableSwitchInputs: /** disable both limit switches and soft limits */
/* turn on both limits. SRX has individual enables and polarity for each limit switch.*/
status = m_impl->SetForwardSoftEnable(false);
if(status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
}
status = m_impl->SetReverseSoftEnable(false);
if(status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
}
/* override enable the limit switches, this circumvents the webdash */
status = m_impl->SetOverrideLimitSwitchEn(CanTalonSRX::kLimitSwitchOverride_DisableFwd_DisableRev);
if(status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
}
break;
}
}
@@ -989,7 +1068,40 @@ void CANTalon::ConfigForwardLimit(double forwardLimitPosition)
wpi_setErrorWithContext(status, getHALErrorMessage(status));
}
}
/**
* Change the fwd limit switch setting to normally open or closed.
* Talon will disable momentarilly if the Talon's current setting
* is dissimilar to the caller's requested setting.
*
* Since Talon saves setting to flash this should only affect
* a given Talon initially during robot install.
*
* @param normallyOpen true for normally open. false for normally closed.
*/
void CANTalon::ConfigFwdLimitSwitchNormallyOpen(bool normallyOpen)
{
CTR_Code status = m_impl->SetParam(CanTalonSRX::eOnBoot_LimitSwitch_Forward_NormallyClosed, normallyOpen ? 0 : 1);
if(status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
}
}
/**
* Change the rev limit switch setting to normally open or closed.
* Talon will disable momentarilly if the Talon's current setting
* is dissimilar to the caller's requested setting.
*
* Since Talon saves setting to flash this should only affect
* a given Talon initially during robot install.
*
* @param normallyOpen true for normally open. false for normally closed.
*/
void CANTalon::ConfigRevLimitSwitchNormallyOpen(bool normallyOpen)
{
CTR_Code status = m_impl->SetParam(CanTalonSRX::eOnBoot_LimitSwitch_Reverse_NormallyClosed, normallyOpen ? 0 : 1);
if(status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
}
}
/**
* TODO documentation (see CANJaguar.cpp)
*/
@@ -1021,9 +1133,12 @@ void CANTalon::ConfigFaultTime(float faultTime)
}
/**
* TODO documentation (see CANJaguar.cpp)
* Fixup the sendMode so Set() serializes the correct demand value.
* Also fills the modeSelecet in the control frame to disabled.
* @param mode Control mode to ultimately enter once user calls Set().
* @see Set()
*/
void CANTalon::SetControlMode(CANSpeedController::ControlMode mode)
void CANTalon::ApplyControlMode(CANSpeedController::ControlMode mode)
{
m_controlMode = mode;
switch (mode) {
@@ -1052,6 +1167,17 @@ void CANTalon::SetControlMode(CANSpeedController::ControlMode mode)
wpi_setErrorWithContext(status, getHALErrorMessage(status));
}
}
/**
* TODO documentation (see CANJaguar.cpp)
*/
void CANTalon::SetControlMode(CANSpeedController::ControlMode mode)
{
if(m_controlMode == mode){
/* we already are in this mode, don't perform disable workaround */
}else{
ApplyControlMode(mode);
}
}
/**
* TODO documentation (see CANJaguar.cpp)

View File

@@ -283,6 +283,24 @@ int DriverStation::GetStickPOV(uint32_t stick, uint32_t pov) {
* @param stick The joystick to read.
* @return The state of the buttons on the joystick.
*/
uint32_t DriverStation::GetStickButtons(uint32_t stick)
{
if (stick >= kJoystickPorts)
{
wpi_setWPIError(BadJoystickIndex);
return 0;
}
return m_joystickButtons[stick].buttons;
}
/**
* The state of one joystick button. Button indexes begin at 1.
*
* @param stick The joystick to read.
* @param button The button index, beginning at 1.
* @return The state of the joystick button.
*/
bool DriverStation::GetStickButton(uint32_t stick, uint8_t button)
{
if (stick >= kJoystickPorts)

View File

@@ -36,6 +36,11 @@ IterativeRobot::~IterativeRobot()
{
}
void IterativeRobot::Prestart() {
// Don't immediately say that the robot's ready to be enabled.
// See below.
}
/**
* Provide an alternate "main loop" via StartCompetition().
*
@@ -54,6 +59,12 @@ void IterativeRobot::StartCompetition()
NetworkTable::GetTable("LiveWindow")->GetSubTable("~STATUS~")->PutBoolean("LW Enabled", false);
RobotInit();
// We call this now (not in Prestart like default) so that the robot
// won't enable until the initialization has finished. This is useful
// because otherwise it's sometimes possible to enable the robot
// before the code is ready.
HALNetworkCommunicationObserveUserProgramStarting();
// loop forever, calling the appropriate mode-dependent function
lw->SetEnabled(false);
while (true)

View File

@@ -37,9 +37,15 @@ RobotBase &RobotBase::getInstance()
return *m_instance;
}
void RobotBase::robotSetup(RobotBase *robot)
{
robot->Prestart();
robot->StartCompetition();
}
/**
* Constructor for a generic robot program.
* User code should be placed in the constuctor that runs before the Autonomous or Operator
* User code should be placed in the constructor that runs before the Autonomous or Operator
* Control period starts. The constructor will run to completion before Autonomous is entered.
*
* This must be used to ensure that the communications code starts. In the future it would be
@@ -88,7 +94,7 @@ bool RobotBase::IsDisabled()
}
/**
* Determine if the robot is currently in Autnomous mode.
* Determine if the robot is currently in Autonomous mode.
* @return True if the robot is currently operating Autonomously as determined by the field controls.
*/
bool RobotBase::IsAutonomous()
@@ -114,6 +120,15 @@ bool RobotBase::IsTest()
return m_ds->IsTest();
}
/**
* This hook is called right before startCompetition(). By default, tell the DS that the robot is now ready to
* be enabled. If you don't want for the robot to be enabled yet, you can override this method to do nothing.
*/
void RobotBase::Prestart()
{
HALNetworkCommunicationObserveUserProgramStarting();
}
/**
* Indicates if new data is available from the driver station.
* @return Has new data arrived over the network since the last time this function was called?

View File

@@ -54,7 +54,7 @@ public abstract class Button extends Trigger {
/**
* Toggles the command whenever the button is pressed (on then off then on)
* @param command
* @param command the command to start
*/
public void toggleWhenPressed(final Command command) {
toggleWhenActive(command);
@@ -62,7 +62,7 @@ public abstract class Button extends Trigger {
/**
* Cancel the command when the button is pressed
* @param command
* @param command the command to start
*/
public void cancelWhenPressed(final Command command) {
cancelWhenActive(command);

View File

@@ -149,7 +149,7 @@ public class SmartDashboard {
* @param key the key
* @param defaultValue the value returned if the key is undefined
* @return the value
* @throws NoSuchEleNetworkTableKeyNotDefinedmentException if there is no value mapped to by the key
* @throws NetworkTableKeyNotDefined if there is no value mapped to by the key
* @throws IllegalArgumentException if the value mapped to by the key is not a double
* @throws IllegalArgumentException if the key is null
*/
@@ -241,7 +241,7 @@ public class SmartDashboard {
* @param key the key
* @param defaultValue the value returned if the key is undefined
* @return the value
* @throws NetworkTableKeyNotDefined if there is no value mapped to by the key
* @throws TableKeyNotDefinedException if there is no value mapped to by the key
* @throws IllegalArgumentException if the value mapped to by the key is not an int
* @throws IllegalArgumentException if the key is null
*/
@@ -274,7 +274,7 @@ public class SmartDashboard {
* @deprecated Use {@link #getNumber(java.lang.String) getNumber} instead
* @param key the key
* @return the value
* @throws NoSuchEleNetworkTableKeyNotDefinedmentException if there is no value mapped to by the key
* @throws TableKeyNotDefinedException if there is no value mapped to by the key
* @throws IllegalArgumentException if the value mapped to by the key is not a double
* @throws IllegalArgumentException if the key is null
*/
@@ -289,7 +289,7 @@ public class SmartDashboard {
* @param key the key
* @param defaultValue the value returned if the key is undefined
* @return the value
* @throws NoSuchEleNetworkTableKeyNotDefinedmentException if there is no value mapped to by the key
* @throws TableKeyNotDefinedException if there is no value mapped to by the key
* @throws IllegalArgumentException if the value mapped to by the key is not a double
* @throws IllegalArgumentException if the key is null
*/

View File

@@ -21,7 +21,6 @@ public class CANTalon implements MotorSafety, PIDOutput, SpeedController {
PercentVbus(0), Follower(5), Voltage(4), Position(1), Speed(2), Current(3), Disabled(15);
public int value;
public static ControlMode valueOf(int value) {
for(ControlMode mode : values()) {
if(mode.value == value) {
@@ -56,9 +55,27 @@ public class CANTalon implements MotorSafety, PIDOutput, SpeedController {
this.value = value;
}
}
/** enumerated types for frame rate ms */
public enum StatusFrameRate {
General(0), Feedback(1), QuadEncoder(2), AnalogTempVbat(3);
public int value;
public static StatusFrameRate valueOf(int value) {
for(StatusFrameRate mode : values()) {
if(mode.value == value) {
return mode;
}
}
return null;
}
private StatusFrameRate(int value) {
this.value = value;
}
}
private CanTalonSRX m_impl;
ControlMode m_controlMode;
private static double kDelayForSolicitedSignals = 0.004;
int m_deviceNumber;
boolean m_controlEnabled;
@@ -74,7 +91,17 @@ public class CANTalon implements MotorSafety, PIDOutput, SpeedController {
m_profile = 0;
m_setPoint = 0;
setProfile(m_profile);
changeControlMode(ControlMode.PercentVbus);
applyControlMode(ControlMode.PercentVbus);
}
public CANTalon(int deviceNumber,int controlPeriodMs) {
m_deviceNumber = deviceNumber;
m_impl = new CanTalonSRX(deviceNumber,controlPeriodMs); /* bound period to be within [1 ms,95 ms] */
m_safetyHelper = new MotorSafetyHelper(this);
m_controlEnabled = true;
m_profile = 0;
m_setPoint = 0;
setProfile(m_profile);
applyControlMode(ControlMode.PercentVbus);
}
@Override
@@ -223,11 +250,52 @@ public class CANTalon implements MotorSafety, PIDOutput, SpeedController {
return CanTalonJNI.intp_value(valuep);
}
/**
* Get the number of of rising edges seen on the index pin.
*
* @return number of rising edges on idx pin.
*/
public int getNumberOfQuadIdxRises() {
long valuep = CanTalonJNI.new_intp();
SWIGTYPE_p_int swigp = new SWIGTYPE_p_int(valuep, true);
m_impl.GetEncIndexRiseEvents(swigp);
return CanTalonJNI.intp_value(valuep);
}
/**
* @return IO level of QUADA pin.
*/
public int getPinStateQuadA(){
long valuep = CanTalonJNI.new_intp();
SWIGTYPE_p_int swigp = new SWIGTYPE_p_int(valuep, true);
m_impl.GetQuadApin(swigp);
return CanTalonJNI.intp_value(valuep);
}
/**
* @return IO level of QUADB pin.
*/
public int getPinStateQuadB() {
long valuep = CanTalonJNI.new_intp();
SWIGTYPE_p_int swigp = new SWIGTYPE_p_int(valuep, true);
m_impl.GetQuadBpin(swigp);
return CanTalonJNI.intp_value(valuep);
}
/**
* @return IO level of QUAD Index pin.
*/
public int getPinStateQuadIdx(){
long valuep = CanTalonJNI.new_intp();
SWIGTYPE_p_int swigp = new SWIGTYPE_p_int(valuep, true);
m_impl.GetQuadIdxpin(swigp);
return CanTalonJNI.intp_value(valuep);
}
/**
* Get the current analog in position, regardless of whether it is the current
* feedback device.
*
* @return The current value from the analog in (0 - 1023).
* @return The 24bit analog position. The bottom ten bits is the ADC (0 - 1023) on
* the analog pin of the Talon. The upper 14 bits
* tracks the overflows and underflows (continuous sensor).
*/
public int getAnalogInPosition() {
long valuep = CanTalonJNI.new_intp();
@@ -235,7 +303,14 @@ public class CANTalon implements MotorSafety, PIDOutput, SpeedController {
m_impl.GetAnalogInWithOv(swigp);
return CanTalonJNI.intp_value(valuep);
}
/**
* Get the current analog in position, regardless of whether it is the current
* feedback device.
* @return The ADC (0 - 1023) on analog pin of the Talon.
*/
public int getAnalogInRaw() {
return getAnalogInPosition() & 0x3FF;
}
/**
* Get the current encoder velocity, regardless of whether it is the current
* feedback device.
@@ -260,7 +335,27 @@ public class CANTalon implements MotorSafety, PIDOutput, SpeedController {
m_impl.GetCloseLoopErr(swigp);
return CanTalonJNI.intp_value(valuep);
}
// Returns true if limit switch is closed. false if open.
public boolean isFwdLimitSwitchClosed() {
long valuep = CanTalonJNI.new_intp();
SWIGTYPE_p_int swigp = new SWIGTYPE_p_int(valuep, true);
m_impl.GetLimitSwitchClosedFor(swigp);
return (CanTalonJNI.intp_value(valuep)==0) ? true : false;
}
// Returns true if limit switch is closed. false if open.
public boolean isRevLimitSwitchClosed() {
long valuep = CanTalonJNI.new_intp();
SWIGTYPE_p_int swigp = new SWIGTYPE_p_int(valuep, true);
m_impl.GetLimitSwitchClosedRev(swigp);
return (CanTalonJNI.intp_value(valuep)==0) ? true : false;
}
// Returns true if break is enabled during neutral. false if coast.
public boolean getBrakeEnableDuringNeutral() {
long valuep = CanTalonJNI.new_intp();
SWIGTYPE_p_int swigp = new SWIGTYPE_p_int(valuep, true);
m_impl.GetBrakeIsEnabled(swigp);
return (CanTalonJNI.intp_value(valuep)==0) ? false : true;
}
// Returns temperature of Talon, in degrees Celsius.
public double getTemp() {
long tempp = CanTalonJNI.new_doublep(); // Create a new swig pointer.
@@ -320,19 +415,33 @@ public class CANTalon implements MotorSafety, PIDOutput, SpeedController {
public ControlMode getControlMode() {
return m_controlMode;
}
public void changeControlMode(ControlMode controlMode) {
/**
* Fixup the m_controlMode so set() serializes the correct demand value.
* Also fills the modeSelecet in the control frame to disabled.
* @param controlMode Control mode to ultimately enter once user calls set().
* @see #set
*/
private void applyControlMode(ControlMode controlMode) {
m_controlMode = controlMode;
if (controlMode == ControlMode.Disabled)
m_controlEnabled = false;
// Disable until set() is called.
m_impl.SetModeSelect(ControlMode.Disabled.value);
}
public void changeControlMode(ControlMode controlMode) {
if(m_controlMode == controlMode){
/* we already are in this mode, don't perform disable workaround */
}else{
applyControlMode(controlMode);
}
}
public void setFeedbackDevice(FeedbackDevice device) {
m_impl.SetFeedbackDeviceSelect(device.value);
}
public void setStatusFrameRateMs(StatusFrameRate stateFrame, int periodMs){
m_impl.SetStatusFrameRate(stateFrame.value,periodMs);
}
public void enableControl() {
changeControlMode(m_controlMode);
m_controlEnabled = true;
@@ -350,7 +459,7 @@ public class CANTalon implements MotorSafety, PIDOutput, SpeedController {
/**
* Get the current proportional constant.
*
* @returns double proportional constant for current profile.
* @return double proportional constant for current profile.
* @throws IllegalStateException if not in Position of Speed mode.
*/
public double getP() {
@@ -365,7 +474,7 @@ public class CANTalon implements MotorSafety, PIDOutput, SpeedController {
m_impl.RequestParam(CanTalonSRX.param_t.eProfileParamSlot1_P);
// Briefly wait for new values from the Talon.
Timer.delay(0.001);
Timer.delay(kDelayForSolicitedSignals);
long pp = CanTalonJNI.new_doublep();
m_impl.GetPgain(m_profile, new SWIGTYPE_p_double(pp, true));
@@ -384,7 +493,7 @@ public class CANTalon implements MotorSafety, PIDOutput, SpeedController {
m_impl.RequestParam(CanTalonSRX.param_t.eProfileParamSlot1_I);
// Briefly wait for new values from the Talon.
Timer.delay(0.001);
Timer.delay(kDelayForSolicitedSignals);
long ip = CanTalonJNI.new_doublep();
m_impl.GetIgain(m_profile, new SWIGTYPE_p_double(ip, true));
@@ -403,7 +512,7 @@ public class CANTalon implements MotorSafety, PIDOutput, SpeedController {
m_impl.RequestParam(CanTalonSRX.param_t.eProfileParamSlot1_D);
// Briefly wait for new values from the Talon.
Timer.delay(0.001);
Timer.delay(kDelayForSolicitedSignals);
long dp = CanTalonJNI.new_doublep();
m_impl.GetDgain(m_profile, new SWIGTYPE_p_double(dp, true));
@@ -422,7 +531,7 @@ public class CANTalon implements MotorSafety, PIDOutput, SpeedController {
m_impl.RequestParam(CanTalonSRX.param_t.eProfileParamSlot1_F);
// Briefly wait for new values from the Talon.
Timer.delay(0.001);
Timer.delay(kDelayForSolicitedSignals);
long fp = CanTalonJNI.new_doublep();
m_impl.GetFgain(m_profile, new SWIGTYPE_p_double(fp, true));
@@ -441,13 +550,21 @@ public class CANTalon implements MotorSafety, PIDOutput, SpeedController {
m_impl.RequestParam(CanTalonSRX.param_t.eProfileParamSlot1_IZone);
// Briefly wait for new values from the Talon.
Timer.delay(0.001);
Timer.delay(kDelayForSolicitedSignals);
long fp = CanTalonJNI.new_intp();
m_impl.GetIzone(m_profile, new SWIGTYPE_p_int(fp, true));
return CanTalonJNI.intp_value(fp);
}
/**
* Get the closed loop ramp rate for the current profile.
*
* Limits the rate at which the throttle will change.
* Only affects position and speed closed loop modes.
*
* @return rampRate Maximum change in voltage, in volts / sec.
* @see #setProfile For selecting a certain profile.
*/
public double getCloseLoopRampRate() {
// if(!(m_controlMode.equals(ControlMode.Position) || m_controlMode.equals(ControlMode.Speed))) {
// throw new IllegalStateException("PID mode only applies in Position and Speed modes.");
@@ -460,11 +577,12 @@ public class CANTalon implements MotorSafety, PIDOutput, SpeedController {
m_impl.RequestParam(CanTalonSRX.param_t.eProfileParamSlot1_CloseLoopRampRate);
// Briefly wait for new values from the Talon.
Timer.delay(0.001);
Timer.delay(kDelayForSolicitedSignals);
long fp = CanTalonJNI.new_intp();
m_impl.GetCloseLoopRampRate(m_profile, new SWIGTYPE_p_int(fp, true));
return CanTalonJNI.intp_value(fp);
double throttlePerMs = CanTalonJNI.intp_value(fp);
return throttlePerMs / 1023.0 * 12.0 * 1000.0;
}
/**
* @return The version of the firmware running on the Talon
@@ -475,7 +593,7 @@ public class CANTalon implements MotorSafety, PIDOutput, SpeedController {
m_impl.RequestParam(CanTalonSRX.param_t.eFirmVers);
// Briefly wait for new values from the Talon.
Timer.delay(0.001);
Timer.delay(kDelayForSolicitedSignals);
long fp = CanTalonJNI.new_intp();
m_impl.GetParamResponseInt32(CanTalonSRX.param_t.eFirmVers, new SWIGTYPE_p_int(fp, true));
@@ -487,13 +605,13 @@ public class CANTalon implements MotorSafety, PIDOutput, SpeedController {
m_impl.RequestParam(CanTalonSRX.param_t.ePidIaccum);
// Briefly wait for new values from the Talon.
Timer.delay(0.001);
Timer.delay(kDelayForSolicitedSignals);
long fp = CanTalonJNI.new_intp();
m_impl.GetParamResponseInt32(CanTalonSRX.param_t.ePidIaccum, new SWIGTYPE_p_int(fp, true));
return CanTalonJNI.intp_value(fp);
}
/**
* Clear the accumulator for I gain.
*/
@@ -505,7 +623,7 @@ public class CANTalon implements MotorSafety, PIDOutput, SpeedController {
* Set the proportional value of the currently selected profile.
*
* @param p Proportional constant for the currently selected PID profile.
* @see setProfile For selecting a certain profile.
* @see #setProfile For selecting a certain profile.
*/
public void setP(double p) {
m_impl.SetPgain(m_profile, p);
@@ -515,7 +633,7 @@ public class CANTalon implements MotorSafety, PIDOutput, SpeedController {
* Set the integration constant of the currently selected profile.
*
* @param i Integration constant for the currently selected PID profile.
* @see setProfile For selecting a certain profile.
* @see #setProfile For selecting a certain profile.
*/
public void setI(double i) {
m_impl.SetIgain(m_profile, i);
@@ -525,7 +643,7 @@ public class CANTalon implements MotorSafety, PIDOutput, SpeedController {
* Set the derivative constant of the currently selected profile.
*
* @param d Derivative constant for the currently selected PID profile.
* @see setProfile For selecting a certain profile.
* @see #setProfile For selecting a certain profile.
*/
public void setD(double d) {
m_impl.SetDgain(m_profile, d);
@@ -535,7 +653,7 @@ public class CANTalon implements MotorSafety, PIDOutput, SpeedController {
* Set the feedforward value of the currently selected profile.
*
* @param f Feedforward constant for the currently selected PID profile.
* @see setProfile For selecting a certain profile.
* @see #setProfile For selecting a certain profile.
*/
public void setF(double f) {
m_impl.SetFgain(m_profile, f);
@@ -550,7 +668,7 @@ public class CANTalon implements MotorSafety, PIDOutput, SpeedController {
* An izone value of 0 means no difference from a standard PIDF loop.
*
* @param izone Width of the integration zone.
* @see setProfile For selecting a certain profile.
* @see #setProfile For selecting a certain profile.
*/
public void setIZone(int izone) {
m_impl.SetIzone(m_profile, izone);
@@ -563,11 +681,11 @@ public class CANTalon implements MotorSafety, PIDOutput, SpeedController {
* Only affects position and speed closed loop modes.
*
* @param rampRate Maximum change in voltage, in volts / sec.
* @see setProfile For selecting a certain profile.
* @see #setProfile For selecting a certain profile.
*/
public void setCloseLoopRampRate(double rampRate) {
// CanTalonSRX takes units of Throttle (0 - 1023) / 10ms.
int rate = (int) (rampRate * 1023.0 / 12.0 * 100.0);
// CanTalonSRX takes units of Throttle (0 - 1023) / 1ms.
int rate = (int) (rampRate * 1023.0 / 12.0 / 1000.0);
m_impl.SetCloseLoopRampRate(m_profile, rate);
}
@@ -581,7 +699,7 @@ public class CANTalon implements MotorSafety, PIDOutput, SpeedController {
*/
public void setVoltageRampRate(double rampRate) {
// CanTalonSRX takes units of Throttle (0 - 1023) / 10ms.
int rate = (int) (rampRate * 1023.0 / 12.0 * 100.0);
int rate = (int) (rampRate * 1023.0 / 12.0 /100.0);
m_impl.SetRampThrottle(rate);
}
@@ -594,14 +712,13 @@ public class CANTalon implements MotorSafety, PIDOutput, SpeedController {
* @param f Feedforward constant.
* @param izone Integration zone -- prevents accumulation of integration error
* with large errors. Setting this to zero will ignore any izone stuff.
* @param ramprate Closed loop ramp rate. Represents maximum change in
* throttle every 10ms.
* @param closeLoopRampRate Closed loop ramp rate. Maximum change in voltage, in volts / sec.
* @param profile which profile to set the pid constants for. You can have two
* profiles, with values of 0 or 1, allowing you to keep a second set of values
* on hand in the talon. In order to switch profiles without recalling setPID,
* you must call setProfile().
*/
public void setPID(double p, double i, double d, double f, int izone, int ramprate, int profile)
public void setPID(double p, double i, double d, double f, int izone, double closeLoopRampRate, int profile)
{
if (profile != 0 && profile != 1)
throw new IllegalArgumentException("Talon PID profile must be 0 or 1.");
@@ -612,7 +729,7 @@ public class CANTalon implements MotorSafety, PIDOutput, SpeedController {
setD(d);
setF(f);
setIZone(izone);
setCloseLoopRampRate(ramprate);
setCloseLoopRampRate(closeLoopRampRate);
}
public void setPID(double p, double i, double d) {
@@ -662,15 +779,15 @@ public class CANTalon implements MotorSafety, PIDOutput, SpeedController {
public void setForwardSoftLimit(int forwardLimit) {
m_impl.SetForwardSoftLimit(forwardLimit);
}
public void enableForwardSoftLimit(boolean enable) {
m_impl.SetForwardSoftEnable(enable ? 1 : 0);
}
public void setReverseSoftLimit(int forwardLimit) {
m_impl.SetReverseSoftLimit(forwardLimit);
public void setReverseSoftLimit(int reverseLimit) {
m_impl.SetReverseSoftLimit(reverseLimit);
}
public void enableReverseSoftLimit(boolean enable) {
m_impl.SetReverseSoftEnable(enable ? 1 : 0);
}
@@ -683,6 +800,34 @@ public class CANTalon implements MotorSafety, PIDOutput, SpeedController {
int mask = 4 + (forward ? 1 : 0) * 2 + (reverse ? 1 : 0);
m_impl.SetOverrideLimitSwitchEn(mask);
}
/**
* Configure the fwd limit switch to be normally open or normally closed.
* Talon will disable momentarilly if the Talon's current setting
* is dissimilar to the caller's requested setting.
*
* Since Talon saves setting to flash this should only affect
* a given Talon initially during robot install.
*
* @param normallyOpen true for normally open. false for normally closed.
*/
public void ConfigFwdLimitSwitchNormallyOpen(boolean normallyOpen)
{
SWIGTYPE_p_CTR_Code status = m_impl.SetParam(CanTalonSRX.param_t.eOnBoot_LimitSwitch_Forward_NormallyClosed,normallyOpen ? 0 : 1);
}
/**
* Configure the rev limit switch to be normally open or normally closed.
* Talon will disable momentarilly if the Talon's current setting
* is dissimilar to the caller's requested setting.
*
* Since Talon saves setting to flash this should only affect
* a given Talon initially during robot install.
*
* @param normallyOpen true for normally open. false for normally closed.
*/
public void ConfigRevLimitSwitchNormallyOpen(boolean normallyOpen)
{
SWIGTYPE_p_CTR_Code status = m_impl.SetParam(CanTalonSRX.param_t.eOnBoot_LimitSwitch_Reverse_NormallyClosed,normallyOpen ? 0 : 1);
}
public void enableBrakeMode(boolean brake) {
m_impl.SetOverrideBrakeType(brake ? 2 : 1);

View File

@@ -0,0 +1,278 @@
package edu.wpi.first.wpilibj;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import com.ni.vision.NIVision;
import com.ni.vision.NIVision.Image;
import com.ni.vision.NIVision.RawData;
import com.ni.vision.VisionException;
//replicates CameraServer.cpp in java lib
public class CameraServer {
public static CameraServer getInstance() {
if (server == null) {
server = new CameraServer();
}
return server;
}
private static CameraServer server;
private AtomicBoolean ready;
private Thread serverThread;
private int m_quality;
private static final int kPort = 1180;
private static final byte[] kMagicNumber = { 0x01, 0x00, 0x00, 0x00 };
private static final int kSize640x480 = 0;
private static final int kSize320x240 = 1;
private static final int kSize160x120 = 2;
private static final int kHardwareCompression = -1;
private static final String kDefaultCameraName = "cam1";
private List<Byte> m_imageData;
private boolean m_autoCaptureStarted;
private CameraServer() {
ready = new AtomicBoolean(false);
m_imageData = new ArrayList<Byte>();
m_quality = 50;
serverThread = new Thread(new Runnable() {
public void run() {
try {
serve();
} catch (IOException e) {
// do stuff here
} catch (InterruptedException e) {
// do stuff here
}
}
});
serverThread.start();
}
/**
* Manually change the image that is served by the MJPEG stream. This can be
* called to pass custom annotated images to the dashboard. Note that, for
* 640x480 video, this method could take between 40 and 50 milliseconds to
* complete.
*
* This shouldn't be called if {@link #startAutomaticCapture} is called.
*
* @param image
* The IMAQ image to show on the dashboard
*/
public synchronized void setImage(Image image) {
// handle multi-threadedness
/* Flatten the IMAQ image to a JPEG */
RawData data = NIVision.imaqFlatten(image,
NIVision.FlattenType.FLATTEN_IMAGE,
NIVision.CompressionType.COMPRESSION_JPEG, 10 * m_quality);
ByteBuffer buffer = data.getBuffer();
m_imageData.clear();
/* Find the start of the JPEG data */
int index = 0;
while (index < buffer.limit() - 1) {
if ((buffer.get(index) & 0xff) == 0xFF
&& (buffer.get(index + 1) & 0xff) == 0xD8)
break;
index++;
}
while (index < buffer.limit()) {
m_imageData.add(buffer.get(index++));
}
if (m_imageData.size() <= 2) {
throw new VisionException(
"data size of flattened image is less than 2. Try another camera! ");
}
data.free();
ready.set(true);
}
/**
* Start automatically capturing images to send to the dashboard.
*
* You should call this method to just see a camera feed on the dashboard
* without doing any vision processing on the roboRIO. {@link #setImage}
* shouldn't be called after this is called.
*
* @param cameraName
* The name of the camera interface (e.g. "cam1")
*/
public void startAutomaticCapture(String cameraName) {
synchronized (this) {
if (m_autoCaptureStarted) {
// print
// "you fucked up \"Automatic capture has already been started\""
return;
}
m_autoCaptureStarted = true;
}
CaptureRunnable runnable = new CaptureRunnable(cameraName);
Thread captureThread = new Thread(runnable);
captureThread.start();
}
private class CaptureRunnable implements Runnable {
String name;
public CaptureRunnable(String name) {
this.name = name;
}
@Override
public void run() {
Image frame = NIVision.imaqCreateImage(
NIVision.ImageType.IMAGE_RGB, 0);
int id = NIVision.IMAQdxOpenCamera(name,
NIVision.IMAQdxCameraControlMode.CameraControlModeController);
NIVision.IMAQdxConfigureGrab(id);
NIVision.IMAQdxStartAcquisition(id);
while (true) {
NIVision.IMAQdxGrab(id, frame, 1);
setImage(frame);
}
// NIVision.IMAQdxStopAcquisition(id);
// NIVision.IMAQdxCloseCamera(id);
}
}
/**
* check if auto capture is started
*
*/
public synchronized boolean isAutoCaptureStarted() {
return m_autoCaptureStarted;
}
/**
* Set the quality of the compressed image sent to the dashboard
*
* @param quality
* The quality of the JPEG image, from 0 to 100
*/
public synchronized void setQuality(int quality) {
m_quality = quality > 100 ? 100 : quality < 0 ? 0 : quality;
}
/**
* Get the quality of the compressed image sent to the dashboard
*
* @return The quality, from 0 to 100
*/
public synchronized int getQuality() {
return m_quality;
}
/**
* Run the M-JPEG server.
*
* This function listens for a connection from the dashboard in a background
* thread, then sends back the M-JPEG stream.
*
* @throws IOException if the Socket connection fails
* @throws InterruptedException if the sleep is interrupted
*/
protected void serve() throws IOException, InterruptedException {
ServerSocket socket = new ServerSocket();
socket.setReuseAddress(true);
InetSocketAddress address = new InetSocketAddress(kPort);
socket.bind(address);
while (true) {
try {
Socket s = socket.accept();
DataInputStream is = new DataInputStream(s.getInputStream());
OutputStream os = s.getOutputStream();
int fps = is.readInt();
int compression = is.readInt();
int size = is.readInt();
if (compression != kHardwareCompression) {
// print to driverstation -->
// ("Choose \"USB Camera HW\" on the dashboard");
s.close();
continue;
}
long period = (long) (1000 / (1.0 * fps));
while (true) {
long t0 = System.currentTimeMillis();
while (!ready.get())
;
ready.set(false);
// write numbers
try {
os.write(kMagicNumber);
// write size of image
synchronized (this) {
os.write(intTobyteArray(m_imageData.size()));
byte[] imageData = new byte[m_imageData.size()];
for (int i = 0; i < m_imageData.size(); i++) {
imageData[i] = m_imageData.get(i).byteValue();
}
os.write(imageData);
}
long dt = System.currentTimeMillis() - t0;
if (dt < period) {
Thread.sleep(period - dt);
}
} catch (IOException ex) {
// print error to driverstation
break;
}
}
} catch (IOException ex) {
// print error to driverstation
continue;
}
}
}
public byte[] intTobyteArray(int n) {
byte[] arr = new byte[4];
arr[0] = (byte) ((n >> 24) & 0xFF);
arr[1] = (byte) ((n >> 16) & 0xFF);
arr[2] = (byte) ((n >> 8) & 0xFF);
arr[3] = (byte) (n & 0xFF);
return arr;
}
}

View File

@@ -16,6 +16,10 @@ import edu.wpi.first.wpilibj.hal.PowerJNI;
public class ControllerPower
{
/**
* Get the input voltage to the robot controller
* @return The controller input voltage value
*/
public static double getInputVoltage()
{
ByteBuffer status = ByteBuffer.allocateDirect(4);
@@ -24,7 +28,11 @@ public class ControllerPower
HALUtil.checkStatus(status.asIntBuffer());
return retVal;
}
/**
* Get the input current to the robot controller
* @return The controller input current value
*/
public static double getInputCurrent()
{
ByteBuffer status = ByteBuffer.allocateDirect(4);
@@ -34,6 +42,10 @@ public class ControllerPower
return retVal;
}
/**
* Get the voltage of the 3.3V rail
* @return The controller 3.3V rail voltage value
*/
public static double getVoltage3V3()
{
ByteBuffer status = ByteBuffer.allocateDirect(4);
@@ -43,6 +55,10 @@ public class ControllerPower
return retVal;
}
/**
* Get the current output of the 3.3V rail
* @return The controller 3.3V rail output current value
*/
public static double getCurrent3V3()
{
ByteBuffer status = ByteBuffer.allocateDirect(4);
@@ -52,6 +68,11 @@ public class ControllerPower
return retVal;
}
/**
* Get the enabled state of the 3.3V rail. The rail may be disabled due to a controller
* brownout, a short circuit on the rail, or controller over-voltage
* @return The controller 3.3V rail enabled value
*/
public static boolean getEnabled3V3()
{
ByteBuffer status = ByteBuffer.allocateDirect(4);
@@ -61,6 +82,10 @@ public class ControllerPower
return retVal;
}
/**
* Get the count of the total current faults on the 3.3V rail since the controller has booted
* @return The number of faults
*/
public static int getFaultCount3V3()
{
ByteBuffer status = ByteBuffer.allocateDirect(4);
@@ -70,6 +95,10 @@ public class ControllerPower
return retVal;
}
/**
* Get the voltage of the 5V rail
* @return The controller 5V rail voltage value
*/
public static double getVoltage5V()
{
ByteBuffer status = ByteBuffer.allocateDirect(4);
@@ -79,6 +108,10 @@ public class ControllerPower
return retVal;
}
/**
* Get the current output of the 5V rail
* @return The controller 5V rail output current value
*/
public static double getCurrent5V()
{
ByteBuffer status = ByteBuffer.allocateDirect(4);
@@ -88,6 +121,11 @@ public class ControllerPower
return retVal;
}
/**
* Get the enabled state of the 5V rail. The rail may be disabled due to a controller
* brownout, a short circuit on the rail, or controller over-voltage
* @return The controller 5V rail enabled value
*/
public static boolean getEnabled5V()
{
ByteBuffer status = ByteBuffer.allocateDirect(4);
@@ -97,6 +135,10 @@ public class ControllerPower
return retVal;
}
/**
* Get the count of the total current faults on the 5V rail since the controller has booted
* @return The number of faults
*/
public static int getFaultCount5V()
{
ByteBuffer status = ByteBuffer.allocateDirect(4);
@@ -106,6 +148,10 @@ public class ControllerPower
return retVal;
}
/**
* Get the voltage of the 6V rail
* @return The controller 6V rail voltage value
*/
public static double getVoltage6V()
{
ByteBuffer status = ByteBuffer.allocateDirect(4);
@@ -115,6 +161,10 @@ public class ControllerPower
return retVal;
}
/**
* Get the current output of the 6V rail
* @return The controller 6V rail output current value
*/
public static double getCurrent6V()
{
ByteBuffer status = ByteBuffer.allocateDirect(4);
@@ -124,6 +174,11 @@ public class ControllerPower
return retVal;
}
/**
* Get the enabled state of the 6V rail. The rail may be disabled due to a controller
* brownout, a short circuit on the rail, or controller over-voltage
* @return The controller 6V rail enabled value
*/
public static boolean getEnabled6V()
{
ByteBuffer status = ByteBuffer.allocateDirect(4);
@@ -132,7 +187,11 @@ public class ControllerPower
HALUtil.checkStatus(status.asIntBuffer());
return retVal;
}
/**
* Get the count of the total current faults on the 6V rail since the controller has booted
* @return The number of faults
*/
public static int getFaultCount6V()
{
ByteBuffer status = ByteBuffer.allocateDirect(4);

View File

@@ -289,6 +289,21 @@ public class DriverStation implements RobotState.Interface {
* @param stick The joystick to read.
* @return The state of the buttons on the joystick.
*/
public synchronized int getStickButtons(final int stick) {
if(stick < 0 || stick >= kJoystickPorts) {
throw new RuntimeException("Joystick index is out of range, should be 0-3");
}
return m_joystickButtons[stick].buttons;
}
/**
* The state of one joystick button. Button indexes begin at 1.
*
* @param stick The joystick to read.
* @param button The button index, beginning at 1.
* @return The state of the joystick button.
*/
public synchronized boolean getStickButton(final int stick, byte button) {
if(stick < 0 || stick >= kJoystickPorts) {
throw new RuntimeException("Joystick index is out of range, should be 0-3");

View File

@@ -107,7 +107,7 @@ public abstract class InterruptableSensorBase extends SensorBase {
/**
* Request one of the 8 interrupts synchronously on this digital input. Request
* interrupts in synchronous mode where the user program will have to
* explicitly wait for the interrupt to occur using {@link waitForInterrupt}.
* explicitly wait for the interrupt to occur using {@link #waitForInterrupt}.
* The default is interrupt on rising edges only.
*/
public void requestInterrupts() {

View File

@@ -59,6 +59,12 @@ public class IterativeRobot extends RobotBase {
m_teleopInitialized = false;
m_testInitialized = false;
}
@Override
protected void prestart() {
// Don't immediately say that the robot's ready to be enabled.
// See below.
}
/**
* Provide an alternate "main loop" via startCompetition().
@@ -68,15 +74,12 @@ public class IterativeRobot extends RobotBase {
UsageReporting.report(tResourceType.kResourceType_Framework, tInstances.kFramework_Iterative);
robotInit();
// tracing support:
final int TRACE_LOOP_MAX = 100;
int loopCount = TRACE_LOOP_MAX;
Object marker = null;
boolean didDisabledPeriodic = false;
boolean didAutonomousPeriodic = false;
boolean didTeleopPeriodic = false;
boolean didTestPeriodic = false;
// We call this now (not in prestart like default) so that the robot
// won't enable until the initialization has finished. This is useful
// because otherwise it's sometimes possible to enable the robot
// before the code is ready.
FRCNetworkCommunicationsLibrary.FRCNetworkCommunicationObserveUserProgramStarting();
// loop forever, calling the appropriate mode-dependent function
LiveWindow.setEnabled(false);
@@ -97,7 +100,6 @@ public class IterativeRobot extends RobotBase {
if (nextPeriodReady()) {
FRCNetworkCommunicationsLibrary.FRCNetworkCommunicationObserveUserProgramDisabled();
disabledPeriodic();
didDisabledPeriodic = true;
}
} else if (isTest()) {
// call TestInit() if we are now just entering test mode from either
@@ -113,7 +115,6 @@ public class IterativeRobot extends RobotBase {
if (nextPeriodReady()) {
FRCNetworkCommunicationsLibrary.FRCNetworkCommunicationObserveUserProgramTest();
testPeriodic();
didTestPeriodic = true;
}
} else if (isAutonomous()) {
// call Autonomous_Init() if this is the first time
@@ -132,7 +133,6 @@ public class IterativeRobot extends RobotBase {
if (nextPeriodReady()) {
FRCNetworkCommunicationsLibrary.FRCNetworkCommunicationObserveUserProgramAutonomous();
autonomousPeriodic();
didAutonomousPeriodic = true;
}
} else {
// call Teleop_Init() if this is the first time
@@ -148,7 +148,6 @@ public class IterativeRobot extends RobotBase {
if (nextPeriodReady()) {
FRCNetworkCommunicationsLibrary.FRCNetworkCommunicationObserveUserProgramTeleop();
teleopPeriodic();
didTeleopPeriodic = true;
}
}
m_ds.waitForData();

View File

@@ -814,7 +814,7 @@ public class Preferences {
* Returns whether or not the given string is ok to use in the
* preference table.
*
* @param value
* @param value the string to check
* @return true if the given string is ok to use in the preference table
*/
public static boolean isAcceptable(String value) {

View File

@@ -130,6 +130,15 @@ public abstract class RobotBase {
*/
public abstract void startCompetition();
/**
* This hook is called right before startCompetition(). By default, tell the
* DS that the robot is now ready to be enabled. If you don't want for the
* robot to be enabled yet, you can override this method to do nothing.
*/
protected void prestart() {
FRCNetworkCommunicationsLibrary.FRCNetworkCommunicationObserveUserProgramStarting();
}
public static boolean getBooleanProperty(String name, boolean defaultValue) {
String propVal = System.getProperty(name);
if (propVal == null) {
@@ -149,7 +158,6 @@ public abstract class RobotBase {
*/
public static void initializeHardwareConfiguration(){
FRCNetworkCommunicationsLibrary.FRCNetworkCommunicationReserve();
FRCNetworkCommunicationsLibrary.FRCNetworkCommunicationObserveUserProgramStarting();
// Set some implementations so that the static methods work properly
Timer.SetImplementation(new HardwareTimer());
@@ -161,8 +169,6 @@ public abstract class RobotBase {
* Starting point for the applications.
*/
public static void main(String args[]) {
boolean errorOnExit = false;
initializeHardwareConfiguration();
UsageReporting.report(tResourceType.kResourceType_Language, tInstances.kLanguage_Java);
@@ -182,14 +188,16 @@ public abstract class RobotBase {
RobotBase robot;
try {
robot = (RobotBase) Class.forName(robotName).newInstance();
robot.prestart();
} catch (Throwable t) {
DriverStation.reportError("ERROR Unhandled exception instantiating robot " + robotName + " " + t.toString() + " at " + Arrays.toString(t.getStackTrace()), false);
System.err.println("WARNING: Robots don't quit!");
System.err.println("ERROR: Could not instantiate robot "+robotName+"!");
System.err.println("ERROR: Could not instantiate robot " + robotName + "!");
System.exit(1);
return;
}
boolean errorOnExit = false;
try {
robot.startCompetition();
} catch (Throwable t) {

View File

@@ -264,7 +264,7 @@ public class SerialPort {
* Set the type of flow control to enable on this port.
*
* By default, flow control is disabled.
* @param flowControl
* @param flowControl the FlowControl value to use
*/
public void setFlowControl(FlowControl flowControl) {
ByteBuffer status = ByteBuffer.allocateDirect(4);

View File

@@ -1,74 +1,81 @@
<?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>wpilibJavaFinal</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/pom.xml</relativePath>
</parent>
<profiles>
<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>
<configuration>
<additionalparam>-Xdoclint:none</additionalparam>
<additionalparam>-Xdoclint:all -Xdoclint:-missing</additionalparam>
<tags>
<tag>
<name>pre</name>
<placement>a</placement>
<head>Precondition:</head>
</tag>
</tags>
</configuration>
</plugin>
</plugins>
</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.wpilibj</groupId>
<artifactId>wpilibJavaDevices</artifactId>
<version>0.1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>edu.wpi.first.wpilibj</groupId>
<artifactId>wpilibJavaJNI</artifactId>
<version>0.1.0-SNAPSHOT</version>
<type>so</type>
</dependency>
<dependency>
<groupId>edu.wpi.first.wpilibj</groupId>
<artifactId>wpilibJava</artifactId>
<version>0.1.0-SNAPSHOT</version>
<classifier>sources</classifier>
</dependency>
<dependency>
<groupId>edu.wpi.first.wpilibj</groupId>
<artifactId>wpilibJavaDevices</artifactId>
<version>0.1.0-SNAPSHOT</version>
<classifier>sources</classifier>
</dependency>
<dependency>
<groupId>edu.wpi.first.wpilibj</groupId>
<artifactId>wpilibJava</artifactId>
<version>0.1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>edu.wpi.first.wpilibj</groupId>
<artifactId>wpilibJavaDevices</artifactId>
<version>0.1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>edu.wpi.first.wpilibj</groupId>
<artifactId>wpilibJavaJNI</artifactId>
<version>0.1.0-SNAPSHOT</version>
<type>so</type>
</dependency>
<dependency>
<groupId>edu.wpi.first.wpilibj</groupId>
<artifactId>wpilibJava</artifactId>
<version>0.1.0-SNAPSHOT</version>
<classifier>sources</classifier>
</dependency>
<dependency>
<groupId>edu.wpi.first.wpilibj</groupId>
<artifactId>wpilibJavaDevices</artifactId>
<version>0.1.0-SNAPSHOT</version>
<classifier>sources</classifier>
</dependency>
</dependencies>
<build>
<plugins>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
@@ -96,7 +103,7 @@
</then>
<else>
<copy todir="${project.build.directory}/classes" >
<fileset dir="${mvn.wpilibJava.jar.path}" />
<fileset dir="${mvn.wpilibJava.jar.path}" />
</copy>
</else>
</if>
@@ -112,7 +119,7 @@
</then>
<else>
<copy todir="${project.build.directory}/classes" >
<fileset dir="${mvn.wpilibJavaDevices.jar.path}" />
<fileset dir="${mvn.wpilibJavaDevices.jar.path}" />
</copy>
</else>
</if>
@@ -128,12 +135,12 @@
<phase>generate-sources</phase>
<configuration>
<target>
<copy todir="${project.build.directory}/classes/linux-arm"
file="${edu.wpi.first.wpilibj:wpilibJavaJNI:so}" />
<copy todir="${project.build.directory}/classes/linux-arm"
file="${edu.wpi.first.wpilibj:wpilibJavaJNI:so}" />
</target>
</configuration>
</execution>
<execution>
<id>generate-sources</id>
<goals>
@@ -172,17 +179,16 @@
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<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>
<includeDependencySources>true</includeDependencySources>
<sourceFileExcludes>
<exclude>edu/wpi/first/wpilibj/image/</exclude>
<exclude>edu/wpi/first/wpilibj/camera/</exclude>
<exclude>edu/wpi/first/wpilibj/visa/</exclude>
</sourceFileExcludes>
<includeDependencySources>true</includeDependencySources>
</configuration>
</plugin>
@@ -201,52 +207,52 @@
</execution>
</executions>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-dependency-plugin
</artifactId>
<versionRange>[2.8,)</versionRange>
<goals>
<goal>copy</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute />
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<versionRange>[2.8,)</versionRange>
<goals>
<goal>unpack</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</plugins>
<pluginManagement>
<plugins>
<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-dependency-plugin
</artifactId>
<versionRange>[2.8,)</versionRange>
<goals>
<goal>copy</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute />
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<versionRange>[2.8,)</versionRange>
<goals>
<goal>unpack</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>

View File

@@ -33,7 +33,7 @@ public class CANVoltageQuadEncoderModeTest extends AbstractCANTest {
/** The stopped value in volts */
private static final double kStoppedValue = 0;
/** The running value in volts */
private static final double kRunningValue = 14;
private static final double kRunningValue = 12;
private static final double kVoltageTolerance = .25;

View File

@@ -18,6 +18,7 @@ import org.junit.runners.model.MultipleFailureException;
import edu.wpi.first.wpilibj.DriverStation;
import edu.wpi.first.wpilibj.RobotBase;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary;
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
/**
@@ -44,6 +45,7 @@ public abstract class AbstractComsSetup {
if (!initialized) {
// Set some implementations so that the static methods work properly
RobotBase.initializeHardwareConfiguration();
FRCNetworkCommunicationsLibrary.FRCNetworkCommunicationObserveUserProgramStarting();
LiveWindow.setEnabled(false);
TestBench.out().println("Started coms");

View File

@@ -36,7 +36,7 @@ static void dxthrowJavaException(JNIEnv *env, IMAQdxError err) {
extern "C" {
JNIEXPORT void JNICALL Java_com_ni_vision_NIVision__1imaqDispose(JNIEnv* , jclass , jlong addr)
JNIEXPORT void JNICALL Java_com_ni_vision_NIVision_imaqDispose(JNIEnv* , jclass , jlong addr)
{
imaqDispose((void*)addr);
}
@@ -4998,239 +4998,239 @@ JNIEXPORT jlong JNICALL Java_com_ni_vision_NIVision__1imaqRake(JNIEnv* env, jcla
* Functions
*/
/* J: void IMAQdxSnap(long id, Image image)
* JN: void IMAQdxSnap(long id, long image)
/* J: void IMAQdxSnap(int id, Image image)
* JN: void IMAQdxSnap(int id, long image)
* C: IMAQdxError IMAQdxSnap(IMAQdxSession id, Image* image)
*/
JNIEXPORT void JNICALL Java_com_ni_vision_NIVision__1IMAQdxSnap(JNIEnv* env, jclass , jlong id, jlong image)
JNIEXPORT void JNICALL Java_com_ni_vision_NIVision__1IMAQdxSnap(JNIEnv* env, jclass , jint id, jlong image)
{
IMAQdxError rv = IMAQdxSnap((IMAQdxSession)id, (Image*)image);
if (rv != IMAQdxErrorSuccess) dxthrowJavaException(env, rv);
}
/* J: void IMAQdxConfigureGrab(long id)
* JN: void IMAQdxConfigureGrab(long id)
/* J: void IMAQdxConfigureGrab(int id)
* JN: void IMAQdxConfigureGrab(int id)
* C: IMAQdxError IMAQdxConfigureGrab(IMAQdxSession id)
*/
JNIEXPORT void JNICALL Java_com_ni_vision_NIVision__1IMAQdxConfigureGrab(JNIEnv* env, jclass , jlong id)
JNIEXPORT void JNICALL Java_com_ni_vision_NIVision__1IMAQdxConfigureGrab(JNIEnv* env, jclass , jint id)
{
IMAQdxError rv = IMAQdxConfigureGrab((IMAQdxSession)id);
if (rv != IMAQdxErrorSuccess) dxthrowJavaException(env, rv);
}
/* J: long IMAQdxGrab(long id, Image image, long waitForNextBuffer)
* JN: long IMAQdxGrab(long id, long image, long waitForNextBuffer, long actualBufferNumber)
/* J: int IMAQdxGrab(int id, Image image, int waitForNextBuffer)
* JN: int IMAQdxGrab(int id, long image, int waitForNextBuffer, long actualBufferNumber)
* C: IMAQdxError IMAQdxGrab(IMAQdxSession id, Image* image, bool32 waitForNextBuffer, uInt32* actualBufferNumber)
*/
JNIEXPORT jlong JNICALL Java_com_ni_vision_NIVision__1IMAQdxGrab(JNIEnv* env, jclass , jlong id, jlong image, jlong waitForNextBuffer, jlong actualBufferNumber)
JNIEXPORT jint JNICALL Java_com_ni_vision_NIVision__1IMAQdxGrab(JNIEnv* env, jclass , jint id, jlong image, jint waitForNextBuffer, jlong actualBufferNumber)
{
IMAQdxError rv = IMAQdxGrab((IMAQdxSession)id, (Image*)image, (bool32)waitForNextBuffer, (uInt32*)actualBufferNumber);
if (rv != IMAQdxErrorSuccess) dxthrowJavaException(env, rv);
return (jlong)rv;
return (jint)rv;
}
/* J: void IMAQdxDiscoverEthernetCameras(String address, long timeout)
* JN: void IMAQdxDiscoverEthernetCameras(long address, long timeout)
/* J: void IMAQdxDiscoverEthernetCameras(String address, int timeout)
* JN: void IMAQdxDiscoverEthernetCameras(long address, int timeout)
* C: IMAQdxError IMAQdxDiscoverEthernetCameras(const char* address, uInt32 timeout)
*/
JNIEXPORT void JNICALL Java_com_ni_vision_NIVision__1IMAQdxDiscoverEthernetCameras(JNIEnv* env, jclass , jlong address, jlong timeout)
JNIEXPORT void JNICALL Java_com_ni_vision_NIVision__1IMAQdxDiscoverEthernetCameras(JNIEnv* env, jclass , jlong address, jint timeout)
{
IMAQdxError rv = IMAQdxDiscoverEthernetCameras((const char*)address, (uInt32)timeout);
if (rv != IMAQdxErrorSuccess) dxthrowJavaException(env, rv);
}
/* J: void IMAQdxResetCamera(String name, long resetAll)
* JN: void IMAQdxResetCamera(long name, long resetAll)
/* J: void IMAQdxResetCamera(String name, int resetAll)
* JN: void IMAQdxResetCamera(long name, int resetAll)
* C: IMAQdxError IMAQdxResetCamera(const char* name, bool32 resetAll)
*/
JNIEXPORT void JNICALL Java_com_ni_vision_NIVision__1IMAQdxResetCamera(JNIEnv* env, jclass , jlong name, jlong resetAll)
JNIEXPORT void JNICALL Java_com_ni_vision_NIVision__1IMAQdxResetCamera(JNIEnv* env, jclass , jlong name, jint resetAll)
{
IMAQdxError rv = IMAQdxResetCamera((const char*)name, (bool32)resetAll);
if (rv != IMAQdxErrorSuccess) dxthrowJavaException(env, rv);
}
/* J: long IMAQdxOpenCamera(String name, IMAQdxCameraControlMode mode)
* JN: long IMAQdxOpenCamera(long name, int mode, long id)
/* J: int IMAQdxOpenCamera(String name, IMAQdxCameraControlMode mode)
* JN: int IMAQdxOpenCamera(long name, int mode, long id)
* C: IMAQdxError IMAQdxOpenCamera(const char* name, IMAQdxCameraControlMode mode, IMAQdxSession* id)
*/
JNIEXPORT jlong JNICALL Java_com_ni_vision_NIVision__1IMAQdxOpenCamera(JNIEnv* env, jclass , jlong name, jint mode, jlong id)
JNIEXPORT jint JNICALL Java_com_ni_vision_NIVision__1IMAQdxOpenCamera(JNIEnv* env, jclass , jlong name, jint mode, jlong id)
{
IMAQdxError rv = IMAQdxOpenCamera((const char*)name, (IMAQdxCameraControlMode)mode, (IMAQdxSession*)id);
if (rv != IMAQdxErrorSuccess) dxthrowJavaException(env, rv);
return (jlong)rv;
return (jint)rv;
}
/* J: void IMAQdxCloseCamera(long id)
* JN: void IMAQdxCloseCamera(long id)
/* J: void IMAQdxCloseCamera(int id)
* JN: void IMAQdxCloseCamera(int id)
* C: IMAQdxError IMAQdxCloseCamera(IMAQdxSession id)
*/
JNIEXPORT void JNICALL Java_com_ni_vision_NIVision__1IMAQdxCloseCamera(JNIEnv* env, jclass , jlong id)
JNIEXPORT void JNICALL Java_com_ni_vision_NIVision__1IMAQdxCloseCamera(JNIEnv* env, jclass , jint id)
{
IMAQdxError rv = IMAQdxCloseCamera((IMAQdxSession)id);
if (rv != IMAQdxErrorSuccess) dxthrowJavaException(env, rv);
}
/* J: void IMAQdxConfigureAcquisition(long id, long continuous, long bufferCount)
* JN: void IMAQdxConfigureAcquisition(long id, long continuous, long bufferCount)
/* J: void IMAQdxConfigureAcquisition(int id, int continuous, int bufferCount)
* JN: void IMAQdxConfigureAcquisition(int id, int continuous, int bufferCount)
* C: IMAQdxError IMAQdxConfigureAcquisition(IMAQdxSession id, bool32 continuous, uInt32 bufferCount)
*/
JNIEXPORT void JNICALL Java_com_ni_vision_NIVision__1IMAQdxConfigureAcquisition(JNIEnv* env, jclass , jlong id, jlong continuous, jlong bufferCount)
JNIEXPORT void JNICALL Java_com_ni_vision_NIVision__1IMAQdxConfigureAcquisition(JNIEnv* env, jclass , jint id, jint continuous, jint bufferCount)
{
IMAQdxError rv = IMAQdxConfigureAcquisition((IMAQdxSession)id, (bool32)continuous, (uInt32)bufferCount);
if (rv != IMAQdxErrorSuccess) dxthrowJavaException(env, rv);
}
/* J: void IMAQdxStartAcquisition(long id)
* JN: void IMAQdxStartAcquisition(long id)
/* J: void IMAQdxStartAcquisition(int id)
* JN: void IMAQdxStartAcquisition(int id)
* C: IMAQdxError IMAQdxStartAcquisition(IMAQdxSession id)
*/
JNIEXPORT void JNICALL Java_com_ni_vision_NIVision__1IMAQdxStartAcquisition(JNIEnv* env, jclass , jlong id)
JNIEXPORT void JNICALL Java_com_ni_vision_NIVision__1IMAQdxStartAcquisition(JNIEnv* env, jclass , jint id)
{
IMAQdxError rv = IMAQdxStartAcquisition((IMAQdxSession)id);
if (rv != IMAQdxErrorSuccess) dxthrowJavaException(env, rv);
}
/* J: long IMAQdxGetImage(long id, Image image, IMAQdxBufferNumberMode mode, long desiredBufferNumber)
* JN: long IMAQdxGetImage(long id, long image, int mode, long desiredBufferNumber, long actualBufferNumber)
/* J: int IMAQdxGetImage(int id, Image image, IMAQdxBufferNumberMode mode, int desiredBufferNumber)
* JN: int IMAQdxGetImage(int id, long image, int mode, int desiredBufferNumber, long actualBufferNumber)
* C: IMAQdxError IMAQdxGetImage(IMAQdxSession id, Image* image, IMAQdxBufferNumberMode mode, uInt32 desiredBufferNumber, uInt32* actualBufferNumber)
*/
JNIEXPORT jlong JNICALL Java_com_ni_vision_NIVision__1IMAQdxGetImage(JNIEnv* env, jclass , jlong id, jlong image, jint mode, jlong desiredBufferNumber, jlong actualBufferNumber)
JNIEXPORT jint JNICALL Java_com_ni_vision_NIVision__1IMAQdxGetImage(JNIEnv* env, jclass , jint id, jlong image, jint mode, jint desiredBufferNumber, jlong actualBufferNumber)
{
IMAQdxError rv = IMAQdxGetImage((IMAQdxSession)id, (Image*)image, (IMAQdxBufferNumberMode)mode, (uInt32)desiredBufferNumber, (uInt32*)actualBufferNumber);
if (rv != IMAQdxErrorSuccess) dxthrowJavaException(env, rv);
return (jlong)rv;
return (jint)rv;
}
/* J: void IMAQdxStopAcquisition(long id)
* JN: void IMAQdxStopAcquisition(long id)
/* J: void IMAQdxStopAcquisition(int id)
* JN: void IMAQdxStopAcquisition(int id)
* C: IMAQdxError IMAQdxStopAcquisition(IMAQdxSession id)
*/
JNIEXPORT void JNICALL Java_com_ni_vision_NIVision__1IMAQdxStopAcquisition(JNIEnv* env, jclass , jlong id)
JNIEXPORT void JNICALL Java_com_ni_vision_NIVision__1IMAQdxStopAcquisition(JNIEnv* env, jclass , jint id)
{
IMAQdxError rv = IMAQdxStopAcquisition((IMAQdxSession)id);
if (rv != IMAQdxErrorSuccess) dxthrowJavaException(env, rv);
}
/* J: void IMAQdxUnconfigureAcquisition(long id)
* JN: void IMAQdxUnconfigureAcquisition(long id)
/* J: void IMAQdxUnconfigureAcquisition(int id)
* JN: void IMAQdxUnconfigureAcquisition(int id)
* C: IMAQdxError IMAQdxUnconfigureAcquisition(IMAQdxSession id)
*/
JNIEXPORT void JNICALL Java_com_ni_vision_NIVision__1IMAQdxUnconfigureAcquisition(JNIEnv* env, jclass , jlong id)
JNIEXPORT void JNICALL Java_com_ni_vision_NIVision__1IMAQdxUnconfigureAcquisition(JNIEnv* env, jclass , jint id)
{
IMAQdxError rv = IMAQdxUnconfigureAcquisition((IMAQdxSession)id);
if (rv != IMAQdxErrorSuccess) dxthrowJavaException(env, rv);
}
/* J: IMAQdxAttributeType IMAQdxGetAttributeType(long id, String name)
* JN: int IMAQdxGetAttributeType(long id, long name, long type)
/* J: IMAQdxAttributeType IMAQdxGetAttributeType(int id, String name)
* JN: int IMAQdxGetAttributeType(int id, long name, long type)
* C: IMAQdxError IMAQdxGetAttributeType(IMAQdxSession id, const char* name, IMAQdxAttributeType* type)
*/
JNIEXPORT jint JNICALL Java_com_ni_vision_NIVision__1IMAQdxGetAttributeType(JNIEnv* env, jclass , jlong id, jlong name, jlong type)
JNIEXPORT jint JNICALL Java_com_ni_vision_NIVision__1IMAQdxGetAttributeType(JNIEnv* env, jclass , jint id, jlong name, jlong type)
{
IMAQdxError rv = IMAQdxGetAttributeType((IMAQdxSession)id, (const char*)name, (IMAQdxAttributeType*)type);
if (rv != IMAQdxErrorSuccess) dxthrowJavaException(env, rv);
return (jint)rv;
}
/* J: long IMAQdxIsAttributeReadable(long id, String name)
* JN: long IMAQdxIsAttributeReadable(long id, long name, long readable)
/* J: int IMAQdxIsAttributeReadable(int id, String name)
* JN: int IMAQdxIsAttributeReadable(int id, long name, long readable)
* C: IMAQdxError IMAQdxIsAttributeReadable(IMAQdxSession id, const char* name, bool32* readable)
*/
JNIEXPORT jlong JNICALL Java_com_ni_vision_NIVision__1IMAQdxIsAttributeReadable(JNIEnv* env, jclass , jlong id, jlong name, jlong readable)
JNIEXPORT jint JNICALL Java_com_ni_vision_NIVision__1IMAQdxIsAttributeReadable(JNIEnv* env, jclass , jint id, jlong name, jlong readable)
{
IMAQdxError rv = IMAQdxIsAttributeReadable((IMAQdxSession)id, (const char*)name, (bool32*)readable);
if (rv != IMAQdxErrorSuccess) dxthrowJavaException(env, rv);
return (jlong)rv;
return (jint)rv;
}
/* J: long IMAQdxIsAttributeWritable(long id, String name)
* JN: long IMAQdxIsAttributeWritable(long id, long name, long writable)
/* J: int IMAQdxIsAttributeWritable(int id, String name)
* JN: int IMAQdxIsAttributeWritable(int id, long name, long writable)
* C: IMAQdxError IMAQdxIsAttributeWritable(IMAQdxSession id, const char* name, bool32* writable)
*/
JNIEXPORT jlong JNICALL Java_com_ni_vision_NIVision__1IMAQdxIsAttributeWritable(JNIEnv* env, jclass , jlong id, jlong name, jlong writable)
JNIEXPORT jint JNICALL Java_com_ni_vision_NIVision__1IMAQdxIsAttributeWritable(JNIEnv* env, jclass , jint id, jlong name, jlong writable)
{
IMAQdxError rv = IMAQdxIsAttributeWritable((IMAQdxSession)id, (const char*)name, (bool32*)writable);
if (rv != IMAQdxErrorSuccess) dxthrowJavaException(env, rv);
return (jlong)rv;
return (jint)rv;
}
/* J: void IMAQdxWriteRegister(long id, long offset, long value)
* JN: void IMAQdxWriteRegister(long id, long offset, long value)
/* J: void IMAQdxWriteRegister(int id, int offset, int value)
* JN: void IMAQdxWriteRegister(int id, int offset, int value)
* C: IMAQdxError IMAQdxWriteRegister(IMAQdxSession id, uInt32 offset, uInt32 value)
*/
JNIEXPORT void JNICALL Java_com_ni_vision_NIVision__1IMAQdxWriteRegister(JNIEnv* env, jclass , jlong id, jlong offset, jlong value)
JNIEXPORT void JNICALL Java_com_ni_vision_NIVision__1IMAQdxWriteRegister(JNIEnv* env, jclass , jint id, jint offset, jint value)
{
IMAQdxError rv = IMAQdxWriteRegister((IMAQdxSession)id, (uInt32)offset, (uInt32)value);
if (rv != IMAQdxErrorSuccess) dxthrowJavaException(env, rv);
}
/* J: long IMAQdxReadRegister(long id, long offset)
* JN: long IMAQdxReadRegister(long id, long offset, long value)
/* J: int IMAQdxReadRegister(int id, int offset)
* JN: int IMAQdxReadRegister(int id, int offset, long value)
* C: IMAQdxError IMAQdxReadRegister(IMAQdxSession id, uInt32 offset, uInt32* value)
*/
JNIEXPORT jlong JNICALL Java_com_ni_vision_NIVision__1IMAQdxReadRegister(JNIEnv* env, jclass , jlong id, jlong offset, jlong value)
JNIEXPORT jint JNICALL Java_com_ni_vision_NIVision__1IMAQdxReadRegister(JNIEnv* env, jclass , jint id, jint offset, jlong value)
{
IMAQdxError rv = IMAQdxReadRegister((IMAQdxSession)id, (uInt32)offset, (uInt32*)value);
if (rv != IMAQdxErrorSuccess) dxthrowJavaException(env, rv);
return (jlong)rv;
return (jint)rv;
}
/* J: void IMAQdxWriteAttributes(long id, String filename)
* JN: void IMAQdxWriteAttributes(long id, long filename)
/* J: void IMAQdxWriteAttributes(int id, String filename)
* JN: void IMAQdxWriteAttributes(int id, long filename)
* C: IMAQdxError IMAQdxWriteAttributes(IMAQdxSession id, const char* filename)
*/
JNIEXPORT void JNICALL Java_com_ni_vision_NIVision__1IMAQdxWriteAttributes(JNIEnv* env, jclass , jlong id, jlong filename)
JNIEXPORT void JNICALL Java_com_ni_vision_NIVision__1IMAQdxWriteAttributes(JNIEnv* env, jclass , jint id, jlong filename)
{
IMAQdxError rv = IMAQdxWriteAttributes((IMAQdxSession)id, (const char*)filename);
if (rv != IMAQdxErrorSuccess) dxthrowJavaException(env, rv);
}
/* J: void IMAQdxReadAttributes(long id, String filename)
* JN: void IMAQdxReadAttributes(long id, long filename)
/* J: void IMAQdxReadAttributes(int id, String filename)
* JN: void IMAQdxReadAttributes(int id, long filename)
* C: IMAQdxError IMAQdxReadAttributes(IMAQdxSession id, const char* filename)
*/
JNIEXPORT void JNICALL Java_com_ni_vision_NIVision__1IMAQdxReadAttributes(JNIEnv* env, jclass , jlong id, jlong filename)
JNIEXPORT void JNICALL Java_com_ni_vision_NIVision__1IMAQdxReadAttributes(JNIEnv* env, jclass , jint id, jlong filename)
{
IMAQdxError rv = IMAQdxReadAttributes((IMAQdxSession)id, (const char*)filename);
if (rv != IMAQdxErrorSuccess) dxthrowJavaException(env, rv);
}
/* J: void IMAQdxResetEthernetCameraAddress(String name, String address, String subnet, String gateway, long timeout)
* JN: void IMAQdxResetEthernetCameraAddress(long name, long address, long subnet, long gateway, long timeout)
/* J: void IMAQdxResetEthernetCameraAddress(String name, String address, String subnet, String gateway, int timeout)
* JN: void IMAQdxResetEthernetCameraAddress(long name, long address, long subnet, long gateway, int timeout)
* C: IMAQdxError IMAQdxResetEthernetCameraAddress(const char* name, const char* address, const char* subnet, const char* gateway, uInt32 timeout)
*/
JNIEXPORT void JNICALL Java_com_ni_vision_NIVision__1IMAQdxResetEthernetCameraAddress(JNIEnv* env, jclass , jlong name, jlong address, jlong subnet, jlong gateway, jlong timeout)
JNIEXPORT void JNICALL Java_com_ni_vision_NIVision__1IMAQdxResetEthernetCameraAddress(JNIEnv* env, jclass , jlong name, jlong address, jlong subnet, jlong gateway, jint timeout)
{
IMAQdxError rv = IMAQdxResetEthernetCameraAddress((const char*)name, (const char*)address, (const char*)subnet, (const char*)gateway, (uInt32)timeout);
if (rv != IMAQdxErrorSuccess) dxthrowJavaException(env, rv);
}
/* J: IMAQdxAttributeVisibility IMAQdxGetAttributeVisibility(long id, String name)
* JN: int IMAQdxGetAttributeVisibility(long id, long name, long visibility)
/* J: IMAQdxAttributeVisibility IMAQdxGetAttributeVisibility(int id, String name)
* JN: int IMAQdxGetAttributeVisibility(int id, long name, long visibility)
* C: IMAQdxError IMAQdxGetAttributeVisibility(IMAQdxSession id, const char* name, IMAQdxAttributeVisibility* visibility)
*/
JNIEXPORT jint JNICALL Java_com_ni_vision_NIVision__1IMAQdxGetAttributeVisibility(JNIEnv* env, jclass , jlong id, jlong name, jlong visibility)
JNIEXPORT jint JNICALL Java_com_ni_vision_NIVision__1IMAQdxGetAttributeVisibility(JNIEnv* env, jclass , jint id, jlong name, jlong visibility)
{
IMAQdxError rv = IMAQdxGetAttributeVisibility((IMAQdxSession)id, (const char*)name, (IMAQdxAttributeVisibility*)visibility);
if (rv != IMAQdxErrorSuccess) dxthrowJavaException(env, rv);

View File

@@ -119,7 +119,7 @@ JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_PowerJNI_getUserCurrentFau
(JNIEnv * env, jclass, jobject status)
{
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
return getUserCurrentFaults3V3(statusPtr);
return getUserCurrentFaults5V(statusPtr);
}
/*

View File

@@ -70,7 +70,7 @@ java_types_map = {
("unsigned int", None): JavaType("int", "int", "jint", "I"),
("uInt32", None): JavaType("int", "int", "jint", "I"),
("IMAQdxSession", None): JavaType("int", "int", "jint", "I"),
("bool32", None): JavaType("boolean", "boolean", "jboolean", "Z"),
("bool32", None): JavaType("int", "int", "jint", "I"),
("long", None): JavaType("long", "long", "jlong", "J"),
("unsigned long", None): JavaType("long", "long", "jlong", "J"),
("__int64", None): JavaType("long", "long", "jlong", "J"),
@@ -209,7 +209,7 @@ if ({size_fname} > 0 && {fname}_addr != 0) {{
strzArrayEmitSized.addWriteBuf("{buftype} {fname}_buf")
strzArrayEmitSized.addWriteBuf("{buftype}[] {fname}_bufs")
strzArrayEmitSized.addWrite("""
{fname}_buf = ByteBuffer.allocateDirect({fname}.length*{pointer_sz});
{fname}_buf = ByteBuffer.allocateDirect({fname}.length*{pointer_sz}).order(ByteOrder.nativeOrder());
for (int i=0, off=0; i<{fname}.length; i++, off += {pointer_sz}) {{
if ({fname}[i] == null)
putPointer({fname}_buf, off, 0);
@@ -263,7 +263,7 @@ strzArrayEmitUnsized.addRead("""
strzArrayEmitUnsized.addWriteBuf("{buftype} {fname}_buf")
strzArrayEmitUnsized.addWriteBuf("{buftype}[] {fname}_bufs")
strzArrayEmitUnsized.addWrite("""
{fname}_buf = ByteBuffer.allocateDirect(({fname}.length+1)*{pointer_sz});
{fname}_buf = ByteBuffer.allocateDirect(({fname}.length+1)*{pointer_sz}).order(ByteOrder.nativeOrder());
for (int i=0, off=0; i<{fname}.length; i++, off += {pointer_sz}) {{
if ({fname}[i] == null)
putPointer({fname}_buf, off, 0);
@@ -295,7 +295,7 @@ if ({size_fname} > 0 && {fname}_addr != 0) {{
}}""" % (4, 4))
enumArrayEmit.addWriteBuf("{buftype} {fname}_buf")
enumArrayEmit.addWrite("""
{fname}_buf = ByteBuffer.allocateDirect({fname}.length*%d);
{fname}_buf = ByteBuffer.allocateDirect({fname}.length*%d).order(ByteOrder.nativeOrder());
for (int i=0, off=0; i<{fname}.length; i++, off += %d) {{
if ({fname} != null)
{fname}_buf.putInt(off, {fname}[i].getValue());
@@ -316,7 +316,7 @@ if ({size_fname} > 0 && {fname}_addr != 0) {{
}}""")
opaqueArrayEmit.addWriteBuf("{buftype} {fname}_buf")
opaqueArrayEmit.addWrite("""
{fname}_buf = ByteBuffer.allocateDirect({fname}.length*{pointer_sz});
{fname}_buf = ByteBuffer.allocateDirect({fname}.length*{pointer_sz}).order(ByteOrder.nativeOrder());
for (int i=0, off=0; i<{fname}.length; i++, off += {pointer_sz}) {{
putPointer({fname}_buf, off, {fname}[i]);
}}""")
@@ -368,7 +368,7 @@ if ({size_fname} > 0 && {fname}_addr != 0) {{
structArrayEmit.addWriteBuf("{buftype} {fname}_buf")
# FIXME: This can be optimized for the read->write case.
structArrayEmit.addWrite("""
{fname}_buf = ByteBuffer.allocateDirect({fname}.length*{struct_sz});
{fname}_buf = ByteBuffer.allocateDirect({fname}.length*{struct_sz}).order(ByteOrder.nativeOrder());
for (int i=0, off=0; i<{fname}.length; i++, off += {struct_sz}) {{
{fname}[i].setBuffer({fname}_buf, off);
{fname}[i].write();
@@ -400,7 +400,7 @@ if ({size_fname} > 0 && {fname}_addr != 0) {{
}}""")
jtypeArrayEmit.addWriteBuf("ByteBuffer {fname}_buf")
jtypeArrayEmit.addWrite("""
{fname}_buf = ByteBuffer.allocateDirect({fname}.length*{struct_sz});
{fname}_buf = ByteBuffer.allocateDirect({fname}.length*{struct_sz}).order(ByteOrder.nativeOrder());
{fname}_buf.as{buftype}().put({fname}).rewind();""")
jtypeArrayEmit.addBackingWrite("putPointer({backing}, {foffset}, {fname}_buf);")
jtypeArrayEmit.toArg = "getByteBufferAddress({fname}_buf)"
@@ -1151,7 +1151,7 @@ static void dxthrowJavaException(JNIEnv *env, IMAQdxError err) {{
extern "C" {{
JNIEXPORT void JNICALL Java_{package}_{classname}__1imaqDispose(JNIEnv* , jclass , jlong addr)
JNIEXPORT void JNICALL Java_{package}_{classname}_imaqDispose(JNIEnv* , jclass , jlong addr)
{{
imaqDispose((void*)addr);
}}""".format(packagepath=self.package.replace(".", "/"),
@@ -1332,7 +1332,7 @@ JNIEXPORT void JNICALL Java_{package}_{classname}__1imaqDispose(JNIEnv* , jclass
return
elif typedef.startswith("union"):
return
else:
elif (name, arr) not in java_types_map:
java_types_map[(name, arr)] = c_to_jtype(typedef, arr).copy()
if arr is None:
java_types_map[(name, "")] = c_to_jtype(typedef, "").copy()
@@ -1495,7 +1495,7 @@ JNIEXPORT void JNICALL Java_{package}_{classname}__1imaqDispose(JNIEnv* , jclass
jn_passedargs[fname] = fname
elif jtype.jni_sig == "Ljava/lang/String;":
if jtype.string_array:
jinit.append("ByteBuffer {fname}_buf = ByteBuffer.allocateDirect({array_size});".format(fname=fname, array_size=256))
jinit.append("ByteBuffer {fname}_buf = ByteBuffer.allocateDirect({array_size}).order(ByteOrder.nativeOrder());".format(fname=fname, array_size=256))
jinit.extend(field["backing_write"])
jn_passedargs[fname] = "{fname} == null ? 0 : getByteBufferAddress({fname}_buf)".format(fname=fname)
else:
@@ -1511,7 +1511,7 @@ JNIEXPORT void JNICALL Java_{package}_{classname}__1imaqDispose(JNIEnv* , jclass
#print(name, jrettype, outparams, retarraysize, retsize)
if outparams or retarraysize or retsize:
# create a return buffer (TODO: optimize size)
jinit.append("ByteBuffer rv_buf = ByteBuffer.allocateDirect(%d);" % ((len(outparams)+1)*8))
jinit.append("ByteBuffer rv_buf = ByteBuffer.allocateDirect(%d).order(ByteOrder.nativeOrder());" % ((len(outparams)+1)*8))
jinit.append("long rv_addr = getByteBufferAddress(rv_buf);")
# create a return structure