edu.wpi.first.wpilibj
Class DigitalModule

java.lang.Object
  extended by edu.wpi.first.wpilibj.SensorBase
      extended by edu.wpi.first.wpilibj.Module
          extended by edu.wpi.first.wpilibj.DigitalModule
All Implemented Interfaces:
FrcBotSimComponent

public class DigitalModule
extends Module

Class representing a digital module

Author:
dtjones

Field Summary
static int kExpectedLoopTiming
          Expected loop timing
 
Fields inherited from class edu.wpi.first.wpilibj.Module
m_hwModule, m_moduleNumber, m_moduleType
 
Fields inherited from class edu.wpi.first.wpilibj.SensorBase
kAnalogChannels, kAnalogModules, kDigitalChannels, kPwmChannels, kRelayChannels, kSolenoidChannels, kSolenoidModules, kSystemClockTicksPerMicrosecond, n_simProperties
 
Constructor Summary
protected DigitalModule(int moduleNumber)
          Create a new digital module

 
Method Summary
 boolean allocateDIO(int channel, boolean input)
          Allocate Digital I/O channels.
 int allocateDO_PWM()
          Allocate a DO PWM Generator.
 void freeDIO(int channel)
          Free the resource associated with a digital I/O channel.
 void freeDO_PWM(int pwmGenerator)
          Free the resource associated with a DO PWM generator.
 short getAllDIO()
          Read the state of all the Digital I/O lines from the FPGA These are not remapped to logical order.
 boolean getDIO(int channel)
          Read a digital I/O bit from the FPGA.
 short getDIODirection()
          Read the direction of all the Digital I/O lines from the FPGA A 1 bit means output and a 0 bit means input.
 boolean getDIODirection(int channel)
          Read the direction of a digital I/O line

 I2C getI2C(int address)
          Return an I2C object for this digital module

static DigitalModule getInstance(int moduleNumber)
          Get an instance of an Digital Module.
 int getPWM(int channel)
          Get a value from a PWM channel.
 byte getRelayForward()
          Get the current state of all of the forward relay channels on this module.
 boolean getRelayForward(int channel)
          Get the current state of the forward relay channel

 byte getRelayReverse()
          Get the current state of all of the reverse relay channels on this module.
 boolean getRelayReverse(int channel)
          Get the current state of the reverse relay channel

 boolean isPulsing()
          Check if any DIO line is currently generating a pulse.
 boolean isPulsing(int channel)
          Check a DIO line to see if it is currently generating a pulse.
 void pulse(int channel, int pulseLength)
          Generate a single pulse.
static int remapDigitalChannel(int channel)
          Convert a channel to its fpga reference

 void setDIO(int channel, boolean value)
          Write a digital I/O bit to the FPGA.
 void setDO_PWMDutyCycle(int pwmGenerator, double dutyCycle)
          Configure the duty-cycle of the PWM generator

 void setDO_PWMOutputChannel(int pwmGenerator, int channel)
          Configure which DO channel the PWM siganl is output on

 void setDO_PWMRate(double rate)
          Change the frequency of the DO PWM generator.
 void setPWM(int channel, int value)
          Set a PWM channel to the desired value.
 void setPWMPeriodScale(int channel, int squelchMask)
          Set how how often the PWM signal is squelched, thus scaling the period.
 void setRelayForward(int channel, boolean on)
          Set the state of a relay.
 void setRelayReverse(int channel, boolean on)
          Set the state of a relay.
static int unmapDigitalChannel(int channel)
          Convert a channel from it's fpge reference

 
Methods inherited from class edu.wpi.first.wpilibj.Module
getModule, getModuleNumber, getModuleType
 
Methods inherited from class edu.wpi.first.wpilibj.SensorBase
checkAnalogChannel, checkAnalogModule, checkDigitalChannel, checkDigitalModule, checkPWMChannel, checkPWMModule, checkRelayChannel, checkRelayModule, checkSolenoidChannel, checkSolenoidModule, free, getDefaultAnalogModule, getDefaultDigitalModule, getDefaultSolenoidModule, getSimProperties, setDefaultAnalogModule, setDefaultDigitalModule, setDefaultSolenoidModule
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

kExpectedLoopTiming

public static final int kExpectedLoopTiming
Expected loop timing

See Also:
Constant Field Values
Constructor Detail

DigitalModule

protected DigitalModule(int moduleNumber)
Create a new digital module

Parameters:
moduleNumber - The number of the digital module to use (1 or 2)
Method Detail

getInstance

public static DigitalModule getInstance(int moduleNumber)
Get an instance of an Digital Module. Singleton digital module creation where a module is allocated on the first use and the same module is returned on subsequent uses.

Parameters:
moduleNumber - The number of the digital module to access.

Returns:
The digital module of the specified number.

remapDigitalChannel

public static int remapDigitalChannel(int channel)
Convert a channel to its fpga reference

Parameters:
channel - the channel to convert

Returns:
the converted channel

unmapDigitalChannel

public static int unmapDigitalChannel(int channel)
Convert a channel from it's fpge reference

Parameters:
channel - the channel to convert

Returns:
the converted channel

setPWM

public void setPWM(int channel,
                   int value)
Set a PWM channel to the desired value. The values range from 0 to 255 and the period is controlled by the PWM Period and MinHigh registers.

