CTRE Phoenix 6 C++ 26.0.0-beta-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 * 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 is strictly determined by the configured invert and not the
24 * leader. If you want motor direction to match or oppose the leader, use Follower instead.
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 StrictFollower 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 /**
40 * \brief The frequency at which this control will update.
41 * This is designated in Hertz, with a minimum of 20 Hz
42 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
43 * Some update frequencies are not supported and will be
44 * promoted up to the next highest supported frequency.
45 *
46 * If this field is set to 0 Hz, the control request will
47 * be sent immediately as a one-shot frame. This may be useful
48 * for advanced applications that require outputs to be
49 * synchronized with data acquisition. In this case, we
50 * recommend not exceeding 50 ms between control calls.
51 */
52 units::frequency::hertz_t UpdateFreqHz{20_Hz};
53
54 /**
55 * \brief Follow the motor output of another Talon while ignoring the leader's
56 * invert setting.
57 *
58 * \details If Talon is in torque control, the torque is copied - which will
59 * increase the total torque applied. If Talon is in duty cycle output
60 * control, the duty cycle is matched. If Talon is in voltage output
61 * control, the motor voltage is matched. Motor direction is strictly
62 * determined by the configured invert and not the leader. If you want
63 * motor direction to match or oppose the leader, use Follower instead.
64 *
65 * The leader must enable the status signal corresponding to its
66 * control output type (DutyCycle, MotorVoltage, TorqueCurrent). The
67 * update rate of the status signal determines the update rate of the
68 * follower's output and should be no slower than 20 Hz.
69 *
70 * \param LeaderID Device ID of the leader to follow.
71 */
73 LeaderID{std::move(LeaderID)}
74 {}
75
76 constexpr ~StrictFollower() override {}
77
78 /**
79 * \brief Gets the name of this control request.
80 *
81 * \returns Name of the control request
82 */
83 constexpr std::string_view GetName() const override
84 {
85 return "StrictFollower";
86 }
87
88 /**
89 * \brief Modifies this Control Request's LeaderID parameter and returns itself for
90 * method-chaining and easier to use request API.
91 *
92 * Device ID of the leader to follow.
93 *
94 * \param newLeaderID Parameter to modify
95 * \returns Itself
96 */
97 constexpr StrictFollower &WithLeaderID(int newLeaderID)
98 {
99 LeaderID = std::move(newLeaderID);
100 return *this;
101 }
102
103 /**
104 * \brief Sets the frequency at which this control will update.
105 * This is designated in Hertz, with a minimum of 20 Hz
106 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
107 * Some update frequencies are not supported and will be
108 * promoted up to the next highest supported frequency.
109 *
110 * If this field is set to 0 Hz, the control request will
111 * be sent immediately as a one-shot frame. This may be useful
112 * for advanced applications that require outputs to be
113 * synchronized with data acquisition. In this case, we
114 * recommend not exceeding 50 ms between control calls.
115 *
116 * \param newUpdateFreqHz Parameter to modify
117 * \returns Itself
118 */
119 constexpr StrictFollower &WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
120 {
121 UpdateFreqHz = newUpdateFreqHz;
122 return *this;
123 }
124
125 /**
126 * \brief Returns a string representation of the object.
127 *
128 * \returns a string representation of the object.
129 */
130 std::string ToString() const override;
131
132 /**
133 * \brief Gets information about this control request.
134 *
135 * \returns Map of control parameter names and corresponding applied values
136 */
137 std::map<std::string, std::string> GetControlInfo() const override;
138};
139
140}
141}
142}
143
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:30
int LeaderID
Device ID of the leader to follow.
Definition StrictFollower.hpp:37
constexpr StrictFollower & WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
Sets the frequency at which this control will update.
Definition StrictFollower.hpp:119
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:52
constexpr std::string_view GetName() const override
Gets the name of this control request.
Definition StrictFollower.hpp:83
constexpr StrictFollower(int LeaderID)
Follow the motor output of another Talon while ignoring the leader's invert setting.
Definition StrictFollower.hpp:72
constexpr StrictFollower & WithLeaderID(int newLeaderID)
Modifies this Control Request's LeaderID parameter and returns itself for method-chaining and easier ...
Definition StrictFollower.hpp:97
constexpr ~StrictFollower() override
Definition StrictFollower.hpp:76
Status codes reported by APIs, including OK, warnings, and errors.
Definition StatusCodes.h:28
Definition motor_constants.h:14