Replaced wpilibj class Init() methods with delegating constructors (#79)

This commit is contained in:
Tyler Veness
2016-05-27 00:06:47 -07:00
committed by Peter Johnson
parent c622c03eff
commit 613309c0a2
22 changed files with 147 additions and 301 deletions

View File

@@ -20,25 +20,12 @@ import edu.wpi.first.wpilibj.tables.ITable;
* @author Colby Skeggs (rail voltage)
*/
public class AnalogPotentiometer implements Potentiometer, LiveWindowSendable {
private double m_fullRange;
private double m_offset;
private AnalogInput m_analogInput;
private boolean m_initAnalogInput;
private double m_fullRange;
private double m_offset;
protected PIDSourceType m_pidSource = PIDSourceType.kDisplacement;
/**
* Common initialization code called by all constructors.
*
* @param input The {@link AnalogInput} this potentiometer is plugged into.
* @param fullRange 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
*/
private void initPot(final AnalogInput input, double fullRange, double offset) {
m_fullRange = fullRange;
m_offset = offset;
m_analogInput = input;
}
/**
* AnalogPotentiometer constructor.
*
@@ -53,9 +40,8 @@ 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 fullRange, double offset) {
AnalogInput input = new AnalogInput(channel);
this(new AnalogInput(channel), fullRange, offset);
m_initAnalogInput = true;
initPot(input, fullRange, offset);
}
/**
@@ -72,8 +58,11 @@ public class AnalogPotentiometer implements Potentiometer, LiveWindowSendable {
* @param offset The offset to add to the scaled value for controlling the zero value
*/
public AnalogPotentiometer(final AnalogInput input, double fullRange, double offset) {
m_analogInput = input;
m_initAnalogInput = false;
initPot(input, fullRange, offset);
m_fullRange = fullRange;
m_offset = offset;
}
/**

View File

@@ -16,6 +16,8 @@ import edu.wpi.first.wpilibj.communication.UsageReporting;
import edu.wpi.first.wpilibj.hal.AnalogJNI;
import edu.wpi.first.wpilibj.util.BoundaryException;
import static java.util.Objects.requireNonNull;
/**
* Class for creating and configuring Analog Triggers.
*
@@ -46,11 +48,11 @@ public class AnalogTrigger {
protected int m_index;
/**
* Initialize an analog trigger from a channel.
* Constructor for an analog trigger given a channel number.
*
* @param channel the port to use for the analog trigger
*/
protected void initTrigger(final int channel) {
public AnalogTrigger(final int channel) {
final long portPointer = AnalogJNI.getPort((byte) channel);
ByteBuffer index = ByteBuffer.allocateDirect(4);
index.order(ByteOrder.LITTLE_ENDIAN);
@@ -62,16 +64,6 @@ public class AnalogTrigger {
UsageReporting.report(tResourceType.kResourceType_AnalogTrigger, channel);
}
/**
* Constructor for an analog trigger given a channel number.
*
* @param channel the port to use for the analog trigger 0-3 are on-board, 4-7 are on the MXP
* port
*/
public AnalogTrigger(final int 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.
@@ -79,10 +71,7 @@ public class AnalogTrigger {
* @param channel the AnalogInput to use for the analog trigger
*/
public AnalogTrigger(AnalogInput channel) {
if (channel == null) {
throw new NullPointerException("The Analog Input given was null");
}
initTrigger(channel.getChannel());
this(requireNonNull(channel, "The Analog Input given was null").getChannel());
}
/**

View File

@@ -24,15 +24,17 @@ public class Compressor extends SensorBase implements LiveWindowSendable {
private long m_pcm;
/**
* Create an instance of the Compressor.
* Constructor.
*
* <p>Most robots that use PCM will have a single module. Use this for supporting a second module
* other than the default.
*
* @param pcmId The PCM CAN device ID.
* @param module The PCM CAN device ID.
*/
public Compressor(int pcmId) {
initCompressor(pcmId);
public Compressor(int module) {
m_table = null;
m_pcm = CompressorJNI.initializeCompressor((byte) module);
}
/**
@@ -41,13 +43,7 @@ public class Compressor extends SensorBase implements LiveWindowSendable {
* ID.
*/
public Compressor() {
initCompressor(getDefaultSolenoidModule());
}
private void initCompressor(int module) {
m_table = null;
m_pcm = CompressorJNI.initializeCompressor((byte) module);
this(getDefaultSolenoidModule());
}
/**

View File

@@ -70,7 +70,10 @@ public class Counter extends SensorBase implements CounterBase, LiveWindowSendab
private PIDSourceType m_pidSource;
private double m_distancePerPulse; // distance of travel for each tick
private void initCounter(final Mode mode) {
/**
* Create an instance of a counter with the given mode.
*/
public Counter(final Mode mode) {
ByteBuffer index = ByteBuffer.allocateDirect(4);
// set the byte order
index.order(ByteOrder.LITTLE_ENDIAN);
@@ -94,7 +97,7 @@ public class Counter extends SensorBase implements CounterBase, LiveWindowSendab
* <p>The counter will start counting immediately.
*/
public Counter() {
initCounter(Mode.kTwoPulse);
this(Mode.kTwoPulse);
}
/**
@@ -107,10 +110,10 @@ public class Counter extends SensorBase implements CounterBase, LiveWindowSendab
* @param source the digital source to count
*/
public Counter(DigitalSource source) {
this();
if (source == null) {
throw new NullPointerException("Digital Source given was null");
}
initCounter(Mode.kTwoPulse);
setUpSource(source);
}
@@ -122,7 +125,7 @@ public class Counter extends SensorBase implements CounterBase, LiveWindowSendab
* @param channel the DIO channel to use as the up source. 0-9 are on-board, 10-25 are on the MXP
*/
public Counter(int channel) {
initCounter(Mode.kTwoPulse);
this();
setUpSource(channel);
}
@@ -139,11 +142,10 @@ public class Counter extends SensorBase implements CounterBase, LiveWindowSendab
*/
public Counter(EncodingType encodingType, DigitalSource upSource, DigitalSource downSource,
boolean inverted) {
initCounter(Mode.kExternalDirection);
this(Mode.kExternalDirection);
if (encodingType == null) {
throw new NullPointerException("Encoding type given was null");
}
if (encodingType != EncodingType.k1X && encodingType != EncodingType.k2X) {
throw new RuntimeException("Counters only support 1X and 2X quadreature decoding!");
}
@@ -176,10 +178,10 @@ public class Counter extends SensorBase implements CounterBase, LiveWindowSendab
* @param trigger the analog trigger to count
*/
public Counter(AnalogTrigger trigger) {
this();
if (trigger == null) {
throw new NullPointerException("The Analog Trigger given was null");
}
initCounter(Mode.kTwoPulse);
setUpSource(trigger.createOutput(AnalogTriggerType.kState));
}

View File

@@ -39,9 +39,28 @@ public class DoubleSolenoid extends SolenoidBase implements LiveWindowSendable {
private byte m_reverseMask; // /< The mask for the reverse channel.
/**
* Common function to implement constructor behavior.
* Constructor. Uses the default PCM ID of 0.
*
* @param forwardChannel The forward channel number on the PCM (0..7).
* @param reverseChannel The reverse channel number on the PCM (0..7).
*/
private synchronized void initSolenoid() {
public DoubleSolenoid(final int forwardChannel, final int reverseChannel) {
this(getDefaultSolenoidModule(), forwardChannel, reverseChannel);
}
/**
* Constructor.
*
* @param moduleNumber The module number of the solenoid module to use.
* @param forwardChannel The forward channel on the module to control (0..7).
* @param reverseChannel The reverse channel on the module to control (0..7).
*/
public DoubleSolenoid(final int moduleNumber, final int forwardChannel,
final int reverseChannel) {
super(moduleNumber);
m_forwardChannel = forwardChannel;
m_reverseChannel = reverseChannel;
checkSolenoidModule(m_moduleNumber);
checkSolenoidChannel(m_forwardChannel);
checkSolenoidChannel(m_reverseChannel);
@@ -66,34 +85,6 @@ public class DoubleSolenoid extends SolenoidBase implements LiveWindowSendable {
LiveWindow.addActuator("DoubleSolenoid", m_moduleNumber, m_forwardChannel, this);
}
/**
* Constructor. Uses the default PCM ID of 0.
*
* @param forwardChannel The forward channel number on the PCM (0..7).
* @param reverseChannel The reverse channel number on the PCM (0..7).
*/
public DoubleSolenoid(final int forwardChannel, final int reverseChannel) {
super(getDefaultSolenoidModule());
m_forwardChannel = forwardChannel;
m_reverseChannel = reverseChannel;
initSolenoid();
}
/**
* Constructor.
*
* @param moduleNumber The module number of the solenoid module to use.
* @param forwardChannel The forward channel on the module to control (0..7).
* @param reverseChannel The reverse channel on the module to control (0..7).
*/
public DoubleSolenoid(final int moduleNumber, final int forwardChannel,
final int reverseChannel) {
super(moduleNumber);
m_forwardChannel = forwardChannel;
m_reverseChannel = reverseChannel;
initSolenoid();
}
/**
* Destructor.
*/

View File

@@ -19,9 +19,14 @@ import edu.wpi.first.wpilibj.livewindow.LiveWindow;
public class Jaguar extends PWMSpeedController {
/**
* Common initialization code called by all constructors.
* Constructor.
*
* @param channel The PWM channel that the Jaguar is attached to. 0-9 are on-board, 10-19 are on
* the MXP port
*/
private void initJaguar() {
public Jaguar(final int channel) {
super(channel);
/*
* Input profile defined by Luminary Micro.
*
@@ -38,15 +43,4 @@ public class Jaguar extends PWMSpeedController {
UsageReporting.report(tResourceType.kResourceType_Jaguar, getChannel());
LiveWindow.addActuator("Jaguar", getChannel(), this);
}
/**
* Constructor.
*
* @param channel The PWM channel that the Jaguar is attached to. 0-9 are on-board, 10-19 are on
* the MXP port
*/
public Jaguar(final int channel) {
super(channel);
initJaguar();
}
}

View File

@@ -98,15 +98,11 @@ public class PWM extends SensorBase implements LiveWindowSendable {
private int m_minPwm;
/**
* Initialize PWMs given a channel.
*
* <p>This method is private and is the common path for all the constructors for creating PWM
* instances. Checks channel value ranges and allocates the appropriate channel. The allocation is
* only done to help users ensure that they don't double assign channels.
* Allocate a PWM given a channel.
*
* @param channel The PWM channel number. 0-9 are on-board, 10-19 are on the MXP port
*/
private void initPWM(final int channel) {
public PWM(final int channel) {
checkPWMChannel(channel);
m_channel = channel;
@@ -123,15 +119,6 @@ public class PWM extends SensorBase implements LiveWindowSendable {
UsageReporting.report(tResourceType.kResourceType_PWM, channel);
}
/**
* Allocate a PWM given a channel.
*
* @param channel The PWM channel.
*/
public PWM(final int channel) {
initPWM(channel);
}
/**
* Free the PWM channel.
*

View File

@@ -24,6 +24,7 @@ public class SafePWM extends PWM implements MotorSafety {
*/
public SafePWM(final int channel) {
super(channel);
m_safetyHelper = new MotorSafetyHelper(this);
m_safetyHelper.setExpiration(0.0);
m_safetyHelper.setSafetyEnabled(false);

View File

@@ -27,20 +27,6 @@ public class Servo extends PWM {
protected static final double kDefaultMaxServoPWM = 2.4;
protected static final double kDefaultMinServoPWM = .6;
/**
* Common initialization code called by all constructors.
*
* <p>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", getChannel(), this);
UsageReporting.report(tResourceType.kResourceType_Servo, getChannel());
}
/**
* Constructor.<br>
*
@@ -52,7 +38,11 @@ public class Servo extends PWM {
*/
public Servo(final int channel) {
super(channel);
initServo();
setBounds(kDefaultMaxServoPWM, 0, 0, 0, kDefaultMinServoPWM);
setPeriodMultiplier(PeriodMultiplier.k4X);
LiveWindow.addActuator("Servo", getChannel(), this);
UsageReporting.report(tResourceType.kResourceType_Servo, getChannel());
}

View File

@@ -28,36 +28,13 @@ public class Solenoid extends SolenoidBase implements LiveWindowSendable {
private final int m_channel; // /< The channel to control.
private long m_solenoidPort;
/**
* Common function to implement constructor behavior.
*/
private synchronized void initSolenoid() {
checkSolenoidModule(m_moduleNumber);
checkSolenoidChannel(m_channel);
try {
allocated.allocate(m_moduleNumber * kSolenoidChannels + m_channel);
} catch (CheckedAllocationException ex) {
throw new AllocationException("Solenoid channel " + m_channel + " on module "
+ m_moduleNumber + " is already allocated");
}
long port = SolenoidJNI.getPortWithModule((byte) m_moduleNumber, (byte) m_channel);
m_solenoidPort = SolenoidJNI.initializeSolenoidPort(port);
LiveWindow.addActuator("Solenoid", m_moduleNumber, m_channel, this);
UsageReporting.report(tResourceType.kResourceType_Solenoid, m_channel, m_moduleNumber);
}
/**
* Constructor using the default PCM ID (0)
*
* @param channel The channel on the PCM to control (0..7).
*/
public Solenoid(final int channel) {
super(getDefaultSolenoidModule());
m_channel = channel;
initSolenoid();
this(getDefaultSolenoidModule(), channel);
}
/**
@@ -69,7 +46,22 @@ public class Solenoid extends SolenoidBase implements LiveWindowSendable {
public Solenoid(final int moduleNumber, final int channel) {
super(moduleNumber);
m_channel = channel;
initSolenoid();
checkSolenoidModule(m_moduleNumber);
checkSolenoidChannel(m_channel);
try {
allocated.allocate(m_moduleNumber * kSolenoidChannels + m_channel);
} catch (CheckedAllocationException ex) {
throw new AllocationException("Solenoid channel " + m_channel + " on module "
+ m_moduleNumber + " is already allocated");
}
long port = SolenoidJNI.getPortWithModule((byte) m_moduleNumber, (byte) m_channel);
m_solenoidPort = SolenoidJNI.initializeSolenoidPort(port);
LiveWindow.addActuator("Solenoid", m_moduleNumber, m_channel, this);
UsageReporting.report(tResourceType.kResourceType_Solenoid, m_channel, m_moduleNumber);
}
/**

View File

@@ -17,7 +17,7 @@ import edu.wpi.first.wpilibj.livewindow.LiveWindow;
public class Talon extends PWMSpeedController {
/**
* Common initialization code called by all constructors.
* Constructor for a Talon (original or Talon SR).
*
* <p>Note that the Talon uses the following bounds for PWM values. These values should work
* reasonably well for most controllers, but if users experience issues such as asymmetric
@@ -28,8 +28,13 @@ public class Talon extends PWMSpeedController {
* <p>- 2.037ms = full "forward" - 1.539ms = the "high end" of the deadband range - 1.513ms =
* center of the deadband range (off) - 1.487ms = the "low end" of the deadband range - .989ms
* = full "reverse"
*
* @param channel The PWM channel that the Talon is attached to. 0-9 are on-board, 10-19 are on
* the MXP port
*/
private void initTalon() {
public Talon(final int channel) {
super(channel);
setBounds(2.037, 1.539, 1.513, 1.487, .989);
setPeriodMultiplier(PeriodMultiplier.k1X);
setRaw(m_centerPwm);
@@ -38,15 +43,4 @@ public class Talon extends PWMSpeedController {
LiveWindow.addActuator("Talon", getChannel(), this);
UsageReporting.report(tResourceType.kResourceType_Talon, getChannel());
}
/**
* Constructor for a Talon (original or Talon SR).
*
* @param channel The PWM channel that the Talon is attached to. 0-9 are on-board, 10-19 are on
* the MXP port
*/
public Talon(final int channel) {
super(channel);
initTalon();
}
}

View File

@@ -19,7 +19,7 @@ import edu.wpi.first.wpilibj.livewindow.LiveWindow;
public class TalonSRX extends PWMSpeedController {
/**
* Common initialization code called by all constructors.
* Constructor for a TalonSRX connected via PWM.
*
* <p>Note that the TalonSRX uses the following bounds for PWM values. These values should work
* reasonably well for most controllers, but if users experience issues such as asymmetric
@@ -31,8 +31,13 @@ public class TalonSRX extends PWMSpeedController {
* center
* of the deadband range (off) - 1.48ms = the "low end" of the deadband range - .997ms = full
* "reverse"
*
* @param channel The PWM channel that the TalonSRX is attached to. 0-9 are on-board, 10-19 are
* on the MXP port
*/
protected void initTalonSRX() {
public TalonSRX(final int channel) {
super(channel);
setBounds(2.004, 1.52, 1.50, 1.48, .997);
setPeriodMultiplier(PeriodMultiplier.k1X);
setRaw(m_centerPwm);
@@ -41,15 +46,4 @@ public class TalonSRX extends PWMSpeedController {
LiveWindow.addActuator("TalonSRX", getChannel(), this);
UsageReporting.report(tResourceType.kResourceType_TalonSRX, getChannel());
}
/**
* Constructor for a TalonSRX connected via PWM.
*
* @param channel The PWM channel that the TalonSRX is attached to. 0-9 are on-board, 10-19 are on
* the MXP port
*/
public TalonSRX(final int channel) {
super(channel);
initTalonSRX();
}
}

View File

@@ -18,7 +18,7 @@ import edu.wpi.first.wpilibj.livewindow.LiveWindow;
public class Victor extends PWMSpeedController {
/**
* Common initialization code called by all constructors.
* Constructor.
*
* <p>Note that the Victor uses the following bounds for PWM values. These values were determined
* empirically and optimized for the Victor 888. These values should work reasonably well for
@@ -30,8 +30,13 @@ public class Victor extends PWMSpeedController {
* <p>- 2.027ms = full "forward" - 1.525ms = the "high end" of the deadband range - 1.507ms =
* center of the deadband range (off) - 1.49ms = the "low end" of the deadband range - 1.026ms =
* full "reverse"
*
* @param channel The PWM channel that the Victor is attached to. 0-9 are
* on-board, 10-19 are on the MXP port
*/
private void initVictor() {
public Victor(final int channel) {
super(channel);
setBounds(2.027, 1.525, 1.507, 1.49, 1.026);
setPeriodMultiplier(PeriodMultiplier.k2X);
setRaw(m_centerPwm);
@@ -40,15 +45,4 @@ public class Victor extends PWMSpeedController {
LiveWindow.addActuator("Victor", getChannel(), this);
UsageReporting.report(tResourceType.kResourceType_Victor, getChannel());
}
/**
* Constructor.
*
* @param channel The PWM channel that the Victor is attached to. 0-9 are on-board, 10-19 are on
* the MXP port
*/
public Victor(final int channel) {
super(channel);
initVictor();
}
}

View File

@@ -17,7 +17,7 @@ import edu.wpi.first.wpilibj.livewindow.LiveWindow;
public class VictorSP extends PWMSpeedController {
/**
* Common initialization code called by all constructors.
* Constructor.
*
* <p>Note that the VictorSP uses the following bounds for PWM values. These values should work
* reasonably well for most controllers, but if users experience issues such as asymmetric
@@ -28,8 +28,13 @@ public class VictorSP extends PWMSpeedController {
* <p>- 2.004ms = full "forward" - 1.52ms = the "high end" of the deadband range - 1.50ms =
* center of the deadband range (off) - 1.48ms = the "low end" of the deadband range - .997ms =
* full "reverse"
*
* @param channel The PWM channel that the VictorSP is attached to. 0-9 are
* on-board, 10-19 are on the MXP port
*/
protected void initVictorSP() {
public VictorSP(final int channel) {
super(channel);
setBounds(2.004, 1.52, 1.50, 1.48, .997);
setPeriodMultiplier(PeriodMultiplier.k1X);
setRaw(m_centerPwm);
@@ -38,15 +43,4 @@ public class VictorSP extends PWMSpeedController {
LiveWindow.addActuator("VictorSP", getChannel(), this);
UsageReporting.report(tResourceType.kResourceType_VictorSP, getChannel());
}
/**
* Constructor.
*
* @param channel The PWM channel that the VictorSP is attached to. 0-9 are on-board, 10-19 are on
* the MXP port
*/
public VictorSP(final int channel) {
super(channel);
initVictorSP();
}
}

View File

@@ -24,19 +24,6 @@ public class AnalogPotentiometer implements Potentiometer, LiveWindowSendable {
private boolean m_init_analog_input;
protected PIDSourceType m_pidSource = PIDSourceType.kDisplacement;
/**
* Common initialization code called by all constructors.
*
* @param input The {@link AnalogInput} 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
*/
private void initPot(final AnalogInput input, double scale, double offset) {
this.m_scale = scale;
this.m_offset = offset;
m_analog_input = input;
}
/**
* AnalogPotentiometer constructor.
*
@@ -50,9 +37,8 @@ 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) {
AnalogInput input = new AnalogInput(channel);
this(new AnalogInput(channel), scale, offset);
m_init_analog_input = true;
initPot(input, scale, offset);
}
/**
@@ -69,7 +55,10 @@ public class AnalogPotentiometer implements Potentiometer, LiveWindowSendable {
*/
public AnalogPotentiometer(final AnalogInput input, double scale, double offset) {
m_init_analog_input = false;
initPot(input, scale, offset);
m_scale = scale;
m_offset = offset;
m_analog_input = input;
}
/**

View File

@@ -45,25 +45,6 @@ public class DoubleSolenoid implements LiveWindowSendable {
private SimSpeedController m_impl;
private Value m_value;
/**
* Common function to implement constructor behavior.
*/
private synchronized void initSolenoid(int moduleNumber, int forwardChannel, int reverseChannel) {
m_forwardChannel = forwardChannel;
m_reverseChannel = reverseChannel;
m_moduleNumber = moduleNumber;
// LiveWindow.addActuator("DoubleSolenoid", m_moduleNumber, m_forwardChannel, this);
if (reverseChannel < forwardChannel) { // Swap ports
int channel = forwardChannel;
forwardChannel = reverseChannel;
reverseChannel = channel;
m_reverseDirection = true;
}
m_impl = new SimSpeedController("simulator/pneumatic/" + moduleNumber + "/" + forwardChannel
+ "/" + moduleNumber + "/" + reverseChannel);
}
/**
* Constructor.
*
@@ -71,7 +52,7 @@ public class DoubleSolenoid implements LiveWindowSendable {
* @param reverseChannel The reverse channel on the module to control.
*/
public DoubleSolenoid(final int forwardChannel, final int reverseChannel) {
initSolenoid(1, forwardChannel, reverseChannel);
this(1, forwardChannel, reverseChannel);
}
/**
@@ -83,7 +64,17 @@ public class DoubleSolenoid implements LiveWindowSendable {
*/
public DoubleSolenoid(final int moduleNumber, final int forwardChannel, final int
reverseChannel) {
initSolenoid(moduleNumber, forwardChannel, reverseChannel);
m_moduleNumber = moduleNumber;
// LiveWindow.addActuator("DoubleSolenoid", m_moduleNumber, m_forwardChannel, this);
if (reverseChannel < forwardChannel) { // Swap ports
int channel = forwardChannel;
m_forwardChannel = reverseChannel;
m_reverseChannel = channel;
m_reverseDirection = true;
}
m_impl = new SimSpeedController("simulator/pneumatic/" + moduleNumber + "/" + forwardChannel
+ "/" + moduleNumber + "/" + reverseChannel);
}
/**

View File

@@ -21,9 +21,11 @@ public class Jaguar implements SpeedController, PIDOutput, MotorSafety, LiveWind
private SimSpeedController impl;
/**
* Common initialization code called by all constructors.
* Constructor.
*
* @param channel The PWM channel that the Jaguar is attached to.
*/
private void initJaguar(final int channel) {
public Jaguar(final int channel) {
this.channel = channel;
impl = new SimSpeedController("simulator/pwm/" + channel);
@@ -34,15 +36,6 @@ public class Jaguar implements SpeedController, PIDOutput, MotorSafety, LiveWind
LiveWindow.addActuator("Jaguar", channel, this);
}
/**
* Constructor.
*
* @param channel The PWM channel that the Jaguar is attached to.
*/
public Jaguar(final int channel) {
initJaguar(channel);
}
/**
* Set the PWM value.
*

View File

@@ -24,7 +24,6 @@ import edu.wpi.first.wpilibj.tables.ITableListener;
*/
public class Relay extends SensorBase implements MotorSafety, LiveWindowSendable {
private MotorSafetyHelper m_safetyHelper;
/**
* This class represents errors in trying to set relay values contradictory to the direction to
* which the relay is set.
@@ -146,9 +145,7 @@ public class Relay extends SensorBase implements MotorSafety, LiveWindowSendable
* @param channel The channel number for this relay.
*/
public Relay(final int channel) {
m_channel = channel;
m_direction = Direction.kBoth;
initRelay();
this(channel, Direction.kBoth);
}
public void free() {

View File

@@ -30,17 +30,6 @@ public class Servo implements SpeedController, LiveWindowSendable {
private SimSpeedController impl;
private int channel;
/**
* Common initialization code called by all constructors.
*
* 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() {
LiveWindow.addActuator("Servo", channel, this);
impl = new SimSpeedController("simulator/pwm/" + channel);
}
/**
* Write out the PID value as seen in the PIDOutput base object.
*
@@ -61,7 +50,8 @@ public class Servo implements SpeedController, LiveWindowSendable {
*/
public Servo(final int channel) {
this.channel = channel;
initServo();
LiveWindow.addActuator("Servo", channel, this);
impl = new SimSpeedController("simulator/pwm/" + channel);
}
private double getServoAngleRange() {

View File

@@ -25,24 +25,13 @@ public class Solenoid implements LiveWindowSendable {
private boolean m_value;
private SimSpeedController m_impl;
/**
* Common function to implement constructor behavior.
*/
private synchronized void initSolenoid(int slot, int channel) {
m_moduleNumber = slot;
m_channel = channel;
m_impl = new SimSpeedController("simulator/pneumatic/" + slot + "/" + channel);
LiveWindow.addActuator("Solenoid", m_moduleNumber, m_channel, this);
}
/**
* Constructor.
*
* @param channel The channel on the module to control.
*/
public Solenoid(final int channel) {
initSolenoid(1, channel);
this(1, channel);
}
/**
@@ -52,7 +41,11 @@ public class Solenoid implements LiveWindowSendable {
* @param channel The channel on the module to control.
*/
public Solenoid(final int moduleNumber, final int channel) {
initSolenoid(moduleNumber, channel);
m_moduleNumber = moduleNumber;
m_channel = channel;
m_impl = new SimSpeedController("simulator/pneumatic/" + moduleNumber + "/" + channel);
LiveWindow.addActuator("Solenoid", m_moduleNumber, m_channel, this);
}
/**

View File

@@ -21,7 +21,7 @@ public class Talon implements SpeedController, PIDOutput, MotorSafety, LiveWindo
private SimSpeedController m_impl;
/**
* Common initialization code called by all constructors.
* Constructor.
*
* <p>Note that the Talon uses the following bounds for PWM values. These values should work
* reasonably well for most controllers, but if users experience issues such as asymmetric
@@ -32,8 +32,10 @@ public class Talon implements SpeedController, PIDOutput, MotorSafety, LiveWindo
* <p>- 2.037ms = full "forward" - 1.539ms = the "high end" of the deadband range - 1.513ms =
* center of the deadband range (off) - 1.487ms = the "low end" of the deadband range - .989ms =
* full "reverse"
*
* @param channel The PWM channel that the Talon is attached to.
*/
private void initTalon(final int channel) {
public Talon(final int channel) {
this.m_channel = channel;
m_impl = new SimSpeedController("simulator/pwm/" + channel);
@@ -44,15 +46,6 @@ public class Talon implements SpeedController, PIDOutput, MotorSafety, LiveWindo
LiveWindow.addActuator("Talon", channel, this);
}
/**
* Constructor.
*
* @param channel The PWM channel that the Talon is attached to.
*/
public Talon(final int channel) {
initTalon(channel);
}
/**
* Set the PWM value.
*

View File

@@ -21,7 +21,7 @@ public class Victor implements SpeedController, PIDOutput, MotorSafety, LiveWind
private SimSpeedController m_impl;
/**
* Common initialization code called by all constructors.
* Constructor.
*
* <p>Note that the Victor uses the following bounds for PWM values. These values were determined
* empirically and optimized for the Victor 888. These values should work reasonably well for
@@ -33,8 +33,10 @@ public class Victor implements SpeedController, PIDOutput, MotorSafety, LiveWind
* <p>- 2.027ms = full "forward" - 1.525ms = the "high end" of the deadband range - 1.507ms = center
* of the deadband range (off) - 1.49ms = the "low end" of the deadband range - 1.026ms = full
* "reverse"
*
* @param channel The PWM channel that the Victor is attached to.
*/
private void initVictor(final int channel) {
public Victor(final int channel) {
this.m_channel = channel;
m_impl = new SimSpeedController("simulator/pwm/" + channel);
@@ -46,15 +48,6 @@ public class Victor implements SpeedController, PIDOutput, MotorSafety, LiveWind
// UsageReporting.report(tResourceType.kResourceType_Talon, getChannel(), getModuleNumber()-1);
}
/**
* Constructor.
*
* @param channel The PWM channel that the Victor is attached to.
*/
public Victor(final int channel) {
initVictor(channel);
}
/**
* Set the PWM value.
*