robotpy / robotpy-rev

RobotPy bindings for REV Robotics' REVLib
Other
9 stars 15 forks source link

[BUG]: SparkMAX PID Controller - cannot setReference #66

Closed wmbelk closed 4 hours ago

wmbelk commented 4 hours ago

Problem description

Getting the PID Controller creates a SparkPIDController. The setReference method expects the SparkMaxPIDController. Givving this error: TypeError: setReference(): incompatible function arguments. The following argument types are supported:

  1. (self: rev._rev.SparkMaxPIDController, value: float, ctrl: rev._rev.CANSparkLowLevel.ControlType, pidSlot: int = 0, arbFeedforward: float = 0, arbFFUnits: rev._rev.SparkMaxPIDController.ArbFFUnits = <ArbFFUnits.kVoltage: 0>) -> rev._rev.REVLibError

Invoked with: <rev._rev.SparkPIDController object at 0x000001E2CDFA90B0>, 0.0

Operating System

Windows

Installed Python Packages

Package                   Version
------------------------- ----------
appdirs                   1.4.4
bcrypt                    4.2.0
cffi                      1.17.1
colorama                  0.4.6
cryptography              43.0.1
flexcache                 0.3
flexparser                0.3.1
iniconfig                 2.0.0
mypy                      1.11.2
mypy-extensions           1.0.0
numpy                     2.1.1
packaging                 23.2
paramiko                  3.5.0
phoenix6                  24.3.0
photonlibpy               2024.3.1
Pint                      0.24.3
pip                       24.2
pluggy                    1.5.0
pycparser                 2.22
pyfrc                     2024.0.1
PyNaCl                    1.5.0
pynetconsole              2.0.4
pyntcore                  2024.3.2.1
pytest                    8.3.3
pytest-reraise            2.1.2
robotpy                   2024.3.2.2
robotpy-apriltag          2024.3.2.1
robotpy-cli               2024.0.0
robotpy-commands-v2       2024.3.1
robotpy-cscore            2024.3.2.1
robotpy-ctre              2024.1.3
robotpy-hal               2024.3.2.1
robotpy-halsim-ds-socket  2024.3.2.1
robotpy-halsim-gui        2024.3.2.1
robotpy-halsim-ws         2024.3.2.1
robotpy-installer         2024.2.2
robotpy-navx              2024.1.1
robotpy-pathplannerlib    2024.2.7
robotpy-playingwithfusion 2024.2.0
robotpy-rev               2024.2.4
robotpy-romi              2024.3.2.1
robotpy-wpilib-utilities  2024.1.0
robotpy-wpimath           2024.3.2.1
robotpy-wpinet            2024.3.2.1
robotpy-wpiutil           2024.3.2.1
robotpy-xrp               2024.3.2.1
setuptools                75.1.0
TEAM2556-Python           0.1.0
tomli                     2.0.2
tomlkit                   0.13.2
typing_extensions         4.12.2
wpilib                    2024.3.2.1

Reproducible example code

import rev
from rev import CANSparkMax

class Drivetrain(Subsystem):
    def __init__(self):
        super().__init__()
        self.leftFrontSteer_Motor = CANSparkMax(DriveConstant.kLeftMotorFront_SteerPort,  rev.CANSparkLowLevel.MotorType.kBrushless)
        self.leftFrontSteer_Motor.restoreFactoryDefaults()
        self.leftFrontSteer_Encoder = self.leftFrontSteer_Motor.getEncoder()
        self.leftFrontSteer_PIDController = self.leftFrontSteer_Motor.getPIDController()

        self.leftFrontSteer_PIDController.setReference(0.0)
virtuald commented 4 hours ago

The error message is hard to read, but it does tell you what the problem is. I'll reformat it here to make it more obvious (though, I can't easily fix the error message).

 TypeError: setReference(): incompatible function arguments. The following argument types are supported:
 1. (
     self: rev._rev.SparkMaxPIDController,
     value: float,
+    ctrl: rev._rev.CANSparkLowLevel.ControlType,
     pidSlot: int = 0,
     arbFeedforward: float = 0,
     arbFFUnits: rev._rev.SparkMaxPIDController.ArbFFUnits = <ArbFFUnits.kVoltage: 0>
 ) -> rev._rev.REVLibError

It requires you to pass in a rev.CANSparkLowLevel.ControlType in addition to the value.