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