Skip to content
This repository has been archived by the owner on Mar 6, 2024. It is now read-only.

RuntimeError: Unable to cast Python instance to C++ type #10

Closed
KenwoodFox opened this issue Jan 16, 2023 · 4 comments
Closed

RuntimeError: Unable to cast Python instance to C++ type #10

KenwoodFox opened this issue Jan 16, 2023 · 4 comments

Comments

@KenwoodFox
Copy link
Member

Strange cast error, at the moment not sure what causes it, clearly its a result of this code (since it crashes the moment you press the diff lock button)

# Stabilize robot to drive straight with gyro (software diff lock)
        commands2.button.JoystickButton(
            self.driverController, self.driveConsts["DiffLock"]
        ).whileTrue(
            commands2.PIDCommand(
                wpimath.controller.PIDController(
                    self.pidConsts["drive"]["kStabilizationP"],
                    self.pidConsts["drive"]["kStabilizationI"],
                    self.pidConsts["drive"]["kStabilizationD"],
                ),
                # Close the loop on the turn rate
                self.robotDrive.getTurnRate,
                # Setpoint is 0xxx
                0,
                # Pipe the output to the turning controls
                lambda output: self.robotDrive.arcadeDrive(
                    -self.driverController.getLeftY(), output
                ),
                # Require the robot drive
                [self.robotDrive],
            )
        )
[0.30] ********** Robot program startup complete **********
[2.59] 0 [phoenix] Library initialization is complete.  
[4.64] 0 [phoenix-diagnostics] Server 2023.0.0 (Jan  6 2023, 01:03:37) running on port: 1250  
[18.19] Max output has been set to 0.5!
[21.75] Max output has been set to 1!
[30.38] ERROR:your.robot:Unhandled exception
[30.38] 1 Unhandled exception /usr/local/lib/python3.11/site-packages/wpilib/_impl/start.py.164:_start 
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/wpilib/_impl/start.py", line 164, in _start
    self.robot.startCompetition()
  File "/usr/local/lib/python3.11/site-packages/wpilib/_impl/start.py", line 164, in _start
    self.robot.startCompetition()
