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