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