CTRE Phoenix 6 C++ 26.1.1
Loading...
Searching...
No Matches
StrictFollower.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) Cross The Road Electronics.  All rights reserved.
3 * License information can be found in CTRE_LICENSE.txt
4 * For support and suggestions contact support@ctr-electronics.com or file
5 * an issue tracker at https://github.com/CrossTheRoadElec/Phoenix-Releases
6 */
7#pragma once
8
10#include <units/frequency.h>
11#include <units/time.h>
12
13namespace ctre {
14namespace phoenix6 {
15namespace controls {
16
17/**
18 * Follow the motor output of another Talon while ignoring the leader's invert
19 * setting.
20 *
21 * The follower will atomically change its output type when it receives the leader's latest output status
22 * signal (DutyCycle, MotorVoltage, TorqueCurrent). If Talon is in torque control, the torque is copied -
23 * which will increase the total torque applied. If Talon is in duty cycle output control, the duty cycle is
24 * matched. If Talon is in voltage output control, the motor voltage is matched. Motor direction is strictly
25 * determined by the configured invert and not the leader. If you want motor direction to match or oppose the
26 * leader, use Follower instead.
27 *
28 * The leader must ensure the status signal corresponding to its control output type (DutyCycle, MotorVoltage,
29 * TorqueCurrent) is enabled. The update rate of the status signal determines the update rate of the
30 * follower's output and should be no slower than 20 Hz.
31 */
32class StrictFollower final : public ControlRequest {
33 ctre::phoenix::StatusCode SendRequest(const char *network, uint32_t deviceHash, std::shared_ptr<ControlRequest> &req) const override;
34
35public:
36 /**
37 * \brief Device ID of the leader to follow.
38 */
40
41 /**
42 * \brief The frequency at which this control will update.
43 * This is designated in Hertz, with a minimum of 20 Hz
44 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
45 * Some update frequencies are not supported and will be
46 * promoted up to the next highest supported frequency.
47 *
48 * If this field is set to 0 Hz, the control request will
49 * be sent immediately as a one-shot frame. This may be useful
50 * for advanced applications that require outputs to be
51 * synchronized with data acquisition. In this case, we
52 * recommend not exceeding 50 ms between control calls.
53 */
54 units::frequency::hertz_t UpdateFreqHz{20_Hz};
55
56 /**
57 * \brief Follow the motor output of another Talon while ignoring the leader's
58 * invert setting.
59 *
60 * \details The follower will atomically change its output type when it receives
61 * the leader's latest output status signal (DutyCycle, MotorVoltage,
62 * TorqueCurrent). If Talon is in torque control, the torque is copied
63 * - which will increase the total torque applied. If Talon is in duty
64 * cycle output control, the duty cycle is matched. If Talon is in
65 * voltage output control, the motor voltage is matched. Motor
66 * direction is strictly determined by the configured invert and not
67 * the leader. If you want motor direction to match or oppose the
68 * leader, use Follower instead.
69 *
70 * The leader must ensure the status signal corresponding to its
71 * control output type (DutyCycle, MotorVoltage, TorqueCurrent) is
72 * enabled. The update rate of the status signal determines the update
73 * rate of the follower's output and should be no slower than 20 Hz.
74 *
75 * \param LeaderID Device ID of the leader to follow.
76 */
78 LeaderID{std::move(LeaderID)}
79 {}
80
81 constexpr ~StrictFollower() override {}
82
83 /**
84 * \brief Gets the name of this control request.
85 *
86 * \returns Name of the control request
87 */
88 constexpr std::string_view GetName() const override
89 {
90 return "StrictFollower";
91 }
92
93 /**
94 * \brief Modifies this Control Request's LeaderID parameter and returns itself for
95 * method-chaining and easier to use request API.
96 *
97 * Device ID of the leader to follow.
98 *
99 * \param newLeaderID Parameter to modify
100 * \returns Itself
101 */
102 constexpr StrictFollower &WithLeaderID(int newLeaderID)
103 {
104 LeaderID = std::move(newLeaderID);
105 return *this;
106 }
107
108 /**
109 * \brief Sets the frequency at which this control will update.
110 * This is designated in Hertz, with a minimum of 20 Hz
111 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
112 * Some update frequencies are not supported and will be
113 * promoted up to the next highest supported frequency.
114 *
115 * If this field is set to 0 Hz, the control request will
116 * be sent immediately as a one-shot frame. This may be useful
117 * for advanced applications that require outputs to be
118 * synchronized with data acquisition. In this case, we
119 * recommend not exceeding 50 ms between control calls.
120 *
121 * \param newUpdateFreqHz Parameter to modify
122 * \returns Itself
123 */
124 constexpr StrictFollower &WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
125 {
126 UpdateFreqHz = newUpdateFreqHz;
127 return *this;
128 }
129
130 /**
131 * \brief Returns a string representation of the object.
132 *
133 * \returns a string representation of the object.
134 */
135 std::string ToString() const override;
136
137 /**
138 * \brief Gets information about this control request.
139 *
140 * \returns Map of control parameter names and corresponding applied values
141 */
142 std::map<std::string, std::string> GetControlInfo() const override;
143};
144
145}
146}
147}
148
Common interface implemented by all control requests.
Definition ControlRequest.hpp:27
Follow the motor output of another Talon while ignoring the leader's invert setting.
Definition StrictFollower.hpp:32
int LeaderID
Device ID of the leader to follow.
Definition StrictFollower.hpp:39
constexpr StrictFollower & WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
Sets the frequency at which this control will update.
Definition StrictFollower.hpp:124
std::string ToString() const override
Returns a string representation of the object.
std::map< std::string, std::string > GetControlInfo() const override
Gets information about this control request.
units::frequency::hertz_t UpdateFreqHz
The frequency at which this control will update.
Definition StrictFollower.hpp:54
constexpr std::string_view GetName() const override
Gets the name of this control request.
Definition StrictFollower.hpp:88
constexpr StrictFollower(int LeaderID)
Follow the motor output of another Talon while ignoring the leader's invert setting.
Definition StrictFollower.hpp:77
constexpr StrictFollower & WithLeaderID(int newLeaderID)
Modifies this Control Request's LeaderID parameter and returns itself for method-chaining and easier ...
Definition StrictFollower.hpp:102
constexpr ~StrictFollower() override
Definition StrictFollower.hpp:81
Status codes reported by APIs, including OK, warnings, and errors.
Definition StatusCodes.h:28
Definition motor_constants.h:14