Completed artf2662: removed Start()/Stop() in Encoders and Counters.

Change-Id: I11954bb5f66e54461455637d79013c1071f5d00f
This commit is contained in:
Colby Skeggs
2014-07-29 09:58:15 -07:00
committed by Thomas Clark
parent c0af235050
commit 0bb13d86ea
23 changed files with 164 additions and 225 deletions

View File

@@ -24,6 +24,9 @@ import edu.wpi.first.wpilibj.util.BoundaryException;
* general purpose class for counting repetitive events. It can return the
* number of counts, the period of the most recent cycle, and detect when the
* signal being counted has stopped by supplying a maximum cycle time.
*
* All counters will immediately start counting - reset() them if you need them
* to be zeroed before use.
*/
public class Counter extends SensorBase implements CounterBase,
LiveWindowSendable, PIDSource {
@@ -91,12 +94,19 @@ public class Counter extends SensorBase implements CounterBase,
UsageReporting.report(tResourceType.kResourceType_Counter, m_index,
mode.value);
status = ByteBuffer.allocateDirect(4);
status.order(ByteOrder.LITTLE_ENDIAN);
CounterJNI.startCounter(m_counter, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
}
/**
* Create an instance of a counter where no sources are selected. Then they
* all must be selected by calling functions to specify the upsource and the
* downsource independently.
*
* The counter will start counting immediately.
*/
public Counter() {
initCounter(Mode.kTwoPulse);
@@ -107,6 +117,8 @@ public class Counter extends SensorBase implements CounterBase,
* existing digital input is to be shared by multiple other objects such as
* encoders.
*
* The counter will start counting immediately.
*
* @param source
* the digital source to count
*/
@@ -121,6 +133,8 @@ public class Counter extends SensorBase implements CounterBase,
* Create an instance of a Counter object. Create an up-Counter instance
* given a channel.
*
* The counter will start counting immediately.
*
* @param channel
* the digital input channel to count
*/
@@ -134,6 +148,8 @@ public class Counter extends SensorBase implements CounterBase,
* up-Counter given an analog trigger. Use the trigger state output from the
* analog trigger.
*
* The counter will start counting immediately.
*
* @param encodingType
* which edges to count
* @param upSource
@@ -175,6 +191,8 @@ public class Counter extends SensorBase implements CounterBase,
* up-Counter given an analog trigger. Use the trigger state output from the
* analog trigger.
*
* The counter will start counting immediately.
*
* @param trigger
* the analog trigger to count
*/
@@ -422,18 +440,6 @@ public class Counter extends SensorBase implements CounterBase,
HALUtil.checkStatus(status.asIntBuffer());
}
/**
* Start the Counter counting. This enables the counter and it starts
* accumulating counts from the associated input channel. The counter value
* is not reset on starting, and still has the previous value.
*/
public void start() {
ByteBuffer status = ByteBuffer.allocateDirect(4);
status.order(ByteOrder.LITTLE_ENDIAN);
CounterJNI.startCounter(m_counter, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
}
/**
* Read the current counter value. Read the value at this instant. It may
* still be running, so it reflects the current value. Next time it is read,
@@ -469,17 +475,6 @@ public class Counter extends SensorBase implements CounterBase,
HALUtil.checkStatus(status.asIntBuffer());
}
/**
* Stop the Counter. Stops the counting but doesn't effect the current
* value.
*/
public void stop() {
ByteBuffer status = ByteBuffer.allocateDirect(4);
status.order(ByteOrder.LITTLE_ENDIAN);
CounterJNI.stopCounter(m_counter, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
}
/**
* Set the maximum period where the device is still considered "moving".
* Sets the maximum period where the device is considered moving. This value

View File

@@ -11,6 +11,9 @@ package edu.wpi.first.wpilibj;
* Interface for counting the number of ticks on a digital input channel.
* Encoders, Gear tooth sensors, and counters should all subclass this so it can be used to
* build more advanced classes for control and driving.
*
* All counters will immediately start counting - reset() them if you need them
* to be zeroed before use.
*/
public interface CounterBase {
@@ -44,11 +47,6 @@ public interface CounterBase {
}
}
/**
* Start the counter
*/
public void start();
/**
* Get the count
* @return the count
@@ -60,11 +58,6 @@ public interface CounterBase {
*/
void reset();
/**
* Stop counting
*/
void stop();
/**
* Get the time between the last two edges counted
* @return the time beteween the last two ticks in seconds

View File

@@ -28,6 +28,9 @@ import edu.wpi.first.wpilibj.util.BoundaryException;
* mounted such that forward movement generates negative values. Quadrature
* encoders have two digital outputs, an A Channel and a B Channel that are out
* of phase with each other to allow the FPGA to do direction sensing.
*
* All encoders will immediately start counting - reset() them if you need them
* to be zeroed before use.
*/
public class Encoder extends SensorBase implements CounterBase, PIDSource, LiveWindowSendable {
@@ -58,6 +61,8 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource, LiveW
* Common initialization code for Encoders. This code allocates resources
* for Encoders and is common to all constructors.
*
* The encoder will start counting immediately.
*
* @param reverseDirection
* If true, counts down instead of up (this is all relative)
* @param encodingType
@@ -102,11 +107,21 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource, LiveW
UsageReporting.report(tResourceType.kResourceType_Encoder,
m_index, m_encodingType.value);
LiveWindow.addSensor("Encoder", m_aSource.getChannelForRouting(), this);
if (m_counter == null) {
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
EncoderJNI.startEncoder(m_encoder, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
}
}
/**
* Encoder constructor. Construct a Encoder given a and b channels.
*
* The encoder will start counting immediately.
*
* @param aChannel
* The a channel digital input channel.
* @param bChannel
@@ -129,6 +144,8 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource, LiveW
/**
* Encoder constructor. Construct a Encoder given a and b channels.
*
* The encoder will start counting immediately.
*
* @param aChannel
* The a channel digital input channel.
* @param bChannel
@@ -141,6 +158,8 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource, LiveW
/**
* Encoder constructor. Construct a Encoder given a and b channels.
*
* The encoder will start counting immediately.
*
* @param aChannel
* The a channel digital input channel.
* @param bChannel
@@ -175,6 +194,8 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource, LiveW
* Encoder constructor. Construct a Encoder given a and b channels.
* Using an index pulse forces 4x encoding
*
* The encoder will start counting immediately.
*
* @param aChannel
* The a channel digital input channel.
* @param bChannel
@@ -201,6 +222,8 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource, LiveW
* Encoder constructor. Construct a Encoder given a and b channels.
* Using an index pulse forces 4x encoding
*
* The encoder will start counting immediately.
*
* @param aChannel
* The a channel digital input channel.
* @param bChannel
@@ -219,6 +242,8 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource, LiveW
* shared. The Encoder class will not allocate the digital inputs and assume
* that they already are counted.
*
* The encoder will start counting immediately.
*
* @param aSource
* The source that should be used for the a channel.
* @param bSource
@@ -248,6 +273,8 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource, LiveW
* shared. The Encoder class will not allocate the digital inputs and assume
* that they already are counted.
*
* The encoder will start counting immediately.
*
* @param aSource
* The source that should be used for the a channel.
* @param bSource
@@ -263,6 +290,8 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource, LiveW
* shared. The Encoder class will not allocate the digital inputs and assume
* that they already are counted.
*
* The encoder will start counting immediately.
*
* @param aSource
* The source that should be used for the a channel.
* @param bSource
@@ -304,6 +333,8 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource, LiveW
* shared. The Encoder class will not allocate the digital inputs and assume
* that they already are counted.
*
* The encoder will start counting immediately.
*
* @param aSource
* The source that should be used for the a channel.
* @param bSource
@@ -337,6 +368,8 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource, LiveW
* shared. The Encoder class will not allocate the digital inputs and assume
* that they already are counted.
*
* The encoder will start counting immediately.
*
* @param aSource
* The source that should be used for the a channel.
* @param bSource
@@ -378,36 +411,6 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource, LiveW
}
}
/**
* Start the Encoder. Starts counting pulses on the Encoder device.
*/
public void start() {
if (m_counter != null) {
m_counter.start();
} else {
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
EncoderJNI.startEncoder(m_encoder, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
}
}
/**
* Stops counting pulses on the Encoder device. The value is not changed.
*/
public void stop() {
if (m_counter != null) {
m_counter.stop();
} else {
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
EncoderJNI.stopEncoder(m_encoder, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
}
}
/**
* Gets the raw value from the encoder. The raw value is the actual count
* unscaled by the 1x, 2x, or 4x scale factor.

View File

@@ -125,7 +125,6 @@ public class Ultrasonic extends SensorBase implements PIDSource, LiveWindowSenda
m_counter.setMaxPeriod(1.0);
m_counter.setSemiPeriodMode(true);
m_counter.reset();
m_counter.start();
m_enabled = true; // make it available for round robin scheduling
setAutomaticMode(originalMode);