Parameters:
channel - The PWM channel to set.
value - The PWM value to set.

getPWM

public int getPWM(int channel)
Get a value from a PWM channel. The values range from 0 to 255.

Parameters:
channel - The PWM channel to read from.

Returns:
The raw PWM value.

setPWMPeriodScale

public void setPWMPeriodScale(int channel,
                              int squelchMask)
Set how how often the PWM signal is squelched, thus scaling the period.

Parameters:
channel - The PWM channel to configure.
squelchMask - The 2-bit mask of outputs to squelch.

setRelayForward

public void setRelayForward(int channel,
                            boolean on)
Set the state of a relay. Set the state of a relay output to be forward. Relays have two outputs and each is independently set to 0v or 12v.

Parameters:
channel - The Relay channel.
on - Indicates whether to set the relay to the On state.

setRelayReverse

public void setRelayReverse(int channel,
                            boolean on)
Set the state of a relay. Set the state of a relay output to be reverse. Relays have two outputs and each is independently set to 0v or 12v.

Parameters:
channel - The Relay channel.
on - Indicates whether to set the relay to the On state.

getRelayForward

public boolean getRelayForward(int channel)
Get the current state of the forward relay channel

Parameters:
channel - the channel of the relay to get

Returns:
The current state of the relay.

getRelayForward

public byte getRelayForward()
Get the current state of all of the forward relay channels on this module.

Returns:
The state of all forward relay channels as a byte.

getRelayReverse

public boolean getRelayReverse(int channel)
Get the current state of the reverse relay channel

Parameters:
channel - the channel of the relay to get

Returns:
The current statte of the relay

getRelayReverse

public byte getRelayReverse()
Get the current state of all of the reverse relay channels on this module.

Returns:
The state of all forward relay channels as a byte.

allocateDIO

public boolean allocateDIO(int channel,
                           boolean input)
Allocate Digital I/O channels. Allocate channels so that they are not accidently reused. Also the direction is set at the time of the allocation.

Parameters:
channel - The channel to allocate.
input - Indicates whether the I/O pin is an input (true) or an output (false).

Returns:
True if the I/O pin was allocated, false otherwise.

freeDIO

public void freeDIO(int channel)
Free the resource associated with a digital I/O channel.

Parameters:
channel - The channel whose resources should be freed.

setDIO

public void setDIO(int channel,
                   boolean value)
Write a digital I/O bit to the FPGA. Set a single value on a digital I/O channel.

Parameters:
channel - The channel to set.
value - The value to set.

getDIO

public boolean getDIO(int channel)
Read a digital I/O bit from the FPGA. Get a single value from a digital I/O channel.

Parameters:
channel - The channel to read

Returns:
The value of the selected channel

getAllDIO

public short getAllDIO()
Read the state of all the Digital I/O lines from the FPGA These are not remapped to logical order. They are still in hardware order.

Returns:
The state of all the Digital IO lines in hardware order

getDIODirection

public boolean getDIODirection(int channel)
Read the direction of a digital I/O line

Parameters:
channel - The channel of the DIO to get the direction of.

Returns:
True if the digital channel is configured as an output, false if it is an input

getDIODirection

public short getDIODirection()
Read the direction of all the Digital I/O lines from the FPGA A 1 bit means output and a 0 bit means input. These are not remapped to logical order. They are still in hardware order.

Returns:
The direction of all the Digital IO lines in hardware order

pulse

public void pulse(int channel,
                  int pulseLength)
Generate a single pulse. Write a pulse to the specified digital output channel. There can only be a single pulse going at any time.

Parameters:
channel - The channel to pulse.
pulseLength - The length of the pulse.

isPulsing

public boolean isPulsing(int channel)
Check a DIO line to see if it is currently generating a pulse.

Parameters:
channel - The channel to check.

Returns:
True if the channel is pulsing, false otherwise.

isPulsing

public boolean isPulsing()
Check if any DIO line is currently generating a pulse.

Returns:
True if any channel is pulsing, false otherwise.

allocateDO_PWM

public int allocateDO_PWM()
Allocate a DO PWM Generator. Allocate PWM generators so that they are not accidently reused.


freeDO_PWM

public void freeDO_PWM(int pwmGenerator)
Free the resource associated with a DO PWM generator.


setDO_PWMRate

public void setDO_PWMRate(double rate)
Change the frequency of the DO PWM generator.

The valid range is from 0.6 Hz to 19 kHz. The frequency resolution is logarithmic.

Parameters:
rate - The frequency to output all digital output PWM signals on this module.

setDO_PWMOutputChannel

public void setDO_PWMOutputChannel(int pwmGenerator,
                                   int channel)
Configure which DO channel the PWM siganl is output on

Parameters:
pwmGenerator - The generator index reserved by allocateDO_PWM()
channel - The Digital Output channel to output on

setDO_PWMDutyCycle

public void setDO_PWMDutyCycle(int pwmGenerator,
                               double dutyCycle)
Configure the duty-cycle of the PWM generator

Parameters:
pwmGenerator - The generator index reserved by allocateDO_PWM()
dutyCycle - The percent duty cycle to output [0..1].

getI2C

public I2C getI2C(int address)
Return an I2C object for this digital module

Parameters:
address - The device address.

Returns:
The associated I2C object.