CTRE Phoenix 6 C++ 26.1.1
Loading...
Searching...
No Matches
Follower.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
11#include <units/frequency.h>
12#include <units/time.h>
13
14namespace ctre {
15namespace phoenix6 {
16namespace controls {
17
18/**
19 * Follow the motor output of another Talon.
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 either
25 * matches the leader's configured direction or opposes it based on the MotorAlignment.
26 *
27 * The leader must ensure the status signal corresponding to its control output type (DutyCycle, MotorVoltage,
28 * TorqueCurrent) is enabled. The update rate of the status signal determines the update rate of the
29 * follower's output and should be no slower than 20 Hz.
30 */
31class Follower final : public ControlRequest {
32 ctre::phoenix::StatusCode SendRequest(const char *network, uint32_t deviceHash, std::shared_ptr<ControlRequest> &req) const override;
33
34public:
35 /**
36 * \brief Device ID of the leader to follow.
37 */
39 /**
40 * \brief Set to Aligned for motor invert to match the leader's configured
41 * Invert - which is typical when leader and follower are mechanically linked
42 * and spin in the same direction. Set to Opposed for motor invert to oppose
43 * the leader's configured Invert - this is typical where the leader and
44 * follower mechanically spin in opposite directions.
45 */
47
48 /**
49 * \brief The frequency at which this control will update.
50 * This is designated in Hertz, with a minimum of 20 Hz
51 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
52 * Some update frequencies are not supported and will be
53 * promoted up to the next highest supported frequency.
54 *
55 * If this field is set to 0 Hz, the control request will
56 * be sent immediately as a one-shot frame. This may be useful
57 * for advanced applications that require outputs to be
58 * synchronized with data acquisition. In this case, we
59 * recommend not exceeding 50 ms between control calls.
60 */
61 units::frequency::hertz_t UpdateFreqHz{20_Hz};
62
63 /**
64 * \brief Follow the motor output of another Talon.
65 *
66 * \details The follower will atomically change its output type when it receives
67 * the leader's latest output status signal (DutyCycle, MotorVoltage,
68 * TorqueCurrent). If Talon is in torque control, the torque is copied
69 * - which will increase the total torque applied. If Talon is in duty
70 * cycle output control, the duty cycle is matched. If Talon is in
71 * voltage output control, the motor voltage is matched. Motor
72 * direction either matches the leader's configured direction or
73 * opposes it based on the MotorAlignment.
74 *
75 * The leader must ensure the status signal corresponding to its
76 * control output type (DutyCycle, MotorVoltage, TorqueCurrent) is
77 * enabled. The update rate of the status signal determines the update
78 * rate of the follower's output and should be no slower than 20 Hz.
79 *
80 * \param LeaderID Device ID of the leader to follow.
81 * \param MotorAlignment Set to Aligned for motor invert to match the leader's
82 * configured Invert - which is typical when leader and
83 * follower are mechanically linked and spin in the same
84 * direction. Set to Opposed for motor invert to oppose
85 * the leader's configured Invert - this is typical where
86 * the leader and follower mechanically spin in opposite
87 * directions.
88 */
93
94 constexpr ~Follower() override {}
95
96 /**
97 * \brief Gets the name of this control request.
98 *
99 * \returns Name of the control request
100 */
101 constexpr std::string_view GetName() const override
102 {
103 return "Follower";
104 }
105
106 /**
107 * \brief Modifies this Control Request's LeaderID parameter and returns itself for
108 * method-chaining and easier to use request API.
109 *
110 * Device ID of the leader to follow.
111 *
112 * \param newLeaderID Parameter to modify
113 * \returns Itself
114 */
115 constexpr Follower &WithLeaderID(int newLeaderID)
116 {
117 LeaderID = std::move(newLeaderID);
118 return *this;
119 }
120
121 /**
122 * \brief Modifies this Control Request's MotorAlignment parameter and returns itself for
123 * method-chaining and easier to use request API.
124 *
125 * Set to Aligned for motor invert to match the leader's configured Invert -
126 * which is typical when leader and follower are mechanically linked and spin in
127 * the same direction. Set to Opposed for motor invert to oppose the leader's
128 * configured Invert - this is typical where the leader and follower
129 * mechanically spin in opposite directions.
130 *
131 * \param newMotorAlignment Parameter to modify
132 * \returns Itself
133 */
135 {
136 MotorAlignment = std::move(newMotorAlignment);
137 return *this;
138 }
139
140 /**
141 * \brief Sets the frequency at which this control will update.
142 * This is designated in Hertz, with a minimum of 20 Hz
143 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
144 * Some update frequencies are not supported and will be
145 * promoted up to the next highest supported frequency.
146 *
147 * If this field is set to 0 Hz, the control request will
148 * be sent immediately as a one-shot frame. This may be useful
149 * for advanced applications that require outputs to be
150 * synchronized with data acquisition. In this case, we
151 * recommend not exceeding 50 ms between control calls.
152 *
153 * \param newUpdateFreqHz Parameter to modify
154 * \returns Itself
155 */
156 constexpr Follower &WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
157 {
158 UpdateFreqHz = newUpdateFreqHz;
159 return *this;
160 }
161
162 /**
163 * \brief Returns a string representation of the object.
164 *
165 * \returns a string representation of the object.
166 */
167 std::string ToString() const override;
168
169 /**
170 * \brief Gets information about this control request.
171 *
172 * \returns Map of control parameter names and corresponding applied values
173 */
174 std::map<std::string, std::string> GetControlInfo() const override;
175};
176
177}
178}
179}
180
Common interface implemented by all control requests.
Definition ControlRequest.hpp:27
Follow the motor output of another Talon.
Definition Follower.hpp:31
constexpr Follower & WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
Sets the frequency at which this control will update.
Definition Follower.hpp:156
constexpr Follower & WithLeaderID(int newLeaderID)
Modifies this Control Request's LeaderID parameter and returns itself for method-chaining and easier ...
Definition Follower.hpp:115
signals::MotorAlignmentValue MotorAlignment
Set to Aligned for motor invert to match the leader's configured Invert - which is typical when leade...
Definition Follower.hpp:46
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.
constexpr Follower(int LeaderID, signals::MotorAlignmentValue MotorAlignment)
Follow the motor output of another Talon.
Definition Follower.hpp:89
int LeaderID
Device ID of the leader to follow.
Definition Follower.hpp:38
constexpr ~Follower() override
Definition Follower.hpp:94
constexpr Follower & WithMotorAlignment(signals::MotorAlignmentValue newMotorAlignment)
Modifies this Control Request's MotorAlignment parameter and returns itself for method-chaining and e...
Definition Follower.hpp:134
constexpr std::string_view GetName() const override
Gets the name of this control request.
Definition Follower.hpp:101
units::frequency::hertz_t UpdateFreqHz
The frequency at which this control will update.
Definition Follower.hpp:61
Status codes reported by APIs, including OK, warnings, and errors.
Definition StatusCodes.h:28
Definition motor_constants.h:14
The relationship between two motors in a mechanism.
Definition SpnEnums.hpp:5130