15#include <units/frequency.h>
16#include <units/time.h>
30class Diff_TorqueCurrentFOC_Position :
public ControlRequest
32 ctre::phoenix::StatusCode SendRequest(
const char *network, uint32_t deviceHash, std::shared_ptr<ControlRequest> &req)
const override
34 if (req.get() !=
this)
36 auto const reqCast =
dynamic_cast<Diff_TorqueCurrentFOC_Position *
>(req.get());
37 if (reqCast !=
nullptr)
43 req = std::make_shared<Diff_TorqueCurrentFOC_Position>(*
this);
47 return c_ctre_phoenix6_RequestControlDiff_TorqueCurrentFOC_Position(network, deviceHash, UpdateFreqHz.to<
double>(), AverageRequest.
Output.to<
double>(), AverageRequest.
MaxAbsDutyCycle.to<
double>(), AverageRequest.
Deadband.to<
double>(), AverageRequest.
OverrideCoastDurNeutral, AverageRequest.
LimitForwardMotion, AverageRequest.
LimitReverseMotion, AverageRequest.
IgnoreHardwareLimits, AverageRequest.
UseTimesync, DifferentialRequest.
Position.to<
double>(), DifferentialRequest.
Velocity.to<
double>(), DifferentialRequest.
FeedForward.to<
double>(), DifferentialRequest.
Slot, DifferentialRequest.
OverrideCoastDurNeutral, DifferentialRequest.
LimitForwardMotion, DifferentialRequest.
LimitReverseMotion, DifferentialRequest.
IgnoreHardwareLimits, DifferentialRequest.
UseTimesync);
58 PositionTorqueCurrentFOC DifferentialRequest;
71 units::frequency::hertz_t UpdateFreqHz{100_Hz};
82 Diff_TorqueCurrentFOC_Position(TorqueCurrentFOC AverageRequest, PositionTorqueCurrentFOC DifferentialRequest) :
ControlRequest{
"Diff_TorqueCurrentFOC_Position"},
83 AverageRequest{
std::move(AverageRequest)},
84 DifferentialRequest{
std::move(DifferentialRequest)}
96 Diff_TorqueCurrentFOC_Position &WithAverageRequest(TorqueCurrentFOC newAverageRequest)
98 AverageRequest = std::move(newAverageRequest);
111 Diff_TorqueCurrentFOC_Position &WithDifferentialRequest(PositionTorqueCurrentFOC newDifferentialRequest)
113 DifferentialRequest = std::move(newDifferentialRequest);
130 Diff_TorqueCurrentFOC_Position &WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
132 UpdateFreqHz = newUpdateFreqHz;
140 std::string ToString()
const override
142 std::stringstream ss;
143 ss <<
"Control: Diff_TorqueCurrentFOC_Position" << std::endl;
144 ss <<
"AverageRequest:" << std::endl;
145 ss <<
" Output: " << AverageRequest.Output.to<
double>() << std::endl;
146 ss <<
" MaxAbsDutyCycle: " << AverageRequest.MaxAbsDutyCycle.to<
double>() << std::endl;
147 ss <<
" Deadband: " << AverageRequest.Deadband.to<
double>() << std::endl;
148 ss <<
" OverrideCoastDurNeutral: " << AverageRequest.OverrideCoastDurNeutral << std::endl;
149 ss <<
" LimitForwardMotion: " << AverageRequest.LimitForwardMotion << std::endl;
150 ss <<
" LimitReverseMotion: " << AverageRequest.LimitReverseMotion << std::endl;
151 ss <<
" IgnoreHardwareLimits: " << AverageRequest.IgnoreHardwareLimits << std::endl;
152 ss <<
" UseTimesync: " << AverageRequest.UseTimesync << std::endl;
153 ss <<
"DifferentialRequest:" << std::endl;
154 ss <<
" Position: " << DifferentialRequest.Position.to<
double>() << std::endl;
155 ss <<
" Velocity: " << DifferentialRequest.Velocity.to<
double>() << std::endl;
156 ss <<
" FeedForward: " << DifferentialRequest.FeedForward.to<
double>() << std::endl;
157 ss <<
" Slot: " << DifferentialRequest.Slot << std::endl;
158 ss <<
" OverrideCoastDurNeutral: " << DifferentialRequest.OverrideCoastDurNeutral << std::endl;
159 ss <<
" LimitForwardMotion: " << DifferentialRequest.LimitForwardMotion << std::endl;
160 ss <<
" LimitReverseMotion: " << DifferentialRequest.LimitReverseMotion << std::endl;
161 ss <<
" IgnoreHardwareLimits: " << DifferentialRequest.IgnoreHardwareLimits << std::endl;
162 ss <<
" UseTimesync: " << DifferentialRequest.UseTimesync << std::endl;
171 std::map<std::string, std::string> GetControlInfo()
const override
173 std::map<std::string, std::string> controlInfo;
174 std::stringstream ss;
175 controlInfo[
"Name"] =
GetName();
176 ss << AverageRequest.ToString(); controlInfo[
"AverageRequest"] = ss.str(); ss.str(std::string{});
177 ss << DifferentialRequest.ToString(); controlInfo[
"DifferentialRequest"] = ss.str(); ss.str(std::string{});
CTREXPORT int c_ctre_phoenix6_RequestControlDiff_TorqueCurrentFOC_Position(const char *canbus, uint32_t ecuEncoding, double updateTime, double AverageRequest_Output, double AverageRequest_MaxAbsDutyCycle, double AverageRequest_Deadband, bool AverageRequest_OverrideCoastDurNeutral, bool AverageRequest_LimitForwardMotion, bool AverageRequest_LimitReverseMotion, bool AverageRequest_IgnoreHardwareLimits, bool AverageRequest_UseTimesync, double DifferentialRequest_Position, double DifferentialRequest_Velocity, double DifferentialRequest_FeedForward, int DifferentialRequest_Slot, bool DifferentialRequest_OverrideCoastDurNeutral, bool DifferentialRequest_LimitForwardMotion, bool DifferentialRequest_LimitReverseMotion, bool DifferentialRequest_IgnoreHardwareLimits, bool DifferentialRequest_UseTimesync)
std::string const & GetName() const
Definition ControlRequest.hpp:52
ControlRequest(ControlRequest const &)=default
int Slot
Select which gains are applied by selecting the slot.
Definition PositionTorqueCurrentFOC.hpp:71
units::angular_velocity::turns_per_second_t Velocity
Velocity to drive toward in rotations per second.
Definition PositionTorqueCurrentFOC.hpp:60
bool UseTimesync
Set to true to delay applying this control request until a timesync boundary (requires Phoenix Pro an...
Definition PositionTorqueCurrentFOC.hpp:114
bool IgnoreHardwareLimits
Set to true to ignore hardware limit switches and the LimitForwardMotion and LimitReverseMotion param...
Definition PositionTorqueCurrentFOC.hpp:103
units::angle::turn_t Position
Position to drive toward in rotations.
Definition PositionTorqueCurrentFOC.hpp:55
units::current::ampere_t FeedForward
Feedforward to apply in torque current in Amperes.
Definition PositionTorqueCurrentFOC.hpp:65
bool LimitReverseMotion
Set to true to force reverse limiting.
Definition PositionTorqueCurrentFOC.hpp:90
bool LimitForwardMotion
Set to true to force forward limiting.
Definition PositionTorqueCurrentFOC.hpp:84
bool OverrideCoastDurNeutral
Set to true to coast the rotor when output is zero (or within deadband).
Definition PositionTorqueCurrentFOC.hpp:78
bool IgnoreHardwareLimits
Set to true to ignore hardware limit switches and the LimitForwardMotion and LimitReverseMotion param...
Definition TorqueCurrentFOC.hpp:106
bool UseTimesync
Set to true to delay applying this control request until a timesync boundary (requires Phoenix Pro an...
Definition TorqueCurrentFOC.hpp:117
units::current::ampere_t Output
Amount of motor current in Amperes.
Definition TorqueCurrentFOC.hpp:55
bool OverrideCoastDurNeutral
Set to true to coast the rotor when output is zero (or within deadband).
Definition TorqueCurrentFOC.hpp:81
bool LimitReverseMotion
Set to true to force reverse limiting.
Definition TorqueCurrentFOC.hpp:93
units::current::ampere_t Deadband
Deadband in Amperes.
Definition TorqueCurrentFOC.hpp:74
bool LimitForwardMotion
Set to true to force forward limiting.
Definition TorqueCurrentFOC.hpp:87
units::dimensionless::scalar_t MaxAbsDutyCycle
The maximum absolute motor output that can be applied, which effectively limits the velocity.
Definition TorqueCurrentFOC.hpp:64
Status codes reported by APIs, including OK, warnings, and errors.
Definition StatusCodes.h:27
@ TorqueCurrentFOC
Requires Pro.
Definition StatusCodes.h:18