2010 FRC Java API


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

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_modules, m_slot
 
Fields inherited from class edu.wpi.first.wpilibj.SensorBase
kAnalogChannels, kAnalogModules, kChassisSlots, kDigitalChannels, kPwmChannels, kRelayChannels, kSolenoidChannels, kSolenoidModules, kSystemClockTicksPerMicrosecond
 
Constructor Summary
protected DigitalModule(int slot)
          Create a neew digital module
 
Method Summary
 boolean allocateDIO(int channel, boolean input)
          Allocate Digital I/O channels.
 void freeDIO(int channel)
          Free the resource associated with a digital I/O channel.
 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 slot)
          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 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 slotToIndex(int slot)
          Convert a slot to a module index
static int unmapDigitalChannel(int channel)
          Convert a channel from it's fpge reference
 
Methods inherited from class edu.wpi.first.wpilibj.Module
getSlot
 
Methods inherited from class edu.wpi.first.wpilibj.SensorBase
checkAnalogChannel, checkAnalogModule, checkDigitalChannel, checkDigitalModule, checkPWMChannel, checkPWMModule, checkRelayChannel, checkRelayModule, checkSolenoidChannel, checkSolenoidModule, free, getDefaultAnalogModule, getDefaultDigitalModule, getDefaultSolenoidModule, setDefaultAnalogModule, setDefaultDigitalModule, setDefaultSolenoidModule
 
Methods inherited from class java.lang.Object
equals, 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 slot)
Create a neew digital module

Parameters:
slot - the slot where the module is located
Method Detail

getInstance

public static DigitalModule getInstance(int slot)
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:
slot - The cRIO slot to access.
Returns:
The digital module attached to the slot specified.

slotToIndex

public static int slotToIndex(int slot)
Convert a slot to a module index

Parameters:
slot -
Returns:
the index

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.

getI2C

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

Parameters:
address - The device address.
Returns:
The associated I2C object.

2010 FRC Java API


Copyright © 2006-2009 Sun Microsystems, Inc. All Rights Reserved.