12#include "frc/MotorSafety.h"
13#include "frc/motorcontrol/MotorController.h"
14#include "wpi/sendable/Sendable.h"
15#include "wpi/sendable/SendableBuilder.h"
16#include "wpi/sendable/SendableHelper.h"
17#include <hal/SimDevice.h>
29 public frc::MotorController,
31 public wpi::SendableHelper<TalonFX>
41 std::string m_description;
44 mutable std::unique_ptr<wpiutils::MotorSafetyImplem> m_motorSafety{};
46 mutable std::recursive_mutex m_motorSafetyLock;
58 controls::NeutralOut m_brakeRef{};
59 controls::VoltageOut m_voltageControl{0_V};
61 hal::SimDevice m_simMotor;
62 hal::SimDouble m_simSupplyVoltage;
63 hal::SimDouble m_simDutyCycle;
64 hal::SimDouble m_simMotorVoltage;
65 hal::SimDouble m_simTorqueCurrent;
66 hal::SimDouble m_simSupplyCurrent;
68 hal::SimDevice m_simForwardLimit;
69 hal::SimBoolean m_simForwardLimitValue;
71 hal::SimDevice m_simReverseLimit;
72 hal::SimBoolean m_simReverseLimitValue;
74 hal::SimDevice m_simRotor;
75 hal::SimDouble m_simRotorPos;
76 hal::SimDouble m_simRotorRawPos;
77 hal::SimDouble m_simRotorVel;
78 hal::SimDouble m_simRotorAccel;
80 int32_t m_simPeriodicUid{-1};
81 std::vector<int32_t> m_simValueChangedUids;
83 static void OnValueChanged(
const char* name,
void *param, HAL_SimValueHandle handle,
84 HAL_Bool readonly,
const struct HAL_Value* value);
85 static void OnPeriodic(
void* param);
88 wpiutils::MotorSafetyImplem &GetMotorSafety()
const;
105 TalonFX(
int deviceId, std::string canbus =
"");
113 TalonFX{deviceId,
std::string{canbus.GetName()}}
123 void Set(
double speed)
override;
135 double Get()
const override;
160 [[deprecated(
"This API is deprecated for removal in 2026."
161 " Since invert is a config, apply the invert setting as part of a full configs::TalonFXConfiguration object."
162 " Invert can be found in the MotorOutput config group.")]]
178 [[deprecated(
"This API is deprecated for removal in 2026."
179 " Since invert is a config, read the invert setting as part of a full configs::TalonFXConfiguration object"
180 " or using a configs::MotorOutputConfigs object."
181 " Applied invert, which may not match the invert config for followers, can also be fetched using GetAppliedRotorPolarity.")]]
Class for getting information about an available CAN bus.
Definition: CANBus.hpp:19
Abstract Control Request class that other control requests extend for use.
Definition: ControlRequest.hpp:29
Request a specified motor duty cycle.
Definition: DutyCycleOut.hpp:28
Class description for the Talon FX integrated motor controller.
Definition: TalonFX.hpp:32
ctre::phoenix::StatusCode SetControlPrivate(controls::ControlRequest &request) override
static constexpr auto kDefaultSafetyExpiration
The default motor safety timeout IF calling application enables the feature.
Definition: TalonFX.hpp:38
void SetInverted(bool isInverted) override
Common interface for inverting direction of a motor controller.
TalonFX(int deviceId, CANBus canbus)
Constructs a new Talon FX motor controller object.
Definition: TalonFX.hpp:112
void Feed()
Feed the motor safety object.
void StopMotor() override
Common interface to stop motor movement until Set is called again.
bool IsAlive() const
Determine of the motor is still operating or has timed out.
void Disable() override
Common interface for disabling a motor controller.
void InitSendable(wpi::SendableBuilder &builder) override
TalonFX(int deviceId, std::string canbus="")
Constructs a new Talon FX motor controller object.
bool IsSafetyEnabled() const
Return the state of the motor safety enabled flag.
void SetVoltage(units::volt_t volts) override
Common interface for seting the direct voltage output of a motor controller.
void SetExpiration(units::second_t expirationTime)
Set the expiration time for the corresponding motor safety object.
units::second_t GetExpiration() const
Retrieve the timeout value for the corresponding motor safety object.
bool GetInverted() const override
Common interface for returning the inversion state of a motor controller.
void Set(double speed) override
Common interface for setting the speed of a motor controller.
ctre::phoenix::StatusCode SetNeutralMode(signals::NeutralModeValue neutralMode, units::second_t timeoutSeconds=100_ms)
Sets the mode of operation when output is neutral or disabled.
void SetSafetyEnabled(bool enabled)
Enable/disable motor safety for this device.
std::string GetDescription() const
double Get() const override
Common interface for getting the current set speed of a motor controller.
Class description for the Talon FX integrated motor controller.
Definition: CoreTalonFX.hpp:2813
StatusSignal< units::dimensionless::scalar_t > & GetDutyCycle(bool refresh=true)
The applied motor duty cycle.
The state of the motor controller bridge when output is neutral or disabled.
Definition: SpnEnums.hpp:1698
Status codes reported by APIs, including OK, warnings, and errors.
Definition: StatusCodes.h:27
Represents the state of one swerve module.
Definition: StatusCodes.h:18