Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SparkMaxRelativeEncoderSim and SparkMaxAbsoluteEncoderSim do not default Position and Velocity Conversion Factor to 1 (as documented) #44

Open
trindels opened this issue Nov 15, 2024 · 1 comment
Labels
bug Something isn't working Pending The issue will be fixed in the next release REV Robotics

Comments

@trindels
Copy link

trindels commented Nov 15, 2024

Describe the bug
SparkMaxRelativeEncoderSim.iterate and SparkMaxAbsoluteEncoderSim.iterate do not work until you properly use setPositionConversionFactor(1) and setVelocityConversionFactor(1). Documentation indicates that 1 should be the default value. Currently, default value is 0.

To Reproduce
Steps to reproduce the behavior:

import rev
import wpilib
import wpimath.units
import wpimath.system.plant

def __init__(self):
    self.controller = wpilib.XboxController(1)
    self.motor = rev.SparkMax( 1, rev.SparkMax.MotorType.kBrushless )
    self.simMotor = rev.SparkMaxSim( self.motor, wpimath.system.plant.DCMotor.NEO(1) )

def periodic(self):
    self.motor.set( self.controller.getLeftX() )

def simulationPeriodic(self):
    maxRpm = wpimath.units.radiansToRotations( wpimath.system.plant.DCMotor.NEO(1).freespeed ) * wpimath.units.kSecondsPerMinute
    rpm = maxRpm * self.motor.get()
    self.simMotor.getRelativeEncoderSim().iterate( rpm, 0.02 )
    self.simMotor.getAbsoluteEncoderSim().iterate( rpm, 0.02 )

    print( self.simMotor.getRelativeEncoderSim().getPosition(), self.simMotor.getRelativeEncoderSim().getVelocity() )
    print( self.simMotor.getAbsoluteEncoderSim().getPosition(), self.simMotor.getAbsoluteEncoderSim().getVelocity() )

Expected behavior
Position and Velocity should properly be the output.
Position += Velocity * dt

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information if applicable):

  • OS: Windows 11
  • OS Language: English
  • Project Information: VSCode, Python 3.13, Simulation Environment

roboRIO (please complete the following information if applicable):

  • roboRIO 1 or 2?: N/A
  • Image version: [Use the roboRIO imaging tool or the WPILib team number setter to determine the image version]

Additional context
Add any other context about the problem here.

@trindels trindels added the bug Something isn't working label Nov 15, 2024
@jfabellera
Copy link
Contributor

Thanks for the report, this will be fixed in the next release.

@jfabellera jfabellera added the Pending The issue will be fixed in the next release label Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Pending The issue will be fixed in the next release REV Robotics
Projects
None yet
Development

No branches or pull requests

2 participants