mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-28 02:11:43 +00:00
Initial checkin of unified hierarchy of WPILib 2015
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package Assemblies;
|
||||
|
||||
import edu.wpi.first.wpilibj.DigitalInput;
|
||||
import edu.wpi.first.wpilibj.DigitalOutput;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author brad
|
||||
*/
|
||||
public class DIOCrossConnect {
|
||||
|
||||
/**
|
||||
* Cross connected Digital I/O lines.
|
||||
* The A1, B1, C1, and D1 are digital module 1 and
|
||||
* A2, B2, C2, and D2 are digital module 2
|
||||
*/
|
||||
public static final int DIOCrossConnectA1 = 8;
|
||||
public static final int DIOCrossConnectA2 = 11;
|
||||
public static final int DIOCrossConnectB1 = 9;
|
||||
public static final int DIOCrossConnectB2 = 10;
|
||||
public static final int DIOCrossConnectC1 = 10;
|
||||
public static final int DIOCrossConnectC2 = 9;
|
||||
public static final int DIOCrossConnectD1 = 11;
|
||||
public static final int DIOCrossConnectD2 = 8;
|
||||
|
||||
public static DigitalOutput getOutputA() {
|
||||
return new DigitalOutput(DIOCrossConnectA1);
|
||||
}
|
||||
|
||||
public static DigitalInput getInputA() {
|
||||
return new DigitalInput(2, DIOCrossConnectA2);
|
||||
}
|
||||
|
||||
public static DigitalOutput getOutputB() {
|
||||
return new DigitalOutput(DIOCrossConnectB1);
|
||||
}
|
||||
|
||||
public static DigitalInput getInputB() {
|
||||
return new DigitalInput(2, DIOCrossConnectB2);
|
||||
}
|
||||
|
||||
public static DigitalOutput getOutputC() {
|
||||
return new DigitalOutput(DIOCrossConnectC1);
|
||||
}
|
||||
|
||||
public static DigitalInput getInputC() {
|
||||
return new DigitalInput(2, DIOCrossConnectC2);
|
||||
}
|
||||
|
||||
public static DigitalOutput getOutputD() {
|
||||
return new DigitalOutput(DIOCrossConnectD1);
|
||||
}
|
||||
|
||||
public static DigitalInput getInputD() {
|
||||
return new DigitalInput(2, DIOCrossConnectD2);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2008. 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 Assemblies;
|
||||
|
||||
import edu.wpi.first.wpilibj.DigitalOutput;
|
||||
import edu.wpi.first.wpilibj.Timer;
|
||||
|
||||
/**
|
||||
* @file FakeCounterSource.java
|
||||
* Simulates an encoder for testing purposes
|
||||
* @author Ryan O'Meara
|
||||
*/
|
||||
public class FakeCounterSource
|
||||
{
|
||||
|
||||
private Thread m_task;
|
||||
private int m_count;
|
||||
private int m_mSec;
|
||||
private DigitalOutput m_output;
|
||||
|
||||
/**
|
||||
* Thread object that allows emulation of an encoder
|
||||
*/
|
||||
private class EncoderThread extends Thread
|
||||
{
|
||||
|
||||
FakeCounterSource m_encoder;
|
||||
|
||||
EncoderThread(FakeCounterSource encode)
|
||||
{
|
||||
m_encoder = encode;
|
||||
}
|
||||
|
||||
public void run()
|
||||
{
|
||||
m_encoder.m_output.set(false);
|
||||
try
|
||||
{
|
||||
for (int i = 0; i < m_encoder.m_count; i++)
|
||||
{
|
||||
Thread.sleep(m_encoder.m_mSec);
|
||||
m_encoder.m_output.set(true);
|
||||
Thread.sleep(m_encoder.m_mSec);
|
||||
m_encoder.m_output.set(false);
|
||||
}
|
||||
} catch (InterruptedException e)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a fake encoder on a given port
|
||||
* @param port The port the encoder is supposed to be on
|
||||
*/
|
||||
public FakeCounterSource(int port)
|
||||
{
|
||||
m_output = new DigitalOutput(port);
|
||||
initEncoder();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new fake encoder on the indicated slot and port
|
||||
* @param slot Slot to create on
|
||||
* @param port THe port that the encoder is supposably on
|
||||
*/
|
||||
public FakeCounterSource(int slot, int port)
|
||||
{
|
||||
m_output = new DigitalOutput(slot, port);
|
||||
initEncoder();
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy Object with minimum memory leak
|
||||
*/
|
||||
public void free()
|
||||
{
|
||||
m_task = null;
|
||||
m_output.free();
|
||||
}
|
||||
|
||||
/**
|
||||
* Common initailization code
|
||||
*/
|
||||
private void initEncoder()
|
||||
{
|
||||
m_mSec = 1;
|
||||
m_task = new EncoderThread(this);
|
||||
m_output.set(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the thread execution task
|
||||
*/
|
||||
public void start()
|
||||
{
|
||||
m_task.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Waits for the thread to complete
|
||||
*/
|
||||
public void complete()
|
||||
{
|
||||
try
|
||||
{
|
||||
m_task.join();
|
||||
} catch (InterruptedException e)
|
||||
{
|
||||
}
|
||||
m_task = new EncoderThread(this);
|
||||
Timer.delay(.5);
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts and completes a task set - does not return until thred has finished
|
||||
* its operations
|
||||
*/
|
||||
public void execute()
|
||||
{
|
||||
start();
|
||||
complete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the count to run encoder
|
||||
* @param count The count to emulate to the controller
|
||||
*/
|
||||
public void setCount(int count)
|
||||
{
|
||||
m_count = count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify the rate to send pulses
|
||||
* @param mSec The rate to send out pulses at
|
||||
*/
|
||||
public void setRate(int mSec)
|
||||
{
|
||||
m_mSec = mSec;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,190 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2008. 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 Assemblies;
|
||||
|
||||
import edu.wpi.first.wpilibj.DigitalOutput;
|
||||
import edu.wpi.first.wpilibj.Timer;
|
||||
|
||||
/**
|
||||
* @file FakeEncoderSource.java
|
||||
* Emulates a quadrature encoder
|
||||
* @author Ryan O'Meara
|
||||
*/
|
||||
public class FakeEncoderSource
|
||||
{
|
||||
|
||||
private Thread m_task;
|
||||
private int m_count;
|
||||
private int m_mSec;
|
||||
private boolean m_forward;
|
||||
private DigitalOutput m_outputA, m_outputB;
|
||||
private boolean allocatedOutputs;
|
||||
|
||||
/**
|
||||
* Thread object that allows emulation of a quadrature encoder
|
||||
*/
|
||||
private class QuadEncoderThread extends Thread
|
||||
{
|
||||
|
||||
FakeEncoderSource m_encoder;
|
||||
|
||||
QuadEncoderThread(FakeEncoderSource encode)
|
||||
{
|
||||
m_encoder = encode;
|
||||
}
|
||||
|
||||
public void run()
|
||||
{
|
||||
|
||||
DigitalOutput lead, lag;
|
||||
|
||||
m_encoder.m_outputA.set(false);
|
||||
m_encoder.m_outputB.set(false);
|
||||
|
||||
if (m_encoder.isForward())
|
||||
{
|
||||
lead = m_encoder.m_outputA;
|
||||
lag = m_encoder.m_outputB;
|
||||
} else
|
||||
{
|
||||
lead = m_encoder.m_outputB;
|
||||
lag = m_encoder.m_outputA;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
for (int i = 0; i < m_encoder.m_count; i++)
|
||||
{
|
||||
lead.set(true);
|
||||
Thread.sleep(m_encoder.m_mSec);
|
||||
lag.set(true);
|
||||
Thread.sleep(m_encoder.m_mSec);
|
||||
lead.set(false);
|
||||
Thread.sleep(m_encoder.m_mSec);
|
||||
lag.set(false);
|
||||
Thread.sleep(m_encoder.m_mSec);
|
||||
}
|
||||
} catch (InterruptedException e)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public FakeEncoderSource(int slotA, int portA, int slotB, int portB)
|
||||
{
|
||||
m_outputA = new DigitalOutput(slotA, portA);
|
||||
m_outputB = new DigitalOutput(slotB, portB);
|
||||
allocatedOutputs = true;
|
||||
initQuadEncoder();
|
||||
}
|
||||
|
||||
public FakeEncoderSource(int portA, int portB)
|
||||
{
|
||||
m_outputA = new DigitalOutput(portA);
|
||||
m_outputB = new DigitalOutput(portB);
|
||||
allocatedOutputs = true;
|
||||
initQuadEncoder();
|
||||
}
|
||||
|
||||
public FakeEncoderSource(DigitalOutput iA, DigitalOutput iB)
|
||||
{
|
||||
m_outputA = iA;
|
||||
m_outputB = iB;
|
||||
allocatedOutputs = false;
|
||||
initQuadEncoder();
|
||||
}
|
||||
|
||||
public void free()
|
||||
{
|
||||
m_task = null;
|
||||
if (allocatedOutputs) {
|
||||
m_outputA.free();
|
||||
m_outputB.free();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Common initialization code
|
||||
*/
|
||||
private void initQuadEncoder()
|
||||
{
|
||||
m_mSec = 1;
|
||||
m_forward = true;
|
||||
m_task = new QuadEncoderThread(this);
|
||||
m_outputA.set(false);
|
||||
m_outputB.set(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the thread
|
||||
*/
|
||||
public void start()
|
||||
{
|
||||
m_task.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Waits for thread to end
|
||||
*/
|
||||
public void complete()
|
||||
{
|
||||
try
|
||||
{
|
||||
m_task.join();
|
||||
} catch (InterruptedException e)
|
||||
{
|
||||
}
|
||||
m_task = new QuadEncoderThread(this);
|
||||
Timer.delay(.5);
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs and waits for thread to end before returning
|
||||
*/
|
||||
public void execute()
|
||||
{
|
||||
start();
|
||||
complete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Rate of pulses to send
|
||||
* @param mSec Pulse Rate
|
||||
*/
|
||||
public void setRate(int mSec)
|
||||
{
|
||||
m_mSec = mSec;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the number of pulses to simulate
|
||||
* @param count Pulse count
|
||||
*/
|
||||
public void setCount(int count)
|
||||
{
|
||||
m_count = count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set which direction the encoder simulates motion in
|
||||
* @param isForward Whether to simulate forward motion
|
||||
*/
|
||||
public void setForward(boolean isForward)
|
||||
{
|
||||
m_forward = isForward;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accesses whether the encoder is simulating forward motion
|
||||
* @return Whether the simulated motion is in the forward direction
|
||||
*/
|
||||
public boolean isForward()
|
||||
{
|
||||
return m_forward;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package Assemblies;
|
||||
|
||||
import edu.wpi.first.wpilibj.AnalogChannel;
|
||||
import edu.wpi.first.wpilibj.Counter;
|
||||
import edu.wpi.first.wpilibj.DigitalOutput;
|
||||
import edu.wpi.first.wpilibj.Encoder;
|
||||
import edu.wpi.first.wpilibj.Jaguar;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author brad
|
||||
*/
|
||||
public class MagneticRotaryAssembly {
|
||||
|
||||
public static Jaguar getJaguar() {
|
||||
return new Jaguar(1, 6);
|
||||
}
|
||||
|
||||
public static DigitalOutput getLimitSWFwd() {
|
||||
return new DigitalOutput(2, 13);
|
||||
}
|
||||
|
||||
public static DigitalOutput getLimitSWRev() {
|
||||
return new DigitalOutput(2, 14);
|
||||
}
|
||||
|
||||
public static Counter getGTS() {
|
||||
return new Counter(1, 5);
|
||||
}
|
||||
|
||||
public static Encoder getEncoder() {
|
||||
return new Encoder(1, 6, 1, 7);
|
||||
}
|
||||
|
||||
public static Counter getHallEffect() {
|
||||
return new Counter(1, 1);
|
||||
}
|
||||
|
||||
public AnalogChannel getMagneticEncoder() {
|
||||
return new AnalogChannel(2, 6);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package Assemblies;
|
||||
|
||||
import edu.wpi.first.wpilibj.AnalogChannel;
|
||||
import edu.wpi.first.wpilibj.Counter;
|
||||
import edu.wpi.first.wpilibj.DigitalOutput;
|
||||
import edu.wpi.first.wpilibj.Jaguar;
|
||||
import edu.wpi.first.wpilibj.Victor;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Fred
|
||||
*/
|
||||
public class PotentiometerAssembly {
|
||||
|
||||
public static Jaguar getJaguar(){
|
||||
return new Jaguar(1,5);
|
||||
}
|
||||
|
||||
public static DigitalOutput getLimSWFwd(){
|
||||
return new DigitalOutput(1, 13);
|
||||
}
|
||||
|
||||
public static DigitalOutput getLimSWRev(){
|
||||
return new DigitalOutput(1, 14);
|
||||
}
|
||||
|
||||
public static Victor getVictor(){
|
||||
return new Victor(1, 2);
|
||||
}
|
||||
|
||||
public static AnalogChannel getPotentiometer(){
|
||||
return new AnalogChannel(1, 3);
|
||||
}
|
||||
|
||||
public static Counter getHallEffect(){
|
||||
return new Counter(1, 4);
|
||||
}
|
||||
|
||||
public static Counter getGearTooth(){
|
||||
return new Counter(2, 7);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package Assemblies;
|
||||
|
||||
import edu.wpi.first.testing.SlowServo;
|
||||
import edu.wpi.first.wpilibj.Gyro;
|
||||
import edu.wpi.first.wpilibj.Servo;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author mwills
|
||||
*/
|
||||
public class RCAssembly {
|
||||
|
||||
public static Servo getServo(){
|
||||
return new SlowServo(1, 1);
|
||||
}
|
||||
|
||||
public static Gyro getGyro(){
|
||||
return new Gyro(1, 1);
|
||||
}
|
||||
|
||||
/*public static SPIAccelerometer getAccelerometer(){
|
||||
return new SPIAccelerometer(2, 1, 2, 3, 4, 5, 6);
|
||||
}*/
|
||||
}
|
||||
Reference in New Issue
Block a user