REVLib - C++
SparkMaxPIDController.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018-2023 REV Robotics
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * 3. Neither the name of REV Robotics nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#pragma once
30
31#ifdef _MSC_VER
32// Disable deprecation warnings for this file when using VS compiler
33#pragma warning(disable : 4996)
34#endif
35
36#ifdef __GNUC__
37#pragma GCC diagnostic push
38#pragma GCC diagnostic ignored "-Wdeprecated"
39#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
40#endif
41
42#include <wpi/deprecated.h>
43
45#include "rev/CANSensor.h"
48#include "rev/ControlType.h"
49#include "rev/REVLibError.h"
50
51namespace rev {
52
53class CANSparkBase;
54
58class WPI_DEPRECATED("Use SparkPIDController instead") SparkMaxPIDController
60 friend class CANSparkBase;
61 friend class SparkPIDController;
62
63public:
69 enum class WPI_DEPRECATED("Use SparkPIDController::AccelStrategy instead")
71 kTrapezoidal = 0,
72 kSCurve = 1
73 };
74
80 enum class WPI_DEPRECATED("Use SparkPIDController::ArbFFUnits instead")
82 kVoltage = 0,
83 kPercentOut = 1
84 };
85
88
90
91 ~SparkMaxPIDController() override = default;
92
114 REVLibError SetReference(
115 double value, CANSparkLowLevel::ControlType ctrl, int pidSlot = 0,
116 double arbFeedforward = 0,
117 SparkMaxPIDController::ArbFFUnits arbFFUnits = ArbFFUnits::kVoltage);
118
145 WPI_DEPRECATED(
146 "Use SetReference(double, CANSparkBase::ControlType, int, double, "
147 "SparkMaxPIDController::ArbFFUnits) instead")
148 REVLibError SetReference(
149 double value, CANSparkMaxLowLevel::ControlType ctrl, int pidSlot = 0,
150 double arbFeedforward = 0,
151 SparkMaxPIDController::ArbFFUnits arbFFUnits = ArbFFUnits::kVoltage);
152
179 WPI_DEPRECATED(
180 "Use SetReference(double, CANSparkBase::ControlType, int, double, "
182 REVLibError SetReference(
183 double value, ControlType ctrl, int pidSlot = 0,
184 double arbFeedforward = 0,
185 CANPIDController::ArbFFUnits arbFFUnits =
186 CANPIDController::ArbFFUnits::kVoltage) override;
187
204 REVLibError SetP(double gain, int slotID = 0) override;
205
222 REVLibError SetI(double gain, int slotID = 0) override;
223
240 REVLibError SetD(double gain, int slotID = 0) override;
241
257 REVLibError SetDFilter(double gain, int slotID = 0) override;
258
275 REVLibError SetFF(double gain, int slotID = 0) override;
276
296 REVLibError SetIZone(double IZone, int slotID = 0) override;
297
317 REVLibError SetOutputRange(double min, double max, int slotID = 0) override;
318
334 double GetP(int slotID = 0) const override;
335
351 double GetI(int slotID = 0) const override;
352
368 double GetD(int slotID = 0) const override;
369
385 double GetDFilter(int slotID = 0) const override;
386
402 double GetFF(int slotID = 0) const override;
403
419 double GetIZone(int slotID = 0) const override;
420
436 double GetOutputMin(int slotID = 0) const override;
437
453 double GetOutputMax(int slotID = 0) const override;
454
468 REVLibError SetSmartMotionMaxVelocity(double maxVel,
469 int slotID = 0) override;
470
485 REVLibError SetSmartMotionMaxAccel(double maxAccel,
486 int slotID = 0) override;
487
500 REVLibError SetSmartMotionMinOutputVelocity(double minVel,
501 int slotID = 0) override;
502
517 REVLibError SetSmartMotionAllowedClosedLoopError(double allowedErr,
518 int slotID = 0) override;
519
536 REVLibError SetSmartMotionAccelStrategy(
537 SparkMaxPIDController::AccelStrategy accelStrategy, int slotID = 0);
538
559 WPI_DEPRECATED(
560 "Use SetSmartMotionAccelStrategy(CANPIDController::AccelStrategy, int) "
561 "instead")
562 REVLibError SetSmartMotionAccelStrategy(
563 CANPIDController::AccelStrategy accelStrategy, int slotID = 0) override;
564
576 double GetSmartMotionMaxVelocity(int slotID = 0) const override;
577
590 double GetSmartMotionMaxAccel(int slotID = 0) const override;
591
602 double GetSmartMotionMinOutputVelocity(int slotID = 0) const override;
603
616 double GetSmartMotionAllowedClosedLoopError(int slotID = 0) const override;
617
629 AccelStrategy GetSmartMotionAccelStrategy(int slotID = 0) const;
630
643 REVLibError SetIMaxAccum(double iMaxAccum, int slotID = 0) override;
644
655 double GetIMaxAccum(int slotID = 0) const override;
656
669 REVLibError SetIAccum(double iAccum) override;
670
677 double GetIAccum() const override;
678
694 REVLibError SetFeedbackDevice(const CANSensor& sensor) override;
695
703 REVLibError SetPositionPIDWrappingEnabled(bool enable);
704
713 REVLibError SetPositionPIDWrappingMaxInput(double value);
714
723 REVLibError SetPositionPIDWrappingMinInput(double value);
724
731 bool GetPositionPIDWrappingEnabled() const override;
732
739 double GetPositionPIDWrappingMaxInput() const override;
740
747 double GetPositionPIDWrappingMinInput() const override;
748
749private:
750 CANSparkBase* m_device;
751
752 explicit SparkMaxPIDController(CANSparkBase& device);
753};
754
755} // namespace rev
756
757#ifdef __GNUC__
758#pragma GCC diagnostic pop
759#endif
Definition: CANPIDController.h:56
ArbFFUnits
Definition: CANPIDController.h:73
AccelStrategy
Definition: CANPIDController.h:64
Definition: CANSensor.h:42
Definition: CANSparkBase.h:72
ControlType
Definition: CANSparkLowLevel.h:80
Definition: CANSparkMaxLowLevel.h:40
Definition: SparkMaxPIDController.h:59
ArbFFUnits
Definition: SparkMaxPIDController.h:81
SparkMaxPIDController & operator=(SparkMaxPIDController &&)=default
~SparkMaxPIDController() override=default
SparkMaxPIDController(SparkMaxPIDController &&)=default
SparkMaxPIDController(const SparkMaxPIDController &rhs)=default
Definition: SparkPIDController.h:38
Definition: CANSparkLowLevel.cpp:39
REVLibError
Definition: REVLibError.h:33
ControlType
Definition: ControlType.h:36