"

2013 FRC Java API

"

edu.wpi.first.wpilibj
Class PWM

java.lang.Object
  extended by edu.wpi.first.wpilibj.SensorBase
      extended by edu.wpi.first.wpilibj.PWM
All Implemented Interfaces:
LiveWindowSendable, Sendable
Direct Known Subclasses:
SafePWM, Servo

public class PWM
extends SensorBase
implements LiveWindowSendable

Class implements the PWM generation in the FPGA. Values supplied as arguments for PWM outputs range from -1.0 to 1.0. They are mapped to the hardware dependent values, in this case 0-255 for the FPGA. Changes are immediately sent to the FPGA, and the update occurs at the next FPGA cycle. There is no delay. As of revision 0.1.4 of the FPGA, the FPGA interprets the 0-255 values as follows: 255 = full "forward" 254 to 129 = linear scaling from "full forward" to "center" 128 = center value 127 to 2 = linear scaling from "center" to "full reverse" 1 = full "reverse" 0 = disabled (i.e. PWM output is held low)


Nested Class Summary
static class PWM.PeriodMultiplier
          Represents the amount to multiply the minimum servo-pulse pwm period by.
 
Field Summary
protected static double kDefaultPwmCenter
          kDefaultPwmCenter is the PWM range center in ms
protected static double kDefaultPwmPeriod
          kDefaultPwmPeriod is in ms - 20ms periods (50 Hz) are the "safest" setting in that this works for all devices - 20ms periods seem to be desirable for Vex Motors - 20ms periods are the specified period for HS-322HD servos, but work reliably down to 10.0 ms; starting at about 8.5ms, the servo sometimes hums and get hot; by 5.0ms the hum is nearly continuous - 10ms periods work well for Victor 884 - 5ms periods allows higher update rates for Luminary Micro Jaguar speed controllers.
protected static int kDefaultPwmStepsDown
          kDefaultPWMStepsDown is the number of PWM steps below the centerpoint
static int kPwmDisabled
           
 
Fields inherited from class edu.wpi.first.wpilibj.SensorBase
kAnalogChannels, kAnalogModules, kDigitalChannels, kPwmChannels, kRelayChannels, kSolenoidChannels, kSolenoidModules, kSystemClockTicksPerMicrosecond
 
Constructor Summary
PWM(int channel)
          Allocate a PWM in the default module given a channel.
PWM(int moduleNumber, int channel)
          Allocate a PWM given a module and channel.
 
Method Summary
 void enableDeadbandElimination(boolean eliminateDeadband)
          Optionally eliminate the deadband from a speed controller.
 void free()
          Free the PWM channel.
 int getChannel()
          Gets the channel number associated with the PWM Object.
 int getModuleNumber()
          Gets the module number associated with the PWM Object.
 double getPosition()
          Get the PWM value in terms of a position.
 int getRaw()
          Get the PWM value directly from the hardware.
 String getSmartDashboardType()
           
 double getSpeed()
          Get the PWM value in terms of speed.
 ITable getTable()
          
 void initTable(ITable subtable)
          Initializes a table for this sendable object.
 void setBounds(int max, int deadbandMax, int center, int deadbandMin, int min)
          Deprecated. Recommended to set bounds in ms using setBounds(double, double, double, double, double)
 void setPeriodMultiplier(PWM.PeriodMultiplier mult)
          Slow down the PWM signal for old devices.
 void setPosition(double pos)
          Set the PWM value based on a position.
 void setRaw(int value)
          Set the PWM value directly to the hardware.
 void startLiveWindowMode()
          Start having this sendable object automatically respond to value changes reflect the value on the table.
 void stopLiveWindowMode()
          Stop having this sendable object automatically respond to value changes.
 void updateTable()
          Update the table for this sendable object with the latest values.
 
Methods inherited from class edu.wpi.first.wpilibj.SensorBase
checkAnalogChannel, checkAnalogModule, checkDigitalChannel, checkDigitalModule, checkPWMChannel, checkPWMModule, checkRelayChannel, checkRelayModule, checkSolenoidChannel, checkSolenoidModule, getDefaultAnalogModule, getDefaultDigitalModule, getDefaultSolenoidModule, setDefaultAnalogModule, setDefaultDigitalModule, setDefaultSolenoidModule
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

kDefaultPwmPeriod

protected static final double kDefaultPwmPeriod
kDefaultPwmPeriod is in ms - 20ms periods (50 Hz) are the "safest" setting in that this works for all devices - 20ms periods seem to be desirable for Vex Motors - 20ms periods are the specified period for HS-322HD servos, but work reliably down to 10.0 ms; starting at about 8.5ms, the servo sometimes hums and get hot; by 5.0ms the hum is nearly continuous - 10ms periods work well for Victor 884 - 5ms periods allows higher update rates for Luminary Micro Jaguar speed controllers. Due to the shipping firmware on the Jaguar, we can't run the update period less than 5.05 ms. kDefaultPwmPeriod is the 1x period (5.05 ms). In hardware, the period scaling is implemented as an output squelch to get longer periods for old devices.

