WPILibC++ 2027.0.0-alpha-5
Loading...
Searching...
No Matches
wpi::PWM Class Reference

Class for sending pulse-width modulation (PWM) signals. More...

#include <wpi/hardware/discrete/PWM.hpp>

Inheritance diagram for wpi::PWM:
wpi::util::Sendable wpi::util::SendableHelper< PWM >

Public Member Functions

 PWM (int channel, bool registerSendable=true)
 Allocate a PWM given a channel number.
 PWM (PWM &&)=default
PWMoperator= (PWM &&)=default
 ~PWM () override
 Free the PWM channel.
void SetPulseTime (wpi::units::microsecond_t time)
 Set the PWM pulse time directly to the hardware.
wpi::units::microsecond_t GetPulseTime () const
 Get the PWM pulse time directly from the hardware.
void SetDisabled ()
 Temporarily disables the PWM output.
void SetOutputPeriod (wpi::units::millisecond_t period)
 Sets the PWM output period.
int GetChannel () const
void SetSimDevice (HAL_SimDeviceHandle device)
 Indicates this input is used by a simulated device.
Public Member Functions inherited from wpi::util::Sendable
virtual constexpr ~Sendable ()=default
Public Member Functions inherited from wpi::util::SendableHelper< PWM >
constexpr SendableHelper (const SendableHelper &rhs)=default
constexpr SendableHelperoperator= (const SendableHelper &rhs)=default

Protected Member Functions

void InitSendable (wpi::util::SendableBuilder &builder) override
 Initializes this Sendable object.
Protected Member Functions inherited from wpi::util::SendableHelper< PWM >
constexpr ~SendableHelper ()

Friends

class AddressableLED

Detailed Description

Class for sending pulse-width modulation (PWM) signals.

Constructor & Destructor Documentation

◆ PWM() [1/2]

wpi::PWM::PWM ( int channel,
bool registerSendable = true )
explicit

Allocate a PWM given a channel number.

Checks channel value range and allocates the appropriate channel. The allocation is only done to help users ensure that they don't double assign channels.

Parameters
channelThe SmartIO channel number.
registerSendableIf true, adds this instance to SendableRegistry

◆ PWM() [2/2]

wpi::PWM::PWM ( PWM && )
default

◆ ~PWM()

wpi::PWM::~PWM ( )
override

Free the PWM channel.

Free the resource associated with the PWM channel and set the value to 0.

Member Function Documentation

◆ GetChannel()

int wpi::PWM::GetChannel ( ) const

◆ GetPulseTime()

wpi::units::microsecond_t wpi::PWM::GetPulseTime ( ) const

Get the PWM pulse time directly from the hardware.

Read a microsecond value from a PWM channel.

Returns
Microsecond PWM control value. Range 0 - 4096.

◆ InitSendable()

void wpi::PWM::InitSendable ( wpi::util::SendableBuilder & builder)
overrideprotectedvirtual

Initializes this Sendable object.

Parameters
buildersendable builder

Implements wpi::util::Sendable.

◆ operator=()

PWM & wpi::PWM::operator= ( PWM && )
default

◆ SetDisabled()

void wpi::PWM::SetDisabled ( )

Temporarily disables the PWM output.

The next set call will re-enable the output.

◆ SetOutputPeriod()

void wpi::PWM::SetOutputPeriod ( wpi::units::millisecond_t period)

Sets the PWM output period.

Parameters
periodThe output period to apply to this channel, in milliseconds. Valid values are 5ms, 10ms, and 20ms. Default is 20 ms.

◆ SetPulseTime()

void wpi::PWM::SetPulseTime ( wpi::units::microsecond_t time)

Set the PWM pulse time directly to the hardware.

Write a microsecond value to a PWM channel.

Parameters
timeMicrosecond PWM value. Range 0 - 4096.

◆ SetSimDevice()

void wpi::PWM::SetSimDevice ( HAL_SimDeviceHandle device)

Indicates this input is used by a simulated device.

Parameters
devicesimulated device handle

◆ AddressableLED

friend class AddressableLED
friend

The documentation for this class was generated from the following file: