mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
Compare commits
24 Commits
2014-simul
...
2014-simul
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d8003899f5 | ||
|
|
f7bb5cd8f6 | ||
|
|
4f2d1d9d32 | ||
|
|
981f941caf | ||
|
|
5ca2506a7b | ||
|
|
25f65a1581 | ||
|
|
15212967ec | ||
|
|
2aa0301707 | ||
|
|
455506976c | ||
|
|
ef5729b3dd | ||
|
|
256b052a55 | ||
|
|
56cf731680 | ||
|
|
0926fa4937 | ||
|
|
4de246876a | ||
|
|
130485d760 | ||
|
|
3b6e5b9b12 | ||
|
|
b2000a20d0 | ||
|
|
9e6d04b2e8 | ||
|
|
f380d9c102 | ||
|
|
1ba20bc1eb | ||
|
|
a0799718f6 | ||
|
|
afe1b0b342 | ||
|
|
072b92e55a | ||
|
|
b27791544b |
3
eclipse-plugins/.gitattributes
vendored
3
eclipse-plugins/.gitattributes
vendored
@@ -1,3 +1,4 @@
|
||||
*runcppprogram text eol=lf
|
||||
*runjavaprogram text eol=lf
|
||||
|
||||
*robotCommand text eol=lf
|
||||
*robotDebugCommand text eol=lf
|
||||
|
||||
@@ -8,13 +8,13 @@
|
||||
#include "Commands/Shoot.h"
|
||||
|
||||
DriveAndShootAutonomous::DriveAndShootAutonomous() {
|
||||
AddSequential(new CloseClaw());
|
||||
AddSequential(new WaitForPressure(), 2);
|
||||
#ifdef REAL
|
||||
// NOTE: Simulation doesn't currently have the concept of hot.
|
||||
AddSequential(new CheckForHotGoal(2));
|
||||
#endif
|
||||
AddSequential(new CloseClaw());
|
||||
AddSequential(new SetPivotSetpoint(45));
|
||||
AddSequential(new DriveForward(8, 0.4));
|
||||
AddSequential(new DriveForward(8, 0.3));
|
||||
AddSequential(new Shoot());
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ DriveTrain::DriveTrain() :
|
||||
|
||||
// Configure encoders
|
||||
rightEncoder = new Encoder(1, 2, true, Encoder::k4X);
|
||||
leftEncoder = new Encoder(5, 6, false, Encoder::k4X); // TODO: Correct encoder module.
|
||||
leftEncoder = new Encoder(3, 4, false, Encoder::k4X);
|
||||
rightEncoder->SetPIDSourceParameter(PIDSource::kDistance);
|
||||
leftEncoder->SetPIDSourceParameter(PIDSource::kDistance);
|
||||
|
||||
|
||||
@@ -7,8 +7,8 @@ Pivot::Pivot() :
|
||||
GetPIDController()->SetContinuous(false);
|
||||
#ifdef SIMULATION
|
||||
// PID is different in simulation.
|
||||
GetPIDController()->SetPID(0.5, 0.00001, 4.5);
|
||||
SetAbsoluteTolerance(2.5);
|
||||
GetPIDController()->SetPID(0.5, 0.001, 2);
|
||||
SetAbsoluteTolerance(5);
|
||||
#endif
|
||||
|
||||
// Motor to move the pivot.
|
||||
|
||||
@@ -70,8 +70,8 @@ public class Robot extends IterativeRobot {
|
||||
}
|
||||
|
||||
public void autonomousInit() {
|
||||
Command auto = (Command) autoChooser.getSelected();
|
||||
auto.start();
|
||||
autonomousCommand = (Command) autoChooser.getSelected();
|
||||
autonomousCommand.start();
|
||||
}
|
||||
|
||||
// This function is called periodically during autonomous
|
||||
|
||||
@@ -10,14 +10,14 @@ import edu.wpi.first.wpilibj.command.CommandGroup;
|
||||
*/
|
||||
public class DriveAndShootAutonomous extends CommandGroup {
|
||||
public DriveAndShootAutonomous() {
|
||||
addSequential(new CloseClaw());
|
||||
addSequential(new WaitForPressure(), 2);
|
||||
if (Robot.isReal()) {
|
||||
// NOTE: Simulation doesn't currently have the concept of hot.
|
||||
addSequential(new CheckForHotGoal(2));
|
||||
}
|
||||
addSequential(new CloseClaw());
|
||||
}
|
||||
addSequential(new SetPivotSetpoint(45));
|
||||
addSequential(new DriveForward(8, 0.4));
|
||||
addSequential(new DriveForward(8, 0.3));
|
||||
addSequential(new Shoot());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,9 +11,9 @@ import edu.wpi.first.wpilibj.command.Command;
|
||||
public class DriveForward extends Command {
|
||||
private double driveForwardSpeed;
|
||||
private double distance;
|
||||
private final double tolerance = .1; // TODO: Was 5
|
||||
private double error;
|
||||
private final double Kp = -1.0 / 5.0;
|
||||
private final double TOLERANCE = .1;
|
||||
private final double KP = -1.0 / 5.0;
|
||||
|
||||
public DriveForward() {
|
||||
this(10, 0.5);
|
||||
@@ -36,16 +36,16 @@ public class DriveForward extends Command {
|
||||
|
||||
protected void execute() {
|
||||
error = (distance - Robot.drivetrain.getRightEncoder().getDistance());
|
||||
if (driveForwardSpeed * Kp * error >= driveForwardSpeed) {
|
||||
if (driveForwardSpeed * KP * error >= driveForwardSpeed) {
|
||||
Robot.drivetrain.tankDrive(driveForwardSpeed, driveForwardSpeed);
|
||||
} else {
|
||||
Robot.drivetrain.tankDrive(driveForwardSpeed * Kp * error,
|
||||
driveForwardSpeed * Kp * error);
|
||||
Robot.drivetrain.tankDrive(driveForwardSpeed * KP * error,
|
||||
driveForwardSpeed * KP * error);
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean isFinished() {
|
||||
return (Math.abs(error) <= tolerance) || isTimedOut();
|
||||
return (Math.abs(error) <= TOLERANCE) || isTimedOut();
|
||||
}
|
||||
|
||||
protected void end() {
|
||||
|
||||
@@ -31,4 +31,4 @@ public class DriveWithJoystick extends Command {
|
||||
protected void interrupted() {
|
||||
end();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -51,7 +51,7 @@ public class DriveTrain extends Subsystem {
|
||||
|
||||
// Configure encoders
|
||||
rightEncoder = new Encoder(1, 2, true, EncodingType.k4X);
|
||||
leftEncoder = new Encoder(5, 6, false, EncodingType.k4X); // XXX: Module 2
|
||||
leftEncoder = new Encoder(3, 4, false, EncodingType.k4X);
|
||||
rightEncoder.setPIDSourceParameter(PIDSourceParameter.kDistance);
|
||||
leftEncoder.setPIDSourceParameter(PIDSourceParameter.kDistance);
|
||||
|
||||
@@ -126,4 +126,4 @@ public class DriveTrain extends Subsystem {
|
||||
public double getAngle() {
|
||||
return gyro.getAngle();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -29,8 +29,8 @@ public class Pivot extends PIDSubsystem {
|
||||
setAbsoluteTolerance(0.005);
|
||||
getPIDController().setContinuous(false);
|
||||
if (Robot.isSimulation()) { // PID is different in simulation.
|
||||
getPIDController().setPID(0.5, 0.00001, 4.5);
|
||||
setAbsoluteTolerance(2.5);
|
||||
getPIDController().setPID(0.5, 0.001, 2);
|
||||
setAbsoluteTolerance(5);
|
||||
}
|
||||
|
||||
// Motor to move the pivot.
|
||||
|
||||
@@ -2,8 +2,10 @@
|
||||
username=admin
|
||||
password=
|
||||
deploy.dir=/home/admin
|
||||
deploy.run.command=./runjavaprogram
|
||||
deploy.debug.command=./debugjavaprogram
|
||||
deploy.kill.command=/usr/local/frc/bin/frcKillRobot.sh -t -r
|
||||
deploy.debug.command = /usr/local/frc/JRE/bin/java -XX:+UsePerfData -agentlib:jdwp=transport=dt_socket,address=8348,server=y,suspend=y -jar ${deploy.dir}/FRCUserProgram.jar
|
||||
deploy.log.file=/var/local/natinst/log/FRC_UserProgram.log
|
||||
command.dir=/home/lvuser/
|
||||
|
||||
# Libraries to use
|
||||
wpilib=${user.home}/wpilib/java/${version}
|
||||
@@ -34,4 +36,4 @@ dist.jar=${dist.dir}/${jar}
|
||||
simulation.dist.jar=${dist.dir}/FRCUserProgramSim.jar
|
||||
wpilib.sim=${wpilib}/sim
|
||||
wpilib.sim.lib=${wpilib.sim}/lib
|
||||
wpilib.sim.tools=${wpilib.sim}/tools
|
||||
wpilib.sim.tools=${wpilib.sim}/tools
|
||||
|
||||
@@ -24,11 +24,11 @@
|
||||
<property name="target" value="10.${ip.upper}.${ip.lower}.2" />
|
||||
<echo>Target IP: ${target}</echo>
|
||||
</target>
|
||||
|
||||
|
||||
<target name="compile" description="Compile the source code.">
|
||||
<mkdir dir="${build.dir}"/>
|
||||
<echo>[athena-compile] Compiling ${src.dir} with classpath=${classpath} to ${build.dir}</echo>
|
||||
|
||||
|
||||
<javac srcdir="${src.dir}"
|
||||
destdir="${build.dir}"
|
||||
includeAntRuntime="no"
|
||||
@@ -40,7 +40,7 @@
|
||||
debug="true">
|
||||
</javac>
|
||||
</target>
|
||||
|
||||
|
||||
<target name="jar" depends="compile">
|
||||
<echo>[athena-jar] Making jar ${dist.jar}.</echo>
|
||||
<mkdir dir="${dist.dir}" />
|
||||
@@ -52,16 +52,16 @@
|
||||
<pathelement path="${classpath}"/>
|
||||
</path>
|
||||
</copy>
|
||||
|
||||
|
||||
<jar destfile="${dist.jar}" update="false">
|
||||
<manifest>
|
||||
<attribute name="Main-Class" value="edu.wpi.first.wpilibj.RobotBase"/>
|
||||
<attribute name="Robot-Class" value="${robot.class}"/>
|
||||
<attribute name="Class-Path" value="."/>
|
||||
</manifest>
|
||||
|
||||
|
||||
<fileset dir="${build.dir}" includes="**/*.class"/>
|
||||
|
||||
|
||||
<zipgroupfileset dir="${build.jars}">
|
||||
<include name="**/*.jar" />
|
||||
</zipgroupfileset>
|
||||
@@ -70,37 +70,39 @@
|
||||
|
||||
<target name="deploy" depends="get-target-ip,jar" description="Deploy the jar and start the program running.">
|
||||
<echo>[athena-deploy] Copying code over.</echo>
|
||||
<scp file="${dist.jar}" todir="${username}@${target}:${deploy.dir}"
|
||||
password="${password}" trust="true"/>
|
||||
<scp file="${wpilib.ant.dir}/runjavaprogram" todir="${username}@${target}:${deploy.dir}"
|
||||
password="${password}" trust="true"/>
|
||||
<scp file="${dist.jar}" todir="${username}@${target}:${deploy.dir}" password="${password}" trust="true"/>
|
||||
<scp file="${wpilib.ant.dir}/robotCommand" todir="${username}@${target}:${command.dir}" password="${password}" trust="true"/>
|
||||
|
||||
<echo>[athena-deploy] Starting program.</echo>
|
||||
<sshexec host="${target}"
|
||||
username="${username}"
|
||||
password="${password}"
|
||||
trust="true"
|
||||
command="chmod a+x run*program; ${deploy.run.command}"/>
|
||||
</target>
|
||||
command=". /etc/profile.d/natinst-path.sh; chmod a+x run*program; ${deploy.kill.command};"/>
|
||||
|
||||
<target name="debug-deploy" depends="get-target-ip,jar" description="Deploy the jar and start the program running in debug mode.">
|
||||
<echo>[athena-debug-deploy] Copying code over.</echo>
|
||||
<scp file="${dist.jar}" todir="${username}@${target}:${deploy.dir}"
|
||||
password="${password}" trust="true"/>
|
||||
<echo>[athena-debug-deploy] Copying Debug Script Over.</echo>
|
||||
<scp file="${wpilib.ant.dir}/debugjavaprogram" todir="${username}@${target}:${deploy.dir}"
|
||||
password="${password}" trust="true"/>
|
||||
<echo>[athena-debug-deploy] Starting program.</echo>
|
||||
<sshexec host="${target}"
|
||||
username="${username}"
|
||||
password="${password}"
|
||||
trust="true"
|
||||
command="chmod a+x debug*program; ${deploy.debug.command}"/>
|
||||
command="tail -f -s 0 -n 1 ${deploy.log.file}"/>
|
||||
</target>
|
||||
|
||||
<target name="debug-deploy" depends="get-target-ip,jar" description="Deploy the jar and start the program running.">
|
||||
<echo>[athena-deploy] Copying code over.</echo>
|
||||
<scp file="${dist.jar}" todir="${username}@${target}:${deploy.dir}" password="${password}" trust="true"/>
|
||||
|
||||
<echo>[athena-deploy] Starting program.</echo>
|
||||
<sshexec host="${target}"
|
||||
username="${username}"
|
||||
password="${password}"
|
||||
trust="true"
|
||||
command=". /etc/profile.d/natinst-path.sh; ${deploy.debug.command}"/>
|
||||
</target>
|
||||
|
||||
<!-- Simulate -->
|
||||
<target name="jar-for-simulation" depends="compile">
|
||||
<echo>[jar-for-simulation] Building jar.</echo>
|
||||
|
||||
|
||||
<jar destfile="${simulation.dist.jar}">
|
||||
<manifest>
|
||||
<attribute name="Built-By" value="${user.name}"/>
|
||||
@@ -123,12 +125,14 @@
|
||||
</exec>
|
||||
</sequential>
|
||||
<sequential>
|
||||
<sleep seconds="5"/>
|
||||
<echo>[simulate] Running DriverStation.</echo>
|
||||
<java jar="${wpilib.sim.tools}/SimDS.jar" fork="true">
|
||||
<jvmarg value="-Djava.library.path=${wpilib.sim.lib}" />
|
||||
</java>
|
||||
</sequential>
|
||||
<sequential>
|
||||
<sleep seconds="5"/>
|
||||
<echo>[simulate] Running Code.</echo>
|
||||
<java jar="${simulation.dist.jar}" fork="true">
|
||||
<jvmarg value="-Djava.library.path=${wpilib.sim.lib}" />
|
||||
@@ -146,12 +150,14 @@
|
||||
</exec>
|
||||
</sequential>
|
||||
<sequential>
|
||||
<sleep seconds="5"/>
|
||||
<echo>[debug-simulate] Running DriverStation.</echo>
|
||||
<java jar="${wpilib.sim.tools}/SimDS.jar" fork="true">
|
||||
<jvmarg value="-Djava.library.path=${wpilib.sim.lib}" />
|
||||
</java>
|
||||
</sequential>
|
||||
<sequential>
|
||||
<sleep seconds="5"/>
|
||||
<echo>[debug-simulate] Running Code.</echo>
|
||||
<java jar="${simulation.dist.jar}" fork="true">
|
||||
<jvmarg value="-Xdebug" />
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
#. ./.profile
|
||||
killall java
|
||||
sleep 1
|
||||
/usr/local/frc/JRE/bin/java -XX:+UsePerfData -agentlib:jdwp=transport=dt_socket,address=8348,server=y,suspend=y -jar FRCUserProgram.jar
|
||||
#nohup java -Djna.library.path=$LD_LIBRARY_PATH -Xmx32M -agentlib:jdwp=transport=dt_socket,address=8348,server=y,suspend=y -jar FRCUserProgram.jar
|
||||
@@ -0,0 +1,3 @@
|
||||
/usr/local/frc/JRE/bin/java
|
||||
-jar /home/admin/FRCUserProgram.jar
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
#. ./.profile
|
||||
killall java
|
||||
killall FRCUserProgram
|
||||
sleep 1
|
||||
nohup /usr/local/frc/JRE/bin/java -jar FRCUserProgram.jar
|
||||
#nohup /usr/local/frc/JRE/bin/java -Djna.library.path=$LD_LIBRARY_PATH -Xmx32M -jar FRCUserProgram.jar
|
||||
@@ -1554,6 +1554,8 @@ void clearSPIReceivedData(void* spi_pointer, int32_t *status) {}
|
||||
* @param port The port to open, 0 for the on-board, 1 for the MXP.
|
||||
*/
|
||||
void i2CInitialize(uint8_t port, int32_t *status) {
|
||||
initializeDigital(status);
|
||||
|
||||
if(port > 1)
|
||||
{
|
||||
//Set port out of range error here
|
||||
@@ -1570,7 +1572,6 @@ void i2CInitialize(uint8_t port, int32_t *status) {
|
||||
} else if(port == 1) {
|
||||
i2CMXPObjCount++;
|
||||
if (i2CMXPHandle > 0) return;
|
||||
initializeDigital(status);
|
||||
digitalSystem->writeEnableMXPSpecialFunction(digitalSystem->readEnableMXPSpecialFunction(status)|0xC000, status);
|
||||
i2CMXPHandle = i2clib_open("/dev/i2c-1");
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#ifndef PCM_H_
|
||||
#define PCM_H_
|
||||
#include "ctre.h" //BIT Defines + Typedefs
|
||||
#include "ctre.h" //BIT Defines + Typedefs
|
||||
#include <NetworkCommunication/CANSessionMux.h> //CAN Comm
|
||||
#include <pthread.h>
|
||||
/* encoder/decoders */
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#ifndef PDP_H_
|
||||
#define PDP_H_
|
||||
#include "ctre.h" //BIT Defines + Typedefs
|
||||
#include "ctre.h" /* BIT Defines + Typedefs */
|
||||
#include <NetworkCommunication/CANSessionMux.h> //CAN Comm
|
||||
#include <pthread.h>
|
||||
/* encoder/decoders */
|
||||
|
||||
BIN
ni-libraries/libFRC_FPGA_ChipObject.so
Normal file → Executable file
BIN
ni-libraries/libFRC_FPGA_ChipObject.so
Normal file → Executable file
Binary file not shown.
BIN
ni-libraries/libFRC_NetworkCommunication.so
Normal file → Executable file
BIN
ni-libraries/libFRC_NetworkCommunication.so
Normal file → Executable file
Binary file not shown.
Binary file not shown.
BIN
ni-libraries/libRoboRIO_FRC_ChipObject.so
Normal file → Executable file
BIN
ni-libraries/libRoboRIO_FRC_ChipObject.so
Normal file → Executable file
Binary file not shown.
BIN
ni-libraries/libi2c.so
Normal file → Executable file
BIN
ni-libraries/libi2c.so
Normal file → Executable file
Binary file not shown.
BIN
ni-libraries/libspi.so
Normal file → Executable file
BIN
ni-libraries/libspi.so
Normal file → Executable file
Binary file not shown.
@@ -21,7 +21,7 @@ all: debs update-repository
|
||||
allwpilib:
|
||||
cd $(allwpilib) && mvn -T 8 clean package -Dwith-eclipse-plugins -DskipTests -DskipIT
|
||||
|
||||
orig: clean
|
||||
orig: pre-orig-clean
|
||||
cd frcsim-gazebo-plugins && tar --exclude="./debian" -czvf \
|
||||
frcsim-gazebo-plugins_${gazebo-plugins-version}.orig.tar.gz frcsim-gazebo-plugins
|
||||
cd frcsim-gazebo-models && tar --exclude="./debian" -czvf \
|
||||
@@ -59,7 +59,7 @@ clean-repository:
|
||||
cd repository && reprepro remove $(codename) frcsim-libwpilibsim-cpp
|
||||
cd repository && reprepro remove $(codename) frcsim
|
||||
|
||||
clean:
|
||||
pre-orig-clean:
|
||||
cd frcsim-gazebo-plugins/frcsim-gazebo-plugins && debuild clean
|
||||
cd frcsim-gazebo-models/frcsim-gazebo-models && debuild clean
|
||||
cd frcsim-eclipse-plugins/frcsim-eclipse-plugins && debuild clean
|
||||
@@ -67,14 +67,26 @@ clean:
|
||||
cd frcsim-libwpilibsim-cpp/frcsim-libwpilibsim-cpp && debuild clean
|
||||
cd frcsim/frcsim && debuild clean
|
||||
|
||||
rm -f frcsim-gazebo-plugins/frcsim-gazebo-plugins_$(gazebo-plugins-package-version).orig.tar.gz
|
||||
rm -f frcsim-gazebo-models/frcsim-gazebo-models_$(gazebo-models-package-version).orig.tar.gz
|
||||
rm -f frcsim-eclipse-plugins/frcsim-eclipse-plugins_$(eclipse-plugins-package-version).orig.tar.gz
|
||||
rm -f frcsim-eclipse-toolchain-plugin/frcsim-eclipse-toolchain-plugin_$(eclipse-toolchain-package-version).orig.tar.gz
|
||||
rm -f frcsim-gazebo-plugins/frcsim-gazebo-plugins_$(gazebo-plugins-version).orig.tar.gz
|
||||
rm -f frcsim-gazebo-models/frcsim-gazebo-models_$(gazebo-models-version).orig.tar.gz
|
||||
rm -f frcsim-eclipse-plugins/frcsim-eclipse-plugins_$(eclipse-plugins-version).orig.tar.gz
|
||||
rm -f frcsim-eclipse-toolchain-plugin/frcsim-eclipse-toolchain-plugin_$(eclipse-toolchain-version).orig.tar.gz
|
||||
rm -f frcsim-libwpilib-cpp/frcsim-libwpilib-cpp_$(libwpilibsim-version).orig.tar.gz
|
||||
rm -f frcsim/frcsim_$(frcsim-package-version).orig.tar.gz
|
||||
rm -f frcsim/frcsim_$(frcsim-version).orig.tar.gz
|
||||
|
||||
pull: pull-gazebo-plugins pull-eclipse-plugins pull-libwpilibsim-cpp orig
|
||||
clean: pre-orig-clean
|
||||
rm -rf frcsim-eclipse-plugins/frcsim-eclipse-plugins/plugins
|
||||
rm -rf frcsim-eclipse-plugins/frcsim-eclipse-plugins/features
|
||||
|
||||
rm -rf frcsim-gazebo-plugins/frcsim-gazebo-plugins/src
|
||||
|
||||
rm -rf frcsim-libwpilibsim-cpp/frcsim-libwpilibsim-cpp/src
|
||||
rm -rf frcsim-libwpilibsim-cpp/frcsim-libwpilibsim-cpp/include
|
||||
rm -f frcsim-libwpilibsim-cpp/frcsim-libwpilibsim-cpp/Makefile
|
||||
rm -f frcsim-libwpilibsim-cpp/frcsim-libwpilibsim-cpp/CMakeLists.txt
|
||||
rm -rf frcsim-libwpilibsim-cpp/frcsim-libwpilibsim-cpp/target
|
||||
|
||||
pull: clean pull-gazebo-plugins pull-eclipse-plugins pull-libwpilibsim-cpp orig
|
||||
|
||||
pull-gazebo-plugins:
|
||||
cp -rf -t frcsim-gazebo-plugins/frcsim-gazebo-plugins/ $(allwpilib)/simulation/frc_gazebo_plugin/*
|
||||
|
||||
@@ -30,7 +30,7 @@ constexpr double CANJaguar::kApproxBusVoltage;
|
||||
static const int32_t kSendMessagePeriod = 20;
|
||||
static const uint32_t kFullMessageIDMask = (CAN_MSGID_API_M | CAN_MSGID_MFR_M | CAN_MSGID_DTYPE_M);
|
||||
|
||||
static const int32_t kReceiveStatusAttempts = 5000;
|
||||
static const int32_t kReceiveStatusAttempts = 50;
|
||||
|
||||
static int32_t sendMessageHelper(uint32_t messageID, const uint8_t *data, uint8_t dataSize, int32_t period)
|
||||
{
|
||||
|
||||
@@ -245,15 +245,15 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
|
||||
}
|
||||
|
||||
/**
|
||||
* set the output set-point value.
|
||||
*
|
||||
* The scale and the units depend on the mode the Jaguar is in.
|
||||
* In PercentVbus Mode, the outputValue is from -1.0 to 1.0 (same as PWM Jaguar).
|
||||
* In Voltage Mode, the outputValue is in Volts.
|
||||
* In Current Mode, the outputValue is in Amps.
|
||||
* In Speed Mode, the outputValue is in Rotations/Minute.
|
||||
* Sets the output set-point value.
|
||||
*
|
||||
* The scale and the units depend on the mode the Jaguar is in.<br>
|
||||
* In PercentVbus Mode, the outputValue is from -1.0 to 1.0 (same as PWMJaguar).<br>
|
||||
* In Voltage Mode, the outputValue is in Volts. <br>
|
||||
* In Current Mode, the outputValue is in Amps. In Speed Mode, the outputValue is in
|
||||
* Rotations/Minute.<br>
|
||||
* In Position Mode, the outputValue is in Rotations.
|
||||
*
|
||||
*
|
||||
* @param outputValue The set-point to sent to the motor controller.
|
||||
* @param syncGroup The update group to add this set() to, pending UpdateSyncGroup(). If 0, update immediately.
|
||||
*/
|
||||
@@ -306,6 +306,19 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
|
||||
verify();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the output set-point value.
|
||||
*
|
||||
* The scale and the units depend on the mode the Jaguar is in.<br>
|
||||
* In PercentVbus Mode, the outputValue is from -1.0 to 1.0 (same as PWMJaguar).<br>
|
||||
* In Voltage Mode, the outputValue is in Volts. <br>
|
||||
* In Current Mode, the outputValue is in Amps. In Speed Mode, the outputValue is in
|
||||
* Rotations/Minute.<br>
|
||||
* In Position Mode, the outputValue is in Rotations.
|
||||
*
|
||||
* @param value
|
||||
* The set-point to sent to the motor controller.
|
||||
*/
|
||||
public void set(double value) {
|
||||
set(value, (byte)0);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,238 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2008-2014. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import edu.wpi.first.wpilibj.can.ICANData;
|
||||
import edu.wpi.first.wpilibj.can.AbstractCANTest;
|
||||
import edu.wpi.first.wpilibj.command.AbstractCommandTest;
|
||||
import edu.wpi.first.wpilibj.fixtures.CANMotorEncoderFixture;
|
||||
import edu.wpi.first.wpilibj.fixtures.MotorEncoderFixture;
|
||||
import edu.wpi.first.wpilibj.test.AbstractComsSetup;
|
||||
import edu.wpi.first.wpilibj.test.TestBench;
|
||||
|
||||
/**
|
||||
* @author jonathanleitschuh
|
||||
*
|
||||
*/
|
||||
public class CANJaguarTest extends AbstractComsSetup implements ICANData{
|
||||
private static final Logger logger = Logger.getLogger(CANJaguarTest.class.getName());
|
||||
private CANMotorEncoderFixture me;
|
||||
|
||||
@Override
|
||||
protected Logger getClassLogger() {
|
||||
return logger;
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
me = TestBench.getInstance().getCanJaguarPair();
|
||||
me.setup();
|
||||
me.getMotor().setPercentMode(CANJaguar.kEncoder, 360);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
me.teardown();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDefaultSpeedGet(){
|
||||
assertEquals("CAN Jaguar did not initilize stopped", 0.0, me.getMotor().get(), .01f);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultBusVoltage(){
|
||||
assertEquals("CAN Jaguar did not start at 14 volts", 14.0f, me.getMotor().getBusVoltage(), 2.0f);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultOutputVoltage(){
|
||||
assertEquals("CAN Jaguar did not start with an output voltage of 0", 0.0f, me.getMotor().getOutputVoltage(), 0.3f);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultOutputCurrent(){
|
||||
assertEquals("CAN Jaguar did not start with an output current of 0", 0.0f, me.getMotor().getOutputCurrent(), 0.3f);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultTemperature(){
|
||||
double room_temp = 18.0f;
|
||||
assertThat("CAN Jaguar did not start with an initial temperature greater than " + room_temp, me.getMotor().getTemperature(), is(greaterThan(room_temp)));
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testDefaultPosition(){
|
||||
assertEquals("CAN Jaguar did not start with an initial position of zero", 0.0f, me.getMotor().getPosition(), 0.3f);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultSpeed(){
|
||||
assertEquals("CAN Jaguar did not start with an initial speed of zero", 0.0f, me.getMotor().getSpeed(), 0.3f);
|
||||
}
|
||||
|
||||
//TODO Check that attached FPGA encoder is zeroed after a delay
|
||||
//TODO Check that attached FPGA encoder speed is zero after a delay
|
||||
|
||||
@Test
|
||||
public void testDefaultForwardLimit(){
|
||||
assertTrue("CAN Jaguar did not start with the Forward Limit Switch Off", me.getMotor().getForwardLimitOK());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultReverseLimit(){
|
||||
assertTrue("CAN Jaguar did not start with the Reverse Limit Switch Off", me.getMotor().getReverseLimitOK());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultNoFaults(){
|
||||
assertEquals(0, me.getMotor().getFaults());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test if we can set a position and reach that position with PID control on
|
||||
* the Jaguar.
|
||||
*/
|
||||
@Test
|
||||
public void testEncoderPositionPID() {
|
||||
me.getMotor().setPositionMode(CANJaguar.kQuadEncoder, 360, 5.0, 0.1, 2.0);
|
||||
me.getMotor().enableControl();
|
||||
|
||||
double setpoint = me.getMotor().getPosition() + 10.0f;
|
||||
|
||||
/* It should get to the setpoint within 10 seconds */
|
||||
me.getMotor().set(setpoint);
|
||||
Timer.delay(10.0f);
|
||||
|
||||
assertEquals("CAN Jaguar should have reached setpoint with PID control", setpoint, me.getMotor().getPosition(), kEncoderPositionTolerance);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if we can get a position in potentiometer mode, using an analog output
|
||||
* as a fake potentiometer.
|
||||
*/
|
||||
@Test
|
||||
public void testFakePotentiometerPosition() {
|
||||
me.getMotor().setPercentMode(CANJaguar.kPotentiometer);
|
||||
me.getMotor().enableControl();
|
||||
|
||||
me.getFakePot().setVoltage(0.0f);
|
||||
Timer.delay(kPotentiometerSettlingTime);
|
||||
assertEquals("CAN Jaguar should have returned the potentiometer position set by the analog output", me.getFakePot().getVoltage() / 3.0f, me.getMotor().getPosition(), kPotentiometerPositionTolerance);
|
||||
|
||||
me.getFakePot().setVoltage(1.0f);
|
||||
Timer.delay(kPotentiometerSettlingTime);
|
||||
assertEquals("CAN Jaguar should have returned the potentiometer position set by the analog output", me.getFakePot().getVoltage() / 3.0f, me.getMotor().getPosition(), kPotentiometerPositionTolerance);
|
||||
|
||||
me.getFakePot().setVoltage(2.0f);
|
||||
Timer.delay(kPotentiometerSettlingTime);
|
||||
assertEquals("CAN Jaguar should have returned the potentiometer position set by the analog output", me.getFakePot().getVoltage() / 3.0f, me.getMotor().getPosition(), kPotentiometerPositionTolerance);
|
||||
|
||||
me.getFakePot().setVoltage(3.0f);
|
||||
Timer.delay(kPotentiometerSettlingTime);
|
||||
assertEquals("CAN Jaguar should have returned the potentiometer position set by the analog output", me.getFakePot().getVoltage() / 3.0f, me.getMotor().getPosition(), kPotentiometerPositionTolerance);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if we can limit the Jaguar to only moving in reverse with a fake
|
||||
* limit switch.
|
||||
*/
|
||||
@Test
|
||||
public void testFakeLimitSwitchForwards() {
|
||||
me.getMotor().setPercentMode(CANJaguar.kQuadEncoder, 360);
|
||||
me.getMotor().configLimitMode(CANJaguar.LimitMode.SwitchInputsOnly);
|
||||
me.getForwardLimit().set(true);
|
||||
me.getReverseLimit().set(false);
|
||||
me.getMotor().enableControl();
|
||||
|
||||
me.getMotor().set(0.0f);
|
||||
Timer.delay(kEncoderSettlingTime);
|
||||
|
||||
/* Make sure we limits are recognized by the Jaguar. */
|
||||
assertFalse(me.getMotor().getForwardLimitOK());
|
||||
assertTrue(me.getMotor().getReverseLimitOK());
|
||||
|
||||
double initialPosition = me.getMotor().getPosition();
|
||||
|
||||
/* Drive the speed controller briefly to move the encoder. If the limit
|
||||
switch is recognized, it shouldn't actually move. */
|
||||
me.getMotor().set(1.0f);
|
||||
Timer.delay(kMotorTime);
|
||||
me.getMotor().set(0.0f);
|
||||
|
||||
/* The position should be the same, since the limit switch was on. */
|
||||
assertEquals("CAN Jaguar should not have moved with the limit switch pressed", initialPosition, me.getMotor().getPosition(), kEncoderPositionTolerance);
|
||||
|
||||
/* Drive the speed controller in the other direction. It should actually
|
||||
move, since only the forward switch is activated.*/
|
||||
me.getMotor().set(-1.0f);
|
||||
Timer.delay(kMotorTime);
|
||||
me.getMotor().set(0.0f);
|
||||
|
||||
/* The position should have decreased */
|
||||
assertThat("CAN Jaguar should have moved in reverse while the forward limit was on", me.getMotor().getPosition(), is(lessThan(initialPosition)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if we can limit the Jaguar to only moving forwards with a fake limit
|
||||
* switch.
|
||||
*/
|
||||
@Test
|
||||
public void testFakeLimitSwitchReverse() {
|
||||
me.getMotor().setPercentMode(CANJaguar.kQuadEncoder, 360);
|
||||
me.getMotor().configLimitMode(CANJaguar.LimitMode.SwitchInputsOnly);
|
||||
me.getForwardLimit().set(false);
|
||||
me.getReverseLimit().set(true);
|
||||
me.getMotor().enableControl();
|
||||
|
||||
me.getMotor().set(0.0f);
|
||||
Timer.delay(kEncoderSettlingTime);
|
||||
|
||||
/* Make sure we limits are recognized by the Jaguar. */
|
||||
assertTrue(me.getMotor().getForwardLimitOK());
|
||||
assertFalse(me.getMotor().getReverseLimitOK());
|
||||
|
||||
double initialPosition = me.getMotor().getPosition();
|
||||
|
||||
/* Drive the speed controller backwards briefly to move the encoder. If
|
||||
the limit switch is recognized, it shouldn't actually move. */
|
||||
me.getMotor().set(-1.0f);
|
||||
Timer.delay(kMotorTime);
|
||||
me.getMotor().set(0.0f);
|
||||
|
||||
/* The position should be the same, since the limit switch was on. */
|
||||
assertEquals("CAN Jaguar should not have moved with the limit switch pressed", initialPosition, me.getMotor().getPosition(), kEncoderPositionTolerance);
|
||||
|
||||
Timer.delay(kEncoderSettlingTime);
|
||||
|
||||
/* Drive the speed controller in the other direction. It should actually
|
||||
move, since only the reverse switch is activated.*/
|
||||
me.getMotor().set(1.0f);
|
||||
Timer.delay(kMotorTime);
|
||||
me.getMotor().set(0.0f);
|
||||
|
||||
/* The position should have increased */
|
||||
assertThat("CAN Jaguar should have moved forwards while the reverse limit was on", me.getMotor().getPosition(), is(greaterThan(initialPosition)));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -12,24 +12,26 @@ import org.junit.runners.Suite.SuiteClasses;
|
||||
|
||||
/**
|
||||
* @author jonathanleitschuh
|
||||
*
|
||||
* Holds all of the tests in the roor wpilibj directory
|
||||
* Please list alphabetically so that it is easy to determine if a test is missing from the list
|
||||
*/
|
||||
@RunWith(Suite.class)
|
||||
@SuiteClasses({
|
||||
AnalogCrossConnectTest.class,
|
||||
AnalogPotentiometerTest.class,
|
||||
CANJaguarTest.class,
|
||||
CounterTest.class,
|
||||
DIOCrossConnectTest.class,
|
||||
EncoderTest.class,
|
||||
MotorEncoderTest.class,
|
||||
PIDTest.class,
|
||||
PCMTest.class,
|
||||
PIDTest.class,
|
||||
PDPTest.class,
|
||||
PrefrencesTest.class,
|
||||
RelayCrossConnectTest.class,
|
||||
SampleTest.class,
|
||||
TiltPanCameraTest.class,
|
||||
TimerTest.class,
|
||||
PDPTest.class
|
||||
TimerTest.class
|
||||
})
|
||||
public class WpiLibJTestSuite {
|
||||
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2008-2014. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
package edu.wpi.first.wpilibj.can;
|
||||
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.lessThan;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import org.junit.After;
|
||||
|
||||
import edu.wpi.first.wpilibj.Timer;
|
||||
import edu.wpi.first.wpilibj.fixtures.CANMotorEncoderFixture;
|
||||
import edu.wpi.first.wpilibj.test.AbstractComsSetup;
|
||||
|
||||
/**
|
||||
* @author jonathanleitschuh
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractCANTest extends AbstractComsSetup implements ICANData{
|
||||
protected CANMotorEncoderFixture me;
|
||||
/**
|
||||
* Tests that CAN in a certain mode will rotate forwards. The implementation of this method is left up to the extending class because each will require difrent values.
|
||||
* Should call {@link AbstractCANTest#testRotateForward(double, double)}
|
||||
*/
|
||||
abstract public void testRotateForward();
|
||||
|
||||
/**
|
||||
* Tests that CAN in a certain mode will rotate forwards. The implementation of this method is left up to the extending class because each will require difrent values.
|
||||
* Should call {@link AbstractCANTest#testRotateReverse(double, double)}
|
||||
*/
|
||||
abstract public void testRotateReverse();
|
||||
|
||||
|
||||
@After
|
||||
public final void tearDown() throws Exception {
|
||||
me.teardown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that a CANMotorEncoderFixture can rotate forward.
|
||||
* Called by extending TestClasses
|
||||
* @param stoppedValue the value where the motor will not be spinning in the current mode
|
||||
* @param runningValue the value where the motor will be spinning in the current mode
|
||||
*/
|
||||
protected void testRotateForward(double stoppedValue, double runningValue){
|
||||
double initialPosition = me.getMotor().getPosition();
|
||||
/* Drive the speed controller briefly to move the encoder */
|
||||
me.getMotor().set(runningValue);
|
||||
Timer.delay(kMotorTime);
|
||||
me.getMotor().set(stoppedValue);
|
||||
|
||||
/* The position should have increased */
|
||||
assertThat("CAN Jaguar position should have increased after the motor moved", me.getMotor().getPosition(), is(greaterThan(initialPosition)));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tests that a CANMotorEncoderFixture can rotate in reverse.
|
||||
* Called by extending TestClasses
|
||||
* @param stoppedValue the value where the motor will not be spinning in the current mode
|
||||
* @param runningValue the value where the motor will be spinning in the current mode
|
||||
*/
|
||||
protected void testRotateReverse(double stoppedValue, double runningValue){
|
||||
double initialPosition = me.getMotor().getPosition();
|
||||
/* Drive the speed controller briefly to move the encoder */
|
||||
me.getMotor().set(runningValue);
|
||||
Timer.delay(kMotorTime);
|
||||
me.getMotor().set(stoppedValue);
|
||||
|
||||
/* The position should have decreased */
|
||||
assertThat( "CAN Jaguar position should have decreased after the motor moved", me.getMotor().getPosition(), is(lessThan(initialPosition)));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2008-2014. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
package edu.wpi.first.wpilibj.can;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Suite;
|
||||
import org.junit.runners.Suite.SuiteClasses;
|
||||
|
||||
/**
|
||||
* @author jonathanleitschuh
|
||||
*
|
||||
*/
|
||||
@RunWith(Suite.class)
|
||||
@SuiteClasses({ CurrentQuadEncoderModeTest.class,
|
||||
PercentQuadEncoderModeTest.class,
|
||||
PositionQuadEncoderModeTest.class,
|
||||
SpeedQuadEncoderModeTest.class,
|
||||
VoltageQuadEncoderModeTest.class
|
||||
})
|
||||
public class CANTestSuite {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2008-2014. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
package edu.wpi.first.wpilibj.can;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import edu.wpi.first.wpilibj.CANJaguar;
|
||||
import edu.wpi.first.wpilibj.Timer;
|
||||
import edu.wpi.first.wpilibj.test.TestBench;
|
||||
|
||||
/**
|
||||
* @author jonathanleitschuh
|
||||
*
|
||||
*/
|
||||
public class CurrentQuadEncoderModeTest extends AbstractCANTest {
|
||||
private static Logger logger = Logger.getLogger(CurrentQuadEncoderModeTest.class.getName());
|
||||
@Override
|
||||
protected Logger getClassLogger() {
|
||||
return logger;
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
me = TestBench.getInstance().getCanJaguarPair();
|
||||
me.setup();
|
||||
me.getMotor().setCurrentMode(CANJaguar.kQuadEncoder, 360, 5.0, 0.1, 2.0);
|
||||
me.getMotor().enableControl();
|
||||
me.getMotor().set(0.0f);
|
||||
/* The motor might still have momentum from the previous test. */
|
||||
Timer.delay(kEncoderSettlingTime);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testRotateForward() {
|
||||
testRotateForward(0, 1.5);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testRotateReverse() {
|
||||
testRotateReverse(0, -1.5);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2008-2014. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
package edu.wpi.first.wpilibj.can;
|
||||
|
||||
/**
|
||||
* @author jonathanleitschuh
|
||||
*
|
||||
*/
|
||||
public interface ICANData {
|
||||
static final double kPotentiometerSettlingTime = 0.05;
|
||||
static final double kMotorTime = 0.5;
|
||||
static final double kEncoderSettlingTime = 0.25;
|
||||
static final double kEncoderPositionTolerance = 5.0/360.0; // +/-5 degrees
|
||||
static final double kPotentiometerPositionTolerance = 10.0/360.0; // +/-10 degrees
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2008-2014. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
package edu.wpi.first.wpilibj.can;
|
||||
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.lessThan;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import edu.wpi.first.wpilibj.CANJaguar;
|
||||
import edu.wpi.first.wpilibj.Timer;
|
||||
import edu.wpi.first.wpilibj.fixtures.CANMotorEncoderFixture;
|
||||
import edu.wpi.first.wpilibj.test.AbstractComsSetup;
|
||||
import edu.wpi.first.wpilibj.test.TestBench;
|
||||
import edu.wpi.first.wpilibj.test.TestBench.BaseCANMotorEncoderFixture;
|
||||
|
||||
/**
|
||||
* @author jonathanleitschuh
|
||||
*
|
||||
*/
|
||||
public class PercentQuadEncoderModeTest extends AbstractCANTest implements ICANData{
|
||||
private static final Logger logger = Logger.getLogger(PercentQuadEncoderModeTest.class.getName());
|
||||
|
||||
@Override
|
||||
protected Logger getClassLogger() {
|
||||
return logger;
|
||||
}
|
||||
@Before
|
||||
public void setUp() {
|
||||
me = TestBench.getInstance().getCanJaguarPair();
|
||||
me.setup();
|
||||
me.getMotor().setPercentMode(CANJaguar.kQuadEncoder, 360);
|
||||
me.getMotor().enableControl();
|
||||
me.getMotor().set(0.0f);
|
||||
/* The motor might still have momentum from the previous test. */
|
||||
Timer.delay(kEncoderSettlingTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if we can drive the motor forwards in percentage mode and get a
|
||||
* position back
|
||||
*/
|
||||
@Test
|
||||
@Override
|
||||
public void testRotateForward() {
|
||||
testRotateForward(0, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if we can drive the motor backwards in percentage mode and get a
|
||||
* position back
|
||||
*/
|
||||
@Test
|
||||
@Override
|
||||
public void testRotateReverse() {
|
||||
testRotateReverse(0, -1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2008-2014. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
package edu.wpi.first.wpilibj.can;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import edu.wpi.first.wpilibj.CANJaguar;
|
||||
import edu.wpi.first.wpilibj.Timer;
|
||||
import edu.wpi.first.wpilibj.test.TestBench;
|
||||
|
||||
/**
|
||||
* @author jonathanleitschuh
|
||||
*
|
||||
*/
|
||||
public class PositionQuadEncoderModeTest extends AbstractCANTest {
|
||||
private static final Logger logger = Logger.getLogger(PositionQuadEncoderModeTest.class.getName());
|
||||
@Override
|
||||
protected Logger getClassLogger() {
|
||||
return logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
me = TestBench.getInstance().getCanJaguarPair();
|
||||
me.setup();
|
||||
me.getMotor().setPositionMode(CANJaguar.kQuadEncoder, 360, 5.0, 0.1, 2.0);
|
||||
me.getMotor().enableControl();
|
||||
/* The motor might still have momentum from the previous test. */
|
||||
Timer.delay(kEncoderSettlingTime);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testRotateForward() {
|
||||
double initial = me.getMotor().getPosition();
|
||||
testRotateForward(initial, initial + 50);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testRotateReverse() {
|
||||
double initial = me.getMotor().getPosition();
|
||||
testRotateReverse(initial, initial - 50);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2008-2014. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
package edu.wpi.first.wpilibj.can;
|
||||
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.lessThan;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import edu.wpi.first.wpilibj.CANJaguar;
|
||||
import edu.wpi.first.wpilibj.Timer;
|
||||
import edu.wpi.first.wpilibj.fixtures.CANMotorEncoderFixture;
|
||||
import edu.wpi.first.wpilibj.test.AbstractComsSetup;
|
||||
import edu.wpi.first.wpilibj.test.TestBench;
|
||||
|
||||
/**
|
||||
* @author jonathanleitschuh
|
||||
*
|
||||
*/
|
||||
public class SpeedQuadEncoderModeTest extends AbstractCANTest implements ICANData {
|
||||
private static final Logger logger = Logger.getLogger(PercentQuadEncoderModeTest.class.getName());
|
||||
|
||||
@Override
|
||||
protected Logger getClassLogger() {
|
||||
return logger;
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
me = TestBench.getInstance().getCanJaguarPair();
|
||||
me.setup();
|
||||
me.getMotor().setSpeedMode(CANJaguar.kQuadEncoder, 360, 5.0, 0.1, 2.0);
|
||||
me.getMotor().enableControl();
|
||||
me.getMotor().set(0.0f);
|
||||
/* The motor might still have momentum from the previous test. */
|
||||
Timer.delay(kEncoderSettlingTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if we can drive the motor forward in Speed mode and get a
|
||||
* position back
|
||||
*/
|
||||
@Test
|
||||
public void testRotateForward() {
|
||||
//Speed is rev/min
|
||||
testRotateForward(0, 1000);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if we can drive the motor backwards in Speed mode and get a
|
||||
* position back
|
||||
*/
|
||||
@Test
|
||||
public void testRotateReverse() {
|
||||
//Speed is rev/min
|
||||
testRotateReverse(0, -1000);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2008-2014. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
package edu.wpi.first.wpilibj.can;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import edu.wpi.first.wpilibj.CANJaguar;
|
||||
import edu.wpi.first.wpilibj.Timer;
|
||||
import edu.wpi.first.wpilibj.fixtures.CANMotorEncoderFixture;
|
||||
import edu.wpi.first.wpilibj.test.AbstractComsSetup;
|
||||
import edu.wpi.first.wpilibj.test.TestBench;
|
||||
|
||||
/**
|
||||
* @author jonathanleitschuh
|
||||
*
|
||||
*/
|
||||
public class VoltageQuadEncoderModeTest extends AbstractCANTest implements ICANData {
|
||||
private static final Logger logger = Logger.getLogger(VoltageQuadEncoderModeTest.class.getName());
|
||||
|
||||
@Override
|
||||
protected Logger getClassLogger() {
|
||||
return logger;
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
me = TestBench.getInstance().getCanJaguarPair();
|
||||
me.setup();
|
||||
me.getMotor().setPercentMode(CANJaguar.kQuadEncoder, 360);
|
||||
me.getMotor().enableControl();
|
||||
me.getMotor().set(0.0f);
|
||||
/* The motor might still have momentum from the previous test. */
|
||||
Timer.delay(kEncoderSettlingTime);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testRotateForward() {
|
||||
testRotateForward(0, 14);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testRotateReverse() {
|
||||
testRotateReverse(0, -14);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2008-2014. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
package edu.wpi.first.wpilibj.fixtures;
|
||||
|
||||
import edu.wpi.first.wpilibj.CANJaguar;
|
||||
import edu.wpi.first.wpilibj.DigitalInput;
|
||||
import edu.wpi.first.wpilibj.DigitalOutput;
|
||||
import edu.wpi.first.wpilibj.mockhardware.FakeEncoderSource;
|
||||
import edu.wpi.first.wpilibj.mockhardware.FakePotentiometerSource;
|
||||
|
||||
/**
|
||||
* @author jonathanleitschuh
|
||||
*
|
||||
*/
|
||||
public abstract class CANMotorEncoderFixture extends MotorEncoderFixture<CANJaguar> implements ITestFixture {
|
||||
private FakePotentiometerSource potSource;
|
||||
private DigitalOutput forwardLimit;
|
||||
private DigitalOutput reverseLimit;
|
||||
private boolean initialized = false;
|
||||
|
||||
protected abstract FakePotentiometerSource giveFakePotentiometerSource();
|
||||
protected abstract DigitalOutput giveFakeForwardLimit();
|
||||
protected abstract DigitalOutput giveFakeReverseLimit();
|
||||
|
||||
public CANMotorEncoderFixture(){}
|
||||
|
||||
public void initialize(){
|
||||
synchronized(this){
|
||||
if(!initialized){
|
||||
potSource = giveFakePotentiometerSource();
|
||||
forwardLimit = giveFakeForwardLimit();
|
||||
reverseLimit = giveFakeReverseLimit();
|
||||
initialized = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean setup() {
|
||||
initialize();
|
||||
return super.setup();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean reset() {
|
||||
initialize();
|
||||
potSource.reset();
|
||||
forwardLimit.set(false);
|
||||
reverseLimit.set(false);
|
||||
getMotor().setPercentMode(); //Get the Jaguar into a mode where setting the speed means stop
|
||||
return super.reset();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean teardown() {
|
||||
potSource.free();
|
||||
forwardLimit.free();
|
||||
reverseLimit.free();
|
||||
boolean superTornDown = super.teardown();
|
||||
getMotor().free();
|
||||
return superTornDown;
|
||||
}
|
||||
|
||||
public FakePotentiometerSource getFakePot(){
|
||||
initialize();
|
||||
return potSource;
|
||||
}
|
||||
|
||||
public DigitalOutput getForwardLimit(){
|
||||
initialize();
|
||||
return forwardLimit;
|
||||
}
|
||||
|
||||
public DigitalOutput getReverseLimit(){
|
||||
initialize();
|
||||
return reverseLimit;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -23,10 +23,10 @@ import edu.wpi.first.wpilibj.test.TestBench;
|
||||
* @author Jonathan Leitschuh
|
||||
*
|
||||
*/
|
||||
public abstract class MotorEncoderFixture implements ITestFixture {
|
||||
public abstract class MotorEncoderFixture <T extends SpeedController> implements ITestFixture {
|
||||
private boolean initialized = false;
|
||||
private boolean tornDown = false;
|
||||
protected SpeedController motor;
|
||||
protected T motor;
|
||||
private Encoder encoder;
|
||||
private Counter counters[] = new Counter[2];
|
||||
protected DigitalInput aSource; //Stored so it can be freed at tear down
|
||||
@@ -34,9 +34,6 @@ public abstract class MotorEncoderFixture implements ITestFixture {
|
||||
|
||||
/**
|
||||
* Default constructor for a MotorEncoderFixture
|
||||
* @param motor The SpeedControler for this MotorEncoder pair
|
||||
* @param aSource One of the inputs for the encoder
|
||||
* @param bSource The other input for the encoder
|
||||
*/
|
||||
public MotorEncoderFixture(){
|
||||
}
|
||||
@@ -47,7 +44,7 @@ public abstract class MotorEncoderFixture implements ITestFixture {
|
||||
* is not also an implementation of PWM interface
|
||||
* @return
|
||||
*/
|
||||
abstract protected SpeedController giveSpeedController();
|
||||
abstract protected T giveSpeedController();
|
||||
/**
|
||||
* Where the implementer of this class should pass one of the digital inputs<br>
|
||||
* CONSTRUCTOR SHOULD NOT BE CALLED FROM OUTSIDE THIS CLASS!
|
||||
@@ -64,10 +61,11 @@ public abstract class MotorEncoderFixture implements ITestFixture {
|
||||
final private void initialize(){
|
||||
synchronized(this){
|
||||
if(!initialized){
|
||||
motor = giveSpeedController();
|
||||
|
||||
aSource = giveDigitalInputA();
|
||||
bSource = giveDigitalInputB();
|
||||
|
||||
motor = giveSpeedController();
|
||||
|
||||
encoder = new Encoder(aSource, bSource);
|
||||
counters[0] = new Counter(aSource);
|
||||
@@ -91,7 +89,7 @@ public abstract class MotorEncoderFixture implements ITestFixture {
|
||||
* Gets the motor for this Object
|
||||
* @return the motor this object refers too
|
||||
*/
|
||||
public SpeedController getMotor(){
|
||||
public T getMotor(){
|
||||
initialize();
|
||||
return motor;
|
||||
}
|
||||
@@ -154,27 +152,47 @@ public abstract class MotorEncoderFixture implements ITestFixture {
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Safely tears down the MotorEncoder Fixture in a way that makes sure that even if an object fails
|
||||
* to initialize the reset of the fixture can still be torn down and the resources deallocated
|
||||
*/
|
||||
@Override
|
||||
public boolean teardown() {
|
||||
String type = getType();
|
||||
if(!tornDown){
|
||||
boolean wasNull = false;
|
||||
initialize();
|
||||
reset();
|
||||
if(motor instanceof PWM){
|
||||
if(motor instanceof PWM && motor != null){
|
||||
((PWM) motor).free();
|
||||
}
|
||||
motor = null;
|
||||
encoder.free();
|
||||
counters[0].free();
|
||||
counters[0] = null;
|
||||
counters[1].free();
|
||||
counters[1] = null;
|
||||
|
||||
aSource.free();
|
||||
aSource = null;
|
||||
bSource.free();
|
||||
bSource = null;
|
||||
motor = null;
|
||||
} else if(motor == null) wasNull = true;
|
||||
if(encoder != null){
|
||||
encoder.free();
|
||||
encoder = null;
|
||||
} else wasNull = true;
|
||||
if(counters[0] != null){
|
||||
counters[0].free();
|
||||
counters[0] = null;
|
||||
} else wasNull = true;
|
||||
if(counters[1] != null){
|
||||
counters[1].free();
|
||||
counters[1] = null;
|
||||
} else wasNull = true;
|
||||
if(aSource != null){
|
||||
aSource.free();
|
||||
aSource = null;
|
||||
} else wasNull = true;
|
||||
if(bSource != null){
|
||||
bSource.free();
|
||||
bSource = null;
|
||||
} else wasNull = true;
|
||||
|
||||
tornDown = true;
|
||||
|
||||
if(wasNull){
|
||||
throw new NullPointerException("MotorEncoderFixture had null params at teardown");
|
||||
}
|
||||
} else {
|
||||
throw new RuntimeException(type + " Motor Encoder torn down multiple times");
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ public class TiltPanCameraFixture implements ITestFixture {
|
||||
Timer.delay(RESET_TIME);
|
||||
gyro.reset();
|
||||
double startTime = Timer.getFPGATimestamp();
|
||||
while(Math.abs(gyro.getAngle()) > 0.1){
|
||||
for(int i = 0; i < 100 && Math.abs(gyro.getAngle()) > 0.1; i++){
|
||||
Timer.delay(.0001);
|
||||
}
|
||||
double endTime = Timer.getFPGATimestamp();
|
||||
|
||||
@@ -14,12 +14,19 @@ import edu.wpi.first.wpilibj.AnalogOutput;
|
||||
*/
|
||||
public class FakePotentiometerSource {
|
||||
private AnalogOutput output;
|
||||
private boolean m_init_output;
|
||||
private double potMaxAngle;
|
||||
private final double defaultPotMaxAngle;
|
||||
public FakePotentiometerSource(AnalogOutput output, double defaultPotMaxAngle){
|
||||
this.defaultPotMaxAngle = defaultPotMaxAngle;
|
||||
potMaxAngle = defaultPotMaxAngle;
|
||||
this.output = output;
|
||||
m_init_output = false;
|
||||
}
|
||||
|
||||
public FakePotentiometerSource(int port, double defaultPotMaxAngle){
|
||||
this(new AnalogOutput(port), defaultPotMaxAngle);
|
||||
m_init_output = true;
|
||||
}
|
||||
|
||||
public void setRange(double range){
|
||||
@@ -34,4 +41,19 @@ public class FakePotentiometerSource {
|
||||
public void setAngle(double angle){
|
||||
output.setVoltage((5.0/potMaxAngle)*angle);
|
||||
}
|
||||
|
||||
public void setVoltage(double voltage){
|
||||
output.setVoltage(voltage);
|
||||
}
|
||||
|
||||
public double getVoltage(){
|
||||
return output.getVoltage();
|
||||
}
|
||||
|
||||
public void free(){
|
||||
if(m_init_output){
|
||||
output.free();
|
||||
m_init_output = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,12 +67,20 @@ public abstract class AbstractComsSetup {
|
||||
/** This causes a stack trace to be printed as the test is running as well as at the end */
|
||||
@Rule
|
||||
public TestWatcher testWatcher = new TestWatcher() {
|
||||
@Override
|
||||
protected void failed(Throwable e, Description description) {
|
||||
System.out.println();
|
||||
getClassLogger().severe("" + description.getDisplayName() + " failed " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
super.failed(e, description);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void starting( Description description ) {
|
||||
System.out.println();
|
||||
getClassLogger().info( description.getDisplayName());
|
||||
super.starting(description);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -26,10 +26,12 @@ import edu.wpi.first.wpilibj.Talon;
|
||||
import edu.wpi.first.wpilibj.Victor;
|
||||
import edu.wpi.first.wpilibj.can.CANMessageNotFoundException;
|
||||
import edu.wpi.first.wpilibj.fixtures.AnalogCrossConnectFixture;
|
||||
import edu.wpi.first.wpilibj.fixtures.CANMotorEncoderFixture;
|
||||
import edu.wpi.first.wpilibj.fixtures.DIOCrossConnectFixture;
|
||||
import edu.wpi.first.wpilibj.fixtures.MotorEncoderFixture;
|
||||
import edu.wpi.first.wpilibj.fixtures.RelayCrossConnectFxiture;
|
||||
import edu.wpi.first.wpilibj.fixtures.TiltPanCameraFixture;
|
||||
import edu.wpi.first.wpilibj.mockhardware.FakePotentiometerSource;
|
||||
|
||||
/**
|
||||
* This class provides access to all of the elements on the test bench, for use
|
||||
@@ -47,11 +49,22 @@ public final class TestBench {
|
||||
* completely stopped
|
||||
*/
|
||||
public static final double MOTOR_STOP_TIME = 0.20;
|
||||
|
||||
public static final int kTalonChannel = 10;
|
||||
public static final int kVictorChannel = 1;
|
||||
public static final int kJaguarChannel = 2;
|
||||
|
||||
|
||||
/* PowerDistributionPanel channels */
|
||||
public static final int kJaguarPDPChannel = 7;
|
||||
public static final int kVictorPDPChannel = 11;
|
||||
public static final int kTalonPDPChannel = 12;
|
||||
|
||||
/* CAN ASSOICATED CHANNELS */
|
||||
public static final int kFakeJaguarPotentiometer = 1;
|
||||
public static final int kFakeJaguarForwardLimit = 16;
|
||||
public static final int kFakeJaguarReverseLimit = 17;
|
||||
public static final int kCANJaguarID = 2;
|
||||
|
||||
//THESE MUST BE IN INCREMENTING ORDER
|
||||
public static final int DIOCrossConnectB2 = 9;
|
||||
@@ -62,14 +75,11 @@ public final class TestBench {
|
||||
/** The Singleton instance of the Test Bench */
|
||||
private static TestBench instance = null;
|
||||
|
||||
private CANJaguar canJag = null; // This is declared externally because it
|
||||
// does not have a free method
|
||||
|
||||
/**
|
||||
* The single constructor for the TestBench. This method is private in order
|
||||
* to prevent multiple TestBench objects from being allocated
|
||||
*/
|
||||
private TestBench() {
|
||||
protected TestBench() {
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -78,12 +88,12 @@ public final class TestBench {
|
||||
*
|
||||
* @return a freshly allocated Talon, Encoder pair
|
||||
*/
|
||||
public MotorEncoderFixture getTalonPair() {
|
||||
public MotorEncoderFixture<Talon> getTalonPair() {
|
||||
|
||||
MotorEncoderFixture talonPair = new MotorEncoderFixture(){
|
||||
MotorEncoderFixture<Talon> talonPair = new MotorEncoderFixture<Talon>(){
|
||||
@Override
|
||||
protected SpeedController giveSpeedController() {
|
||||
return new Talon(10);
|
||||
protected Talon giveSpeedController() {
|
||||
return new Talon(kTalonChannel);
|
||||
}
|
||||
@Override
|
||||
protected DigitalInput giveDigitalInputA() {
|
||||
@@ -103,12 +113,12 @@ public final class TestBench {
|
||||
*
|
||||
* @return a freshly allocated Victor, Encoder pair
|
||||
*/
|
||||
public MotorEncoderFixture getVictorPair() {
|
||||
public MotorEncoderFixture<Victor> getVictorPair() {
|
||||
|
||||
MotorEncoderFixture vicPair = new MotorEncoderFixture(){
|
||||
MotorEncoderFixture<Victor> vicPair = new MotorEncoderFixture<Victor>(){
|
||||
@Override
|
||||
protected SpeedController giveSpeedController() {
|
||||
return new Victor(1);
|
||||
protected Victor giveSpeedController() {
|
||||
return new Victor(kVictorChannel);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -130,11 +140,11 @@ public final class TestBench {
|
||||
*
|
||||
* @return a freshly allocated Jaguar, Encoder pair
|
||||
*/
|
||||
public MotorEncoderFixture getJaguarPair() {
|
||||
MotorEncoderFixture jagPair = new MotorEncoderFixture(){
|
||||
public MotorEncoderFixture<Jaguar> getJaguarPair() {
|
||||
MotorEncoderFixture<Jaguar> jagPair = new MotorEncoderFixture<Jaguar>(){
|
||||
@Override
|
||||
protected SpeedController giveSpeedController() {
|
||||
return new Jaguar(2);
|
||||
protected Jaguar giveSpeedController() {
|
||||
return new Jaguar(kJaguarChannel);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -149,6 +159,33 @@ public final class TestBench {
|
||||
};
|
||||
return jagPair;
|
||||
}
|
||||
|
||||
public class BaseCANMotorEncoderFixture extends CANMotorEncoderFixture{
|
||||
@Override
|
||||
protected CANJaguar giveSpeedController() {
|
||||
return new CANJaguar(kCANJaguarID);
|
||||
}
|
||||
@Override
|
||||
protected DigitalInput giveDigitalInputA() {
|
||||
return new DigitalInput(18);
|
||||
}
|
||||
@Override
|
||||
protected DigitalInput giveDigitalInputB() {
|
||||
return new DigitalInput(19);
|
||||
}
|
||||
@Override
|
||||
protected FakePotentiometerSource giveFakePotentiometerSource() {
|
||||
return new FakePotentiometerSource(kFakeJaguarPotentiometer, 360);
|
||||
}
|
||||
@Override
|
||||
protected DigitalOutput giveFakeForwardLimit() {
|
||||
return new DigitalOutput(kFakeJaguarForwardLimit);
|
||||
}
|
||||
@Override
|
||||
protected DigitalOutput giveFakeReverseLimit() {
|
||||
return new DigitalOutput(kFakeJaguarReverseLimit);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new set of objects representing a connected set of CANJaguar
|
||||
@@ -158,31 +195,8 @@ public final class TestBench {
|
||||
*
|
||||
* @return an existing CANJaguar and a freshly allocated Encoder
|
||||
*/
|
||||
public MotorEncoderFixture getCanJaguarPair() {
|
||||
MotorEncoderFixture canPair;
|
||||
if (canJag == null) { // Again this is because the CanJaguar does not
|
||||
// have a free method
|
||||
try {
|
||||
canJag = new CANJaguar(1);
|
||||
} catch (CANMessageNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
canPair = new MotorEncoderFixture(){
|
||||
@Override
|
||||
protected SpeedController giveSpeedController() {
|
||||
return canJag;
|
||||
}
|
||||
@Override
|
||||
protected DigitalInput giveDigitalInputA() {
|
||||
return new DigitalInput(6);
|
||||
}
|
||||
@Override
|
||||
protected DigitalInput giveDigitalInputB() {
|
||||
return new DigitalInput(7);
|
||||
}
|
||||
};
|
||||
assert canPair != null;
|
||||
public CANMotorEncoderFixture getCanJaguarPair() {
|
||||
CANMotorEncoderFixture canPair = new BaseCANMotorEncoderFixture();
|
||||
return canPair;
|
||||
}
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ import edu.wpi.first.wpilibj.SampleTest;
|
||||
import edu.wpi.first.wpilibj.TiltPanCameraTest;
|
||||
import edu.wpi.first.wpilibj.TimerTest;
|
||||
import edu.wpi.first.wpilibj.WpiLibJTestSuite;
|
||||
import edu.wpi.first.wpilibj.can.CANTestSuite;
|
||||
import edu.wpi.first.wpilibj.command.ButtonTest;
|
||||
import edu.wpi.first.wpilibj.command.CommandParallelGroupTest;
|
||||
import edu.wpi.first.wpilibj.command.CommandScheduleTest;
|
||||
@@ -49,6 +50,7 @@ import edu.wpi.first.wpilibj.smartdashboard.SmartDashboardTestSuite;
|
||||
@RunWith(Suite.class)
|
||||
@SuiteClasses({
|
||||
WpiLibJTestSuite.class,
|
||||
CANTestSuite.class,
|
||||
CommandTestSuite.class,
|
||||
SmartDashboardTestSuite.class
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user