Removed analog and digital module numbers

AnalogModule and DigitalModule classes still exist, at least until they are
refactored into the classes that use them.

Change-Id: I5544d5418822f19d54ba0a5d651e64fad8b7b10d
This commit is contained in:
thomasclark
2014-06-13 17:45:10 -04:00
parent aa3b24092a
commit 58021f7397
90 changed files with 852 additions and 1988 deletions

View File

@@ -74,11 +74,10 @@ public class ADXL345_I2C extends SensorBase {
/**
* Constructor.
*
* @param module The slot of the digital module that the sensor is plugged into.
* @param range The range (+ or -) that the accelerometer will measure.
*/
public ADXL345_I2C(int moduleNumber, DataFormat_Range range) {
DigitalModule module = DigitalModule.getInstance(moduleNumber);
public ADXL345_I2C(DataFormat_Range range) {
DigitalModule module = DigitalModule.getInstance(1);
m_i2c = module.getI2C(kAddress);
// Turn on the measurements
@@ -86,7 +85,7 @@ public class ADXL345_I2C extends SensorBase {
// Specify the data format to read
m_i2c.write(kDataFormatRegister, kDataFormat_FullRes | range.value);
UsageReporting.report(tResourceType.kResourceType_ADXL345, tInstances.kADXL345_I2C, moduleNumber-1);
UsageReporting.report(tResourceType.kResourceType_ADXL345, tInstances.kADXL345_I2C);
}
/**

View File

@@ -32,16 +32,15 @@ public class Accelerometer extends SensorBase implements PIDSource, ISensor, Liv
* Common initialization
*/
private void initAccelerometer() {
UsageReporting.report(tResourceType.kResourceType_Accelerometer, m_analogChannel.getChannel(), m_analogChannel.getModuleNumber()-1);
LiveWindow.addSensor("Accelerometer", m_analogChannel.getModuleNumber(), m_analogChannel.getChannel(), this);
UsageReporting.report(tResourceType.kResourceType_Accelerometer, m_analogChannel.getChannel());
LiveWindow.addSensor("Accelerometer", m_analogChannel.getChannel(), this);
}
/**
* Create a new instance of an accelerometer.
*
* The accelerometer is assumed to be in the first analog module in the given analog channel. The
* constructor allocates desired analog channel.
* @param channel the port that the accelerometer is on on the default module
* The constructor allocates desired analog channel.
* @param channel the port that the accelerometer is on
*/
public Accelerometer(final int channel) {
m_allocatedChannel = true;
@@ -49,20 +48,6 @@ public class Accelerometer extends SensorBase implements PIDSource, ISensor, Liv
initAccelerometer();
}
/**
* Create new instance of accelerometer.
*
* Make a new instance of the accelerometer given a module and channel. The constructor allocates
* the desired analog channel from the specified module
* @param slot the slot that the module is in
* @param channel the port that the Accelerometer is on on the module
*/
public Accelerometer(final int slot, final int channel) {
m_allocatedChannel = true;
m_analogChannel = new AnalogInput(slot, channel);
initAccelerometer();
}
/**
* Create a new instance of Accelerometer from an existing AnalogChannel.
* Make a new instance of accelerometer given an AnalogChannel. This is particularly

View File

@@ -43,53 +43,33 @@ public class AnalogInput extends SensorBase implements PIDSource,
LiveWindowSendable {
private static final int kAccumulatorSlot = 1;
private static Resource channels = new Resource(kAnalogModules
* kAnalogInputChannels);
private static Resource channels = new Resource(kAnalogInputChannels);
private ByteBuffer m_port;
private int m_moduleNumber, m_channel;
private int m_channel;
private static final int[] kAccumulatorChannels = { 0, 1 };
private long m_accumulatorOffset;
/**
* Construct an analog channel on the default module.
* Construct an analog channel.
*
* @param channel
* The channel number to represent.
*/
public AnalogInput(final int channel) {
this(getDefaultAnalogModule(), channel);
}
/**
* Construct an analog channel on a specified module.
*
* @param moduleNumber
* The digital module to use (1 or 2).
* @param channel
* The channel number to represent.
*/
public AnalogInput(final int moduleNumber, final int channel) {
m_channel = channel;
m_moduleNumber = moduleNumber;
if (AnalogJNI.checkAnalogModule((byte)moduleNumber) == 0) {
throw new AllocationException("Analog input channel " + m_channel
+ " on module " + m_moduleNumber
+ " cannot be allocated. Module is not present.");
}
if (AnalogJNI.checkAnalogInputChannel(channel) == 0) {
throw new AllocationException("Analog input channel " + m_channel
+ " on module " + m_moduleNumber
+ " cannot be allocated. Channel is not present.");
}
try {
channels.allocate((moduleNumber - 1) * kAnalogInputChannels + channel);
channels.allocate(channel);
} catch (CheckedAllocationException e) {
throw new AllocationException("Analog input channel " + m_channel
+ " on module " + m_moduleNumber + " is already allocated");
+ " is already allocated");
}
ByteBuffer port_pointer = AnalogJNI.getPortWithModule(
(byte) moduleNumber, (byte) channel);
ByteBuffer port_pointer = AnalogJNI.getPortWithModule((byte) 1, (byte) channel);
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
@@ -97,28 +77,26 @@ public class AnalogInput extends SensorBase implements PIDSource,
m_port = AnalogJNI.initializeAnalogInputPort(port_pointer, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
LiveWindow.addSensor("AnalogInput", moduleNumber, channel, this);
UsageReporting.report(tResourceType.kResourceType_AnalogChannel,
channel, moduleNumber - 1);
LiveWindow.addSensor("AnalogInput", channel, this);
UsageReporting.report(tResourceType.kResourceType_AnalogChannel, channel);
}
/**
* Channel destructor.
*/
public void free() {
channels.free(((m_moduleNumber - 1) * kAnalogInputChannels + m_channel));
channels.free(m_channel);
m_channel = 0;
m_moduleNumber = 0;
m_accumulatorOffset = 0;
}
/**
* Get the analog module that this channel is on.
* Get the analog module.
*
* @return The AnalogModule that this channel is on.
* @return The AnalogModule.
*/
public AnalogModule getModule() {
return AnalogModule.getInstance(m_moduleNumber);
return AnalogModule.getInstance(1);
}
/**
@@ -239,15 +217,6 @@ public class AnalogInput extends SensorBase implements PIDSource,
return m_channel;
}
/**
* Gets the number of the analog module this channel is on.
*
* @return The module number of the analog module this channel is on.
*/
public int getModuleNumber() {
return m_moduleNumber;
}
/**
* Set the number of averaging bits. This sets the number of averaging bits.
* The actual number of averaged samples is 2**bits. The averaging is done
@@ -435,7 +404,6 @@ public class AnalogInput extends SensorBase implements PIDSource,
}
if (!isAccumulatorChannel()) {
throw new IllegalArgumentException("Channel " + m_channel
+ " on module " + m_moduleNumber
+ " is not an accumulator channel.");
}
ByteBuffer value = ByteBuffer.allocateDirect(8);
@@ -459,9 +427,6 @@ public class AnalogInput extends SensorBase implements PIDSource,
* @return The analog channel is attached to an accumulator.
*/
public boolean isAccumulatorChannel() {
if (m_moduleNumber != kAccumulatorSlot) {
return false;
}
for (int i = 0; i < kAccumulatorChannels.length; i++) {
if (m_channel == kAccumulatorChannels[i]) {
return true;

View File

@@ -59,7 +59,7 @@ public class AnalogOutput extends SensorBase implements LiveWindowSendable {
m_port = AnalogJNI.initializeAnalogOutputPort(port_pointer, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
LiveWindow.addSensor("AnalogOutput", 1, channel, this);
LiveWindow.addSensor("AnalogOutput", channel, this);
UsageReporting.report(tResourceType.kResourceType_AnalogChannel, channel, 1);
}

View File

@@ -12,40 +12,20 @@ import edu.wpi.first.wpilibj.tables.ITable;
* @author Alex Henning
*/
public class AnalogPotentiometer implements Potentiometer, LiveWindowSendable {
private int m_module, m_channel;
private int m_channel;
private double m_scale, m_offset;
private AnalogInput m_analog_input;
/**
* Common initialization code called by all constructors.
*/
private void initPot(final int slot, final int channel, double scale, double offset) {
this.m_module = slot;
private void initPot(final int channel, double scale, double offset) {
this.m_channel = channel;
this.m_scale = scale;
this.m_offset = offset;
m_analog_input = new AnalogInput(slot, channel);
m_analog_input = new AnalogInput(channel);
}
/**
* AnalogPotentiometer constructor.
*
* Use the scaling and offset values so that the output produces
* meaningful values. I.E: you have a 270 degree potentiometer and
* you want the output to be degrees with the halfway point as 0
* degrees. The scale value is 270.0(degrees)/5.0(volts) and the
* offset is -135.0 since the halfway point after scaling is 135
* degrees.
*
* @param slot The analog module this potentiometer is plugged into.
* @param channel The analog channel this potentiometer is plugged into.
* @param scale The scaling to multiply the voltage by to get a meaningful unit.
* @param offset The offset to add to the scaled value for controlling the zero value
*/
public AnalogPotentiometer(final int slot, final int channel, double scale, double offset) {
initPot(slot, channel, scale, offset);
}
/**
* AnalogPotentiometer constructor.
*
@@ -61,9 +41,9 @@ public class AnalogPotentiometer implements Potentiometer, LiveWindowSendable {
* @param offset The offset to add to the scaled value for controlling the zero value
*/
public AnalogPotentiometer(final int channel, double scale, double offset) {
initPot(1, channel, scale, offset);
initPot(channel, scale, offset);
}
/**
* AnalogPotentiometer constructor.
*
@@ -78,18 +58,18 @@ public class AnalogPotentiometer implements Potentiometer, LiveWindowSendable {
* @param scale The scaling to multiply the voltage by to get a meaningful unit.
*/
public AnalogPotentiometer(final int channel, double scale) {
initPot(1, channel, scale, 0);
initPot(channel, scale, 0);
}
/**
* AnalogPotentiometer constructor.
*
* @param channel The analog channel this potentiometer is plugged into.
*/
public AnalogPotentiometer(final int channel) {
initPot(1, channel, 1, 0);
initPot(channel, 1, 0);
}
/**
* Get the current reading of the potentiomere.
*
@@ -98,8 +78,8 @@ public class AnalogPotentiometer implements Potentiometer, LiveWindowSendable {
public double get() {
return m_analog_input.getVoltage() * m_scale + m_offset;
}
/**
* Implement the PIDSource interface.
*
@@ -108,7 +88,7 @@ public class AnalogPotentiometer implements Potentiometer, LiveWindowSendable {
public double pidGet() {
return get();
}
/*
* Live Window code, only does anything if live window is activated.
*/
@@ -116,7 +96,7 @@ public class AnalogPotentiometer implements Potentiometer, LiveWindowSendable {
return "Analog Input";
}
private ITable m_table;
/**
* {@inheritDoc}
*/
@@ -124,7 +104,7 @@ public class AnalogPotentiometer implements Potentiometer, LiveWindowSendable {
m_table = subtable;
updateTable();
}
/**
* {@inheritDoc}
*/
@@ -133,20 +113,20 @@ public class AnalogPotentiometer implements Potentiometer, LiveWindowSendable {
m_table.putNumber("Value", get());
}
}
/**
* {@inheritDoc}
*/
public ITable getTable(){
return m_table;
}
/**
* Analog Channels don't have to do anything special when entering the LiveWindow.
* {@inheritDoc}
*/
public void startLiveWindowMode() {}
/**
* Analog Channels don't have to do anything special when exiting the LiveWindow.
* {@inheritDoc}

View File

@@ -21,7 +21,7 @@ import edu.wpi.first.wpilibj.util.BoundaryException;
/**
* Class for creating and configuring Analog Triggers
*
*
* @author dtjones
*/
public class AnalogTrigger implements IInputOutput {
@@ -33,7 +33,7 @@ public class AnalogTrigger implements IInputOutput {
/**
* Create a new exception with the given message
*
*
* @param message
* the message to pass with the exception
*/
@@ -50,18 +50,13 @@ public class AnalogTrigger implements IInputOutput {
protected int m_index;
/**
* Initialize an analog trigger from a module number and channel. This is
* the common code for the two constructors that use a module number and
* channel.
*
* @param moduleNumber
* The number of the analog module to create this trigger on.
* Initialize an analog trigger from a channel.
*
* @param channel
* the port to use for the analog trigger
*/
protected void initTrigger(final int moduleNumber, final int channel) {
ByteBuffer port_pointer = AnalogJNI.getPortWithModule(
(byte) moduleNumber, (byte) channel);
protected void initTrigger(final int channel) {
ByteBuffer port_pointer = AnalogJNI.getPortWithModule((byte) 1, (byte) channel);
IntBuffer status = IntBuffer.allocate(1);
IntBuffer index = IntBuffer.allocate(1);
// XXX: Uncomment when analog has been fixed
@@ -70,44 +65,29 @@ public class AnalogTrigger implements IInputOutput {
//HALUtil.checkStatus(status);
//m_index = index.get(0);
UsageReporting.report(tResourceType.kResourceType_AnalogTrigger,
channel, moduleNumber-1);
UsageReporting.report(tResourceType.kResourceType_AnalogTrigger, channel);
}
/**
* Constructor for an analog trigger given a channel number. The default
* module is used in this case.
*
* Constructor for an analog trigger given a channel number.
*
* @param channel
* the port to use for the analog trigger
*/
public AnalogTrigger(final int channel) {
initTrigger(AnalogModule.getDefaultAnalogModule(), channel);
}
/**
* Constructor for an analog trigger given both the module number and
* channel.
*
* @param moduleNumber
* The number of the analog module to create this trigger on.
* @param channel
* the port to use for the analog trigger
*/
public AnalogTrigger(final int moduleNumber, final int channel) {
initTrigger(moduleNumber, channel);
initTrigger(channel);
}
/**
* Construct an analog trigger given an analog channel. This should be used
* in the case of sharing an analog channel between the trigger and an
* analog input object.
*
*
* @param channel
* the AnalogChannel to use for the analog trigger
* the AnalogInput to use for the analog trigger
*/
public AnalogTrigger(AnalogInput channel) {
initTrigger(channel.getModuleNumber(), channel.getChannel());
initTrigger(channel.getChannel());
}
/**
@@ -124,7 +104,7 @@ public class AnalogTrigger implements IInputOutput {
* Set the upper and lower limits of the analog trigger. The limits are
* given in ADC codes. If oversampling is used, the units must be scaled
* appropriately.
*
*
* @param lower
* the lower raw limit
* @param upper
@@ -142,7 +122,7 @@ public class AnalogTrigger implements IInputOutput {
/**
* Set the upper and lower limits of the analog trigger. The limits are
* given as floating point voltage values.
*
*
* @param lower
* the lower voltage limit
* @param upper
@@ -165,7 +145,7 @@ public class AnalogTrigger implements IInputOutput {
* Configure the analog trigger to use the averaged vs. raw values. If the
* value is true, then the averaged value is selected for the analog
* trigger, otherwise the immediate value is used.
*
*
* @param useAveragedValue
* true to use an averaged value, false otherwise
*/
@@ -181,7 +161,7 @@ public class AnalogTrigger implements IInputOutput {
* will operate with a 3 point average rejection filter. This is designed to
* help with 360 degree pot applications for the period where the pot
* crosses through zero.
*
*
* @param useFilteredValue
* true to use a filterd value, false otherwise
*/
@@ -195,7 +175,7 @@ public class AnalogTrigger implements IInputOutput {
/**
* Return the index of the analog trigger. This is the FPGA index of this
* analog trigger instance.
*
*
* @return The index of the analog trigger.
*/
public int getIndex() {
@@ -205,7 +185,7 @@ public class AnalogTrigger implements IInputOutput {
/**
* Return the InWindow output of the analog trigger. True if the analog
* input is between the upper and lower limits.
*
*
* @return The InWindow output of the analog trigger.
*/
public boolean getInWindow() {
@@ -219,7 +199,7 @@ public class AnalogTrigger implements IInputOutput {
* Return the TriggerState output of the analog trigger. True if above upper
* limit. False if below lower limit. If in Hysteresis, maintain previous
* state.
*
*
* @return The TriggerState output of the analog trigger.
*/
public boolean getTriggerState() {
@@ -233,7 +213,7 @@ public class AnalogTrigger implements IInputOutput {
* Creates an AnalogTriggerOutput object. Gets an output object that can be
* used for routing. Caller is responsible for deleting the
* AnalogTriggerOutput object.
*
*
* @param type
* An enum of the type of output object to create.
* @return A pointer to a new AnalogTriggerOutput object.

View File

@@ -12,74 +12,74 @@ import edu.wpi.first.wpilibj.tables.ITable;
public class Compressor extends SensorBase implements IDevice, LiveWindowSendable {
private ByteBuffer m_pcm;
public Compressor(int module) {
initCompressor(module);
public Compressor(int pcmId) {
initCompressor(pcmId);
}
public Compressor() {
initCompressor(getDefaultSolenoidModule());
}
private void initCompressor(int module) {
m_table = null;
m_pcm = CompressorJNI.initializeCompressor((byte)module);
}
public void start() {
setClosedLoopControl(true);
}
public void stop() {
setClosedLoopControl(false);
}
public boolean enabled() {
ByteBuffer status = ByteBuffer.allocateDirect(4);
status.order(ByteOrder.LITTLE_ENDIAN);
boolean on = CompressorJNI.getCompressor(m_pcm, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
return on;
}
public boolean getPressureSwitchValue() {
ByteBuffer status = ByteBuffer.allocateDirect(4);
status.order(ByteOrder.LITTLE_ENDIAN);
boolean on = CompressorJNI.getPressureSwitch(m_pcm, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
return on;
}
public float getCompressorCurrent() {
ByteBuffer status = ByteBuffer.allocateDirect(4);
status.order(ByteOrder.LITTLE_ENDIAN);
float current = CompressorJNI.getCompressorCurrent(m_pcm, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
return current;
}
public void setClosedLoopControl(boolean on) {
ByteBuffer status = ByteBuffer.allocateDirect(4);
status.order(ByteOrder.LITTLE_ENDIAN);
CompressorJNI.setClosedLoopControl(m_pcm, on, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
}
public boolean getClosedLoopControl() {
ByteBuffer status = ByteBuffer.allocateDirect(4);
status.order(ByteOrder.LITTLE_ENDIAN);
boolean on = CompressorJNI.getClosedLoopControl(m_pcm, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
return on;
}
@@ -90,7 +90,7 @@ public class Compressor extends SensorBase implements IDevice, LiveWindowSendabl
@Override
public void stopLiveWindowMode() {
}
@Override
public String getSmartDashboardType() {
return "Compressor";
@@ -103,7 +103,7 @@ public class Compressor extends SensorBase implements IDevice, LiveWindowSendabl
m_table = subtable;
updateTable();
}
@Override
public ITable getTable() {
return m_table;

View File

@@ -106,7 +106,7 @@ public class Counter extends SensorBase implements CounterBase,
* Create an instance of a counter from a Digital Input. This is used if an
* existing digital input is to be shared by multiple other objects such as
* encoders.
*
*
* @param source
* the digital source to count
*/
@@ -119,8 +119,8 @@ public class Counter extends SensorBase implements CounterBase,
/**
* Create an instance of a Counter object. Create an up-Counter instance
* given a channel. The default digital module is assumed.
*
* given a channel.
*
* @param channel
* the digital input channel to count
*/
@@ -129,25 +129,11 @@ public class Counter extends SensorBase implements CounterBase,
setUpSource(channel);
}
/**
* Create an instance of a Counter object. Create an instance of an
* up-Counter given a digital module and a channel.
*
* @param slot
* The cRIO chassis slot for the digital module used
* @param channel
* The channel in the digital module
*/
public Counter(int slot, int channel) {
initCounter(Mode.kTwoPulse);
setUpSource(slot, channel);
}
/**
* Create an instance of a Counter object. Create an instance of a simple
* up-Counter given an analog trigger. Use the trigger state output from the
* analog trigger.
*
*
* @param encodingType
* which edges to count
* @param upSource
@@ -188,7 +174,7 @@ public class Counter extends SensorBase implements CounterBase,
* Create an instance of a Counter object. Create an instance of a simple
* up-Counter given an analog trigger. Use the trigger state output from the
* analog trigger.
*
*
* @param trigger
* the analog trigger to count
*/
@@ -214,22 +200,8 @@ public class Counter extends SensorBase implements CounterBase,
}
/**
* Set the up source for the counter as digital input channel and slot.
*
* @param slot
* the location of the digital module to use
* @param channel
* the digital port to count
*/
public void setUpSource(int slot, int channel) {
setUpSource(new DigitalInput(slot, channel));
m_allocatedUpSource = true;
}
/**
* Set the upsource for the counter as a digital input channel. The slot
* will be the default digital module slot.
*
* Set the upsource for the counter as a digital input channel.
*
* @param channel
* the digital port to count
*/
@@ -241,7 +213,7 @@ public class Counter extends SensorBase implements CounterBase,
/**
* Set the source object that causes the counter to count up. Set the up
* counting DigitalSource.
*
*
* @param source
* the digital source to count
*/
@@ -262,7 +234,7 @@ public class Counter extends SensorBase implements CounterBase,
/**
* Set the up counting source to be an analog trigger.
*
*
* @param analogTrigger
* The analog trigger object that is used for the Up Source
* @param triggerType
@@ -276,7 +248,7 @@ public class Counter extends SensorBase implements CounterBase,
/**
* Set the edge sensitivity on an up counting source. Set the up source to
* either detect rising edges or falling edges.
*
*
* @param risingEdge
* true to count rising edge
* @param fallingEdge
@@ -311,9 +283,8 @@ public class Counter extends SensorBase implements CounterBase,
}
/**
* Set the down counting source to be a digital input channel. The slot will
* be set to the default digital module slot.
*
* Set the down counting source to be a digital input channel.
*
* @param channel
* the digital port to count
*/
@@ -322,23 +293,10 @@ public class Counter extends SensorBase implements CounterBase,
m_allocatedDownSource = true;
}
/**
* Set the down counting source to be a digital input slot and channel.
*
* @param slot
* the location of the digital module to use
* @param channel
* the digital port to count
*/
public void setDownSource(int slot, int channel) {
setDownSource(new DigitalInput(slot, channel));
m_allocatedDownSource = true;
}
/**
* Set the source object that causes the counter to count down. Set the down
* counting DigitalSource.
*
*
* @param source
* the digital source to count
*/
@@ -363,7 +321,7 @@ public class Counter extends SensorBase implements CounterBase,
/**
* Set the down counting source to be an analog trigger.
*
*
* @param analogTrigger
* The analog trigger object that is used for the Down Source
* @param triggerType
@@ -377,7 +335,7 @@ public class Counter extends SensorBase implements CounterBase,
/**
* Set the edge sensitivity on a down counting source. Set the down source
* to either detect rising edges or falling edges.
*
*
* @param risingEdge
* true to count the rising edge
* @param fallingEdge
@@ -435,7 +393,7 @@ public class Counter extends SensorBase implements CounterBase,
/**
* Set Semi-period mode on this counter. Counts up on both rising and
* falling edges.
*
*
* @param highSemiPeriod
* true to count up on both rising and falling
*/
@@ -451,7 +409,7 @@ public class Counter extends SensorBase implements CounterBase,
* Configure the counter to count in up or down based on the length of the
* input pulse. This mode is most useful for direction sensitive gear tooth
* sensors.
*
*
* @param threshold
* The pulse length beyond which the counter counts the opposite
* direction. Units are seconds.
@@ -492,7 +450,7 @@ public class Counter extends SensorBase implements CounterBase,
/**
* Read the current scaled counter value. Read the value at this instant,
* scaled by the distance per pulse (defaults to 1).
*
*
* @return
*/
public double getDistance() {
@@ -527,7 +485,7 @@ public class Counter extends SensorBase implements CounterBase,
* Sets the maximum period where the device is considered moving. This value
* is used to determine the "stopped" state of the counter using the
* GetStopped method.
*
*
* @param maxPeriod
* The maximum period where the counted device is considered
* moving in seconds.
@@ -552,7 +510,7 @@ public class Counter extends SensorBase implements CounterBase,
* been no events since an FPGA reset) and you will likely not see the
* stopped bit become true (since it is updated at the end of an average and
* there are no samples to average).
*
*
* @param enabled
* true to continue updating
*/
@@ -569,7 +527,7 @@ public class Counter extends SensorBase implements CounterBase,
* stopped based on the MaxPeriod value set using the SetMaxPeriod method.
* If the clock exceeds the MaxPeriod, then the device (and counter) are
* assumed to be stopped and it returns true.
*
*
* @return Returns true if the most recent counter period exceeds the
* MaxPeriod value set by SetMaxPeriod.
*/
@@ -583,7 +541,7 @@ public class Counter extends SensorBase implements CounterBase,
/**
* The last direction the counter value changed.
*
*
* @return The last direction the counter value changed.
*/
public boolean getDirection() {
@@ -598,7 +556,7 @@ public class Counter extends SensorBase implements CounterBase,
* Set the Counter to return reversed sensing on the direction. This allows
* counters to change the direction they are counting in the case of 1X and
* 2X quadrature encoding only. Any other counter mode isn't supported.
*
*
* @param reverseDirection
* true if the value counted should be negated.
*/
@@ -614,7 +572,7 @@ public class Counter extends SensorBase implements CounterBase,
* Get the Period of the most recent count. Returns the time interval of the
* most recent count. This can be used for velocity calculations to
* determine shaft speed.
*
*
* @returns The period of the last two pulses in units of seconds.
*/
public double getPeriod() {
@@ -629,7 +587,7 @@ public class Counter extends SensorBase implements CounterBase,
* Get the current rate of the Counter. Read the current rate of the counter
* accounting for the distance per pulse value. The default value for
* distance per pulse (1) yields units of pulses per second.
*
*
* @return The rate in units/sec
*/
public double getRate() {
@@ -641,7 +599,7 @@ public class Counter extends SensorBase implements CounterBase,
* timer to average when calculating the period. Perform averaging to
* account for mechanical imperfections or as oversampling to increase
* resolution.
*
*
* @param samplesToAverage
* The number of samples to average from 1 to 127.
*/
@@ -662,7 +620,7 @@ public class Counter extends SensorBase implements CounterBase,
* timer to average when calculating the period. Perform averaging to
* account for mechanical imperfections or as oversampling to increase
* resolution.
*
*
* @return SamplesToAverage The number of samples being averaged (from 1 to
* 127)
*/
@@ -680,7 +638,7 @@ public class Counter extends SensorBase implements CounterBase,
* encoder. Set this value based on the Pulses per Revolution and factor in
* any gearing reductions. This distance can be in any units you like,
* linear or angular.
*
*
* @param distancePerPulse
* The scale factor that will be used to convert pulses to useful
* units.
@@ -692,7 +650,7 @@ public class Counter extends SensorBase implements CounterBase,
/**
* Set which parameter of the encoder you are using as a process control
* variable. The counter class supports the rate and distance parameters.
*
*
* @param pidSource
* An enum to select the parameter.
*/

View File

@@ -34,35 +34,21 @@ public class DigitalInput extends DigitalSource implements IInputOutput,
/**
* Create an instance of a Digital Input class. Creates a digital input
* given a channel and uses the default module.
*
* given a channel.
*
* @param channel
* the port for the digital input
*/
public DigitalInput(int channel) {
this(getDefaultDigitalModule(), channel);
}
initDigitalPort(channel, true);
/**
* Create an instance of a Digital Input class. Creates a digital input
* given an channel and module.
*
* @param moduleNumber
* The number of the digital module to use for this input
* @param channel
* the port for the digital input
*/
public DigitalInput(int moduleNumber, int channel) {
initDigitalPort(moduleNumber, channel, true);
UsageReporting.report(tResourceType.kResourceType_DigitalInput,
channel, moduleNumber - 1);
UsageReporting.report(tResourceType.kResourceType_DigitalInput, channel);
}
/**
* Get the value from a digital input channel. Retrieve the value of a
* single digital input channel from the FPGA.
*
*
* @return the stats of the digital input
*/
public boolean get() {
@@ -76,7 +62,7 @@ public class DigitalInput extends DigitalSource implements IInputOutput,
/**
* Get the channel of the digital input
*
*
* @return The GPIO channel number that this object represents.
*/
public int getChannel() {
@@ -89,7 +75,7 @@ public class DigitalInput extends DigitalSource implements IInputOutput,
/**
* Request interrupts asynchronously on this digital input.
*
*
* @param handler
* The address of the interrupt handler function of type
* tInterruptHandler that will be called whenever there is an
@@ -150,7 +136,7 @@ public class DigitalInput extends DigitalSource implements IInputOutput,
/**
* Set which edge to trigger interrupts on
*
*
* @param risingEdge
* true to interrupt on rising edge
* @param fallingEdge

View File

@@ -36,29 +36,15 @@ public class DigitalOutput extends DigitalSource implements IInputOutput,
/**
* Create an instance of a digital output. Create an instance of a digital
* output given a module number and channel.
*
* @param moduleNumber
* The number of the digital module to use
* @param channel
* the port to use for the digital output
*/
public DigitalOutput(int moduleNumber, int channel) {
initDigitalPort(moduleNumber, channel, false);
UsageReporting.report(tResourceType.kResourceType_DigitalOutput,
channel, moduleNumber - 1);
}
/**
* Create an instance of a digital output. Create a digital output given a
* channel. The default module is used.
*
* output given a channel.
*
* @param channel
* the port to use for the digital output
*/
public DigitalOutput(int channel) {
this(getDefaultDigitalModule(), channel);
initDigitalPort(channel, false);
UsageReporting.report(tResourceType.kResourceType_DigitalOutput, channel);
}
/**
@@ -74,7 +60,7 @@ public class DigitalOutput extends DigitalSource implements IInputOutput,
/**
* Set the value of a digital output.
*
*
* @param value
* true is on, off is false
*/
@@ -96,7 +82,7 @@ public class DigitalOutput extends DigitalSource implements IInputOutput,
/**
* Generate a single pulse. Write a pulse to the specified digital output
* channel. There can only be a single pulse going at any time.
*
*
* @param channel
* The channel to pulse.
* @param pulseLength
@@ -114,7 +100,7 @@ public class DigitalOutput extends DigitalSource implements IInputOutput,
* @deprecated Generate a single pulse. Write a pulse to the specified
* digital output channel. There can only be a single pulse
* going at any time.
*
*
* @param channel
* The channel to pulse.
* @param pulseLength
@@ -134,7 +120,7 @@ public class DigitalOutput extends DigitalSource implements IInputOutput,
/**
* Determine if the pulse is still going. Determine if a previously started
* pulse is still going.
*
*
* @return true if pulsing
*/
public boolean isPulsing() {
@@ -148,12 +134,12 @@ public class DigitalOutput extends DigitalSource implements IInputOutput,
/**
* Change the PWM frequency of the PWM output on a Digital Output line.
*
*
* The valid range is from 0.6 Hz to 19 kHz. The frequency resolution is
* logarithmic.
*
*
* There is only one PWM frequency per digital module.
*
*
* @param rate
* The frequency to output all digital output PWM signals on this
* module.
@@ -162,22 +148,22 @@ public class DigitalOutput extends DigitalSource implements IInputOutput,
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
PWMJNI.setPWMRateWithModule((byte) m_moduleNumber, rate,
PWMJNI.setPWMRateWithModule((byte) 1, rate,
status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
}
/**
* Enable a PWM Output on this line.
*
*
* Allocate one of the 4 DO PWM generator resources from this module.
*
*
* Supply the initial duty-cycle to output so as to avoid a glitch when
* first starting.
*
*
* The resolution of the duty cycle is 8-bit for low frequencies (1kHz or
* less) but is reduced the higher the frequency of the PWM signal is.
*
*
* @param initialDutyCycle
* The duty-cycle to start generating. [0..1]
*/
@@ -187,19 +173,17 @@ public class DigitalOutput extends DigitalSource implements IInputOutput,
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
m_pwmGenerator = PWMJNI.allocatePWMWithModule(
(byte) m_moduleNumber, status.asIntBuffer());
m_pwmGenerator = PWMJNI.allocatePWMWithModule((byte) 1, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
PWMJNI.setPWMDutyCycle(m_pwmGenerator, initialDutyCycle,
status.asIntBuffer());
status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
PWMJNI.setPWMOutputChannelWithModule((byte) m_moduleNumber,
m_pwmGenerator, m_channel, status.asIntBuffer());
PWMJNI.setPWMOutputChannelWithModule((byte) 1, m_pwmGenerator, m_channel, status.asIntBuffer());
}
/**
* Change this line from a PWM output back to a static Digital Output line.
*
*
* Free up one of the 4 DO PWM generator resources that were in use.
*/
public void disablePWM() {
@@ -209,17 +193,16 @@ public class DigitalOutput extends DigitalSource implements IInputOutput,
status.order(ByteOrder.LITTLE_ENDIAN);
PWMJNI.setPWMOutputChannel(m_pwmGenerator, kDigitalChannels, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
PWMJNI.freePWMWithModule((byte) m_moduleNumber, m_pwmGenerator,
status.asIntBuffer());
PWMJNI.freePWMWithModule((byte) 1, m_pwmGenerator, status.asIntBuffer());
m_pwmGenerator = null;
}
/**
* Change the duty-cycle that is being generated on the line.
*
*
* The resolution of the duty cycle is 8-bit for low frequencies (1kHz or
* less) but is reduced the higher the frequency of the PWM signal is.
*
*
* @param dutyCycle
* The duty-cycle to change to. [0..1]
*/
@@ -227,8 +210,7 @@ public class DigitalOutput extends DigitalSource implements IInputOutput,
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
PWMJNI.setPWMDutyCycleWithModule((byte) m_moduleNumber,
m_pwmGenerator, dutyCycle, status.asIntBuffer());
PWMJNI.setPWMDutyCycleWithModule((byte) 1, m_pwmGenerator, dutyCycle, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
}

View File

@@ -25,34 +25,26 @@ import edu.wpi.first.wpilibj.util.CheckedAllocationException;
*/
public abstract class DigitalSource extends InterruptableSensorBase {
protected static Resource channels = new Resource(kDigitalChannels
* kDigitalModules);
protected static Resource channels = new Resource(kDigitalChannels);
protected ByteBuffer m_port;
protected int m_moduleNumber, m_channel;
protected int m_channel;
protected void initDigitalPort(int moduleNumber, int channel, boolean input) {
protected void initDigitalPort(int channel, boolean input) {
m_channel = channel;
m_moduleNumber = moduleNumber;
if (DIOJNI.checkDigitalModule((byte) m_moduleNumber) != 1) {
throw new AllocationException("Digital input " + m_channel
+ " on module " + m_moduleNumber
+ " cannot be allocated. Module is not present.");
}
checkDigitalChannel(m_channel); // XXX: Replace with
// HALLibrary.checkDigitalChannel when
// implemented
try {
channels.allocate((m_moduleNumber - 1) * kDigitalChannels
+ m_channel);
channels.allocate(m_channel);
} catch (CheckedAllocationException ex) {
throw new AllocationException("Digital input " + m_channel
+ " on module " + m_moduleNumber + " is already allocated");
+ " is already allocated");
}
ByteBuffer port_pointer = DIOJNI.getPortWithModule(
(byte) moduleNumber, (byte) channel);
ByteBuffer port_pointer = DIOJNI.getPortWithModule((byte) 1, (byte) channel);
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
@@ -63,19 +55,18 @@ public abstract class DigitalSource extends InterruptableSensorBase {
}
public void free() {
channels.free(((m_moduleNumber - 1) * kDigitalChannels + m_channel));
channels.free(m_channel);
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
DIOJNI.freeDIO(m_port, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
m_channel = 0;
m_moduleNumber = 0;
}
/**
* Get the channel routing number
*
*
* @return channel routing number
*/
public int getChannelForRouting() {
@@ -84,16 +75,16 @@ public abstract class DigitalSource extends InterruptableSensorBase {
/**
* Get the module routing number
*
* @return module routing number
*
* @return 0
*/
public int getModuleForRouting() {
return m_moduleNumber - 1;
return 0;
}
/**
* Is this an analog trigger
*
*
* @return true if this is an analog trigger
*/
public boolean getAnalogTriggerForRouting() {

View File

@@ -103,152 +103,11 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource,
UsageReporting.report(tResourceType.kResourceType_Encoder,
m_index, m_encodingType.value);
LiveWindow.addSensor("Encoder", m_aSource.getModuleForRouting(),
m_aSource.getChannelForRouting(), this);
LiveWindow.addSensor("Encoder", m_aSource.getChannelForRouting(), this);
}
/**
* Encoder constructor. Construct a Encoder given a and b modules and
* channels fully specified.
*
* @param aSlot
* The a channel digital input module.
* @param aChannel
* The a channel digital input channel.
* @param bSlot
* The b channel digital input module.
* @param bChannel
* The b channel digital input channel.
* @param reverseDirection
* represents the orientation of the encoder and inverts the
* output values if necessary so forward represents positive
* values.
*/
public Encoder(final int aSlot, final int aChannel, final int bSlot,
final int bChannel, boolean reverseDirection) {
m_allocatedA = true;
m_allocatedB = true;
m_allocatedI = false;
m_aSource = new DigitalInput(aSlot, aChannel);
m_bSource = new DigitalInput(bSlot, bChannel);
initEncoder(reverseDirection);
}
/**
* Encoder constructor. Construct a Encoder given a and b modules and
* channels fully specified.
*
* @param aSlot
* The a channel digital input module.
* @param aChannel
* The a channel digital input channel.
* @param bSlot
* The b channel digital input module.
* @param bChannel
* The b channel digital input channel.
*/
public Encoder(final int aSlot, final int aChannel, final int bSlot,
final int bChannel) {
this(aSlot, aChannel, bSlot, bChannel, false);
}
/**
* Encoder constructor. Construct a Encoder given a and b modules and
* channels fully specified.
*
* @param aSlot
* The a channel digital input module.
* @param aChannel
* The a channel digital input channel.
* @param bSlot
* The b channel digital input module.
* @param bChannel
* The b channel digital input channel.
* @param reverseDirection
* represents the orientation of the encoder and inverts the
* output values if necessary so forward represents positive
* values.
* @param encodingType
* either k1X, k2X, or k4X to indicate 1X, 2X or 4X decoding. If
* 4X is selected, then an encoder FPGA object is used and the
* returned counts will be 4x the encoder spec'd value since all
* rising and falling edges are counted. If 1X or 2X are selected
* then a counter object will be used and the returned value will
* either exactly match the spec'd count or be double (2x) the
* spec'd count.
*/
public Encoder(final int aSlot, final int aChannel, final int bSlot,
final int bChannel, boolean reverseDirection,
final EncodingType encodingType) {
m_allocatedA = true;
m_allocatedB = true;
m_allocatedI = false;
m_aSource = new DigitalInput(aSlot, aChannel);
m_bSource = new DigitalInput(bSlot, bChannel);
if (encodingType == null)
throw new NullPointerException("Given encoding type was null");
m_encodingType = encodingType;
initEncoder(reverseDirection);
}
/**
* Encoder constructor. Construct a Encoder given a and b modules and
* channels fully specified. Using the index pulse forces 4x encoding.
*
* @param aSlot
* The a channel digital input module.
* @param aChannel
* The a channel digital input channel.
* @param bSlot
* The b channel digital input module.
* @param bChannel
* The b channel digital input channel.
* @param indexSlot
* The index channel digital input module.
* @param indexChannel
* The index channel digital input channel.
* @param reverseDirection
* represents the orientation of the encoder and inverts the
* output values if necessary so forward represents positive
* values.
*/
public Encoder(final int aSlot, final int aChannel, final int bSlot,
final int bChannel, final int indexSlot, final int indexChannel,
boolean reverseDirection) {
m_allocatedA = true;
m_allocatedB = true;
m_allocatedI = true;
m_aSource = new DigitalInput(aSlot, aChannel);
m_bSource = new DigitalInput(bSlot, bChannel);
m_indexSource = new DigitalInput(indexSlot, indexChannel);
initEncoder(reverseDirection);
}
/**
* Encoder constructor. Construct a Encoder given a and b modules and
* channels fully specified. Using the index pulse forces 4x encoding.
*
* @param aSlot
* The a channel digital input module.
* @param aChannel
* The a channel digital input channel.
* @param bSlot
* The b channel digital input module.
* @param bChannel
* The b channel digital input channel.
* @param indexSlot
* The index channel digital input module.
* @param indexChannel
* The index channel digital input channel.
*/
public Encoder(final int aSlot, final int aChannel, final int bSlot,
final int bChannel, final int indexSlot, final int indexChannel) {
this(aSlot, aChannel, bSlot, bChannel, indexSlot, indexChannel, false);
}
/**
* Encoder constructor. Construct a Encoder given a and b channels assuming
* the default module.
* Encoder constructor. Construct a Encoder given a and b channels.
*
* @param aChannel
* The a channel digital input channel.
@@ -270,8 +129,7 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource,
}
/**
* Encoder constructor. Construct a Encoder given a and b channels assuming
* the default module.
* Encoder constructor. Construct a Encoder given a and b channels.
*
* @param aChannel
* The a channel digital input channel.
@@ -283,8 +141,7 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource,
}
/**
* Encoder constructor. Construct a Encoder given a and b channels assuming
* the default module.
* Encoder constructor. Construct a Encoder given a and b channels.
*
* @param aChannel
* The a channel digital input channel.
@@ -317,8 +174,8 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource,
}
/**
* Encoder constructor. Construct a Encoder given a and b channels assuming
* the default module. Using an index pulse forces 4x encoding
* Encoder constructor. Construct a Encoder given a and b channels.
* Using an index pulse forces 4x encoding
*
* @param aChannel
* The a channel digital input channel.
@@ -343,8 +200,8 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource,
}
/**
* Encoder constructor. Construct a Encoder given a and b channels assuming
* the default module. Using an index pulse forces 4x encoding
* Encoder constructor. Construct a Encoder given a and b channels.
* Using an index pulse forces 4x encoding
*
* @param aChannel
* The a channel digital input channel.

View File

@@ -34,9 +34,18 @@ public class GearTooth extends Counter implements ISensor {
/**
* Construct a GearTooth sensor given a channel.
*
* The default module is assumed.
* No direction sensing is assumed.
*
* @param channel The GPIO channel on the digital module that the sensor is connected to.
* @param channel The GPIO channel that the sensor is connected to.
*/
public GearTooth(final int channel) {
this(channel,false);
}
/**
* Construct a GearTooth sensor given a channel.
*
* @param channel The GPIO channel that the sensor is connected to.
* @param directionSensitive Enable the pulse length decoding in hardware to specify count direction.
*/
public GearTooth(final int channel, boolean directionSensitive) {
@@ -47,48 +56,7 @@ public class GearTooth extends Counter implements ISensor {
} else {
UsageReporting.report(tResourceType.kResourceType_GearTooth, channel, DigitalModule.getDefaultDigitalModule()-1);
}
}
/**
* Construct a GearTooth sensor given a channel.
*
* The default module is assumed.
* No direction sensing is assumed.
*
* @param channel The GPIO channel on the digital module that the sensor is connected to.
*/
public GearTooth(final int channel) {
this(channel,false);
}
/**
* Construct a GearTooth sensor given a channel and module.
*
* @param slot The slot in the chassis that the digital module is plugged in to.
* @param channel The GPIO channel on the digital module that the sensor is connected to.
* @param directionSensitive Enable the pulse length decoding in hardware to specify count direction.
*/
public GearTooth(final int slot, final int channel, boolean directionSensitive) {
super(slot, channel);
enableDirectionSensing(directionSensitive);
if(directionSensitive) {
UsageReporting.report(tResourceType.kResourceType_GearTooth, channel, DigitalModule.getDefaultDigitalModule()-1, "D");
} else {
UsageReporting.report(tResourceType.kResourceType_GearTooth, channel, DigitalModule.getDefaultDigitalModule()-1);
}
LiveWindow.addSensor("GearTooth", slot, channel, this);
}
/**
* Construct a GearTooth sensor given a channel and module.
*
* No direction sensing is assumed.
*
* @param slot The slot in the chassis that the digital module is plugged in to.
* @param channel The GPIO channel on the digital module that the sensor is connected to.
*/
public GearTooth(final int slot, final int channel) {
this(slot, channel,false);
LiveWindow.addSensor("GearTooth", channel, this);
}
/**

View File

@@ -79,31 +79,13 @@ public class Gyro extends SensorBase implements PIDSource, ISensor,
setPIDSourceParameter(PIDSourceParameter.kAngle);
UsageReporting.report(tResourceType.kResourceType_Gyro,
m_analog.getChannel(), m_analog.getModuleNumber() - 1);
LiveWindow.addSensor("Gyro", m_analog.getModuleNumber(),
m_analog.getChannel(), this);
}
/**
* Gyro constructor given a slot and a channel. .
*
* @param slot
* The cRIO slot for the analog module the gyro is connected to.
* @param channel
* The analog channel the gyro is connected to.
*/
public Gyro(int slot, int channel) {
m_analog = new AnalogInput(slot, channel);
m_channelAllocated = true;
initGyro();
UsageReporting.report(tResourceType.kResourceType_Gyro, m_analog.getChannel());
LiveWindow.addSensor("Gyro", m_analog.getChannel(), this);
}
/**
* Gyro constructor with only a channel.
*
* Use the default analog module slot.
*
*
* @param channel
* The analog channel the gyro is connected to.
*/
@@ -117,7 +99,7 @@ public class Gyro extends SensorBase implements PIDSource, ISensor,
* Gyro constructor with a precreated analog channel object. Use this
* constructor when the analog channel needs to be shared. There is no
* reference counting when an AnalogChannel is passed to the gyro.
*
*
* @param channel
* The AnalogChannel object that the gyro is connected to.
*/
@@ -156,13 +138,13 @@ public class Gyro extends SensorBase implements PIDSource, ISensor,
/**
* Return the actual angle in degrees that the robot is currently facing.
*
*
* The angle is based on the current accumulator value corrected by the
* oversampling rate, the gyro type and the A/D calibration values. The
* angle is continuous, that is can go beyond 360 degrees. This make
* algorithms that wouldn't want to see a discontinuity in the gyro output
* as it sweeps past 0 on the second time around.
*
*
* @return the current heading of the robot in degrees. This heading is
* based on integration of the returned rate from the gyro.
*/
@@ -186,9 +168,9 @@ public class Gyro extends SensorBase implements PIDSource, ISensor,
/**
* Return the rate of rotation of the gyro
*
*
* The rate is based on the most recent reading of the gyro analog value
*
*
* @return the current rate in degrees per second
*/
public double getRate() {
@@ -206,7 +188,7 @@ public class Gyro extends SensorBase implements PIDSource, ISensor,
* Set the gyro type based on the sensitivity. This takes the number of
* volts/degree/second sensitivity of the gyro and uses it in subsequent
* calculations to allow the code to work with multiple gyros.
*
*
* @param voltsPerDegreePerSecond
* The type of gyro specified as the voltage that represents one
* degree/second.
@@ -218,7 +200,7 @@ public class Gyro extends SensorBase implements PIDSource, ISensor,
/**
* Set which parameter of the encoder you are using as a process control
* variable. The Gyro class supports the rate and angle parameters
*
*
* @param pidSource
* An enum to select the parameter.
*/
@@ -229,7 +211,7 @@ public class Gyro extends SensorBase implements PIDSource, ISensor,
/**
* Get the angle of the gyro for use with PIDControllers
*
*
* @return the current angle according to the gyro
*/
public double pidGet() {

View File

@@ -109,7 +109,7 @@ public class HiTechnicColorSensor extends SensorBase implements ISensor, LiveWin
throw new ColorSensorException("Invalid Sensor type");
}
LiveWindow.addSensor("HiTechnicColorSensor", slot, 0, this);
LiveWindow.addSensor("HiTechnicColorSensor", slot, this);
UsageReporting.report(tResourceType.kResourceType_HiTechnicColorSensor, module.getModuleNumber()-1);
}

View File

@@ -53,11 +53,9 @@ public class HiTechnicCompass extends SensorBase implements ISensor, LiveWindowS
/**
* Constructor.
*
* @param slot The slot of the digital module that the sensor is plugged into.
*/
public HiTechnicCompass(int slot) {
DigitalModule module = DigitalModule.getInstance(slot);
public HiTechnicCompass() {
DigitalModule module = DigitalModule.getInstance(1);
m_i2c = module.getI2C(kAddress);
// Verify Sensor
@@ -70,8 +68,8 @@ public class HiTechnicCompass extends SensorBase implements ISensor, LiveWindowS
throw new CompassException("Invalid Sensor type");
}
UsageReporting.report(tResourceType.kResourceType_HiTechnicCompass, module.getModuleNumber()-1);
LiveWindow.addSensor("HiTechnicCompass", slot, 0, this);
UsageReporting.report(tResourceType.kResourceType_HiTechnicCompass, 1);
LiveWindow.addSensor("HiTechnicCompass", 1, this);
}
/**

View File

@@ -18,10 +18,10 @@ import edu.wpi.first.wpilibj.util.BoundaryException;
/**
* I2C bus interface class.
*
*
* This class is intended to be used by sensor (and other I2C device) drivers.
* It probably should not be used directly.
*
*
* It is constructed by calling DigitalModule::GetI2C() on a DigitalModule
* object.
*/
@@ -31,25 +31,24 @@ public class I2C extends SensorBase {
private int m_deviceAddress;
private boolean m_compatibilityMode;
/**
* Constructor.
*
* @param module
* The Digital Module to which the device is connected.
* @param deviceAddress
* The address of the device on the I2C bus.
*/
public I2C(DigitalModule module, int deviceAddress) {
if (module == null) {
throw new NullPointerException("Digital Module given was null");
}
m_module = module;
m_deviceAddress = deviceAddress;
m_compatibilityMode = true;
/**
* Constructor.
*
* @param module
* The Digital Module to which the device is connected.
* @param deviceAddress
* The address of the device on the I2C bus.
*/
public I2C(DigitalModule module, int deviceAddress) {
if (module == null) {
throw new NullPointerException("Digital Module given was null");
}
m_module = module;
m_deviceAddress = deviceAddress;
m_compatibilityMode = true;
UsageReporting.report(tResourceType.kResourceType_I2C, deviceAddress,
module.getModuleNumber()-1);
}
UsageReporting.report(tResourceType.kResourceType_I2C, deviceAddress);
}
/**
* Destructor.
@@ -59,10 +58,10 @@ public class I2C extends SensorBase {
/**
* Generic transaction.
*
*
* This is a lower-level interface to the I2C hardware giving you more
* control over each transaction.
*
*
* @param dataToSend
* Buffer of data to send as part of the transaction.
* @param sendSize
@@ -105,10 +104,10 @@ public class I2C extends SensorBase {
/**
* Attempt to address a device on the I2C bus.
*
*
* This allows you to figure out if there is a device on the I2C bus that
* responds to the address specified in the constructor.
*
*
* @return Transfer Aborted... false for success, true for aborted.
*/
public boolean addressOnly() {
@@ -117,10 +116,10 @@ public class I2C extends SensorBase {
/**
* Execute a write transaction with the device.
*
*
* Write a single byte to a register on a device and wait until the
* transaction is complete.
*
*
* @param registerAddress
* The address of the register on the device to be written.
* @param data
@@ -135,11 +134,11 @@ public class I2C extends SensorBase {
/**
* Execute a read transaction with the device.
*
*
* Read 1 to 7 bytes from a device. Most I2C devices will auto-increment the
* register pointer internally allowing you to read up to 7 consecutive
* registers on a device in a single transaction.
*
*
* @param registerAddress
* The register to read first in the transaction.
* @param count
@@ -163,9 +162,9 @@ public class I2C extends SensorBase {
/**
* Send a broadcast write to all devices on the I2C bus.
*
*
* This is not currently implemented!
*
*
* @param registerAddress
* The register to write on all devices on the bus.
* @param data
@@ -176,30 +175,30 @@ public class I2C extends SensorBase {
/**
* SetCompatabilityMode
*
*
* Enables bitwise clock skewing detection. This will reduce the I2C
* interface speed, but will allow you to communicate with devices that skew
* the clock at abnormal times. Compatability mode is enabled by default.
*
*
* @param enable
* Enable compatability mode for this sensor or not.
*/
public void setCompatabilityMode(boolean enable) {
m_compatibilityMode = enable;
UsageReporting.report(tResourceType.kResourceType_I2C,
m_deviceAddress, m_module.getModuleNumber() - 1, "C");
m_deviceAddress, 1, "C");
}
/**
* Verify that a device's registers contain expected values.
*
*
* Most devices will have a set of registers that contain a known value that
* can be used to identify them. This allows an I2C device driver to easily
* verify that the device contains the expected value.
*
*
* @pre The device must support and be configured to use register
* auto-increment.
*
*
* @param registerAddress
* The base register to start reading from the device.
* @param count

View File

@@ -34,31 +34,20 @@ public class Jaguar extends SafePWM implements SpeedController, IDeviceControlle
setPeriodMultiplier(PeriodMultiplier.k1X);
setRaw(m_centerPwm);
UsageReporting.report(tResourceType.kResourceType_Jaguar, getChannel(), getModuleNumber()-1);
LiveWindow.addActuator("Jaguar", getModuleNumber(), getChannel(), this);
UsageReporting.report(tResourceType.kResourceType_Jaguar, getChannel());
LiveWindow.addActuator("Jaguar", getChannel(), this);
}
/**
* Constructor that assumes the default digital module.
* Constructor.
*
* @param channel The PWM channel on the digital module that the Jaguar is attached to.
* @param channel The PWM channel that the Jaguar is attached to.
*/
public Jaguar(final int channel) {
super(channel);
initJaguar();
}
/**
* Constructor that specifies the digital module.
*
* @param slot The slot in the chassis that the digital module is plugged into.
* @param channel The PWM channel on the digital module that the Jaguar is attached to.
*/
public Jaguar(final int slot, final int channel) {
super(slot, channel);
initJaguar();
}
/**
* Set the PWM value.
*

View File

@@ -38,7 +38,7 @@ public class PWM extends SensorBase implements LiveWindowSendable {
* resource tracking into the HAL. This will wait until we get the unit
* tests running for the first time.
*/
private static Resource allocated = new Resource( kPwmChannels);
/**
@@ -106,49 +106,35 @@ public class PWM extends SensorBase implements LiveWindowSendable {
int m_minPwm;
/**
* Initialize PWMs given an module and channel.
* Initialize PWMs given a channel.
*
* This method is private and is the common path for all the constructors for creating PWM
* instances. Checks module and channel value ranges and allocates the appropriate channel.
* The allocation is only done to help users ensure that they don't double assign channels.
*/
private void initPWM(final int moduleNumber, final int channel) {
checkPWMModule(moduleNumber);
private void initPWM(final int channel) {
checkPWMChannel(channel);
try {
allocated.allocate((moduleNumber - 1) * kPwmChannels + channel);
allocated.allocate(channel);
} catch (CheckedAllocationException e) {
throw new AllocationException(
"PWM channel " + channel + " on module " + moduleNumber + " is already allocated");
"PWM channel " + channel + " is already allocated");
}
m_channel = channel;
m_module = DigitalModule.getInstance(moduleNumber);
m_module = DigitalModule.getInstance(1);
m_module.setPWM(m_channel, kPwmDisabled);
m_eliminateDeadband = false;
UsageReporting.report(tResourceType.kResourceType_PWM, channel, moduleNumber-1);
UsageReporting.report(tResourceType.kResourceType_PWM, channel);
}
/**
* Allocate a PWM given a module and channel.
* Allocate a PWM using a module and channel number.
* Allocate a PWM given a channel.
*
* @param moduleNumber The module number of the digital module to use.
* @param channel The PWM channel on the digital module.
*/
public PWM(final int moduleNumber, final int channel) {
initPWM(moduleNumber, channel);
}
/**
* Allocate a PWM in the default module given a channel.
*
* Using a default module allocate a PWM given the channel number.
*
* @param channel The PWM channel on the digital module.
* @param channel The PWM channel.
*/
public PWM(final int channel) {
initPWM(getDefaultDigitalModule(), channel);
initPWM(channel);
}
/**
@@ -159,7 +145,7 @@ public class PWM extends SensorBase implements LiveWindowSendable {
public void free() {
m_module.setPWM(m_channel, kPwmDisabled);
m_module.freeDIO(m_channel);
allocated.free((m_module.getModuleNumber() - 1) * kPwmChannels + m_channel);
allocated.free(m_channel);
}
/**
@@ -211,15 +197,6 @@ public class PWM extends SensorBase implements LiveWindowSendable {
m_minPwm = (int)((min-kDefaultPwmCenter)/loopTime+kDefaultPwmStepsDown-1);
}
/**
* Gets the module number associated with the PWM Object.
*
* @return The module's number.
*/
public int getModuleNumber() {
return m_module.getModuleNumber();
}
/**
* Gets the channel number associated with the PWM Object.
*

View File

@@ -30,13 +30,6 @@ import edu.wpi.first.wpilibj.util.CheckedAllocationException;
*/
public class Relay extends SensorBase implements IDeviceController,
LiveWindowSendable {
/*
* XXX: Refactor to no longer depend on the DigitalModule, and move all
* resource tracking into the HAL. This will wait until we get the unit
* tests running for the first time.
*/
/**
* This class represents errors in trying to set relay values contradictory
* to the direction to which the relay is set.
@@ -45,7 +38,7 @@ public class Relay extends SensorBase implements IDeviceController,
/**
* Create a new exception with the given message
*
*
* @param message
* the message to pass with the exception
*/
@@ -128,62 +121,34 @@ public class Relay extends SensorBase implements IDeviceController,
* Common relay initialization method. This code is common to all Relay
* constructors and initializes the relay and reserves all resources that
* need to be locked. Initially the relay is set to both lines at 0v.
*
* @param moduleNumber
* The number of the digital module to use.
*/
private void initRelay(final int moduleNumber) {
SensorBase.checkRelayModule(moduleNumber);
private void initRelay() {
SensorBase.checkRelayChannel(m_channel);
try {
if (m_direction == Direction.kBoth
|| m_direction == Direction.kForward) {
relayChannels.allocate(((moduleNumber - 1) * kRelayChannels
+ m_channel) * 2);
UsageReporting.report(tResourceType.kResourceType_Relay,
m_channel, moduleNumber - 1);
relayChannels.allocate(m_channel * 2);
UsageReporting.report(tResourceType.kResourceType_Relay, m_channel);
}
if (m_direction == Direction.kBoth
|| m_direction == Direction.kReverse) {
relayChannels.allocate(((moduleNumber - 1) * kRelayChannels
+ m_channel) * 2 + 1);
UsageReporting.report(tResourceType.kResourceType_Relay,
m_channel + 128, moduleNumber - 1);
relayChannels.allocate(m_channel * 2 + 1);
UsageReporting.report(tResourceType.kResourceType_Relay, m_channel + 128);
}
} catch (CheckedAllocationException e) {
throw new AllocationException("Relay channel " + m_channel
+ " on module " + moduleNumber + " is already allocated");
throw new AllocationException("Relay channel " + m_channel + " is already allocated");
}
m_module = DigitalModule.getInstance(moduleNumber);
m_module = DigitalModule.getInstance(1);
m_module.setRelayForward(m_channel, false);
m_module.setRelayReverse(m_channel, false);
LiveWindow.addActuator("Relay", moduleNumber, m_channel, this);
LiveWindow.addActuator("Relay", m_channel, this);
}
/**
* Relay constructor given the module and the channel.
*
* @param moduleNumber
* The number of the digital module to use.
* Relay constructor given a channel.
*
* @param channel
* The channel number within the module for this relay.
* @param direction
* The direction that the Relay object will control.
*/
public Relay(final int moduleNumber, final int channel, Direction direction) {
if (direction == null)
throw new NullPointerException("Null Direction was given");
m_channel = channel;
m_direction = direction;
initRelay(moduleNumber);
}
/**
* Relay constructor given a channel only where the default digital module
* is used.
*
* @param channel
* The channel number within the default module for this relay.
* The channel number for this relay.
* @param direction
* The direction that the Relay object will control.
*/
@@ -192,35 +157,19 @@ public class Relay extends SensorBase implements IDeviceController,
throw new NullPointerException("Null Direction was given");
m_channel = channel;
m_direction = direction;
initRelay(getDefaultDigitalModule());
initRelay();
}
/**
* Relay constructor given the module and the channel, allowing both
* directions.
*
* @param moduleNumber
* The number of the digital module to use.
* Relay constructor given a channel, allowing both directions.
*
* @param channel
* The channel number within the module for this relay.
*/
public Relay(final int moduleNumber, final int channel) {
m_channel = channel;
m_direction = Direction.kBoth;
initRelay(moduleNumber);
}
/**
* Relay constructor given a channel only where the default digital module
* is used, allowing both directions.
*
* @param channel
* The channel number within the default module for this relay.
* The channel number for this relay.
*/
public Relay(final int channel) {
m_channel = channel;
m_direction = Direction.kBoth;
initRelay(getDefaultDigitalModule());
initRelay();
}
public void free() {
@@ -243,17 +192,17 @@ public class Relay extends SensorBase implements IDeviceController,
/**
* Set the relay state.
*
*
* Valid values depend on which directions of the relay are controlled by
* the object.
*
*
* When set to kBothDirections, the relay can be set to any of the four
* states: 0v-0v, 12v-0v, 0v-12v, 12v-12v
*
*
* When set to kForwardOnly or kReverseOnly, you can specify the constant
* for the direction or you can simply specify kOff_val and kOn_val. Using
* only kOff_val and kOn_val is recommended.
*
*
* @param value
* The state to set the relay.
*/
@@ -310,12 +259,12 @@ public class Relay extends SensorBase implements IDeviceController,
/**
* Get the Relay State
*
*
* Gets the current state of the relay.
*
*
* When set to kForwardOnly or kReverseOnly, value is returned as kOn/kOff
* not kForward/kReverse (per the recommendation in Set)
*
*
* @return The current state of the relay as a Relay::Value
*/
public Value get() {
@@ -344,12 +293,12 @@ public class Relay extends SensorBase implements IDeviceController,
/**
* Set the Relay Direction
*
*
* Changes which values the relay can be set to depending on which direction
* is used
*
*
* Valid inputs are kBothDirections, kForwardOnly, and kReverseOnly
*
*
* @param direction
* The direction for the relay to operate in
*/
@@ -364,7 +313,7 @@ public class Relay extends SensorBase implements IDeviceController,
m_direction = direction;
initRelay(m_module.getModuleNumber());
initRelay();
}
/*

View File

@@ -82,8 +82,8 @@ public class RobotDrive implements MotorSafety, IUtility {
* Set up parameters for a two wheel drive system where the
* left and right motor pwm channels are specified in the call.
* This call assumes Jaguars for controlling the motors.
* @param leftMotorChannel The PWM channel number on the default digital module that drives the left motor.
* @param rightMotorChannel The PWM channel number on the default digital module that drives the right motor.
* @param leftMotorChannel The PWM channel number that drives the left motor.
* @param rightMotorChannel The PWM channel number that drives the right motor.
*/
public RobotDrive(final int leftMotorChannel, final int rightMotorChannel) {
m_sensitivity = kDefaultSensitivity;
@@ -105,10 +105,10 @@ public class RobotDrive implements MotorSafety, IUtility {
* Set up parameters for a four wheel drive system where all four motor
* pwm channels are specified in the call.
* This call assumes Jaguars for controlling the motors.
* @param frontLeftMotor Front left motor channel number on the default digital module
* @param rearLeftMotor Rear Left motor channel number on the default digital module
* @param frontRightMotor Front right motor channel number on the default digital module
* @param rearRightMotor Rear Right motor channel number on the default digital module
* @param frontLeftMotor Front left motor channel number
* @param rearLeftMotor Rear Left motor channel number
* @param frontRightMotor Front right motor channel number
* @param rearRightMotor Rear Right motor channel number
*/
public RobotDrive(final int frontLeftMotor, final int rearLeftMotor,
final int frontRightMotor, final int rearRightMotor) {

View File

@@ -34,16 +34,6 @@ public class SafePWM extends PWM implements MotorSafety {
initSafePWM();
}
/**
* Constructor for a SafePWM object taking channel and slot numbers.
* @param slot The slot number of the digital module for this PWM object
* @param channel The channel number in the module for this PWM object
*/
public SafePWM(final int slot, final int channel) {
super(slot, channel);
initSafePWM();
}
/*
* Set the expiration time for the PWM object
* @param timeout The timeout (in seconds) for this motor object
@@ -100,7 +90,7 @@ public class SafePWM extends PWM implements MotorSafety {
}
public String getDescription() {
return "PWM "+getChannel()+" on module "+getModuleNumber();
return "PWM "+getChannel();
}
public void disable() {

View File

@@ -24,7 +24,7 @@ public class Servo extends PWM implements IDevice {
private static final double kMaxServoAngle = 180.0;
private static final double kMinServoAngle = 0.0;
private static final double kDefaultMaxServoPWM = 2.4;
private static final double kDefaultMinServoPWM = .6;
@@ -33,43 +33,29 @@ public class Servo extends PWM implements IDevice {
*
* InitServo() assigns defaults for the period multiplier for the servo PWM control signal, as
* well as the minimum and maximum PWM values supported by the servo.
*
*
*/
private void initServo() {
setBounds(kDefaultMaxServoPWM, 0, 0, 0, kDefaultMinServoPWM);
setPeriodMultiplier(PeriodMultiplier.k4X);
LiveWindow.addActuator("Servo", getModuleNumber(), getChannel(), this);
UsageReporting.report(tResourceType.kResourceType_Servo, getChannel(), getModuleNumber()-1);
LiveWindow.addActuator("Servo", getChannel(), this);
UsageReporting.report(tResourceType.kResourceType_Servo, getChannel());
}
/**
* Constructor that assumes the default digital module.<br>
*
* Constructor.<br>
*
* By default {@value #kDefaultMaxServoPWM} ms is used as the maxPWM value<br>
* By default {@value #kDefaultMinServoPWM} ms is used as the minPWM value<br>
*
* @param channel The PWM channel on the digital module to which the servo is attached.
* @param channel The PWM channel to which the servo is attached.
*/
public Servo(final int channel) {
super(channel);
initServo();
}
/**
* Constructor that specifies the digital module.<br>
*
* By default {@value #kDefaultMaxServoPWM} ms is used as the maxPWM value<br>
* By default {@value #kDefaultMinServoPWM} ms is used as the minPWM value<br>
*
* @param slot The slot in the chassis that the digital module is plugged into.
* @param channel The PWM channel on the digital module to which the servo is attached.
*/
public Servo(final int slot, final int channel) {
super(slot, channel);
initServo();
}
/**
* Set the servo position.

View File

@@ -36,31 +36,20 @@ public class Talon extends SafePWM implements SpeedController, IDeviceController
setPeriodMultiplier(PeriodMultiplier.k2X);
setRaw(m_centerPwm);
LiveWindow.addActuator("Talon", getModuleNumber(), getChannel(), this);
UsageReporting.report(tResourceType.kResourceType_Talon, getChannel(), getModuleNumber()-1);
LiveWindow.addActuator("Talon", getChannel(), this);
UsageReporting.report(tResourceType.kResourceType_Talon, getChannel());
}
/**
* Constructor that assumes the default digital module.
* Constructor.
*
* @param channel The PWM channel on the digital module that the Victor is attached to.
* @param channel The PWM channel that the Victor is attached to.
*/
public Talon(final int channel) {
super(channel);
initTalon();
}
/**
* Constructor that specifies the digital module.
*
* @param slot The slot in the chassis that the digital module is plugged into.
* @param channel The PWM channel on the digital module that the Victor is attached to.
*/
public Talon(final int slot, final int channel) {
super(slot, channel);
initTalon();
}
/**
* Set the PWM value.
*

View File

@@ -78,7 +78,7 @@ public class Ultrasonic extends SensorBase implements PIDSource, ISensor,
* Background task that goes through the list of ultrasonic sensors and
* pings each one in turn. The counter is configured to read the timing of
* the returned echo pulse.
*
*
* DANGER WILL ROBINSON, DANGER WILL ROBINSON: This code runs as a task and
* assumes that none of the ultrasonic sensors will change while it's
* running. If one does, then this will certainly break. Make sure to
@@ -133,16 +133,14 @@ public class Ultrasonic extends SensorBase implements PIDSource, ISensor,
m_instances++;
UsageReporting.report(tResourceType.kResourceType_Ultrasonic,
m_instances);
LiveWindow.addSensor("Ultrasonic", m_echoChannel.getModuleForRouting(),
m_echoChannel.getChannel(), this);
LiveWindow.addSensor("Ultrasonic", m_echoChannel.getChannel(), this);
}
/**
* Create an instance of the Ultrasonic Sensor using the default module.
* Create an instance of the Ultrasonic Sensor.
* This is designed to supchannel the Daventech SRF04 and Vex ultrasonic
* sensors. This constructor assumes that both digital I/O channels are in
* the default digital module.
*
* sensors.
*
* @param pingChannel
* The digital output channel that sends the pulse to initiate
* the sensor sending the ping.
@@ -162,11 +160,11 @@ public class Ultrasonic extends SensorBase implements PIDSource, ISensor,
}
/**
* Create an instance of the Ultrasonic Sensor using the default module.
* Create an instance of the Ultrasonic Sensor.
* This is designed to supchannel the Daventech SRF04 and Vex ultrasonic
* sensors. This constructor assumes that both digital I/O channels are in
* the default digital module. Default unit is inches.
*
*
* @param pingChannel
* The digital output channel that sends the pulse to initiate
* the sensor sending the ping.
@@ -182,7 +180,7 @@ public class Ultrasonic extends SensorBase implements PIDSource, ISensor,
/**
* Create an instance of an Ultrasonic Sensor from a DigitalInput for the
* echo channel and a DigitalOutput for the ping channel.
*
*
* @param pingChannel
* The digital output object that starts the sensor doing a ping.
* Requires a 10uS pulse to start.
@@ -208,7 +206,7 @@ public class Ultrasonic extends SensorBase implements PIDSource, ISensor,
* Create an instance of an Ultrasonic Sensor from a DigitalInput for the
* echo channel and a DigitalOutput for the ping channel. Default unit is
* inches.
*
*
* @param pingChannel
* The digital output object that starts the sensor doing a ping.
* Requires a 10uS pulse to start.
@@ -220,58 +218,6 @@ public class Ultrasonic extends SensorBase implements PIDSource, ISensor,
this(pingChannel, echoChannel, Unit.kInches);
}
/**
* Create an instance of the Ultrasonic sensor using specified modules. This
* is designed to supchannel the Daventech SRF04 and Vex ultrasonic sensors.
* This constructors takes the channel and module slot for each of the
* required digital I/O channels.
*
* @param pingSlot
* The digital module that the pingChannel is in.
* @param pingChannel
* The digital output channel that sends the pulse to initiate
* the sensor sending the ping.
* @param echoSlot
* The digital module that the echoChannel is in.
* @param echoChannel
* The digital input channel that receives the echo. The length
* of time that the echo is high represents the round trip time
* of the ping, and the distance.
* @param units
* The units returned in either kInches or kMilliMeters
*/
public Ultrasonic(final int pingSlot, final int pingChannel,
final int echoSlot, final int echoChannel, Unit units) {
m_pingChannel = new DigitalOutput(pingSlot, pingChannel);
m_echoChannel = new DigitalInput(echoSlot, echoChannel);
m_allocatedChannels = true;
m_units = units;
initialize();
}
/**
* Create an instance of the Ultrasonic sensor using specified modules. This
* is designed to supchannel the Daventech SRF04 and Vex ultrasonic sensors.
* This constructors takes the channel and module slot for each of the
* required digital I/O channels. Defualt unit is inches.
*
* @param pingSlot
* The digital module that the pingChannel is in.
* @param pingChannel
* The digital output channel that sends the pulse to initiate
* the sensor sending the ping.
* @param echoSlot
* The digital module that the echoChannel is in.
* @param echoChannel
* The digital input channel that receives the echo. The length
* of time that the echo is high represents the round trip time
* of the ping, and the distance.
*/
public Ultrasonic(final int pingSlot, final int pingChannel,
final int echoSlot, final int echoChannel) {
this(pingSlot, pingChannel, echoSlot, echoChannel, Unit.kInches);
}
/**
* Destructor for the ultrasonic sensor. Delete the instance of the
* ultrasonic sensor by freeing the allocated digital channels. If the
@@ -320,7 +266,7 @@ public class Ultrasonic extends SensorBase implements PIDSource, ISensor,
/**
* Turn Automatic mode on/off. When in Automatic mode, all sensors will fire
* in round robin, waiting a set time between each sensor.
*
*
* @param enabling
* Set to true if round robin scheduling should start for all the
* ultrasonic sensors. This scheduling method assures that the
@@ -385,7 +331,7 @@ public class Ultrasonic extends SensorBase implements PIDSource, ISensor,
* in a counter that will increment on each edge of the echo (return)
* signal. If the count is not at least 2, then the range has not yet been
* measured, and is invalid.
*
*
* @return true if the range is valid
*/
public boolean isRangeValid() {
@@ -394,7 +340,7 @@ public class Ultrasonic extends SensorBase implements PIDSource, ISensor,
/**
* Get the range in inches from the ultrasonic sensor.
*
*
* @return double Range in inches of the target returned from the ultrasonic
* sensor. If there is no valid value yet, i.e. at least one
* measurement hasn't completed, then return 0.
@@ -409,7 +355,7 @@ public class Ultrasonic extends SensorBase implements PIDSource, ISensor,
/**
* Get the range in millimeters from the ultrasonic sensor.
*
*
* @return double Range in millimeters of the target returned by the
* ultrasonic sensor. If there is no valid value yet, i.e. at least
* one measurement hasn't complted, then return 0.
@@ -420,7 +366,7 @@ public class Ultrasonic extends SensorBase implements PIDSource, ISensor,
/**
* Get the range in the current DistanceUnit for the PIDSource base object.
*
*
* @return The range in DistanceUnit
*/
public double pidGet() {
@@ -437,7 +383,7 @@ public class Ultrasonic extends SensorBase implements PIDSource, ISensor,
/**
* Set the current DistanceUnit that should be used for the PIDSource base
* object.
*
*
* @param units
* The DistanceUnit that should be used.
*/
@@ -447,7 +393,7 @@ public class Ultrasonic extends SensorBase implements PIDSource, ISensor,
/**
* Get the current DistanceUnit that is used for the PIDSource base object.
*
*
* @return The type of DistanceUnit that is being used.
*/
public Unit getDistanceUnits() {
@@ -456,7 +402,7 @@ public class Ultrasonic extends SensorBase implements PIDSource, ISensor,
/**
* Is the ultrasonic enabled
*
*
* @return true if the ultrasonic is enabled
*/
public boolean isEnabled() {
@@ -465,7 +411,7 @@ public class Ultrasonic extends SensorBase implements PIDSource, ISensor,
/**
* Set if the ultrasonic is enabled
*
*
* @param enable
* set to true to enable the ultrasonic
*/

View File

@@ -38,31 +38,20 @@ public class Victor extends SafePWM implements SpeedController, IDeviceControlle
setPeriodMultiplier(PeriodMultiplier.k2X);
setRaw(m_centerPwm);
LiveWindow.addActuator("Victor", getModuleNumber(), getChannel(), this);
UsageReporting.report(tResourceType.kResourceType_Victor, getChannel(), getModuleNumber()-1);
LiveWindow.addActuator("Victor", getChannel(), this);
UsageReporting.report(tResourceType.kResourceType_Victor, getChannel());
}
/**
* Constructor that assumes the default digital module.
* Constructor.
*
* @param channel The PWM channel on the digital module that the Victor is attached to.
* @param channel The PWM channel that the Victor is attached to.
*/
public Victor(final int channel) {
super(channel);
initVictor();
}
/**
* Constructor that specifies the digital module.
*
* @param slot The slot in the chassis that the digital module is plugged into.
* @param channel The PWM channel on the digital module that the Victor is attached to.
*/
public Victor(final int slot, final int channel) {
super(slot, channel);
initVictor();
}
/**
* Set the PWM value.
*

View File

@@ -169,24 +169,38 @@ public class LiveWindow {
}
/**
* Add Sensor to LiveWindow. The components are shown with the module type,
* slot and channel like this: Gyro[1, 2] for a gyro object connected to the
* first analog module in channel 2
* Add Sensor to LiveWindow. The components are shown with the type and
* channel like this: Gyro[1] for a gyro object connected to the first
* analog channel.
*
* @param moduleType A string indicating the type of the module used in the
* naming (above)
* @param moduleNumber The number of the particular module type
* @param channel The channel number the device is connected to
* @param component A reference to the object being added
*/
public static void addSensor(String moduleType, int moduleNumber, int channel, LiveWindowSendable component) {
addSensor("Ungrouped", moduleType + "[" + moduleNumber + "," + channel + "]", component);
public static void addSensor(String moduleType, int channel, LiveWindowSendable component) {
addSensor("Ungrouped", moduleType + "[" + channel + "]", component);
if (sensors.contains(component)) {
sensors.removeElement(component);
}
sensors.addElement(component);
}
/**
* Add Actuator to LiveWindow. The components are shown with the module
* type, slot and channel like this: Servo[1,2] for a servo object connected
* to the first digital module and PWM port 2.
*
* @param moduleType A string that defines the module name in the label for
* the value
* @param channel The channel number the device is plugged into (usually
* PWM)
* @param component The reference to the object being added
*/
public static void addActuator(String moduleType, int channel, LiveWindowSendable component) {
addActuator("Ungrouped", moduleType + "[" + channel + "]", component);
}
/**
* Add Actuator to LiveWindow. The components are shown with the module
* type, slot and channel like this: Servo[1,2] for a servo object connected