See Also:
Constant Field Values

kDefaultPwmCenter

protected static final double kDefaultPwmCenter
kDefaultPwmCenter is the PWM range center in ms

See Also:
Constant Field Values

kDefaultPwmStepsDown

protected static final int kDefaultPwmStepsDown
kDefaultPWMStepsDown is the number of PWM steps below the centerpoint

See Also:
Constant Field Values

kPwmDisabled

public static final int kPwmDisabled
See Also:
Constant Field Values
Constructor Detail

PWM

public PWM(int moduleNumber,
           int channel)
Allocate a PWM given a module and channel. Allocate a PWM using a module and channel number.

Parameters:
moduleNumber - The module number of the digital module to use.
channel - The PWM channel on the digital module.

PWM

public PWM(int channel)
Allocate a PWM in the default module given a channel. Using a default module allocate a PWM given the channel number.

Parameters:
channel - The PWM channel on the digital module.
Method Detail

free

public void free()
Free the PWM channel. Free the resource associated with the PWM channel and set the value to 0.

Overrides:
free in class SensorBase

enableDeadbandElimination

public void enableDeadbandElimination(boolean eliminateDeadband)
Optionally eliminate the deadband from a speed controller.

Parameters:
eliminateDeadband - If true, set the motor curve on the Jaguar to eliminate the deadband in the middle of the range. Otherwise, keep the full range without modifying any values.

setBounds

public void setBounds(int max,
                      int deadbandMax,
                      int center,
                      int deadbandMin,
                      int min)
Deprecated. Recommended to set bounds in ms using setBounds(double, double, double, double, double)

Set the bounds on the PWM values. This sets the bounds on the PWM values for a particular each type of controller. The values determine the upper and lower speeds as well as the deadband bracket.

Parameters:
max - The Minimum pwm value
deadbandMax - The high end of the deadband range
center - The center speed (off)
deadbandMin - The low end of the deadband range
min - The minimum pwm value

getModuleNumber

public int getModuleNumber()
Gets the module number associated with the PWM Object.

Returns:
The module's number.

getChannel

public int getChannel()
Gets the channel number associated with the PWM Object.

Returns:
The channel number.

setPosition

public void setPosition(double pos)
Set the PWM value based on a position. This is intended to be used by servos.

Parameters:
pos - The position to set the servo between 0.0 and 1.0.

getPosition

public double getPosition()
Get the PWM value in terms of a position. This is intended to be used by servos.

Returns:
The position the servo is set to between 0.0 and 1.0.

getSpeed

public double getSpeed()
Get the PWM value in terms of speed. This is intended to be used by speed controllers.

Returns:
The most recently set speed between -1.0 and 1.0.

setRaw

public void setRaw(int value)
Set the PWM value directly to the hardware. Write a raw value to a PWM channel.

Parameters:
value - Raw PWM value. Range 0 - 255.

getRaw

public int getRaw()
Get the PWM value directly from the hardware. Read a raw value from a PWM channel.

Returns:
Raw PWM control value. Range: 0 - 255.

setPeriodMultiplier

public void setPeriodMultiplier(PWM.PeriodMultiplier mult)
Slow down the PWM signal for old devices.

Parameters:
mult - The period multiplier to apply to this channel

getSmartDashboardType

public String getSmartDashboardType()
Specified by:
getSmartDashboardType in interface Sendable
Returns:
the string representation of the named data type that will be used by the smart dashboard for this sendable

initTable

public void initTable(ITable subtable)
Initializes a table for this sendable object.

Specified by:
initTable in interface Sendable
Parameters:
subtable - The table to put the values in.

updateTable

public void updateTable()
Update the table for this sendable object with the latest values.

Specified by:
updateTable in interface LiveWindowSendable

getTable

public ITable getTable()

Specified by:
getTable in interface Sendable
Returns:
the table that is currently associated with the sendable

startLiveWindowMode

public void startLiveWindowMode()
Start having this sendable object automatically respond to value changes reflect the value on the table.

Specified by:
startLiveWindowMode in interface LiveWindowSendable

stopLiveWindowMode

public void stopLiveWindowMode()
Stop having this sendable object automatically respond to value changes.

Specified by:
stopLiveWindowMode in interface LiveWindowSendable

"

2013 FRC Java API

"

"
For updated information see the Java FRC site
"