CTRE Phoenix 6 C++ 25.4.0
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
11#include <sstream>
12
13#include <units/frequency.h>
14#include <units/time.h>
15
16namespace ctre {
17namespace phoenix6 {
18namespace controls {
19
20/**
21 * Follow the motor output of another Talon while ignoring the master's invert
22 * setting.
23 *
24 * If Talon is in torque control, the torque is copied - which will increase the total torque applied. If
25 * Talon is in percent supply output control, the duty cycle is matched. Motor direction is strictly
26 * determined by the configured invert and not the master. If you want motor direction to match or oppose the
27 * master, use FollowerRequest instead.
28 */
30{
31 ctre::phoenix::StatusCode SendRequest(const char *network, uint32_t deviceHash, std::shared_ptr<ControlRequest> &req) const override
32 {
33 if (req.get() != this)
34 {
35 auto const reqCast = dynamic_cast<StrictFollower *>(req.get());
36 if (reqCast != nullptr)
37 {
38 *reqCast = *this;
39 }
40 else
41 {
42 req = std::make_shared<StrictFollower>(*this);
43 }
44 }
45
46 return c_ctre_phoenix6_RequestControlStrictFollower(network, deviceHash, UpdateFreqHz.to<double>(), MasterID);
47 }
48
49public:
50 /**
51 * \brief Device ID of the master to follow.
52 */
54
55 /**
56 * \brief The period at which this control will update at.
57 * This is designated in Hertz, with a minimum of 20 Hz
58 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
59 *
60 * If this field is set to 0 Hz, the control request will
61 * be sent immediately as a one-shot frame. This may be useful
62 * for advanced applications that require outputs to be
63 * synchronized with data acquisition. In this case, we
64 * recommend not exceeding 50 ms between control calls.
65 */
66 units::frequency::hertz_t UpdateFreqHz{20_Hz};
67
68 /**
69 * \brief Follow the motor output of another Talon while ignoring the master's
70 * invert setting.
71 *
72 * \details If Talon is in torque control, the torque is copied - which will
73 * increase the total torque applied. If Talon is in percent supply
74 * output control, the duty cycle is matched. Motor direction is
75 * strictly determined by the configured invert and not the master. If
76 * you want motor direction to match or oppose the master, use
77 * FollowerRequest instead.
78 *
79 * \param MasterID Device ID of the master to follow.
80 */
81 StrictFollower(int MasterID) : ControlRequest{"StrictFollower"},
82 MasterID{std::move(MasterID)}
83 {}
84
85 /**
86 * \brief Modifies this Control Request's MasterID parameter and returns itself for
87 * method-chaining and easier to use request API.
88 *
89 * Device ID of the master to follow.
90 *
91 * \param newMasterID Parameter to modify
92 * \returns Itself
93 */
94 StrictFollower &WithMasterID(int newMasterID)
95 {
96 MasterID = std::move(newMasterID);
97 return *this;
98 }
99 /**
100 * \brief Sets the period at which this control will update at.
101 * This is designated in Hertz, with a minimum of 20 Hz
102 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
103 *
104 * If this field is set to 0 Hz, the control request will
105 * be sent immediately as a one-shot frame. This may be useful
106 * for advanced applications that require outputs to be
107 * synchronized with data acquisition. In this case, we
108 * recommend not exceeding 50 ms between control calls.
109 *
110 * \param newUpdateFreqHz Parameter to modify
111 * \returns Itself
112 */
113 StrictFollower &WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
114 {
115 UpdateFreqHz = newUpdateFreqHz;
116 return *this;
117 }
118 /**
119 * \brief Returns a string representation of the object.
120 *
121 * \returns a string representation of the object.
122 */
123 std::string ToString() const override
124 {
125 std::stringstream ss;
126 ss << "Control: StrictFollower" << std::endl;
127 ss << " MasterID: " << MasterID << std::endl;
128 return ss.str();
129 }
130
131 /**
132 * \brief Gets information about this control request.
133 *
134 * \returns Map of control parameter names and corresponding applied values
135 */
136 std::map<std::string, std::string> GetControlInfo() const override
137 {
138 std::map<std::string, std::string> controlInfo;
139 std::stringstream ss;
140 controlInfo["Name"] = GetName();
141 ss << MasterID; controlInfo["MasterID"] = ss.str(); ss.str(std::string{});
142 return controlInfo;
143 }
144};
145
146}
147}
148}
149
CTREXPORT int c_ctre_phoenix6_RequestControlStrictFollower(const char *canbus, uint32_t ecuEncoding, double updateFrequency, int MasterID)
Abstract Control Request class that other control requests extend for use.
Definition ControlRequest.hpp:30
std::string const & GetName() const
Definition ControlRequest.hpp:53
Follow the motor output of another Talon while ignoring the master's invert setting.
Definition StrictFollower.hpp:30
StrictFollower(int MasterID)
Follow the motor output of another Talon while ignoring the master's invert setting.
Definition StrictFollower.hpp:81
int MasterID
Device ID of the master to follow.
Definition StrictFollower.hpp:53
std::string ToString() const override
Returns a string representation of the object.
Definition StrictFollower.hpp:123
StrictFollower & WithMasterID(int newMasterID)
Modifies this Control Request's MasterID parameter and returns itself for method-chaining and easier ...
Definition StrictFollower.hpp:94
std::map< std::string, std::string > GetControlInfo() const override
Gets information about this control request.
Definition StrictFollower.hpp:136
units::frequency::hertz_t UpdateFreqHz
The period at which this control will update at.
Definition StrictFollower.hpp:66
StrictFollower & WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
Sets the period at which this control will update at.
Definition StrictFollower.hpp:113
Status codes reported by APIs, including OK, warnings, and errors.
Definition StatusCodes.h:27
Definition Diff_PositionDutyCycle_Position.hpp:15
Definition span.hpp:401