UnicodeDecodeError calling sparkmax.iterate() with 2025 robotpy

After updating to 2025 robotpy, when I simulate my code, which is basically 1 fairly minimal subsystem, I get the following error:

22:35:07:729 ERROR   : robotpy             : The robot program quit unexpectedly. This is usually due to a 
code error.
The above stacktrace can help determine where the error occurred.
Traceback (most recent call last):
  File "/home/leo/programming/FRC2429_2025/other_robots/crank_rewritten/.venv/lib/python3.11/site-packages/
pyfrc/physics/core.py", line 195, in _simulationPeriodic
    self.engine.update_sim(now, tm_diff)
  File "/home/leo/programming/FRC2429_2025/other_robots/crank_rewritten/robot/physics.py", line 54, in upda
te_sim
    self.robot.container.lower_crank.sparkmax_sim.iterate(math.radians(self.arm_sim.getVelocityDps()), volt
age, tm_diff)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x97 in position 29: invalid start byte

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/leo/programming/FRC2429_2025/other_robots/crank_rewritten/.venv/lib/python3.11/site-packages/
wpilib/_impl/start.py", line 160, in start
    return self._start(robot_cls)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/leo/programming/FRC2429_2025/other_robots/crank_rewritten/.venv/lib/python3.11/site-packages/
wpilib/_impl/start.py", line 247, in _start
    self.robot.startCompetition()
  File "/home/leo/programming/FRC2429_2025/other_robots/crank_rewritten/.venv/lib/python3.11/site-packages/
pyfrc/physics/core.py", line 197, in _simulationPeriodic
    raise Exception(
Exception: User physics code raised an exception (see above)

The subsystem creates a SparkMax object, creates a configuration, then uses SparkMax.configure to apply it. If it’s simulated, the subsystem will create an attribute of itself containing a SparkMaxSim.
Every answer I found when I looked up the error related to reading files, which is not happening here as far as I can tell.
For convenience, here’s my update_sim method, which is causing the problem.

    def update_sim(self, now, tm_diff):

        wpilib.simulation.RoboRioSim.setVInVoltage(
                wpilib.simulation.BatterySim.calculate([self.arm_sim.getCurrentDraw()])
        )
        voltage = wpilib.simulation.RoboRioSim.getVInVoltage()

        self.arm_sim.setInputVoltage(voltage * self.robot.container.lower_crank.sparkmax_sim.getAppliedOutput())

        self.arm_sim.update(tm_diff)

        self.robot.container.lower_crank.sparkmax_sim.iterate(math.radians(self.arm_sim.getVelocityDps()), voltage, tm_diff)
        # self.robot.container.lower_crank.set_encoder_position(self.arm_sim.getAngle())

        self.crank_mech2d.setAngle(math.degrees(self.arm_sim.getAngle()))

        # l_encoder = self.drivetrain.wheelSpeeds.left * tm_diff

REV is calling HAL_SendError with invalid strings, which fails when Python tries to convert the string to unicode. I’ve opened Invalid bytes passed to HAL_SendError cause confusing unicode errors · Issue #113 · robotpy/mostrobotpy · GitHub to track this, but it’s also a bug in the underlying rev libraries so I’ll file a bug with them too.

It appears that this occurs because the control mode for the motor hasn’t been initialized yet (it seems to be -1). This bug will also occur if you use control modes 4 and 6, or if voltage is 0.

1 Like