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