13#include <units/angle.h>
14#include <units/angular_velocity.h>
15#include <units/voltage.h>
16#include <units/frequency.h>
17#include <units/time.h>
32 ctre::phoenix::StatusCode SendRequest(
const char *network, uint32_t deviceHash, std::shared_ptr<ControlRequest> &req)
override
34 if (req.get() !=
this)
37 if (reqCast !=
nullptr)
43 req = std::make_shared<PositionVoltage>(*
this);
47 return c_ctre_phoenix6_RequestControlPositionVoltage(network, deviceHash,
UpdateFreqHz.to<
double>(),
Position.to<
double>(),
Velocity.to<
double>(),
EnableFOC,
FeedForward.to<
double>(),
Slot,
OverrideBrakeDurNeutral,
LimitForwardMotion,
LimitReverseMotion,
UseTimesync);
59 units::angular_velocity::turns_per_second_t
Velocity;
269 Slot = std::move(newSlot);
368 std::stringstream ss;
369 ss <<
"Control: PositionVoltage" << std::endl;
370 ss <<
" Position: " <<
Position.to<
double>() <<
" rotations" << std::endl;
371 ss <<
" Velocity: " <<
Velocity.to<
double>() <<
" rotations per second" << std::endl;
372 ss <<
" EnableFOC: " <<
EnableFOC << std::endl;
373 ss <<
" FeedForward: " <<
FeedForward.to<
double>() <<
" Volts" << std::endl;
374 ss <<
" Slot: " <<
Slot << std::endl;
378 ss <<
" UseTimesync: " <<
UseTimesync << std::endl;
389 std::map<std::string, std::string> controlInfo;
390 std::stringstream ss;
391 controlInfo[
"Name"] =
GetName();
392 ss <<
Position.to<
double>(); controlInfo[
"Position"] = ss.str(); ss.str(std::string{});
393 ss <<
Velocity.to<
double>(); controlInfo[
"Velocity"] = ss.str(); ss.str(std::string{});
394 ss <<
EnableFOC; controlInfo[
"EnableFOC"] = ss.str(); ss.str(std::string{});
395 ss <<
FeedForward.to<
double>(); controlInfo[
"FeedForward"] = ss.str(); ss.str(std::string{});
396 ss <<
Slot; controlInfo[
"Slot"] = ss.str(); ss.str(std::string{});
398 ss <<
LimitForwardMotion; controlInfo[
"LimitForwardMotion"] = ss.str(); ss.str(std::string{});
399 ss <<
LimitReverseMotion; controlInfo[
"LimitReverseMotion"] = ss.str(); ss.str(std::string{});
400 ss <<
UseTimesync; controlInfo[
"UseTimesync"] = ss.str(); ss.str(std::string{});
CTREXPORT int c_ctre_phoenix6_RequestControlPositionVoltage(const char *canbus, uint32_t ecuEncoding, double updateTime, double Position, double Velocity, bool EnableFOC, double FeedForward, int Slot, bool OverrideBrakeDurNeutral, bool LimitForwardMotion, bool LimitReverseMotion, bool UseTimesync)
Abstract Control Request class that other control requests extend for use.
Definition: ControlRequest.hpp:29
std::string const & GetName() const
Definition: ControlRequest.hpp:52
Request PID to target position with voltage feedforward.
Definition: PositionVoltage.hpp:31
units::frequency::hertz_t UpdateFreqHz
The period at which this control will update at.
Definition: PositionVoltage.hpp:121
bool UseTimesync
Set to true to delay applying this control request until a timesync boundary (requires Phoenix Pro an...
Definition: PositionVoltage.hpp:108
bool EnableFOC
Set to true to use FOC commutation (requires Phoenix Pro), which increases peak power by ~15%.
Definition: PositionVoltage.hpp:72
PositionVoltage & WithVelocity(units::angular_velocity::turns_per_second_t newVelocity)
Modifies this Control Request's Velocity parameter and returns itself for method-chaining and easier ...
Definition: PositionVoltage.hpp:211
bool LimitReverseMotion
Set to true to force reverse limiting.
Definition: PositionVoltage.hpp:101
PositionVoltage & WithSlot(int newSlot)
Modifies this Control Request's Slot parameter and returns itself for method-chaining and easier to u...
Definition: PositionVoltage.hpp:267
PositionVoltage & WithFeedForward(units::voltage::volt_t newFeedForward)
Modifies this Control Request's FeedForward parameter and returns itself for method-chaining and easi...
Definition: PositionVoltage.hpp:250
PositionVoltage & WithEnableFOC(bool newEnableFOC)
Modifies this Control Request's EnableFOC parameter and returns itself for method-chaining and easier...
Definition: PositionVoltage.hpp:235
PositionVoltage & WithLimitForwardMotion(bool newLimitForwardMotion)
Modifies this Control Request's LimitForwardMotion parameter and returns itself for method-chaining a...
Definition: PositionVoltage.hpp:302
PositionVoltage(units::angle::turn_t Position, units::angular_velocity::turns_per_second_t Velocity=0.0_tps, bool EnableFOC=true, units::voltage::volt_t FeedForward=0.0_V, int Slot=0, bool OverrideBrakeDurNeutral=false, bool LimitForwardMotion=false, bool LimitReverseMotion=false, bool UseTimesync=false)
Request PID to target position with voltage feedforward.
Definition: PositionVoltage.hpp:174
std::string ToString() const override
Returns a string representation of the object.
Definition: PositionVoltage.hpp:366
units::angle::turn_t Position
Position to drive toward in rotations.
Definition: PositionVoltage.hpp:54
std::map< std::string, std::string > GetControlInfo() const override
Gets information about this control request.
Definition: PositionVoltage.hpp:387
units::voltage::volt_t FeedForward
Feedforward to apply in volts.
Definition: PositionVoltage.hpp:76
PositionVoltage & WithUseTimesync(bool newUseTimesync)
Modifies this Control Request's UseTimesync parameter and returns itself for method-chaining and easi...
Definition: PositionVoltage.hpp:337
int Slot
Select which gains are applied by selecting the slot.
Definition: PositionVoltage.hpp:82
PositionVoltage & WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
Sets the period at which this control will update at.
Definition: PositionVoltage.hpp:356
PositionVoltage & WithLimitReverseMotion(bool newLimitReverseMotion)
Modifies this Control Request's LimitReverseMotion parameter and returns itself for method-chaining a...
Definition: PositionVoltage.hpp:319
PositionVoltage & WithOverrideBrakeDurNeutral(bool newOverrideBrakeDurNeutral)
Modifies this Control Request's OverrideBrakeDurNeutral parameter and returns itself for method-chain...
Definition: PositionVoltage.hpp:285
PositionVoltage & WithPosition(units::angle::turn_t newPosition)
Modifies this Control Request's Position parameter and returns itself for method-chaining and easier ...
Definition: PositionVoltage.hpp:195
bool OverrideBrakeDurNeutral
Set to true to static-brake the rotor when output is zero (or within deadband).
Definition: PositionVoltage.hpp:89
units::angular_velocity::turns_per_second_t Velocity
Velocity to drive toward in rotations per second.
Definition: PositionVoltage.hpp:59
bool LimitForwardMotion
Set to true to force forward limiting.
Definition: PositionVoltage.hpp:95
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