CTRE Phoenix C++ 5.33.1
IMotorController.h
Go to the documentation of this file.
1/* Copyright (C) Cross The Road Electronics 2024 */
2#pragma once
3
21#include "IFollower.h"
22
23namespace ctre {
24namespace phoenix {
25namespace motorcontrol {
26
27namespace can {
28// Forward-Proto BaseTalon
29class BaseTalon;
30}
31
32/**
33 * Interface for motor controllers
34 */
35class IMotorController: public virtual IFollower {
36public:
38 }
39 //------ Set output routines. ----------//
40 /**
41 * Sets the appropriate output on the talon, depending on the mode.
42 * @param Mode The output mode to apply.
43 * In PercentOutput, the output is between -1.0 and 1.0, with 0.0 as stopped.
44 * In Current mode, output value is in amperes.
45 * In Velocity mode, output value is in position change / 100ms.
46 * In Position mode, output value is in encoder ticks or an analog value,
47 * depending on the sensor.
48 * In Follower mode, the output value is the integer device ID of the talon to
49 * duplicate.
50 *
51 * @param demand The setpoint value, as described above.
52 *
53 *
54 * Standard Driving Example:
55 * _talonLeft.set(ControlMode.PercentOutput, leftJoy);
56 * _talonRght.set(ControlMode.PercentOutput, rghtJoy);
57 */
58 virtual void Set(ControlMode Mode, double demand) = 0;
59 /**
60 * @param mode Sets the appropriate output on the talon, depending on the mode.
61 * @param demand0 The output value to apply.
62 * such as advanced feed forward and/or auxiliary close-looping in firmware.
63 * In PercentOutput, the output is between -1.0 and 1.0, with 0.0 as stopped.
64 * In Current mode, output value is in amperes.
65 * In Velocity mode, output value is in position change / 100ms.
66 * In Position mode, output value is in encoder ticks or an analog value,
67 * depending on the sensor. See
68 * In Follower mode, the output value is the integer device ID of the talon to
69 * duplicate.
70 *
71 * @param demand1Type The demand type for demand1.
72 * Neutral: Ignore demand1 and apply no change to the demand0 output.
73 * AuxPID: Use demand1 to set the target for the auxiliary PID 1.
74 * ArbitraryFeedForward: Use demand1 as an arbitrary additive value to the
75 * demand0 output. In PercentOutput the demand0 output is the motor output,
76 * and in closed-loop modes the demand0 output is the output of PID0.
77 * @param demand1 Supplmental output value. Units match the set mode.
78 *
79 *
80 * Arcade Drive Example:
81 * _talonLeft.set(ControlMode.PercentOutput, joyForward, DemandType.ArbitraryFeedForward, +joyTurn);
82 * _talonRght.set(ControlMode.PercentOutput, joyForward, DemandType.ArbitraryFeedForward, -joyTurn);
83 *
84 * Drive Straight Example:
85 * Note: Selected Sensor Configuration is necessary for both PID0 and PID1.
86 * _talonLeft.follow(_talonRght, FollwerType.AuxOutput1);
87 * _talonRght.set(ControlMode.PercentOutput, joyForward, DemandType.AuxPID, desiredRobotHeading);
88 *
89 * Drive Straight to a Distance Example:
90 * Note: Other configurations (sensor selection, PID gains, etc.) need to be set.
91 * _talonLeft.follow(_talonRght, FollwerType.AuxOutput1);
92 * _talonRght.set(ControlMode.MotionMagic, targetDistance, DemandType.AuxPID, desiredRobotHeading);
93 */
94 virtual void Set(ControlMode mode, double demand0, DemandType demand1Type, double demand1) = 0;
95 /**
96 * Neutral the motor output by setting control mode to disabled.
97 */
98 virtual void NeutralOutput() = 0;
99 /**
100 * Sets the mode of operation during neutral throttle output.
101 *
102 * @param neutralMode
103 * The desired mode of operation when the Controller output
104 * throttle is neutral (ie brake/coast)
105 **/
106 virtual void SetNeutralMode(NeutralMode neutralMode) = 0;
107
108 //------ Invert behavior ----------//
109 /**
110 * Sets the phase of the sensor. Use when controller forward/reverse output
111 * doesn't correlate to appropriate forward/reverse reading of sensor.
112 * Pick a value so that positive PercentOutput yields a positive change in sensor.
113 * After setting this, user can freely call SetInverted() with any value.
114 *
115 * @param PhaseSensor
116 * Indicates whether to invert the phase of the sensor.
117 */
118 virtual void SetSensorPhase(bool PhaseSensor) = 0;
119 /**
120 * Inverts the hbridge output of the motor controller.
121 *
122 * This does not impact sensor phase and should not be used to correct sensor polarity.
123 *
124 * This will invert the hbridge output but NOT the LEDs.
125 * This ensures....
126 * - Green LEDs always represents positive request from robot-controller/closed-looping mode.
127 * - Green LEDs correlates to forward limit switch.
128 * - Green LEDs correlates to forward soft limit.
129 *
130 * @param invert
131 * Invert state to set.
132 */
133 virtual void SetInverted(bool invert) = 0;
134 /**
135 * Inverts the hbridge output of the motor controller in relation to the master if present
136 *
137 * This does not impact sensor phase and should not be used to correct sensor polarity.
138 *
139 * This will allow you to either:
140 * - Not invert the motor
141 * - Invert the motor
142 * - Always follow the master regardless of master's inversion
143 * - Always oppose the master regardless of master's inversion
144 *
145 * @param invertType
146 * Invert state to set.
147 */
148 virtual void SetInverted(InvertType invertType) = 0;
149 /**
150 * @return invert setting of motor output.
151 */
152 virtual bool GetInverted() const = 0;
153
154 //----- Factory Default Configuration -----//
155 /**
156 * Revert all configurations to factory default values.
157 * Use this before your individual config* calls to avoid having to config every single param.
158 *
159 * Alternatively you can use the configAllSettings routine.
160 *
161 * @param timeout
162 * Timeout value in ms. Function will generate error if config is
163 * not successful within timeout.
164 * @return Error Code generated by function. 0 indicates no error.
165 */
166 virtual ErrorCode ConfigFactoryDefault(int timeout) = 0;
167
168 //----- general output shaping ------------------//
169 /**
170 * Configures the open-loop ramp rate of throttle output.
171 *
172 * @param secondsFromNeutralToFull
173 * Minimum desired time to go from neutral to full throttle. A
174 * value of '0' will disable the ramp.
175 * @param timeoutMs
176 * Timeout value in ms. If nonzero, function will wait for
177 * config success and report an error if it times out.
178 * If zero, no blocking or checking is performed.
179 * @return Error Code generated by function. 0 indicates no error.
180 */
181 virtual ErrorCode ConfigOpenloopRamp(double secondsFromNeutralToFull,
182 int timeoutMs = 0) = 0;
183 /**
184 * Configures the closed-loop ramp rate of throttle output.
185 *
186 * @param secondsFromNeutralToFull
187 * Minimum desired time to go from neutral to full throttle. A
188 * value of '0' will disable the ramp.
189 * @param timeoutMs
190 * Timeout value in ms. If nonzero, function will wait for
191 * config success and report an error if it times out.
192 * If zero, no blocking or checking is performed.
193 * @return Error Code generated by function. 0 indicates no error.
194 */
195 virtual ErrorCode ConfigClosedloopRamp(double secondsFromNeutralToFull,
196 int timeoutMs = 0) = 0;
197 /**
198 * Configures the forward peak output percentage.
199 *
200 * @param percentOut
201 * Desired peak output percentage. [0,1]
202 * @param timeoutMs
203 * Timeout value in ms. If nonzero, function will wait for
204 * config success and report an error if it times out.
205 * If zero, no blocking or checking is performed.
206 * @return Error Code generated by function. 0 indicates no error.
207 */
208 virtual ErrorCode ConfigPeakOutputForward(double percentOut,
209 int timeoutMs = 0) = 0;
210 /**
211 * Configures the reverse peak output percentage.
212 *
213 * @param percentOut
214 * Desired peak output percentage.
215 * @param timeoutMs
216 * Timeout value in ms. If nonzero, function will wait for
217 * config success and report an error if it times out.
218 * If zero, no blocking or checking is performed.
219 * @return Error Code generated by function. 0 indicates no error.
220 */
221 virtual ErrorCode ConfigPeakOutputReverse(double percentOut,
222 int timeoutMs = 0) = 0;
223 /**
224 * Configures the forward nominal output percentage.
225 *
226 * @param percentOut
227 * Nominal (minimum) percent output. [0,+1]
228 * @param timeoutMs
229 * Timeout value in ms. If nonzero, function will wait for
230 * config success and report an error if it times out.
231 * If zero, no blocking or checking is performed.
232 * @return Error Code generated by function. 0 indicates no error.
233 */
234 virtual ErrorCode ConfigNominalOutputForward(double percentOut,
235 int timeoutMs = 0) = 0;
236 /**
237 * Configures the reverse nominal output percentage.
238 *
239 * @param percentOut
240 * Nominal (minimum) percent output. [-1,0]
241 * @param timeoutMs
242 * Timeout value in ms. If nonzero, function will wait for
243 * config success and report an error if it times out.
244 * If zero, no blocking or checking is performed.
245 * @return Error Code generated by function. 0 indicates no error.
246 */
247 virtual ErrorCode ConfigNominalOutputReverse(double percentOut,
248 int timeoutMs = 0) = 0;
249 /**
250 * Configures the output deadband percentage.
251 *
252 * @param percentDeadband
253 * Desired deadband percentage. Minimum is 0.1%, Maximum is 25%.
254 * Pass 0.04 for 4% (factory default).
255 * @param timeoutMs
256 * Timeout value in ms. If nonzero, function will wait for
257 * config success and report an error if it times out.
258 * If zero, no blocking or checking is performed.
259 * @return Error Code generated by function. 0 indicates no error.
260 */
261 virtual ErrorCode ConfigNeutralDeadband(double percentDeadband,
262 int timeoutMs = 0) = 0;
263
264 //------ Voltage Compensation ----------//
265 /**
266 * Configures the Voltage Compensation saturation voltage.
267 *
268 * @param voltage
269 * This is the max voltage to apply to the hbridge when voltage
270 * compensation is enabled. For example, if 10 (volts) is specified
271 * and a TalonSRX is commanded to 0.5 (PercentOutput, closed-loop, etc)
272 * then the TalonSRX will attempt to apply a duty-cycle to produce 5V.
273 * @param timeoutMs
274 * Timeout value in ms. If nonzero, function will wait for
275 * config success and report an error if it times out.
276 * If zero, no blocking or checking is performed.
277 * @return Error Code generated by function. 0 indicates no error.
278 */
280 int timeoutMs = 0) = 0;
281 /**
282 * Configures the voltage measurement filter.
283 *
284 * @param filterWindowSamples
285 * Number of samples in the rolling average of voltage
286 * measurement.
287 * @param timeoutMs
288 * Timeout value in ms. If nonzero, function will wait for
289 * config success and report an error if it times out.
290 * If zero, no blocking or checking is performed.
291 * @return Error Code generated by function. 0 indicates no error.
292 */
293 virtual ErrorCode ConfigVoltageMeasurementFilter(int filterWindowSamples,
294 int timeoutMs = 0) = 0;
295 /**
296 * Enables voltage compensation. If enabled, voltage compensation works in
297 * all control modes.
298 *
299 * Be sure to configure the saturation voltage before enabling this.
300 *
301 * @param enable
302 * Enable state of voltage compensation.
303 **/
304 virtual void EnableVoltageCompensation(bool enable) = 0;
305
306 /**
307 * Returns the enable state of Voltage Compensation that the caller has set.
308 *
309 * @return TRUE if voltage compensation is enabled.
310 */
312
313 //------ General Status ----------//
314 /**
315 * Gets the bus voltage seen by the device.
316 *
317 * @return The bus voltage value (in volts).
318 */
319 virtual double GetBusVoltage() = 0;
320 /**
321 * Gets the output percentage of the motor controller.
322 *
323 * @return Output of the motor controller (in percent).
324 */
325 virtual double GetMotorOutputPercent() = 0;
326 /**
327 * @return applied voltage to motor in volts.
328 */
329 virtual double GetMotorOutputVoltage() = 0;
330 /**
331 * Gets the temperature of the motor controller.
332 *
333 * @return Temperature of the motor controller (in 'C)
334 */
335 virtual double GetTemperature() = 0;
336
337 //------ sensor selection ----------//
338 /**
339 * Select the remote feedback device for the motor controller.
340 * Most CTRE CAN motor controllers will support remote sensors over CAN.
341 *
342 * @param feedbackDevice
343 * Remote Feedback Device to select.
344 * @param pidIdx
345 * 0 for Primary closed-loop. 1 for auxiliary closed-loop.
346 * @param timeoutMs
347 * Timeout value in ms. If nonzero, function will wait for
348 * config success and report an error if it times out.
349 * If zero, no blocking or checking is performed.
350 * @return Error Code generated by function. 0 indicates no error.
351 */
352 [[deprecated("This device's Phoenix 5 API is deprecated for removal in the 2025 season."
353 "Users should update to Phoenix 6 firmware and migrate to the Phoenix 6 API."
354 "A migration guide is available at https://v6.docs.ctr-electronics.com/en/stable/docs/migration/migration-guide/index.html")]]
356 RemoteFeedbackDevice feedbackDevice, int pidIdx = 0, int timeoutMs = 0) = 0;
357 /**
358 * The Feedback Coefficient is a scalar applied to the value of the
359 * feedback sensor. Useful when you need to scale your sensor values
360 * within the closed-loop calculations. Default value is 1.
361 *
362 * Selected Feedback Sensor register in firmware is the decoded sensor value
363 * multiplied by the Feedback Coefficient.
364 *
365 * @param coefficient
366 * Feedback Coefficient value. Maximum value of 1.
367 * Resolution is 1/(2^16). Cannot be 0.
368 * @param pidIdx
369 * 0 for Primary closed-loop. 1 for auxiliary closed-loop.
370 * @param timeoutMs
371 * Timeout value in ms. If nonzero, function will wait for
372 * config success and report an error if it times out.
373 * If zero, no blocking or checking is performed.
374 * @return Error Code generated by function. 0 indicates no error.
375 */
377 double coefficient, int pidIdx = 0, int timeoutMs = 0) = 0;
378 /**
379 * Select what remote device and signal to assign to Remote Sensor 0 or Remote Sensor 1.
380 * After binding a remote device and signal to Remote Sensor X, you may select Remote Sensor X
381 * as a PID source for closed-loop features.
382 *
383 * @param deviceID
384 * The device ID of the remote sensor device.
385 * @param remoteSensorSource
386 * The remote sensor device and signal type to bind.
387 * @param remoteOrdinal
388 * 0 for configuring Remote Sensor 0,
389 * 1 for configuring Remote Sensor 1
390 * @param timeoutMs
391 * Timeout value in ms. If nonzero, function will wait for
392 * config success and report an error if it times out.
393 * If zero, no blocking or checking is performed.
394 * @return Error Code generated by function. 0 indicates no error.
395 */
396 [[deprecated("This device's Phoenix 5 API is deprecated for removal in the 2025 season."
397 "Users should update to Phoenix 6 firmware and migrate to the Phoenix 6 API."
398 "A migration guide is available at https://v6.docs.ctr-electronics.com/en/stable/docs/migration/migration-guide/index.html")]]
400 RemoteSensorSource remoteSensorSource, int remoteOrdinal,
401 int timeoutMs = 0)= 0;
402 /**
403 * Select what remote device and signal to assign to Remote Sensor 0 or Remote Sensor 1.
404 * After binding a remote device and signal to Remote Sensor X, you may select Remote Sensor X
405 * as a PID source for closed-loop features.
406 *
407 * @param canCoderRef
408 * CANCoder device reference to use.
409 * @param remoteOrdinal
410 * 0 for configuring Remote Sensor 0,
411 * 1 for configuring Remote Sensor 1
412 * @param timeoutMs
413 * Timeout value in ms. If nonzero, function will wait for
414 * config success and report an error if it times out.
415 * If zero, no blocking or checking is performed.
416 * @return Error Code generated by function. 0 indicates no error.
417 */
418 [[deprecated("This device's Phoenix 5 API is deprecated for removal in the 2025 season."
419 "Users should update to Phoenix 6 firmware and migrate to the Phoenix 6 API."
420 "A migration guide is available at https://v6.docs.ctr-electronics.com/en/stable/docs/migration/migration-guide/index.html")]]
421 virtual ErrorCode ConfigRemoteFeedbackFilter(ctre::phoenix::sensors::CANCoder &canCoderRef, int remoteOrdinal, int timeoutMs = 0)= 0;
422 /**
423 * Select what remote device and signal to assign to Remote Sensor 0 or Remote Sensor 1.
424 * After binding a remote device and signal to Remote Sensor X, you may select Remote Sensor X
425 * as a PID source for closed-loop features.
426 *
427 * @param talonRef
428 * Talon device reference to use.
429 * @param remoteOrdinal
430 * 0 for configuring Remote Sensor 0,
431 * 1 for configuring Remote Sensor 1
432 * @param timeoutMs
433 * Timeout value in ms. If nonzero, function will wait for
434 * config success and report an error if it times out.
435 * If zero, no blocking or checking is performed.
436 * @return Error Code generated by function. 0 indicates no error.
437 */
438 [[deprecated("This device's Phoenix 5 API is deprecated for removal in the 2025 season."
439 "Users should update to Phoenix 6 firmware and migrate to the Phoenix 6 API."
440 "A migration guide is available at https://v6.docs.ctr-electronics.com/en/stable/docs/migration/migration-guide/index.html")]]
441 virtual ErrorCode ConfigRemoteFeedbackFilter(ctre::phoenix::motorcontrol::can::BaseTalon &talonRef, int remoteOrdinal, int timeoutMs = 0)= 0;
442 /**
443 * Select what sensor term should be bound to switch feedback device.
444 * Sensor Sum = Sensor Sum Term 0 - Sensor Sum Term 1
445 * Sensor Difference = Sensor Diff Term 0 - Sensor Diff Term 1
446 * The four terms are specified with this routine. Then Sensor Sum/Difference
447 * can be selected for closed-looping.
448 *
449 * @param sensorTerm Which sensor term to bind to a feedback source.
450 * @param feedbackDevice The sensor signal to attach to sensorTerm.
451 * @param timeoutMs
452 * Timeout value in ms. If nonzero, function will wait for
453 * config success and report an error if it times out.
454 * If zero, no blocking or checking is performed.
455 * @return Error Code generated by function. 0 indicates no error.
456 */
457 [[deprecated("This device's Phoenix 5 API is deprecated for removal in the 2025 season."
458 "Users should update to Phoenix 6 firmware and migrate to the Phoenix 6 API."
459 "A migration guide is available at https://v6.docs.ctr-electronics.com/en/stable/docs/migration/migration-guide/index.html")]]
460 virtual ErrorCode ConfigSensorTerm(SensorTerm sensorTerm, FeedbackDevice feedbackDevice, int timeoutMs = 0)= 0;
461
462 //------- sensor status --------- //
463 /**
464 * Get the selected sensor position (in raw sensor units).
465 *
466 * @param pidIdx
467 * 0 for Primary closed-loop. 1 for auxiliary closed-loop. See
468 * Phoenix-Documentation for how to interpret.
469 *
470 * @return Position of selected sensor (in raw sensor units).
471 */
472 virtual double GetSelectedSensorPosition(int pidIdx = 0) = 0;
473 /**
474 * Get the selected sensor velocity.
475 *
476 * @param pidIdx
477 * 0 for Primary closed-loop. 1 for auxiliary closed-loop.
478 * @return selected sensor (in raw sensor units) per 100ms.
479 * See Phoenix-Documentation for how to interpret.
480 */
481 virtual double GetSelectedSensorVelocity(int pidIdx = 0) = 0;
482 /**
483 * Sets the sensor position to the given value.
484 *
485 * @param sensorPos
486 * Position to set for the selected sensor (in raw sensor units).
487 * @param pidIdx
488 * 0 for Primary closed-loop. 1 for auxiliary closed-loop.
489 * @param timeoutMs
490 * Timeout value in ms. If nonzero, function will wait for
491 * config success and report an error if it times out.
492 * If zero, no blocking or checking is performed.
493 * @return Error Code generated by function. 0 indicates no error.
494 */
495 virtual ErrorCode SetSelectedSensorPosition(double sensorPos, int pidIdx = 0,
496 int timeoutMs = 50) = 0;
497
498 //------ status frame period changes ----------//
499 /**
500 * Sets the period of the given control frame.
501 *
502 * @param frame
503 * Frame whose period is to be changed.
504 * @param periodMs
505 * Period in ms for the given frame.
506 * @return Error Code generated by function. 0 indicates no error.
507 */
509 int periodMs) = 0;
510 /**
511 * Sets the period of the given status frame.
512 *
513 * User ensure CAN Bus utilization is not high.
514 *
515 * This setting is not persistent and is lost when device is reset. If this
516 * is a concern, calling application can use HasResetOccurred() to determine if the
517 * status frame needs to be reconfigured.
518 *
519 * @param frame
520 * Frame whose period is to be changed.
521 * @param periodMs
522 * Period in ms for the given frame.
523 * @param timeoutMs
524 * Timeout value in ms. If nonzero, function will wait for config
525 * success and report an error if it times out. If zero, no
526 * blocking or checking is performed.
527 * @return Error Code generated by function. 0 indicates no error.
528 */
529 virtual ErrorCode SetStatusFramePeriod(StatusFrame frame, uint8_t periodMs,
530 int timeoutMs = 0) = 0;
531 /**
532 * Gets the period of the given status frame.
533 *
534 * @param frame
535 * Frame to get the period of.
536 * @param timeoutMs
537 * Timeout value in ms. If nonzero, function will wait for
538 * config success and report an error if it times out.
539 * If zero, no blocking or checking is performed.
540 * @return Period of the given status frame.
541 */
542 virtual int GetStatusFramePeriod(StatusFrame frame, int timeoutMs = 0) = 0;
543
544 //----- velocity signal conditionaing ------//
545 /* not supported */
546
547 //------ remote limit switch ----------//
548 /**
549 * Configures the forward limit switch for a remote source. For example, a
550 * CAN motor controller may need to monitor the Limit-F pin of another Talon
551 * or CANifier.
552 *
553 * @param type
554 * Remote limit switch source. User can choose between a remote
555 * Talon SRX, CANifier, or deactivate the feature.
556 * @param normalOpenOrClose
557 * Setting for normally open, normally closed, or disabled. This
558 * setting matches the Phoenix Tuner drop down.
559 * @param deviceID
560 * Device ID of remote source (Talon SRX or CANifier device ID).
561 * @param timeoutMs
562 * Timeout value in ms. If nonzero, function will wait for config
563 * success and report an error if it times out. If zero, no
564 * blocking or checking is performed.
565 * @return Error Code generated by function. 0 indicates no error.
566 */
568 RemoteLimitSwitchSource type, LimitSwitchNormal normalOpenOrClose,
569 int deviceID, int timeoutMs = 0) = 0;
570 /**
571 * Configures the reverse limit switch for a remote source. For example, a
572 * CAN motor controller may need to monitor the Limit-R pin of another Talon
573 * or CANifier.
574 *
575 * @param type
576 * Remote limit switch source. User can choose between a remote
577 * Talon SRX, CANifier, or deactivate the feature.
578 * @param normalOpenOrClose
579 * Setting for normally open, normally closed, or disabled. This
580 * setting matches the Phoenix Tuner drop down.
581 * @param deviceID
582 * Device ID of remote source (Talon SRX or CANifier device ID).
583 * @param timeoutMs
584 * Timeout value in ms. If nonzero, function will wait for config
585 * success and report an error if it times out. If zero, no
586 * blocking or checking is performed.
587 * @return Error Code generated by function. 0 indicates no error.
588 */
590 RemoteLimitSwitchSource type, LimitSwitchNormal normalOpenOrClose,
591 int deviceID, int timeoutMs = 0) = 0;
592 /**
593 * Sets the enable state for limit switches.
594 *
595 * @param enable
596 * Enable state for limit switches.
597 **/
598 virtual void OverrideLimitSwitchesEnable(bool enable) = 0;
599
600 //------ local limit switch ----------//
601 /* not supported */
602
603 //------ soft limit ----------//
604 /**
605 * Configures the forward soft limit threhold.
606 *
607 * @param forwardSensorLimit
608 * Forward Sensor Position Limit (in raw sensor units).
609 * @param timeoutMs
610 * Timeout value in ms. If nonzero, function will wait for
611 * config success and report an error if it times out.
612 * If zero, no blocking or checking is performed.
613 * @return Error Code generated by function. 0 indicates no error.
614 */
615 virtual ErrorCode ConfigForwardSoftLimitThreshold(double forwardSensorLimit,
616 int timeoutMs = 0) = 0;
617 /**
618 * Configures the reverse soft limit threshold.
619 *
620 * @param reverseSensorLimit
621 * Reverse Sensor Position Limit (in raw sensor units).
622 * @param timeoutMs
623 * Timeout value in ms. If nonzero, function will wait for
624 * config success and report an error if it times out.
625 * If zero, no blocking or checking is performed.
626 * @return Error Code generated by function. 0 indicates no error.
627 */
628 virtual ErrorCode ConfigReverseSoftLimitThreshold(double reverseSensorLimit,
629 int timeoutMs = 0) = 0;
630 /**
631 * Configures the forward soft limit enable.
632 *
633 * @param enable
634 * Forward Sensor Position Limit Enable.
635 * @param timeoutMs
636 * Timeout value in ms. If nonzero, function will wait for
637 * config success and report an error if it times out.
638 * If zero, no blocking or checking is performed.
639 * @return Error Code generated by function. 0 indicates no error.
640 */
642 int timeoutMs = 0) = 0;
643 /**
644 * Configures the reverse soft limit enable.
645 *
646 * @param enable
647 * Reverse Sensor Position Limit Enable.
648 * @param timeoutMs
649 * Timeout value in ms. If nonzero, function will wait for config
650 * success and report an error if it times out. If zero, no
651 * blocking or checking is performed.
652 * @return Error Code generated by function. 0 indicates no error.
653 */
655 int timeoutMs = 0) = 0;
656 /**
657 * Can be used to override-disable the soft limits.
658 * This function can be used to quickly disable soft limits without
659 * having to modify the persistent configuration.
660 *
661 * @param enable
662 * Enable state for soft limit switches.
663 */
664 virtual void OverrideSoftLimitsEnable(bool enable) = 0;
665
666 //------ Current Lim ----------//
667 /* not supported */
668
669 //------ Config Close loop ----------//
670 /**
671 * Sets the 'P' constant in the given parameter slot.
672 * This is multiplied by closed loop error in sensor units.
673 * Note the closed loop output interprets a final value of 1023 as full output.
674 * So use a gain of '0.25' to get full output if err is 4096u (Mag Encoder 1 rotation)
675 *
676 * @param slotIdx
677 * Parameter slot for the constant.
678 * @param value
679 * Value of the P constant.
680 * @param timeoutMs
681 * Timeout value in ms. If nonzero, function will wait for
682 * config success and report an error if it times out.
683 * If zero, no blocking or checking is performed.
684 * @return Error Code generated by function. 0 indicates no error.
685 */
686 virtual ErrorCode Config_kP(int slotIdx, double value, int timeoutMs = 0) = 0;
687 /**
688 * Sets the 'I' constant in the given parameter slot.
689 * This is multiplied by accumulated closed loop error in sensor units every PID Loop.
690 * Note the closed loop output interprets a final value of 1023 as full output.
691 * So use a gain of '0.00025' to get full output if err is 4096u for 1000 loops (accumulater holds 4,096,000),
692 * [which is equivalent to one CTRE mag encoder rotation for 1000 milliseconds].
693 *
694 * @param slotIdx
695 * Parameter slot for the constant.
696 * @param value
697 * Value of the I constant.
698 * @param timeoutMs
699 * Timeout value in ms. If nonzero, function will wait for
700 * config success and report an error if it times out.
701 * If zero, no blocking or checking is performed.
702 * @return Error Code generated by function. 0 indicates no error.
703 */
704 virtual ErrorCode Config_kI(int slotIdx, double value, int timeoutMs = 0) = 0;
705 /**
706 * Sets the 'D' constant in the given parameter slot.
707 *
708 * This is multiplied by derivative error (sensor units per PID loop, typically 1ms).
709 * Note the closed loop output interprets a final value of 1023 as full output.
710 * So use a gain of '250' to get full output if derr is 4096u (Mag Encoder 1 rotation) per 1000 loops (typ 1 sec)
711 *
712 * @param slotIdx
713 * Parameter slot for the constant.
714 * @param value
715 * Value of the D constant.
716 * @param timeoutMs
717 * Timeout value in ms. If nonzero, function will wait for
718 * config success and report an error if it times out.
719 * If zero, no blocking or checking is performed.
720 * @return Error Code generated by function. 0 indicates no error.
721 */
722 virtual ErrorCode Config_kD(int slotIdx, double value, int timeoutMs = 0) = 0;
723 /**
724 * Sets the 'F' constant in the given parameter slot.
725 *
726 * See documentation for calculation details.
727 * If using velocity, motion magic, or motion profile,
728 * use (1023 * duty-cycle / sensor-velocity-sensor-units-per-100ms).
729 *
730 * @param slotIdx
731 * Parameter slot for the constant.
732 * @param value
733 * Value of the F constant.
734 * @param timeoutMs
735 * Timeout value in ms. If nonzero, function will wait for
736 * config success and report an error if it times out.
737 * If zero, no blocking or checking is performed.
738 * @return Error Code generated by function. 0 indicates no error.
739 */
740 virtual ErrorCode Config_kF(int slotIdx, double value, int timeoutMs = 0) = 0;
741 /**
742 * Sets the Integral Zone constant in the given parameter slot. If the
743 * (absolute) closed-loop error is outside of this zone, integral
744 * accumulator is automatically cleared. This ensures than integral wind up
745 * events will stop after the sensor gets far enough from its target.
746 *
747 * @param slotIdx
748 * Parameter slot for the constant.
749 * @param izone
750 * Value of the Integral Zone constant (closed loop error units X
751 * 1ms).
752 * @param timeoutMs
753 * Timeout value in ms. If nonzero, function will wait for config
754 * success and report an error if it times out. If zero, no
755 * blocking or checking is performed.
756 * @return Error Code generated by function. 0 indicates no error.
757 */
758 virtual ErrorCode Config_IntegralZone(int slotIdx, double izone,
759 int timeoutMs = 0) = 0;
760 /**
761 * Sets the allowable closed-loop error in the given parameter slot.
762 *
763 * @param slotIdx
764 * Parameter slot for the constant.
765 * @param allowableCloseLoopError
766 * Value of the allowable closed-loop error in sensor units (or sensor units per 100ms for velocity).
767 * @param timeoutMs
768 * Timeout value in ms. If nonzero, function will wait for
769 * config success and report an error if it times out.
770 * If zero, no blocking or checking is performed.
771 * @return Error Code generated by function. 0 indicates no error.
772 */
774 double allowableCloseLoopError, int timeoutMs = 0) = 0;
775 /**
776 * Sets the maximum integral accumulator in the given parameter slot.
777 *
778 * @param slotIdx
779 * Parameter slot for the constant.
780 * @param iaccum
781 * Value of the maximum integral accumulator (closed loop error
782 * units X 1ms).
783 * @param timeoutMs
784 * Timeout value in ms. If nonzero, function will wait for config
785 * success and report an error if it times out. If zero, no
786 * blocking or checking is performed.
787 * @return Error Code generated by function. 0 indicates no error.
788 */
789 virtual ErrorCode ConfigMaxIntegralAccumulator(int slotIdx, double iaccum,
790 int timeoutMs = 0) = 0;
791 /**
792 * Sets the peak closed-loop output. This peak output is slot-specific and
793 * is applied to the output of the associated PID loop.
794 * This setting is seperate from the generic Peak Output setting.
795 *
796 * @param slotIdx
797 * Parameter slot for the constant.
798 * @param percentOut
799 * Peak Percent Output from 0 to 1. This value is absolute and
800 * the magnitude will apply in both forward and reverse directions.
801 * @param timeoutMs
802 * Timeout value in ms. If nonzero, function will wait for
803 * config success and report an error if it times out.
804 * If zero, no blocking or checking is performed.
805 * @return Error Code generated by function. 0 indicates no error.
806 */
807 virtual ErrorCode ConfigClosedLoopPeakOutput(int slotIdx, double percentOut, int timeoutMs = 0) = 0;
808 /**
809 * Sets the loop time (in milliseconds) of the PID closed-loop calculations.
810 * Default value is 1 ms.
811 *
812 * @param slotIdx
813 * Parameter slot for the constant.
814 * @param loopTimeMs
815 * Loop timing of the closed-loop calculations. Minimum value of
816 * 1 ms, maximum of 64 ms.
817 * @param timeoutMs
818 * Timeout value in ms. If nonzero, function will wait for
819 * config success and report an error if it times out.
820 * If zero, no blocking or checking is performed.
821 * @return Error Code generated by function. 0 indicates no error.
822 */
823 virtual ErrorCode ConfigClosedLoopPeriod(int slotIdx, int loopTimeMs, int timeoutMs = 0) = 0;
824
825 /**
826 * Configures the Polarity of the Auxiliary PID (PID1).
827 *
828 * Standard Polarity:
829 * Primary Output = PID0 + PID1,
830 * Auxiliary Output = PID0 - PID1,
831 *
832 * Inverted Polarity:
833 * Primary Output = PID0 - PID1,
834 * Auxiliary Output = PID0 + PID1,
835 *
836 * @param invert
837 * If true, use inverted PID1 output polarity.
838 * @param timeoutMs
839 * Timeout value in ms. If nonzero, function will wait for config
840 * success and report an error if it times out. If zero, no
841 * blocking or checking is performed.
842 * @return Error Code
843 */
844 virtual ErrorCode ConfigAuxPIDPolarity(bool invert, int timeoutMs = 0) = 0;
845
846 //------ Close loop State ----------//
847 /**
848 * Sets the integral accumulator. Typically this is used to clear/zero the
849 * integral accumulator, however some use cases may require seeding the
850 * accumulator for a faster response.
851 *
852 * @param iaccum
853 * Value to set for the integral accumulator (closed loop error
854 * units X 1ms).
855 * @param pidIdx
856 * 0 for Primary closed-loop. 1 for auxiliary closed-loop.
857 * @param timeoutMs
858 * Timeout value in ms. If nonzero, function will wait for config
859 * success and report an error if it times out. If zero, no
860 * blocking or checking is performed.
861 * @return Error Code generated by function. 0 indicates no error.
862 */
863 virtual ErrorCode SetIntegralAccumulator(double iaccum, int pidIdx = 0,
864 int timeoutMs = 0) = 0;
865 /**
866 * Gets the closed-loop error. The units depend on which control mode is in
867 * use.
868 *
869 * If closed-loop is seeking a target sensor position, closed-loop error is the difference between target
870 * and current sensor value (in sensor units. Example 4096 units per rotation for CTRE Mag Encoder).
871 *
872 * If closed-loop is seeking a target sensor velocity, closed-loop error is the difference between target
873 * and current sensor value (in sensor units per 100ms).
874 *
875 * If using motion profiling or Motion Magic, closed loop error is calculated against the current target,
876 * and not the "final" target at the end of the profile/movement.
877 *
878 * See Phoenix-Documentation information on units.
879 *
880 *
881 * @param pidIdx
882 * 0 for Primary closed-loop. 1 for auxiliary closed-loop.
883 * @return Closed-loop error value.
884 */
885 virtual double GetClosedLoopError(int pidIdx = 0) = 0;
886 /**
887 * Gets the iaccum value.
888 *
889 * @param pidIdx
890 * 0 for Primary closed-loop. 1 for auxiliary closed-loop.
891 * @return Integral accumulator value (Closed-loop error X 1ms).
892 */
893 virtual double GetIntegralAccumulator(int pidIdx = 0) = 0;
894 /**
895 * Gets the derivative of the closed-loop error.
896 *
897 * @param pidIdx
898 * 0 for Primary closed-loop. 1 for auxiliary closed-loop.
899 * @return The error derivative value.
900 */
901 virtual double GetErrorDerivative(int pidIdx = 0) = 0;
902
903 /**
904 * Selects which profile slot to use for closed-loop control.
905 *
906 * @param slotIdx
907 * Profile slot to select.
908 * @param pidIdx
909 * 0 for Primary closed-loop. 1 for auxiliary closed-loop.
910 **/
911 virtual ErrorCode SelectProfileSlot(int slotIdx, int pidIdx) = 0;
912
913 /**
914 * Gets the current target of a given closed loop.
915 *
916 * @param pidIdx
917 * 0 for Primary closed-loop. 1 for auxiliary closed-loop.
918 * @return The closed loop target.
919 */
920 virtual double GetClosedLoopTarget(int pidIdx = 0) = 0;
921 /**
922 * Gets the active trajectory target position for using
923 * MotionMagic/MotionProfile control modes.
924 *
925 * @param pidIdx
926 * 0 for Primary closed-loop. 1 for auxiliary closed-loop.
927 * @return The Active Trajectory Position in sensor units.
928 */
929 virtual double GetActiveTrajectoryPosition(int pidIdx = 0) = 0;
930 /**
931 * Gets the active trajectory target velocity for using
932 * MotionMagic/MotionProfile control modes.
933 *
934 * @param pidIdx
935 * 0 for Primary closed-loop. 1 for auxiliary closed-loop.
936 * @return The Active Trajectory Velocity in sensor units per 100ms.
937 */
938 virtual double GetActiveTrajectoryVelocity(int pidIdx = 0) = 0;
939 /**
940 * Gets the active trajectory arbitrary feedforward using
941 * MotionMagic/MotionProfile control modes.
942 *
943 * @param pidIdx
944 * 0 for Primary closed-loop. 1 for auxiliary closed-loop.
945 * @return The Active Trajectory ArbFeedFwd in units of percent output
946 * (where 0.01 is 1%).
947 */
948 virtual double GetActiveTrajectoryArbFeedFwd(int pidIdx = 0) = 0;
949
950 //------ Motion Profile Settings used in Motion Magic ----------//
951 /**
952 * Sets the Motion Magic Cruise Velocity. This is the peak target velocity
953 * that the motion magic curve generator can use.
954 *
955 * @param sensorUnitsPer100ms
956 * Motion Magic Cruise Velocity (in raw sensor units per 100 ms).
957 * @param timeoutMs
958 * Timeout value in ms. If nonzero, function will wait for config
959 * success and report an error if it times out. If zero, no
960 * blocking or checking is performed.
961 * @return Error Code generated by function. 0 indicates no error.
962 */
963 virtual ErrorCode ConfigMotionCruiseVelocity(double sensorUnitsPer100ms,
964 int timeoutMs = 0) = 0;
965 /**
966 * Sets the Motion Magic Acceleration. This is the target acceleration that
967 * the motion magic curve generator can use.
968 *
969 * @param sensorUnitsPer100msPerSec
970 * Motion Magic Acceleration (in raw sensor units per 100 ms per
971 * second).
972 * @param timeoutMs
973 * Timeout value in ms. If nonzero, function will wait for config
974 * success and report an error if it times out. If zero, no
975 * blocking or checking is performed.
976 * @return Error Code generated by function. 0 indicates no error.
977 */
978 virtual ErrorCode ConfigMotionAcceleration(double sensorUnitsPer100msPerSec,
979 int timeoutMs = 0) = 0;
980
981 /**
982 * Sets the Motion Magic S Curve Strength.
983 * Call this before using Motion Magic.
984 * Modifying this during a Motion Magic action should be avoided.
985 *
986 * @param curveStrength
987 * 0 to use Trapezoidal Motion Profile. [1,8] for S-Curve (greater value yields greater smoothing).
988 * @param timeoutMs
989 * Timeout value in ms. If nonzero, function will wait for config
990 * success and report an error if it times out. If zero, no
991 * blocking or checking is performed.
992 * @return Error Code generated by function. 0 indicates no error.
993 */
994 virtual ErrorCode ConfigMotionSCurveStrength(int curveStrength, int timeoutMs) = 0;
995 //------ Motion Profile Buffer ----------//
996 /**
997 * Clear the buffered motion profile in both controller's RAM (bottom), and in the
998 * API (top).
999 *
1000 * @return Error Code generated by function. 0 indicates no error
1001 */
1003 /**
1004 * Retrieve just the buffer count for the api-level (top) buffer. This
1005 * routine performs no CAN or data structure lookups, so its fast and ideal
1006 * if caller needs to quickly poll the progress of trajectory points being
1007 * emptied into controller's RAM. Otherwise just use GetMotionProfileStatus.
1008 *
1009 * @return number of trajectory points in the top buffer.
1010 */
1012 /**
1013 * Push another trajectory point into the top level buffer (which is emptied
1014 * into the motor controller's bottom buffer as room allows).
1015 * @param trajPt to push into buffer.
1016 * The members should be filled in with these values...
1017 *
1018 * targPos: servo position in sensor units.
1019 * targVel: velocity to feed-forward in sensor units
1020 * per 100ms.
1021 * profileSlotSelect0 Which slot to get PIDF gains. PID is used for position servo. F is used
1022 * as the Kv constant for velocity feed-forward. Typically this is hardcoded
1023 * to the a particular slot, but you are free gain schedule if need be.
1024 * Choose from [0,3]
1025 * profileSlotSelect1 Which slot to get PIDF gains for auxiliary PId.
1026 * This only has impact during MotionProfileArc Control mode.
1027 * Choose from [0,1].
1028 * isLastPoint set to nonzero to signal motor controller to keep processing this
1029 * trajectory point, instead of jumping to the next one
1030 * when timeDurMs expires. Otherwise MP executer will
1031 * eventually see an empty buffer after the last point
1032 * expires, causing it to assert the IsUnderRun flag.
1033 * However this may be desired if calling application
1034 * never wants to terminate the MP.
1035 * zeroPos set to nonzero to signal motor controller to "zero" the selected
1036 * position sensor before executing this trajectory point.
1037 * Typically the first point should have this set only thus
1038 * allowing the remainder of the MP positions to be relative to
1039 * zero.
1040 * timeDur Duration to apply this trajectory pt.
1041 * This time unit is ADDED to the exising base time set by
1042 * configMotionProfileTrajectoryPeriod().
1043 * @return CTR_OKAY if trajectory point push ok. ErrorCode if buffer is
1044 * full due to kMotionProfileTopBufferCapacity.
1045 */
1047 const ctre::phoenix::motion::TrajectoryPoint & trajPt)= 0;
1048 /**
1049 * Retrieve just the buffer full for the api-level (top) buffer. This
1050 * routine performs no CAN or data structure lookups, so its fast and ideal
1051 * if caller needs to quickly poll. Otherwise just use
1052 * GetMotionProfileStatus.
1053 *
1054 * @return number of trajectory points in the top buffer.
1055 */
1057 /**
1058 * This must be called periodically to funnel the trajectory points from the
1059 * API's top level buffer to the controller's bottom level buffer. Recommendation
1060 * is to call this twice as fast as the execution rate of the motion
1061 * profile. So if MP is running with 20ms trajectory points, try calling
1062 * this routine every 10ms. All motion profile functions are thread-safe
1063 * through the use of a mutex, so there is no harm in having the caller
1064 * utilize threading.
1065 */
1067 /**
1068 * Retrieve all status information.
1069 * For best performance, Caller can snapshot all status information regarding the
1070 * motion profile executer.
1071 *
1072 * @param statusToFill Caller supplied object to fill.
1073 *
1074 * The members are filled, as follows...
1075 *
1076 * topBufferRem: The available empty slots in the trajectory buffer.
1077 * The robot API holds a "top buffer" of trajectory points, so your applicaion
1078 * can dump several points at once. The API will then stream them into the
1079 * low-level buffer, allowing the motor controller to act on them.
1080 *
1081 * topBufferRem: The number of points in the top trajectory buffer.
1082 *
1083 * btmBufferCnt: The number of points in the low level controller buffer.
1084 *
1085 * hasUnderrun: Set if isUnderrun ever gets set.
1086 * Can be manually cleared by clearMotionProfileHasUnderrun() or automatically cleared by startMotionProfile().
1087 *
1088 * isUnderrun: This is set if controller needs to shift a point from its buffer into
1089 * the active trajectory point however
1090 * the buffer is empty.
1091 * This gets cleared automatically when is resolved.
1092 *
1093 * activePointValid: True if the active trajectory point is not empty, false otherwise. The members in activePoint are only valid if this signal is set.
1094 *
1095 * isLast: is set/cleared based on the MP executer's current
1096 * trajectory point's IsLast value. This assumes
1097 * IsLast was set when PushMotionProfileTrajectory
1098 * was used to insert the currently processed trajectory
1099 * point.
1100 *
1101 * profileSlotSelect: The currently processed trajectory point's
1102 * selected slot. This can differ in the currently selected slot used
1103 * for Position and Velocity servo modes
1104 *
1105 * outputEnable: The current output mode of the motion profile
1106 * executer (disabled, enabled, or hold). When changing the set()
1107 * value in MP mode, it's important to check this signal to
1108 * confirm the change takes effect before interacting with the top buffer.
1109 * @return Error Code generated by function. 0 indicates no error.
1110 */
1113 /**
1114 * Clear the "Has Underrun" flag. Typically this is called after application
1115 * has confirmed an underrun had occured.
1116 *
1117 * @param timeoutMs
1118 * Timeout value in ms. If nonzero, function will wait for config
1119 * success and report an error if it times out. If zero, no
1120 * blocking or checking is performed.
1121 * @return Error Code generated by function. 0 indicates no error.
1122 */
1123 virtual ErrorCode ClearMotionProfileHasUnderrun(int timeoutMs = 0)= 0;
1124 /**
1125 * Calling application can opt to speed up the handshaking between the robot
1126 * API and the controller to increase the download rate of the controller's Motion
1127 * Profile. Ideally the period should be no more than half the period of a
1128 * trajectory point.
1129 *
1130 * @param periodMs
1131 * The transmit period in ms.
1132 * @return Error Code generated by function. 0 indicates no error.
1133 */
1135 /**
1136 * When trajectory points are processed in the motion profile executer, the MPE determines
1137 * how long to apply the active trajectory point by summing baseTrajDurationMs with the
1138 * timeDur of the trajectory point (see TrajectoryPoint).
1139 *
1140 * This allows general selection of the execution rate of the points with 1ms resolution,
1141 * while allowing some degree of change from point to point.
1142 * @param baseTrajDurationMs The base duration time of every trajectory point.
1143 * This is summed with the trajectory points unique timeDur.
1144 * @param timeoutMs
1145 * Timeout value in ms. If nonzero, function will wait for
1146 * config success and report an error if it times out.
1147 * If zero, no blocking or checking is performed.
1148 * @return Error Code generated by function. 0 indicates no error.
1149 */
1150 virtual ErrorCode ConfigMotionProfileTrajectoryPeriod(int baseTrajDurationMs, int timeoutMs = 0)=0;
1151
1152 //------Feedback Device Interaction Settings---------//
1153 /**
1154 * Disables continuous tracking of the position for analog and pulse-width.
1155 * If the signal goes from 4095 to 0 (pulse-width) a motor controller will continue to read 4096 by default.
1156 * If overflow tracking is disabled, it will wrap to 0 (not continuous)
1157 *
1158 * If using pulse-width on CTRE Mag Encoder (within one rotation) or absolute analog sensor (within one rotation),
1159 * setting feedbackNotContinuous to true is recommended, to prevent intermittent
1160 * connections from causing sensor "jumps" of 4096 (or 1024 for analog) units.
1161 *
1162 * @param feedbackNotContinuous True to disable the overflow tracking.
1163 *
1164 * @param timeoutMs
1165 * Timeout value in ms. If nonzero, function will wait for
1166 * config success and report an error if it times out.
1167 * If zero, no blocking or checking is performed.
1168 * @return Error Code generated by function. 0 indicates no error.
1169 */
1170 virtual ErrorCode ConfigFeedbackNotContinuous(bool feedbackNotContinuous, int timeoutMs = 0) = 0;
1171 /**
1172 * Disables going to neutral (brake/coast) when a remote sensor is no longer detected.
1173 *
1174 * @param remoteSensorClosedLoopDisableNeutralOnLOS disable going to neutral
1175 *
1176 * @param timeoutMs
1177 * Timeout value in ms. If nonzero, function will wait for
1178 * config success and report an error if it times out.
1179 * If zero, no blocking or checking is performed.
1180 * @return Error Code generated by function. 0 indicates no error.
1181 */
1182 virtual ErrorCode ConfigRemoteSensorClosedLoopDisableNeutralOnLOS(bool remoteSensorClosedLoopDisableNeutralOnLOS, int timeoutMs = 0) = 0;
1183 /**
1184 * Enables clearing the position of the feedback sensor when the forward
1185 * limit switch is triggered
1186 *
1187 * @param clearPositionOnLimitF Whether clearing is enabled, defaults false
1188 * @param timeoutMs
1189 * Timeout value in ms. If nonzero, function will wait for
1190 * config success and report an error if it times out.
1191 * If zero, no blocking or checking is performed.
1192 * @return Error Code generated by function. 0 indicates no error.
1193 */
1194 virtual ErrorCode ConfigClearPositionOnLimitF(bool clearPositionOnLimitF, int timeoutMs = 0) = 0;
1195 /**
1196 * Enables clearing the position of the feedback sensor when the reverse
1197 * limit switch is triggered
1198 *
1199 * @param clearPositionOnLimitR Whether clearing is enabled, defaults false
1200 * @param timeoutMs
1201 * Timeout value in ms. If nonzero, function will wait for
1202 * config success and report an error if it times out.
1203 * If zero, no blocking or checking is performed.
1204 * @return Error Code generated by function. 0 indicates no error.
1205 */
1206 virtual ErrorCode ConfigClearPositionOnLimitR(bool clearPositionOnLimitR, int timeoutMs = 0) = 0;
1207 /**
1208 * Enables clearing the position of the feedback sensor when the quadrature index signal
1209 * is detected
1210 *
1211 * @param clearPositionOnQuadIdx Whether clearing is enabled, defaults false
1212 * @param timeoutMs
1213 * Timeout value in ms. If nonzero, function will wait for
1214 * config success and report an error if it times out.
1215 * If zero, no blocking or checking is performed.
1216 * @return Error Code generated by function. 0 indicates no error.
1217 */
1218 virtual ErrorCode ConfigClearPositionOnQuadIdx(bool clearPositionOnQuadIdx, int timeoutMs = 0) = 0;
1219 /**
1220 * Disables limit switches triggering (if enabled) when the sensor is no longer detected.
1221 *
1222 * @param limitSwitchDisableNeutralOnLOS disable triggering
1223 *
1224 * @param timeoutMs
1225 * Timeout value in ms. If nonzero, function will wait for
1226 * config success and report an error if it times out.
1227 * If zero, no blocking or checking is performed.
1228 * @return Error Code generated by function. 0 indicates no error.
1229 */
1230 virtual ErrorCode ConfigLimitSwitchDisableNeutralOnLOS(bool limitSwitchDisableNeutralOnLOS, int timeoutMs = 0) = 0;
1231 /**
1232 * Disables soft limits triggering (if enabled) when the sensor is no longer detected.
1233 *
1234 * @param softLimitDisableNeutralOnLOS disable triggering
1235 *
1236 * @param timeoutMs
1237 * Timeout value in ms. If nonzero, function will wait for
1238 * config success and report an error if it times out.
1239 * If zero, no blocking or checking is performed.
1240 * @return Error Code generated by function. 0 indicates no error.
1241 */
1242 virtual ErrorCode ConfigSoftLimitDisableNeutralOnLOS(bool softLimitDisableNeutralOnLOS, int timeoutMs = 0) = 0;
1243 /**
1244 * Sets the edges per rotation of a pulse width sensor. (This should be set for
1245 * tachometer use).
1246 *
1247 * @param pulseWidthPeriod_EdgesPerRot edges per rotation
1248 *
1249 * @param timeoutMs
1250 * Timeout value in ms. If nonzero, function will wait for
1251 * config success and report an error if it times out.
1252 * If zero, no blocking or checking is performed.
1253 * @return Error Code generated by function. 0 indicates no error.
1254 */
1255 virtual ErrorCode ConfigPulseWidthPeriod_EdgesPerRot(int pulseWidthPeriod_EdgesPerRot, int timeoutMs = 0) = 0;
1256 /**
1257 * Sets the number of samples to use in smoothing a pulse width sensor with a rolling
1258 * average. Default is 1 (no smoothing).
1259 *
1260 * @param pulseWidthPeriod_FilterWindowSz samples for rolling avg
1261 *
1262 * @param timeoutMs
1263 * Timeout value in ms. If nonzero, function will wait for
1264 * config success and report an error if it times out.
1265 * If zero, no blocking or checking is performed.
1266 * @return Error Code generated by function. 0 indicates no error.
1267 */
1268 virtual ErrorCode ConfigPulseWidthPeriod_FilterWindowSz(int pulseWidthPeriod_FilterWindowSz, int timeoutMs = 0) = 0;
1269
1270 //------ error ----------//
1271 /**
1272 * Gets the last error generated by this object. Not all functions return an
1273 * error code but can potentially report errors. This function can be used
1274 * to retrieve those error codes.
1275 *
1276 * @return Last Error Code generated by a function.
1277 */
1279
1280 //------ Faults ----------//
1281 /**
1282 * Polls the various fault flags.
1283 *
1284 * @param toFill
1285 * Caller's object to fill with latest fault flags.
1286 * @return Last Error Code generated by a function.
1287 */
1288 virtual ErrorCode GetFaults(Faults & toFill) = 0;
1289 /**
1290 * Polls the various sticky fault flags.
1291 *
1292 * @param toFill
1293 * Caller's object to fill with latest sticky fault flags.
1294 * @return Last Error Code generated by a function.
1295 */
1297 /**
1298 * Clears all sticky faults.
1299 *
1300 * @param timeoutMs
1301 * Timeout value in ms. If nonzero, function will wait for config
1302 * success and report an error if it times out. If zero, no
1303 * blocking or checking is performed.
1304 * @return Last Error Code generated by a function.
1305 */
1306 virtual ErrorCode ClearStickyFaults(int timeoutMs = 0) = 0;
1307
1308 //------ Firmware ----------//
1309 /**
1310 * Gets the firmware version of the device.
1311 *
1312 * @return Firmware version of device. For example: version 1-dot-2 is
1313 * 0x0102.
1314 */
1315 virtual int GetFirmwareVersion() = 0;
1316 /**
1317 * Returns true if the device has reset since last call.
1318 *
1319 * @return Has a Device Reset Occurred?
1320 */
1321 virtual bool HasResetOccurred() = 0;
1322
1323 //------ Custom Persistent Params ----------//
1324 /**
1325 * Sets the value of a custom parameter. This is for arbitrary use.
1326 *
1327 * Sometimes it is necessary to save calibration/limit/target information in
1328 * the device. Particularly if the device is part of a subsystem that can be
1329 * replaced.
1330 *
1331 * @param newValue
1332 * Value for custom parameter.
1333 * @param paramIndex
1334 * Index of custom parameter [0,1]
1335 * @param timeoutMs
1336 * Timeout value in ms. If nonzero, function will wait for config
1337 * success and report an error if it times out. If zero, no
1338 * blocking or checking is performed.
1339 * @return Error Code generated by function. 0 indicates no error.
1340 */
1341 virtual ErrorCode ConfigSetCustomParam(int newValue, int paramIndex,
1342 int timeoutMs = 0) = 0;
1343 /**
1344 * Gets the value of a custom parameter.
1345 *
1346 * @param paramIndex
1347 * Index of custom parameter [0,1].
1348 * @param timeoutMs
1349 * Timeout value in ms. If nonzero, function will wait for config
1350 * success and report an error if it times out. If zero, no
1351 * blocking or checking is performed.
1352 * @return Value of the custom param.
1353 */
1354 virtual int ConfigGetCustomParam(int paramIndex, int timeoutMs = 0) = 0;
1355
1356 //------ Generic Param API, typically not used ----------//
1357 /**
1358 * Sets a parameter. Generally this is not used. This can be utilized in -
1359 * Using new features without updating API installation. - Errata
1360 * workarounds to circumvent API implementation. - Allows for rapid testing
1361 * / unit testing of firmware.
1362 *
1363 * @param param
1364 * Parameter enumeration.
1365 * @param value
1366 * Value of parameter.
1367 * @param subValue
1368 * Subvalue for parameter. Maximum value of 255.
1369 * @param ordinal
1370 * Ordinal of parameter.
1371 * @param timeoutMs
1372 * Timeout value in ms. If nonzero, function will wait for config
1373 * success and report an error if it times out. If zero, no
1374 * blocking or checking is performed.
1375 * @return Error Code generated by function. 0 indicates no error.
1376 */
1377 virtual ErrorCode ConfigSetParameter(ParamEnum param, double value,
1378 uint8_t subValue, int ordinal, int timeoutMs = 0) = 0;
1379 /**
1380 * Gets a parameter.
1381 *
1382 * @param paramEnum
1383 * Parameter enumeration.
1384 * @param ordinal
1385 * Ordinal of parameter.
1386 * @param timeoutMs
1387 * Timeout value in ms. If nonzero, function will wait for
1388 * config success and report an error if it times out.
1389 * If zero, no blocking or checking is performed.
1390 * @return Value of parameter.
1391 */
1392 virtual double ConfigGetParameter(ParamEnum paramEnum, int ordinal,
1393 int timeoutMs = 0) = 0;
1394
1395 //------ Misc. ----------//
1396 /**
1397 * @return BaseID of device
1398 */
1399 virtual int GetBaseID() = 0;
1400 /**
1401 * Returns the Device ID
1402 *
1403 * @return Device number.
1404 */
1405 virtual int GetDeviceID() = 0;
1406 /**
1407 * @return control mode motor controller is in
1408 */
1410
1411 // ----- Follower ------//
1412 /* in parent interface */
1413};
1414
1415}
1416} // namespace phoenix
1417}
Interface for followers.
Definition: IFollower.h:14
Interface for motor controllers.
Definition: IMotorController.h:35
virtual void NeutralOutput()=0
Neutral the motor output by setting control mode to disabled.
virtual ErrorCode SetStatusFramePeriod(StatusFrame frame, uint8_t periodMs, int timeoutMs=0)=0
Sets the period of the given status frame.
virtual ErrorCode SetControlFramePeriod(ControlFrame frame, int periodMs)=0
Sets the period of the given control frame.
virtual ErrorCode ConfigMotionProfileTrajectoryPeriod(int baseTrajDurationMs, int timeoutMs=0)=0
When trajectory points are processed in the motion profile executer, the MPE determines how long to a...
virtual double GetSelectedSensorVelocity(int pidIdx=0)=0
Get the selected sensor velocity.
virtual void Set(ControlMode mode, double demand0, DemandType demand1Type, double demand1)=0
virtual ErrorCode ConfigClosedloopRamp(double secondsFromNeutralToFull, int timeoutMs=0)=0
Configures the closed-loop ramp rate of throttle output.
virtual ErrorCode ConfigRemoteFeedbackFilter(ctre::phoenix::motorcontrol::can::BaseTalon &talonRef, int remoteOrdinal, int timeoutMs=0)=0
Select what remote device and signal to assign to Remote Sensor 0 or Remote Sensor 1.
virtual ErrorCode Config_kD(int slotIdx, double value, int timeoutMs=0)=0
Sets the 'D' constant in the given parameter slot.
virtual ErrorCode ConfigMaxIntegralAccumulator(int slotIdx, double iaccum, int timeoutMs=0)=0
Sets the maximum integral accumulator in the given parameter slot.
virtual ErrorCode GetLastError()=0
Gets the last error generated by this object.
virtual ErrorCode GetStickyFaults(StickyFaults &toFill)=0
Polls the various sticky fault flags.
virtual ErrorCode ConfigRemoteFeedbackFilter(int deviceID, RemoteSensorSource remoteSensorSource, int remoteOrdinal, int timeoutMs=0)=0
Select what remote device and signal to assign to Remote Sensor 0 or Remote Sensor 1.
virtual ErrorCode ConfigSelectedFeedbackSensor(RemoteFeedbackDevice feedbackDevice, int pidIdx=0, int timeoutMs=0)=0
Select the remote feedback device for the motor controller.
virtual void SetNeutralMode(NeutralMode neutralMode)=0
Sets the mode of operation during neutral throttle output.
virtual void OverrideLimitSwitchesEnable(bool enable)=0
Sets the enable state for limit switches.
virtual ErrorCode ConfigFeedbackNotContinuous(bool feedbackNotContinuous, int timeoutMs=0)=0
Disables continuous tracking of the position for analog and pulse-width.
virtual double GetSelectedSensorPosition(int pidIdx=0)=0
Get the selected sensor position (in raw sensor units).
virtual bool IsVoltageCompensationEnabled()=0
Returns the enable state of Voltage Compensation that the caller has set.
virtual ErrorCode SetIntegralAccumulator(double iaccum, int pidIdx=0, int timeoutMs=0)=0
Sets the integral accumulator.
virtual ErrorCode ConfigLimitSwitchDisableNeutralOnLOS(bool limitSwitchDisableNeutralOnLOS, int timeoutMs=0)=0
Disables limit switches triggering (if enabled) when the sensor is no longer detected.
virtual ErrorCode ConfigAuxPIDPolarity(bool invert, int timeoutMs=0)=0
Configures the Polarity of the Auxiliary PID (PID1).
virtual ErrorCode ChangeMotionControlFramePeriod(int periodMs)=0
Calling application can opt to speed up the handshaking between the robot API and the controller to i...
virtual double GetActiveTrajectoryVelocity(int pidIdx=0)=0
Gets the active trajectory target velocity for using MotionMagic/MotionProfile control modes.
virtual ErrorCode ConfigRemoteFeedbackFilter(ctre::phoenix::sensors::CANCoder &canCoderRef, int remoteOrdinal, int timeoutMs=0)=0
Select what remote device and signal to assign to Remote Sensor 0 or Remote Sensor 1.
virtual ErrorCode ConfigPulseWidthPeriod_EdgesPerRot(int pulseWidthPeriod_EdgesPerRot, int timeoutMs=0)=0
Sets the edges per rotation of a pulse width sensor.
virtual double ConfigGetParameter(ParamEnum paramEnum, int ordinal, int timeoutMs=0)=0
Gets a parameter.
virtual ErrorCode ConfigVoltageMeasurementFilter(int filterWindowSamples, int timeoutMs=0)=0
Configures the voltage measurement filter.
virtual ErrorCode ConfigSoftLimitDisableNeutralOnLOS(bool softLimitDisableNeutralOnLOS, int timeoutMs=0)=0
Disables soft limits triggering (if enabled) when the sensor is no longer detected.
virtual double GetErrorDerivative(int pidIdx=0)=0
Gets the derivative of the closed-loop error.
virtual ErrorCode ConfigForwardLimitSwitchSource(RemoteLimitSwitchSource type, LimitSwitchNormal normalOpenOrClose, int deviceID, int timeoutMs=0)=0
Configures the forward limit switch for a remote source.
virtual int GetDeviceID()=0
Returns the Device ID.
virtual double GetClosedLoopTarget(int pidIdx=0)=0
Gets the current target of a given closed loop.
virtual ErrorCode ConfigReverseLimitSwitchSource(RemoteLimitSwitchSource type, LimitSwitchNormal normalOpenOrClose, int deviceID, int timeoutMs=0)=0
Configures the reverse limit switch for a remote source.
virtual ErrorCode ConfigNominalOutputForward(double percentOut, int timeoutMs=0)=0
Configures the forward nominal output percentage.
virtual double GetClosedLoopError(int pidIdx=0)=0
Gets the closed-loop error.
virtual ErrorCode ConfigFactoryDefault(int timeout)=0
Revert all configurations to factory default values.
virtual double GetMotorOutputPercent()=0
Gets the output percentage of the motor controller.
virtual ErrorCode ConfigNeutralDeadband(double percentDeadband, int timeoutMs=0)=0
Configures the output deadband percentage.
virtual double GetBusVoltage()=0
Gets the bus voltage seen by the device.
virtual ErrorCode Config_IntegralZone(int slotIdx, double izone, int timeoutMs=0)=0
Sets the Integral Zone constant in the given parameter slot.
virtual ErrorCode ConfigReverseSoftLimitEnable(bool enable, int timeoutMs=0)=0
Configures the reverse soft limit enable.
virtual ErrorCode Config_kF(int slotIdx, double value, int timeoutMs=0)=0
Sets the 'F' constant in the given parameter slot.
virtual int ConfigGetCustomParam(int paramIndex, int timeoutMs=0)=0
Gets the value of a custom parameter.
virtual ErrorCode ClearStickyFaults(int timeoutMs=0)=0
Clears all sticky faults.
virtual ErrorCode ConfigNominalOutputReverse(double percentOut, int timeoutMs=0)=0
Configures the reverse nominal output percentage.
virtual ErrorCode GetFaults(Faults &toFill)=0
Polls the various fault flags.
virtual double GetIntegralAccumulator(int pidIdx=0)=0
Gets the iaccum value.
virtual ErrorCode ConfigAllowableClosedloopError(int slotIdx, double allowableCloseLoopError, int timeoutMs=0)=0
Sets the allowable closed-loop error in the given parameter slot.
virtual ErrorCode SelectProfileSlot(int slotIdx, int pidIdx)=0
Selects which profile slot to use for closed-loop control.
virtual double GetTemperature()=0
Gets the temperature of the motor controller.
virtual ErrorCode ConfigSetCustomParam(int newValue, int paramIndex, int timeoutMs=0)=0
Sets the value of a custom parameter.
virtual ErrorCode ConfigPeakOutputReverse(double percentOut, int timeoutMs=0)=0
Configures the reverse peak output percentage.
virtual ErrorCode SetSelectedSensorPosition(double sensorPos, int pidIdx=0, int timeoutMs=50)=0
Sets the sensor position to the given value.
virtual void Set(ControlMode Mode, double demand)=0
Sets the appropriate output on the talon, depending on the mode.
virtual ErrorCode ConfigSetParameter(ParamEnum param, double value, uint8_t subValue, int ordinal, int timeoutMs=0)=0
Sets a parameter.
virtual int GetMotionProfileTopLevelBufferCount()=0
Retrieve just the buffer count for the api-level (top) buffer.
virtual ErrorCode GetMotionProfileStatus(ctre::phoenix::motion::MotionProfileStatus &statusToFill)=0
Retrieve all status information.
virtual void SetInverted(bool invert)=0
Inverts the hbridge output of the motor controller.
virtual ErrorCode ConfigSensorTerm(SensorTerm sensorTerm, FeedbackDevice feedbackDevice, int timeoutMs=0)=0
Select what sensor term should be bound to switch feedback device.
virtual ErrorCode ConfigPulseWidthPeriod_FilterWindowSz(int pulseWidthPeriod_FilterWindowSz, int timeoutMs=0)=0
Sets the number of samples to use in smoothing a pulse width sensor with a rolling average.
virtual ErrorCode ConfigClosedLoopPeakOutput(int slotIdx, double percentOut, int timeoutMs=0)=0
Sets the peak closed-loop output.
virtual ErrorCode ConfigForwardSoftLimitThreshold(double forwardSensorLimit, int timeoutMs=0)=0
Configures the forward soft limit threhold.
virtual ErrorCode ConfigReverseSoftLimitThreshold(double reverseSensorLimit, int timeoutMs=0)=0
Configures the reverse soft limit threshold.
virtual ErrorCode ClearMotionProfileHasUnderrun(int timeoutMs=0)=0
Clear the "Has Underrun" flag.
virtual ErrorCode ConfigClosedLoopPeriod(int slotIdx, int loopTimeMs, int timeoutMs=0)=0
Sets the loop time (in milliseconds) of the PID closed-loop calculations.
virtual ErrorCode ConfigMotionSCurveStrength(int curveStrength, int timeoutMs)=0
Sets the Motion Magic S Curve Strength.
virtual ErrorCode Config_kP(int slotIdx, double value, int timeoutMs=0)=0
Sets the 'P' constant in the given parameter slot.
virtual void OverrideSoftLimitsEnable(bool enable)=0
Can be used to override-disable the soft limits.
virtual ErrorCode Config_kI(int slotIdx, double value, int timeoutMs=0)=0
Sets the 'I' constant in the given parameter slot.
virtual bool HasResetOccurred()=0
Returns true if the device has reset since last call.
virtual ErrorCode ConfigClearPositionOnQuadIdx(bool clearPositionOnQuadIdx, int timeoutMs=0)=0
Enables clearing the position of the feedback sensor when the quadrature index signal is detected.
virtual ErrorCode ConfigSelectedFeedbackCoefficient(double coefficient, int pidIdx=0, int timeoutMs=0)=0
The Feedback Coefficient is a scalar applied to the value of the feedback sensor.
virtual ErrorCode ConfigVoltageCompSaturation(double voltage, int timeoutMs=0)=0
Configures the Voltage Compensation saturation voltage.
virtual void EnableVoltageCompensation(bool enable)=0
Enables voltage compensation.
virtual ErrorCode ConfigForwardSoftLimitEnable(bool enable, int timeoutMs=0)=0
Configures the forward soft limit enable.
virtual ErrorCode ConfigOpenloopRamp(double secondsFromNeutralToFull, int timeoutMs=0)=0
Configures the open-loop ramp rate of throttle output.
virtual double GetActiveTrajectoryPosition(int pidIdx=0)=0
Gets the active trajectory target position for using MotionMagic/MotionProfile control modes.
virtual ErrorCode ConfigClearPositionOnLimitR(bool clearPositionOnLimitR, int timeoutMs=0)=0
Enables clearing the position of the feedback sensor when the reverse limit switch is triggered.
virtual void ProcessMotionProfileBuffer()=0
This must be called periodically to funnel the trajectory points from the API's top level buffer to t...
virtual ErrorCode ConfigMotionCruiseVelocity(double sensorUnitsPer100ms, int timeoutMs=0)=0
Sets the Motion Magic Cruise Velocity.
virtual void SetInverted(InvertType invertType)=0
Inverts the hbridge output of the motor controller in relation to the master if present.
virtual ~IMotorController()
Definition: IMotorController.h:37
virtual bool IsMotionProfileTopLevelBufferFull()=0
Retrieve just the buffer full for the api-level (top) buffer.
virtual ErrorCode ConfigPeakOutputForward(double percentOut, int timeoutMs=0)=0
Configures the forward peak output percentage.
virtual ErrorCode ConfigClearPositionOnLimitF(bool clearPositionOnLimitF, int timeoutMs=0)=0
Enables clearing the position of the feedback sensor when the forward limit switch is triggered.
virtual ErrorCode ConfigMotionAcceleration(double sensorUnitsPer100msPerSec, int timeoutMs=0)=0
Sets the Motion Magic Acceleration.
virtual ErrorCode ConfigRemoteSensorClosedLoopDisableNeutralOnLOS(bool remoteSensorClosedLoopDisableNeutralOnLOS, int timeoutMs=0)=0
Disables going to neutral (brake/coast) when a remote sensor is no longer detected.
virtual double GetActiveTrajectoryArbFeedFwd(int pidIdx=0)=0
Gets the active trajectory arbitrary feedforward using MotionMagic/MotionProfile control modes.
virtual int GetStatusFramePeriod(StatusFrame frame, int timeoutMs=0)=0
Gets the period of the given status frame.
virtual void SetSensorPhase(bool PhaseSensor)=0
Sets the phase of the sensor.
virtual ErrorCode PushMotionProfileTrajectory(const ctre::phoenix::motion::TrajectoryPoint &trajPt)=0
Push another trajectory point into the top level buffer (which is emptied into the motor controller's...
virtual int GetFirmwareVersion()=0
Gets the firmware version of the device.
virtual ErrorCode ClearMotionProfileTrajectories()=0
Clear the buffered motion profile in both controller's RAM (bottom), and in the API (top).
CTRE Talon SRX Motor Controller when used on CAN Bus.
Definition: BaseTalon.h:267
CTRE CANCoder.
Definition: CANCoder.h:233
ControlMode
Choose the control mode for a motor controller.
Definition: ControlMode.h:11
DemandType
How to interpret a demand value.
Definition: DemandType.h:10
InvertType
Choose the invert type of the motor controller.
Definition: InvertType.h:14
SensorTerm
Choose the sensor term for a motor controller.
Definition: SensorTerm.h:11
LimitSwitchNormal
Choose whether the limit switch is normally open or normally closed.
Definition: LimitSwitchType.h:62
RemoteSensorSource
Choose the remote sensor source for a motor controller.
Definition: RemoteSensorSource.h:13
RemoteFeedbackDevice
Choose the remote feedback device for a motor controller.
Definition: FeedbackDevice.h:179
RemoteLimitSwitchSource
Remote Limit switch source enum.
Definition: LimitSwitchType.h:35
FeedbackDevice
Choose the feedback device for a motor controller.
Definition: FeedbackDevice.h:14
NeutralMode
Choose the neutral mode for a motor controller.
Definition: NeutralMode.h:11
ControlFrame
Control Frames for motor controllers.
Definition: ControlFrame.h:11
StatusFrame
The different status frames available to motor controllers.
Definition: StatusFrame.h:99
ParamEnum
Signal enumeration for generic signal access.
Definition: paramEnum.h:13
ErrorCode
Definition: ErrorCode.h:13
namespace ctre
Definition: paramEnum.h:5
Motion Profile Status This is simply a data transer object.
Definition: MotionProfileStatus.h:15
Motion Profile Trajectory Point This is simply a data transfer object.
Definition: TrajectoryPoint.h:11
All the faults available to motor controllers.
Definition: Faults.h:11
All the sticky faults available to motor controllers.
Definition: StickyFaults.h:11