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 iterate not properly setting the position #43

Open
trindels opened this issue Nov 15, 2024 · 1 comment
Open
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( velocity, dt ) is setting Position value to match the Velocity value scaled to the dt.

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 )

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

Expected behavior
Position should be increasing incrementally based on the velocity. Position = Position + ( Velocity / 60 * 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

This will be fixed along with #44 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