RuntimeError: Unable to cast Python instance to C++ type (#define PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for details)

[30.38] Traceback (most recent call last):
[30.38]   File "/usr/local/lib/python3.11/site-packages/wpilib/_impl/start.py", line 164, in _start
[30.38]     self.robot.startCompetition()
[30.38] RuntimeError: Unable to cast Python instance to C++ type (#define PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for details)
[30.38] 12:10:13:921 ERROR   : your.robot          : Unhandled exception
[30.38] Traceback (most recent call last):
[30.38]   File "/usr/local/lib/python3.11/site-packages/wpilib/_impl/start.py", line 164, in _start
[30.39]     self.robot.startCompetition()
[30.39] RuntimeError: Unable to cast Python instance to C++ type (#define PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for details)
[30.39] Warning at /usr/local/lib/python3.11/site-packages/wpilib/_impl/start.py.164:_start: Unhandled exception
[30.39] 
[30.39] Traceback (most recent call last):
[30.39]   File "/usr/local/lib/python3.11/site-packages/wpilib/_impl/start.py", line 164, in _start
[30.39]     self.robot.startCompetition()
[30.39]   File "/usr/local/lib/python3.11/site-packages/wpilib/_impl/start.py", line 164, in _start
[30.39]     self.robot.startCompetition()
[30.39] RuntimeError: Unable to cast Python instance to C++ type (#define PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for details)
[30.39] 
[30.39] 
[30.39] 16 Warning: Watchdog not fed within 0.020000s Main      at <no python frames>
        at  + 0x31440 [0xb5e4a440]

[30.39] Warning at Main: Warning: Watchdog not fed within 0.020000s
[30.39]         at <no python frames>
[30.39]         at  + 0x31440 [0xb5e4a440]
[30.39] 
[30.39] 
[30.40] CommandScheduler loop time overrun.
[30.40] ERROR:robotpy:The robot program quit unexpectedly. This is usually due to a code error.
[30.40] The above stacktrace can help determine where the error occurred.
[30.40] Traceback (most recent call last):
[30.40]   File "/usr/local/lib/python3.11/site-packages/wpilib/_impl/start.py", line 75, in start
[30.40]     return self._start(robot_cls)
[30.40]            ^^^^^^^^^^^^^^^^^^^^^^
[30.40]   File "/usr/local/lib/python3.11/site-packages/wpilib/_impl/start.py", line 164, in _start
[30.40]     self.robot.startCompetition()
[30.40] RuntimeError: Unable to cast Python instance to C++ type (#define PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for details)
[30.40] 1 The robot program quit unexpectedly. This is usually due to a code error.
The above stacktrace can help determine where the error occurred.
 /usr/local/lib/python3.11/site-packages/wpilib/_impl/start.py.164:_start 
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/wpilib/_impl/start.py", line 75, in start
    return self._start(robot_cls)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/wpilib/_impl/start.py", line 164, in _start
    self.robot.startCompetition()
  File "/usr/local/lib/python3.11/site-packages/wpilib/_impl/start.py", line 75, in start
    return self._start(robot_cls)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/wpilib/_impl/start.py", line 164, in _start
    self.robot.startCompetition()
RuntimeError: Unable to cast Python instance to C++ type (#define PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for details)

[30.40] 12:10:13:930 ERROR   : robotpy             : The robot program quit unexpectedly. This is usually due to a code error.
[30.40] The above stacktrace can help determine where the error occurred.
[30.40] Traceback (most recent call last):
[30.40]   File "/usr/local/lib/python3.11/site-packages/wpilib/_impl/start.py", line 75, in start
[30.40]     return self._start(robot_cls)
[30.41]            ^^^^^^^^^^^^^^^^^^^^^^
[30.41]   File "/usr/local/lib/python3.11/site-packages/wpilib/_impl/start.py", line 164, in _start
[30.41]     self.robot.startCompetition()
[30.41] RuntimeError: Unable to cast Python instance to C++ type (#define PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for details)
[30.41] Warning at /usr/local/lib/python3.11/site-packages/wpilib/_impl/start.py.164:_start: The robot program quit unexpectedly. This is usually due to a code error.
[30.41] The above stacktrace can help determine where the error occurred.
[30.41] 
[30.41] 
[30.41] Traceback (most recent call last):
[30.41]   File "/usr/local/lib/python3.11/site-packages/wpilib/_impl/start.py", line 75, in start
[30.42]     return self._start(robot_cls)
[30.42]            ^^^^^^^^^^^^^^^^^^^^^^
[30.42]   File "/usr/local/lib/python3.11/site-packages/wpilib/_impl/start.py", line 164, in _start
[30.42]     self.robot.startCompetition()
[30.42]   File "/usr/local/lib/python3.11/site-packages/wpilib/_impl/start.py", line 75, in start
[30.42]     return self._start(robot_cls)
[30.42]            ^^^^^^^^^^^^^^^^^^^^^^
[30.42]   File "/usr/local/lib/python3.11/site-packages/wpilib/_impl/start.py", line 164, in _start
[30.42]     self.robot.startCompetition()
[30.42] RuntimeError: Unable to cast Python instance to C++ type (#define PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for details)
[30.43] 
[30.43] 
^CTraceback (most recent call last):
  File "/home/joe/git/concord_robotics/1721-ChargedUp/rio/robot.py", line 83, in <module>
    wpilib.run(MyRobot)
  File "/home/joe/.local/share/virtualenvs/rio-pTRoqLhR/lib/python3.10/site-packages/wpilib/_impl/main.py", line 210, in run
    retval = options.cmdobj.run(options, robot_class, **kwargs)
  File "/home/joe/.local/share/virtualenvs/rio-pTRoqLhR/lib/python3.10/site-packages/pyfrc/mains/cli_deploy.py", line 202, in run
    if not self._do_deploy(ssh, options, robot_filename, robot_path):
  File "/home/joe/.local/share/virtualenvs/rio-pTRoqLhR/lib/python3.10/site-packages/pyfrc/mains/cli_deploy.py", line 493, in _do_deploy
    nc_thread.join()
  File "/usr/lib/python3.10/threading.py", line 1096, in join
    self._wait_for_tstate_lock()
  File "/usr/lib/python3.10/threading.py", line 1116, in _wait_for_tstate_lock
    if lock.acquire(block, timeout):
KeyboardInterrupt
@KenwoodFox
Copy link
Member Author

Robot just locks up with MAX cpu and requires a code restart to resume.

@virtuald
Copy link

getHeading and/or getTurnRate are returning Rotation2d instead of float, and that value is being fed into the PIDController.

KenwoodFox added a commit that referenced this issue Jan 18, 2023
@KenwoodFox
Copy link
Member Author

getHeading and/or getTurnRate are returning Rotation2d instead of float, and that value is being fed into the PIDController.

Yep! This was exactly correct! Thank you so much for taking a look at in here, I knew it was a simple code issue but the way the error is produced makes it very hard to see what was causing it vs something like "PID loop doesn't have matching method for type Rotation2d"

Thanks again! Ill close the local issue but leave the commandsv2 issue open?

@virtuald
Copy link

Yes, leave the commandsv2 issue open for now.

KenwoodFox added a commit that referenced this issue Jan 21, 2023
Kredcool added a commit that referenced this issue Jan 22, 2023
* CTR doesn't like just telling you code commands

* currently we only have a reset command for the Yaw

* add reset command for the Pitch

* Minor fixups

* the imu works

* aadded imu readings, for testing puroses

* a tempary fix

* The pigeon is slowy but appears to be working, it may not work for our purpose

* this breaks the robot because I haven't found what to import

* I didn't spend a lot of time on this I promise

* better than rev

* so I found our previous navX

* This is a fix for #10

* Remove, whatever these were for

* the reset feature was for the pigeon and not the navx

* updating the pipfile.lock

Co-authored-by: kredcool <kredcool2007@outlook.com>
Co-authored-by: KenwoodFox <kenwood364@gmail.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants