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