CTRE Phoenix C++ 5.35.1
Loading...
Searching...
No Matches
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 */
353 RemoteFeedbackDevice feedbackDevice, int pidIdx = 0, int timeoutMs = 0) = 0;
354 /**
355 * The Feedback Coefficient is a scalar applied to the value of the
356 * feedback sensor. Useful when you need to scale your sensor values
357 * within the closed-loop calculations. Default value is 1.
358 *
359 * Selected Feedback Sensor register in firmware is the decoded sensor value
360 * multiplied by the Feedback Coefficient.
361 *
362 * @param coefficient
363 * Feedback Coefficient value. Maximum value of 1.
364 * Resolution is 1/(2^16). Cannot be 0.
365 * @param pidIdx
366 * 0 for Primary closed-loop. 1 for auxiliary closed-loop.
367 * @param timeoutMs
368 * Timeout value in ms. If nonzero, function will wait for
369 * config success and report an error if it times out.
370 * If zero, no blocking or checking is performed.
371 * @return Error Code generated by function. 0 indicates no error.
372 */
374 double coefficient, int pidIdx = 0, int timeoutMs = 0) = 0;
375 /**
376 * Select what remote device and signal to assign to Remote Sensor 0 or Remote Sensor 1.
377 * After binding a remote device and signal to Remote Sensor X, you may select Remote Sensor X
378 * as a PID source for closed-loop features.
379 *
380 * @param deviceID
381 * The device ID of the remote sensor device.
382 * @param remoteSensorSource
383 * The remote sensor device and signal type to bind.
384 * @param remoteOrdinal
385 * 0 for configuring Remote Sensor 0,
386 * 1 for configuring Remote Sensor 1
387 * @param timeoutMs
388 * Timeout value in ms. If nonzero, function will wait for
389 * config success and report an error if it times out.
390 * If zero, no blocking or checking is performed.
391 * @return Error Code generated by function. 0 indicates no error.
392 */
394 RemoteSensorSource remoteSensorSource, int remoteOrdinal,
395 int timeoutMs = 0)= 0;
396 /**
397 * Select what remote device and signal to assign to Remote Sensor 0 or Remote Sensor 1.
398 * After binding a remote device and signal to Remote Sensor X, you may select Remote Sensor X
399 * as a PID source for closed-loop features.
400 *
401 * @param canCoderRef
402 * CANCoder device reference to use.
403 * @param remoteOrdinal
404 * 0 for configuring Remote Sensor 0,
405 * 1 for configuring Remote Sensor 1
406 * @param timeoutMs
407 * Timeout value in ms. If nonzero, function will wait for
408 * config success and report an error if it times out.
409 * If zero, no blocking or checking is performed.
410 * @return Error Code generated by function. 0 indicates no error.
411 */
412 [[deprecated("This device's Phoenix 5 API is deprecated for removal in the 2025 season."
413 "Users should update to Phoenix 6 firmware and migrate to the Phoenix 6 API."
414 "A migration guide is available at https://v6.docs.ctr-electronics.com/en/stable/docs/migration/migration-guide/index.html")]]
415 virtual ErrorCode ConfigRemoteFeedbackFilter(ctre::phoenix::sensors::CANCoder &canCoderRef, int remoteOrdinal, int timeoutMs = 0)= 0;
416 /**
417 * Select what remote device and signal to assign to Remote Sensor 0 or Remote Sensor 1.
418 * After binding a remote device and signal to Remote Sensor X, you may select Remote Sensor X
419 * as a PID source for closed-loop features.
420 *
421 * @param talonRef
422 * Talon device reference to use.
423 * @param remoteOrdinal
424 * 0 for configuring Remote Sensor 0,
425 * 1 for configuring Remote Sensor 1
426 * @param timeoutMs
427 * Timeout value in ms. If nonzero, function will wait for
428 * config success and report an error if it times out.
429 * If zero, no blocking or checking is performed.
430 * @return Error Code generated by function. 0 indicates no error.
431 */
432 virtual ErrorCode ConfigRemoteFeedbackFilter(ctre::phoenix::motorcontrol::can::BaseTalon &talonRef, int remoteOrdinal, int timeoutMs = 0)= 0;
433 /**
434 * Select what sensor term should be bound to switch feedback device.
435 * Sensor Sum = Sensor Sum Term 0 - Sensor Sum Term 1
436 * Sensor Difference = Sensor Diff Term 0 - Sensor Diff Term 1
437 * The four terms are specified with this routine. Then Sensor Sum/Difference
438 * can be selected for closed-looping.
439 *
440 * @param sensorTerm Which sensor term to bind to a feedback source.
441 * @param feedbackDevice The sensor signal to attach to sensorTerm.
442 * @param timeoutMs
443 * Timeout value in ms. If nonzero, function will wait for
444 * config success and report an error if it times out.
445 * If zero, no blocking or checking is performed.
446 * @return Error Code generated by function. 0 indicates no error.
447 */
448 virtual ErrorCode ConfigSensorTerm(SensorTerm sensorTerm, FeedbackDevice feedbackDevice, int timeoutMs = 0)= 0;
449
450 //------- sensor status --------- //
451 /**
452 * Get the selected sensor position (in raw sensor units).
453 *
454 * @param pidIdx
455 * 0 for Primary closed-loop. 1 for auxiliary closed-loop. See
456 * Phoenix-Documentation for how to interpret.
457 *
458 * @return Position of selected sensor (in raw sensor units).
459 */
460 virtual double GetSelectedSensorPosition(int pidIdx = 0) = 0;
461 /**
462 * Get the selected sensor velocity.
463 *
464 * @param pidIdx
465 * 0 for Primary closed-loop. 1 for auxiliary closed-loop.
466 * @return selected sensor (in raw sensor units) per 100ms.
467 * See Phoenix-Documentation for how to interpret.
468 */
469 virtual double GetSelectedSensorVelocity(int pidIdx = 0) = 0;
470 /**
471 * Sets the sensor position to the given value.
472 *
473 * @param sensorPos
474 * Position to set for the selected sensor (in raw sensor units).
475 * @param pidIdx
476 * 0 for Primary closed-loop. 1 for auxiliary closed-loop.
477 * @param timeoutMs
478 * Timeout value in ms. If nonzero, function will wait for
479 * config success and report an error if it times out.
480 * If zero, no blocking or checking is performed.
481 * @return Error Code generated by function. 0 indicates no error.
482 */
483 virtual ErrorCode SetSelectedSensorPosition(double sensorPos, int pidIdx = 0,
484 int timeoutMs = 50) = 0;
485
486 //------ status frame period changes ----------//
487 /**
488 * Sets the period of the given control frame.
489 *
490 * @param frame
491 * Frame whose period is to be changed.
492 * @param periodMs
493 * Period in ms for the given frame.
494 * @return Error Code generated by function. 0 indicates no error.
495 */
497 int periodMs) = 0;
498 /**
499 * Sets the period of the given status frame.
500 *
501 * User ensure CAN Bus utilization is not high.
502 *
503 * This setting is not persistent and is lost when device is reset. If this
504 * is a concern, calling application can use HasResetOccurred() to determine if the
505 * status frame needs to be reconfigured.
506 *
507 * @param frame
508 * Frame whose period is to be changed.
509 * @param periodMs
510 * Period in ms for the given frame.
511 * @param timeoutMs
512 * Timeout value in ms. If nonzero, function will wait for config
513 * success and report an error if it times out. If zero, no
514 * blocking or checking is performed.
515 * @return Error Code generated by function. 0 indicates no error.
516 */
517 virtual ErrorCode SetStatusFramePeriod(StatusFrame frame, uint8_t periodMs,
518 int timeoutMs = 0) = 0;
519 /**
520 * Gets the period of the given status frame.
521 *
522 * @param frame
523 * Frame to get the period of.
524 * @param timeoutMs
525 * Timeout value in ms. If nonzero, function will wait for
526 * config success and report an error if it times out.
527 * If zero, no blocking or checking is performed.
528 * @return Period of the given status frame.
529 */
530 virtual int GetStatusFramePeriod(StatusFrame frame, int timeoutMs = 0) = 0;
531
532 //----- velocity signal conditionaing ------//
533 /* not supported */
534
535 //------ remote limit switch ----------//
536 /**
537 * Configures the forward limit switch for a remote source. For example, a
538 * CAN motor controller may need to monitor the Limit-F pin of another Talon
539 * or CANifier.
540 *
541 * @param type
542 * Remote limit switch source. User can choose between a remote
543 * Talon SRX, CANifier, or deactivate the feature.
544 * @param normalOpenOrClose
545 * Setting for normally open, normally closed, or disabled. This
546 * setting matches the Phoenix Tuner drop down.
547 * @param deviceID
548 * Device ID of remote source (Talon SRX or CANifier device ID).
549 * @param timeoutMs
550 * Timeout value in ms. If nonzero, function will wait for config
551 * success and report an error if it times out. If zero, no
552 * blocking or checking is performed.
553 * @return Error Code generated by function. 0 indicates no error.
554 */
556 RemoteLimitSwitchSource type, LimitSwitchNormal normalOpenOrClose,
557 int deviceID, int timeoutMs = 0) = 0;
558 /**
559 * Configures the reverse limit switch for a remote source. For example, a
560 * CAN motor controller may need to monitor the Limit-R pin of another Talon
561 * or CANifier.
562 *
563 * @param type
564 * Remote limit switch source. User can choose between a remote
565 * Talon SRX, CANifier, or deactivate the feature.
566 * @param normalOpenOrClose
567 * Setting for normally open, normally closed, or disabled. This
568 * setting matches the Phoenix Tuner drop down.
569 * @param deviceID
570 * Device ID of remote source (Talon SRX or CANifier device ID).
571 * @param timeoutMs
572 * Timeout value in ms. If nonzero, function will wait for config
573 * success and report an error if it times out. If zero, no
574 * blocking or checking is performed.
575 * @return Error Code generated by function. 0 indicates no error.
576 */
578 RemoteLimitSwitchSource type, LimitSwitchNormal normalOpenOrClose,
579 int deviceID, int timeoutMs = 0) = 0;
580 /**
581 * Sets the enable state for limit switches.
582 *
583 * @param enable
584 * Enable state for limit switches.
585 **/
586 virtual void OverrideLimitSwitchesEnable(bool enable) = 0;
587
588 //------ local limit switch ----------//
589 /* not supported */
590
591 //------ soft limit ----------//
592 /**
593 * Configures the forward soft limit threhold.
594 *
595 * @param forwardSensorLimit
596 * Forward Sensor Position Limit (in raw sensor units).
597 * @param timeoutMs
598 * Timeout value in ms. If nonzero, function will wait for
599 * config success and report an error if it times out.
600 * If zero, no blocking or checking is performed.
601 * @return Error Code generated by function. 0 indicates no error.
602 */
603 virtual ErrorCode ConfigForwardSoftLimitThreshold(double forwardSensorLimit,
604 int timeoutMs = 0) = 0;
605 /**
606 * Configures the reverse soft limit threshold.
607 *
608 * @param reverseSensorLimit
609 * Reverse Sensor Position Limit (in raw sensor units).
610 * @param timeoutMs
611 * Timeout value in ms. If nonzero, function will wait for
612 * config success and report an error if it times out.
613 * If zero, no blocking or checking is performed.
614 * @return Error Code generated by function. 0 indicates no error.
615 */
616 virtual ErrorCode ConfigReverseSoftLimitThreshold(double reverseSensorLimit,
617 int timeoutMs = 0) = 0;
618 /**
619 * Configures the forward soft limit enable.
620 *
621 * @param enable
622 * Forward Sensor Position Limit Enable.
623 * @param timeoutMs
624 * Timeout value in ms. If nonzero, function will wait for
625 * config success and report an error if it times out.
626 * If zero, no blocking or checking is performed.
627 * @return Error Code generated by function. 0 indicates no error.
628 */
630 int timeoutMs = 0) = 0;
631 /**
632 * Configures the reverse soft limit enable.
633 *
634 * @param enable
635 * Reverse Sensor Position Limit Enable.
636 * @param timeoutMs
637 * Timeout value in ms. If nonzero, function will wait for config
638 * success and report an error if it times out. If zero, no
639 * blocking or checking is performed.
640 * @return Error Code generated by function. 0 indicates no error.
641 */
643 int timeoutMs = 0) = 0;
644 /**
645 * Can be used to override-disable the soft limits.
646 * This function can be used to quickly disable soft limits without
647 * having to modify the persistent configuration.
648 *
649 * @param enable
650 * Enable state for soft limit switches.
651 */
652 virtual void OverrideSoftLimitsEnable(bool enable) = 0;
653
654 //------ Current Lim ----------//
655 /* not supported */
656
657 //------ Config Close loop ----------//
658 /**
659 * Sets the 'P' constant in the given parameter slot.
660 * This is multiplied by closed loop error in sensor units.
661 * Note the closed loop output interprets a final value of 1023 as full output.
662 * So use a gain of '0.25' to get full output if err is 4096u (Mag Encoder 1 rotation)
663 *
664 * @param slotIdx
665 * Parameter slot for the constant.
666 * @param value
667 * Value of the P constant.
668 * @param timeoutMs
669 * Timeout value in ms. If nonzero, function will wait for
670 * config success and report an error if it times out.
671 * If zero, no blocking or checking is performed.
672 * @return Error Code generated by function. 0 indicates no error.
673 */
674 virtual ErrorCode Config_kP(int slotIdx, double value, int timeoutMs = 0) = 0;
675 /**
676 * Sets the 'I' constant in the given parameter slot.
677 * This is multiplied by accumulated closed loop error in sensor units every PID Loop.
678 * Note the closed loop output interprets a final value of 1023 as full output.
679 * So use a gain of '0.00025' to get full output if err is 4096u for 1000 loops (accumulater holds 4,096,000),
680 * [which is equivalent to one CTRE mag encoder rotation for 1000 milliseconds].
681 *
682 * @param slotIdx
683 * Parameter slot for the constant.
684 * @param value
685 * Value of the I constant.
686 * @param timeoutMs
687 * Timeout value in ms. If nonzero, function will wait for
688 * config success and report an error if it times out.
689 * If zero, no blocking or checking is performed.
690 * @return Error Code generated by function. 0 indicates no error.
691 */
692 virtual ErrorCode Config_kI(int slotIdx, double value, int timeoutMs = 0) = 0;
693 /**
694 * Sets the 'D' constant in the given parameter slot.
695 *
696 * This is multiplied by derivative error (sensor units per PID loop, typically 1ms).
697 * Note the closed loop output interprets a final value of 1023 as full output.
698 * So use a gain of '250' to get full output if derr is 4096u (Mag Encoder 1 rotation) per 1000 loops (typ 1 sec)
699 *
700 * @param slotIdx
701 * Parameter slot for the constant.
702 * @param value
703 * Value of the D constant.
704 * @param timeoutMs
705 * Timeout value in ms. If nonzero, function will wait for
706 * config success and report an error if it times out.
707 * If zero, no blocking or checking is performed.
708 * @return Error Code generated by function. 0 indicates no error.
709 */
710 virtual ErrorCode Config_kD(int slotIdx, double value, int timeoutMs = 0) = 0;
711 /**
712 * Sets the 'F' constant in the given parameter slot.
713 *
714 * See documentation for calculation details.
715 * If using velocity, motion magic, or motion profile,
716 * use (1023 * duty-cycle / sensor-velocity-sensor-units-per-100ms).
717 *
718 * @param slotIdx
719 * Parameter slot for the constant.
720 * @param value
721 * Value of the F constant.
722 * @param timeoutMs
723 * Timeout value in ms. If nonzero, function will wait for
724 * config success and report an error if it times out.
725 * If zero, no blocking or checking is performed.
726 * @return Error Code generated by function. 0 indicates no error.
727 */
728 virtual ErrorCode Config_kF(int slotIdx, double value, int timeoutMs = 0) = 0;
729 /**
730 * Sets the Integral Zone constant in the given parameter slot. If the
731 * (absolute) closed-loop error is outside of this zone, integral
732 * accumulator is automatically cleared. This ensures than integral wind up
733 * events will stop after the sensor gets far enough from its target.
734 *
735 * @param slotIdx
736 * Parameter slot for the constant.
737 * @param izone
738 * Value of the Integral Zone constant (closed loop error units X
739 * 1ms).
740 * @param timeoutMs
741 * Timeout value in ms. If nonzero, function will wait for config
742 * success and report an error if it times out. If zero, no
743 * blocking or checking is performed.
744 * @return Error Code generated by function. 0 indicates no error.
745 */
746 virtual ErrorCode Config_IntegralZone(int slotIdx, double izone,
747 int timeoutMs = 0) = 0;
748 /**
749 * Sets the allowable closed-loop error in the given parameter slot.
750 *
751 * @param slotIdx
752 * Parameter slot for the constant.
753 * @param allowableCloseLoopError
754 * Value of the allowable closed-loop error in sensor units (or sensor units per 100ms for velocity).
755 * @param timeoutMs
756 * Timeout value in ms. If nonzero, function will wait for
757 * config success and report an error if it times out.
758 * If zero, no blocking or checking is performed.
759 * @return Error Code generated by function. 0 indicates no error.
760 */
762 double allowableCloseLoopError, int timeoutMs = 0) = 0;
763 /**
764 * Sets the maximum integral accumulator in the given parameter slot.
765 *
766 * @param slotIdx
767 * Parameter slot for the constant.
768 * @param iaccum
769 * Value of the maximum integral accumulator (closed loop error
770 * units X 1ms).
771 * @param timeoutMs
772 * Timeout value in ms. If nonzero, function will wait for config
773 * success and report an error if it times out. If zero, no
774 * blocking or checking is performed.
775 * @return Error Code generated by function. 0 indicates no error.
776 */
777 virtual ErrorCode ConfigMaxIntegralAccumulator(int slotIdx, double iaccum,
778 int timeoutMs = 0) = 0;
779 /**
780 * Sets the peak closed-loop output. This peak output is slot-specific and
781 * is applied to the output of the associated PID loop.
782 * This setting is seperate from the generic Peak Output setting.
783 *
784 * @param slotIdx
785 * Parameter slot for the constant.
786 * @param percentOut
787 * Peak Percent Output from 0 to 1. This value is absolute and
788 * the magnitude will apply in both forward and reverse directions.
789 * @param timeoutMs
790 * Timeout value in ms. If nonzero, function will wait for
791 * config success and report an error if it times out.
792 * If zero, no blocking or checking is performed.
793 * @return Error Code generated by function. 0 indicates no error.
794 */
795 virtual ErrorCode ConfigClosedLoopPeakOutput(int slotIdx, double percentOut, int timeoutMs = 0) = 0;
796 /**
797 * Sets the loop time (in milliseconds) of the PID closed-loop calculations.
798 * Default value is 1 ms.
799 *
800 * @param slotIdx
801 * Parameter slot for the constant.
802 * @param loopTimeMs
803 * Loop timing of the closed-loop calculations. Minimum value of
804 * 1 ms, maximum of 64 ms.
805 * @param timeoutMs
806 * Timeout value in ms. If nonzero, function will wait for
807 * config success and report an error if it times out.
808 * If zero, no blocking or checking is performed.
809 * @return Error Code generated by function. 0 indicates no error.
810 */
811 virtual ErrorCode ConfigClosedLoopPeriod(int slotIdx, int loopTimeMs, int timeoutMs = 0) = 0;
812
813 /**
814 * Configures the Polarity of the Auxiliary PID (PID1).
815 *
816 * Standard Polarity:
817 * Primary Output = PID0 + PID1,
818 * Auxiliary Output = PID0 - PID1,
819 *
820 * Inverted Polarity:
821 * Primary Output = PID0 - PID1,
822 * Auxiliary Output = PID0 + PID1,
823 *
824 * @param invert
825 * If true, use inverted PID1 output polarity.
826 * @param timeoutMs
827 * Timeout value in ms. If nonzero, function will wait for config
828 * success and report an error if it times out. If zero, no
829 * blocking or checking is performed.
830 * @return Error Code
831 */
832 virtual ErrorCode ConfigAuxPIDPolarity(bool invert, int timeoutMs = 0) = 0;
833
834 //------ Close loop State ----------//
835 /**
836 * Sets the integral accumulator. Typically this is used to clear/zero the
837 * integral accumulator, however some use cases may require seeding the
838 * accumulator for a faster response.
839 *
840 * @param iaccum
841 * Value to set for the integral accumulator (closed loop error
842 * units X 1ms).
843 * @param pidIdx
844 * 0 for Primary closed-loop. 1 for auxiliary closed-loop.
845 * @param timeoutMs
846 * Timeout value in ms. If nonzero, function will wait for config
847 * success and report an error if it times out. If zero, no
848 * blocking or checking is performed.
849 * @return Error Code generated by function. 0 indicates no error.
850 */
851 virtual ErrorCode SetIntegralAccumulator(double iaccum, int pidIdx = 0,
852 int timeoutMs = 0) = 0;
853 /**
854 * Gets the closed-loop error. The units depend on which control mode is in
855 * use.
856 *
857 * If closed-loop is seeking a target sensor position, closed-loop error is the difference between target
858 * and current sensor value (in sensor units. Example 4096 units per rotation for CTRE Mag Encoder).
859 *
860 * If closed-loop is seeking a target sensor velocity, closed-loop error is the difference between target
861 * and current sensor value (in sensor units per 100ms).
862 *
863 * If using motion profiling or Motion Magic, closed loop error is calculated against the current target,
864 * and not the "final" target at the end of the profile/movement.
865 *
866 * See Phoenix-Documentation information on units.
867 *
868 *
869 * @param pidIdx
870 * 0 for Primary closed-loop. 1 for auxiliary closed-loop.
871 * @return Closed-loop error value.
872 */
873 virtual double GetClosedLoopError(int pidIdx = 0) = 0;
874 /**
875 * Gets the iaccum value.
876 *
877 * @param pidIdx
878 * 0 for Primary closed-loop. 1 for auxiliary closed-loop.
879 * @return Integral accumulator value (Closed-loop error X 1ms).
880 */
881 virtual double GetIntegralAccumulator(int pidIdx = 0) = 0;
882 /**
883 * Gets the derivative of the closed-loop error.
884 *
885 * @param pidIdx
886 * 0 for Primary closed-loop. 1 for auxiliary closed-loop.
887 * @return The error derivative value.
888 */
889 virtual double GetErrorDerivative(int pidIdx = 0) = 0;
890
891 /**
892 * Selects which profile slot to use for closed-loop control.
893 *
894 * @param slotIdx
895 * Profile slot to select.
896 * @param pidIdx
897 * 0 for Primary closed-loop. 1 for auxiliary closed-loop.
898 **/
899 virtual ErrorCode SelectProfileSlot(int slotIdx, int pidIdx) = 0;
900
901 /**
902 * Gets the current target of a given closed loop.
903 *
904 * @param pidIdx
905 * 0 for Primary closed-loop. 1 for auxiliary closed-loop.
906 * @return The closed loop target.
907 */
908 virtual double GetClosedLoopTarget(int pidIdx = 0) = 0;
909 /**
910 * Gets the active trajectory target position for using
911 * MotionMagic/MotionProfile control modes.
912 *
913 * @param pidIdx
914 * 0 for Primary closed-loop. 1 for auxiliary closed-loop.
915 * @return The Active Trajectory Position in sensor units.
916 */
917 virtual double GetActiveTrajectoryPosition(int pidIdx = 0) = 0;
918 /**
919 * Gets the active trajectory target velocity for using
920 * MotionMagic/MotionProfile control modes.
921 *
922 * @param pidIdx
923 * 0 for Primary closed-loop. 1 for auxiliary closed-loop.
924 * @return The Active Trajectory Velocity in sensor units per 100ms.
925 */
926 virtual double GetActiveTrajectoryVelocity(int pidIdx = 0) = 0;
927 /**
928 * Gets the active trajectory arbitrary feedforward using
929 * MotionMagic/MotionProfile control modes.
930 *
931 * @param pidIdx
932 * 0 for Primary closed-loop. 1 for auxiliary closed-loop.
933 * @return The Active Trajectory ArbFeedFwd in units of percent output
934 * (where 0.01 is 1%).
935 */
936 virtual double GetActiveTrajectoryArbFeedFwd(int pidIdx = 0) = 0;
937
938 //------ Motion Profile Settings used in Motion Magic ----------//
939 /**
940 * Sets the Motion Magic Cruise Velocity. This is the peak target velocity
941 * that the motion magic curve generator can use.
942 *
943 * @param sensorUnitsPer100ms
944 * Motion Magic Cruise Velocity (in raw sensor units per 100 ms).
945 * @param timeoutMs
946 * Timeout value in ms. If nonzero, function will wait for config
947 * success and report an error if it times out. If zero, no
948 * blocking or checking is performed.
949 * @return Error Code generated by function. 0 indicates no error.
950 */
951 virtual ErrorCode ConfigMotionCruiseVelocity(double sensorUnitsPer100ms,
952 int timeoutMs = 0) = 0;
953 /**
954 * Sets the Motion Magic Acceleration. This is the target acceleration that
955 * the motion magic curve generator can use.
956 *
957 * @param sensorUnitsPer100msPerSec
958 * Motion Magic Acceleration (in raw sensor units per 100 ms per
959 * second).
960 * @param timeoutMs
961 * Timeout value in ms. If nonzero, function will wait for config
962 * success and report an error if it times out. If zero, no
963 * blocking or checking is performed.
964 * @return Error Code generated by function. 0 indicates no error.
965 */
966 virtual ErrorCode ConfigMotionAcceleration(double sensorUnitsPer100msPerSec,
967 int timeoutMs = 0) = 0;
968
969 /**
970 * Sets the Motion Magic S Curve Strength.
971 * Call this before using Motion Magic.
972 * Modifying this during a Motion Magic action should be avoided.
973 *
974 * @param curveStrength
975 * 0 to use Trapezoidal Motion Profile. [1,8] for S-Curve (greater value yields greater smoothing).
976 * @param timeoutMs
977 * Timeout value in ms. If nonzero, function will wait for config
978 * success and report an error if it times out. If zero, no
979 * blocking or checking is performed.
980 * @return Error Code generated by function. 0 indicates no error.
981 */
982 virtual ErrorCode ConfigMotionSCurveStrength(int curveStrength, int timeoutMs) = 0;
983 //------ Motion Profile Buffer ----------//
984 /**
985 * Clear the buffered motion profile in both controller's RAM (bottom), and in the
986 * API (top).
987 *
988 * @return Error Code generated by function. 0 indicates no error
989 */
991 /**
992 * Retrieve just the buffer count for the api-level (top) buffer. This
993 * routine performs no CAN or data structure lookups, so its fast and ideal
994 * if caller needs to quickly poll the progress of trajectory points being
995 * emptied into controller's RAM. Otherwise just use GetMotionProfileStatus.
996 *
997 * @return number of trajectory points in the top buffer.
998 */
1000 /**
1001 * Push another trajectory point into the top level buffer (which is emptied
1002 * into the motor controller's bottom buffer as room allows).
1003 * @param trajPt to push into buffer.
1004 * The members should be filled in with these values...
1005 *
1006 * targPos: servo position in sensor units.
1007 * targVel: velocity to feed-forward in sensor units
1008 * per 100ms.
1009 * profileSlotSelect0 Which slot to get PIDF gains. PID is used for position servo. F is used
1010 * as the Kv constant for velocity feed-forward. Typically this is hardcoded
1011 * to the a particular slot, but you are free gain schedule if need be.
1012 * Choose from [0,3]
1013 * profileSlotSelect1 Which slot to get PIDF gains for auxiliary PId.
1014 * This only has impact during MotionProfileArc Control mode.
1015 * Choose from [0,1].
1016 * isLastPoint set to nonzero to signal motor controller to keep processing this
1017 * trajectory point, instead of jumping to the next one
1018 * when timeDurMs expires. Otherwise MP executer will
1019 * eventually see an empty buffer after the last point
1020 * expires, causing it to assert the IsUnderRun flag.
1021 * However this may be desired if calling application
1022 * never wants to terminate the MP.
1023 * zeroPos set to nonzero to signal motor controller to "zero" the selected
1024 * position sensor before executing this trajectory point.
1025 * Typically the first point should have this set only thus
1026 * allowing the remainder of the MP positions to be relative to
1027 * zero.
1028 * timeDur Duration to apply this trajectory pt.
1029 * This time unit is ADDED to the exising base time set by
1030 * configMotionProfileTrajectoryPeriod().
1031 * @return CTR_OKAY if trajectory point push ok. ErrorCode if buffer is
1032 * full due to kMotionProfileTopBufferCapacity.
1033 */
1035 const ctre::phoenix::motion::TrajectoryPoint & trajPt)= 0;
1036 /**
1037 * Retrieve just the buffer full for the api-level (top) buffer. This
1038 * routine performs no CAN or data structure lookups, so its fast and ideal
1039 * if caller needs to quickly poll. Otherwise just use
1040 * GetMotionProfileStatus.
1041 *
1042 * @return number of trajectory points in the top buffer.
1043 */
1045 /**
1046 * This must be called periodically to funnel the trajectory points from the
1047 * API's top level buffer to the controller's bottom level buffer. Recommendation
1048 * is to call this twice as fast as the execution rate of the motion
1049 * profile. So if MP is running with 20ms trajectory points, try calling
1050 * this routine every 10ms. All motion profile functions are thread-safe
1051 * through the use of a mutex, so there is no harm in having the caller
1052 * utilize threading.
1053 */
1055 /**
1056 * Retrieve all status information.
1057 * For best performance, Caller can snapshot all status information regarding the
1058 * motion profile executer.
1059 *
1060 * @param statusToFill Caller supplied object to fill.
1061 *
1062 * The members are filled, as follows...
1063 *
1064 * topBufferRem: The available empty slots in the trajectory buffer.
1065 * The robot API holds a "top buffer" of trajectory points, so your applicaion
1066 * can dump several points at once. The API will then stream them into the
1067 * low-level buffer, allowing the motor controller to act on them.
1068 *
1069 * topBufferRem: The number of points in the top trajectory buffer.
1070 *
1071 * btmBufferCnt: The number of points in the low level controller buffer.
1072 *
1073 * hasUnderrun: Set if isUnderrun ever gets set.
1074 * Can be manually cleared by clearMotionProfileHasUnderrun() or automatically cleared by startMotionProfile().
1075 *
1076 * isUnderrun: This is set if controller needs to shift a point from its buffer into
1077 * the active trajectory point however
1078 * the buffer is empty.
1079 * This gets cleared automatically when is resolved.
1080 *
1081 * activePointValid: True if the active trajectory point is not empty, false otherwise. The members in activePoint are only valid if this signal is set.
1082 *
1083 * isLast: is set/cleared based on the MP executer's current
1084 * trajectory point's IsLast value. This assumes
1085 * IsLast was set when PushMotionProfileTrajectory
1086 * was used to insert the currently processed trajectory
1087 * point.
1088 *
1089 * profileSlotSelect: The currently processed trajectory point's
1090 * selected slot. This can differ in the currently selected slot used
1091 * for Position and Velocity servo modes
1092 *
1093 * outputEnable: The current output mode of the motion profile
1094 * executer (disabled, enabled, or hold). When changing the set()
1095 * value in MP mode, it's important to check this signal to
1096 * confirm the change takes effect before interacting with the top buffer.
1097 * @return Error Code generated by function. 0 indicates no error.
1098 */
1101 /**
1102 * Clear the "Has Underrun" flag. Typically this is called after application
1103 * has confirmed an underrun had occured.
1104 *
1105 * @param timeoutMs
1106 * Timeout value in ms. If nonzero, function will wait for config
1107 * success and report an error if it times out. If zero, no
1108 * blocking or checking is performed.
1109 * @return Error Code generated by function. 0 indicates no error.
1110 */
1111 virtual ErrorCode ClearMotionProfileHasUnderrun(int timeoutMs = 0)= 0;
1112 /**
1113 * Calling application can opt to speed up the handshaking between the robot
1114 * API and the controller to increase the download rate of the controller's Motion
1115 * Profile. Ideally the period should be no more than half the period of a
1116 * trajectory point.
1117 *
1118 * @param periodMs
1119 * The transmit period in ms.
1120 * @return Error Code generated by function. 0 indicates no error.
1121 */
1123 /**
1124 * When trajectory points are processed in the motion profile executer, the MPE determines
1125 * how long to apply the active trajectory point by summing baseTrajDurationMs with the
1126 * timeDur of the trajectory point (see TrajectoryPoint).
1127 *
1128 * This allows general selection of the execution rate of the points with 1ms resolution,
1129 * while allowing some degree of change from point to point.
1130 * @param baseTrajDurationMs The base duration time of every trajectory point.
1131 * This is summed with the trajectory points unique timeDur.
1132 * @param timeoutMs
1133 * Timeout value in ms. If nonzero, function will wait for
1134 * config success and report an error if it times out.
1135 * If zero, no blocking or checking is performed.
1136 * @return Error Code generated by function. 0 indicates no error.
1137 */
1138 virtual ErrorCode ConfigMotionProfileTrajectoryPeriod(int baseTrajDurationMs, int timeoutMs = 0)=0;
1139
1140 //------Feedback Device Interaction Settings---------//
1141 /**
1142 * Disables continuous tracking of the position for analog and pulse-width.
1143 * If the signal goes from 4095 to 0 (pulse-width) a motor controller will continue to read 4096 by default.
1144 * If overflow tracking is disabled, it will wrap to 0 (not continuous)
1145 *
1146 * If using pulse-width on CTRE Mag Encoder (within one rotation) or absolute analog sensor (within one rotation),
1147 * setting feedbackNotContinuous to true is recommended, to prevent intermittent
1148 * connections from causing sensor "jumps" of 4096 (or 1024 for analog) units.
1149 *
1150 * @param feedbackNotContinuous True to disable the overflow tracking.
1151 *
1152 * @param timeoutMs
1153 * Timeout value in ms. If nonzero, function will wait for
1154 * config success and report an error if it times out.
1155 * If zero, no blocking or checking is performed.
1156 * @return Error Code generated by function. 0 indicates no error.
1157 */
1158 virtual ErrorCode ConfigFeedbackNotContinuous(bool feedbackNotContinuous, int timeoutMs = 0) = 0;
1159 /**
1160 * Disables going to neutral (brake/coast) when a remote sensor is no longer detected.
1161 *
1162 * @param remoteSensorClosedLoopDisableNeutralOnLOS disable going to neutral
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 ConfigRemoteSensorClosedLoopDisableNeutralOnLOS(bool remoteSensorClosedLoopDisableNeutralOnLOS, int timeoutMs = 0) = 0;
1171 /**
1172 * Enables clearing the position of the feedback sensor when the forward
1173 * limit switch is triggered
1174 *
1175 * @param clearPositionOnLimitF Whether clearing is enabled, defaults false
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 ConfigClearPositionOnLimitF(bool clearPositionOnLimitF, int timeoutMs = 0) = 0;
1183 /**
1184 * Enables clearing the position of the feedback sensor when the reverse
1185 * limit switch is triggered
1186 *
1187 * @param clearPositionOnLimitR 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 ConfigClearPositionOnLimitR(bool clearPositionOnLimitR, int timeoutMs = 0) = 0;
1195 /**
1196 * Enables clearing the position of the feedback sensor when the quadrature index signal
1197 * is detected
1198 *
1199 * @param clearPositionOnQuadIdx 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 ConfigClearPositionOnQuadIdx(bool clearPositionOnQuadIdx, int timeoutMs = 0) = 0;
1207 /**
1208 * Disables limit switches triggering (if enabled) when the sensor is no longer detected.
1209 *
1210 * @param limitSwitchDisableNeutralOnLOS disable triggering
1211 *
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 ConfigLimitSwitchDisableNeutralOnLOS(bool limitSwitchDisableNeutralOnLOS, int timeoutMs = 0) = 0;
1219 /**
1220 * Disables soft limits triggering (if enabled) when the sensor is no longer detected.
1221 *
1222 * @param softLimitDisableNeutralOnLOS 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 ConfigSoftLimitDisableNeutralOnLOS(bool softLimitDisableNeutralOnLOS, int timeoutMs = 0) = 0;
1231 /**
1232 * Sets the edges per rotation of a pulse width sensor. (This should be set for
1233 * tachometer use).
1234 *
1235 * @param pulseWidthPeriod_EdgesPerRot edges per rotation
1236 *
1237 * @param timeoutMs
1238 * Timeout value in ms. If nonzero, function will wait for
1239 * config success and report an error if it times out.
1240 * If zero, no blocking or checking is performed.
1241 * @return Error Code generated by function. 0 indicates no error.
1242 */
1243 virtual ErrorCode ConfigPulseWidthPeriod_EdgesPerRot(int pulseWidthPeriod_EdgesPerRot, int timeoutMs = 0) = 0;
1244 /**
1245 * Sets the number of samples to use in smoothing a pulse width sensor with a rolling
1246 * average. Default is 1 (no smoothing).
1247 *
1248 * @param pulseWidthPeriod_FilterWindowSz samples for rolling avg
1249 *
1250 * @param timeoutMs
1251 * Timeout value in ms. If nonzero, function will wait for
1252 * config success and report an error if it times out.
1253 * If zero, no blocking or checking is performed.
1254 * @return Error Code generated by function. 0 indicates no error.
1255 */
1256 virtual ErrorCode ConfigPulseWidthPeriod_FilterWindowSz(int pulseWidthPeriod_FilterWindowSz, int timeoutMs = 0) = 0;
1257
1258 //------ error ----------//
1259 /**
1260 * Gets the last error generated by this object. Not all functions return an
1261 * error code but can potentially report errors. This function can be used
1262 * to retrieve those error codes.
1263 *
1264 * @return Last Error Code generated by a function.
1265 */
1267
1268 //------ Faults ----------//
1269 /**
1270 * Polls the various fault flags.
1271 *
1272 * @param toFill
1273 * Caller's object to fill with latest fault flags.
1274 * @return Last Error Code generated by a function.
1275 */
1276 virtual ErrorCode GetFaults(Faults & toFill) = 0;
1277 /**
1278 * Polls the various sticky fault flags.
1279 *
1280 * @param toFill
1281 * Caller's object to fill with latest sticky fault flags.
1282 * @return Last Error Code generated by a function.
1283 */
1285 /**
1286 * Clears all sticky faults.
1287 *
1288 * @param timeoutMs
1289 * Timeout value in ms. If nonzero, function will wait for config
1290 * success and report an error if it times out. If zero, no
1291 * blocking or checking is performed.
1292 * @return Last Error Code generated by a function.
1293 */
1294 virtual ErrorCode ClearStickyFaults(int timeoutMs = 0) = 0;
1295
1296 //------ Firmware ----------//
1297 /**
1298 * Gets the firmware version of the device.
1299 *
1300 * @return Firmware version of device. For example: version 1-dot-2 is
1301 * 0x0102.
1302 */
1303 virtual int GetFirmwareVersion() = 0;
1304 /**
1305 * Returns true if the device has reset since last call.
1306 *
1307 * @return Has a Device Reset Occurred?
1308 */
1309 virtual bool HasResetOccurred() = 0;
1310
1311 //------ Custom Persistent Params ----------//
1312 /**
1313 * Sets the value of a custom parameter. This is for arbitrary use.
1314 *
1315 * Sometimes it is necessary to save calibration/limit/target information in
1316 * the device. Particularly if the device is part of a subsystem that can be
1317 * replaced.
1318 *
1319 * @param newValue
1320 * Value for custom parameter.
1321 * @param paramIndex
1322 * Index of custom parameter [0,1]
1323 * @param timeoutMs
1324 * Timeout value in ms. If nonzero, function will wait for config
1325 * success and report an error if it times out. If zero, no
1326 * blocking or checking is performed.
1327 * @return Error Code generated by function. 0 indicates no error.
1328 */
1329 virtual ErrorCode ConfigSetCustomParam(int newValue, int paramIndex,
1330 int timeoutMs = 0) = 0;
1331 /**
1332 * Gets the value of a custom parameter.
1333 *
1334 * @param paramIndex
1335 * Index of custom parameter [0,1].
1336 * @param timeoutMs
1337 * Timeout value in ms. If nonzero, function will wait for config
1338 * success and report an error if it times out. If zero, no
1339 * blocking or checking is performed.
1340 * @return Value of the custom param.
1341 */
1342 virtual int ConfigGetCustomParam(int paramIndex, int timeoutMs = 0) = 0;
1343
1344 //------ Generic Param API, typically not used ----------//
1345 /**
1346 * Sets a parameter. Generally this is not used. This can be utilized in -
1347 * Using new features without updating API installation. - Errata
1348 * workarounds to circumvent API implementation. - Allows for rapid testing
1349 * / unit testing of firmware.
1350 *
1351 * @param param
1352 * Parameter enumeration.
1353 * @param value
1354 * Value of parameter.
1355 * @param subValue
1356 * Subvalue for parameter. Maximum value of 255.
1357 * @param ordinal
1358 * Ordinal of parameter.
1359 * @param timeoutMs
1360 * Timeout value in ms. If nonzero, function will wait for config
1361 * success and report an error if it times out. If zero, no
1362 * blocking or checking is performed.
1363 * @return Error Code generated by function. 0 indicates no error.
1364 */
1365 virtual ErrorCode ConfigSetParameter(ParamEnum param, double value,
1366 uint8_t subValue, int ordinal, int timeoutMs = 0) = 0;
1367 /**
1368 * Gets a parameter.
1369 *
1370 * @param paramEnum
1371 * Parameter enumeration.
1372 * @param ordinal
1373 * Ordinal of parameter.
1374 * @param timeoutMs
1375 * Timeout value in ms. If nonzero, function will wait for
1376 * config success and report an error if it times out.
1377 * If zero, no blocking or checking is performed.
1378 * @return Value of parameter.
1379 */
1380 virtual double ConfigGetParameter(ParamEnum paramEnum, int ordinal,
1381 int timeoutMs = 0) = 0;
1382
1383 //------ Misc. ----------//
1384 /**
1385 * @return BaseID of device
1386 */
1387 virtual int GetBaseID() = 0;
1388 /**
1389 * Returns the Device ID
1390 *
1391 * @return Device number.
1392 */
1393 virtual int GetDeviceID() = 0;
1394 /**
1395 * @return control mode motor controller is in
1396 */
1398
1399 // ----- Follower ------//
1400 /* in parent interface */
1401};
1402
1403}
1404} // namespace phoenix
1405}
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:260
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:131
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
WPI Compliant CANcoder class.
Definition CANCoderStatusFrame.h:4
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