robotpy / robotpy-commands-v1

Python bindings for the original WPILib Command Framework
0 stars 3 forks source link

Task scheduler crash in Teleop mode #1

Closed picode98 closed 4 years ago

picode98 commented 4 years ago

I tried running some existing pre-season code, and found that it crashes when I attempt to enter Teleop mode. Full output is as follows:

16:07:28:680 INFO    : wpilib              : WPILib version 2020.1.2.2
16:07:28:680 INFO    : wpilib              : HAL version 2020.1.2.1
16:07:28:681 WARNING : wpilib              : Core component versions are not identical! This is not a supported configuration, and you may run into errors!
16:07:28:681 INFO    : wpilib              : Running with simulated HAL.
16:07:28:684 INFO    : halsim_gui          : WPILib HAL Simulation 2020.1.2.1
HAL Extensions: Attempting to load: halsim_gui
Simulator GUI Initializing.
Simulator GUI Initialized!
HAL Extensions: Successfully loaded extension
Not loading CameraServerShared
robot.py:10: DeprecationWarning: 'redirect_output' setting via enable_attach will be deprecated in the future versions of the debugger. This can be set using redirectOutput in Launch config in VS Code, using Tee output option in Visual Studio, or debugOptions configuration for any client.
ptvsd.enable_attach(address=('0.0.0.0', 5678), redirect_output = True)
Default frc::IterativeRobotBase::RobotInit() method... Override me!
Default frc::IterativeRobotBase::DisabledInit() method... Override me!
Default frc::IterativeRobotBase::RobotPeriodic() method... Override me!
Default frc::IterativeRobotBase::TeleopInit() method... Override me!
Joystick Axis missing, check if all controllers are plugged in
16:07:45:712 ERROR   : wpilib.ds           : Unhandled exception
Traceback (most recent call last):
File "C:\Users\saama\Documents\HCRC\venv-robotpy2020beta\lib\site-packages\wpilib\_impl\start.py", line 94, in start
    self.robot.startCompetition()
File "C:\Users\saama\Documents\HCRC\venv-robotpy2020beta\lib\site-packages\commandbased\commandbasedrobot.py", line 15, in startCompetition
    super().startCompetition()
File "robot.py", line 18, in teleopPeriodic
    super().teleopPeriodic()
File "C:\Users\saama\Documents\HCRC\venv-robotpy2020beta\lib\site-packages\commandbased\commandbasedrobot.py", line 24, in commandPeriodic
    self.scheduler.run()
RuntimeError: Tried to call pure virtual function "CxxBase::_isFinished"

Locals at innermost frame:

{'self': <__main__.Robot object at 0x0000021DE6994B88>}

Error at C:\Users\saama\Documents\HCRC\venv-robotpy2020beta\lib\site-packages\comWatchdog not fed within m0.020000ans
dbased\commandbasedrobot.py.24:commandPeriodic: Unhandled exception

Traceback (most recent call last):
File "C:\Users\saama\Documents\HCRC\venv-robotpy2020beta\lib\site-packages\wpilib\_impl\start.py", line 94, in start
    self.robot.startCompetition()
File "C:\Users\saama\Documents\HCRC\venv-robotpy2020beta\lib\site-packages\commandbased\commandbasedrobot.py", line 15, in startCompetition
    super().startCompetition()
File "robot.py", line 18, in teleopPeriodic
    super().teleopPeriodic()
File "C:\Users\saama\Documents\HCRC\venv-robotpy2020beta\lib\site-packages\commandbased\commandbasedrobot.py", line 24, in commandPeriodic
    self.scheduler.run()
File "C:\Users\saama\Documents\HCRC\venv-robotpy2020beta\lib\site-packages\wpilib\_impl\start.py", line 94, in start
    self.robot.startCompetition()
File "C:\Users\saama\Documents\HCRC\venv-robotpy2020beta\lib\site-packages\commandbased\commandbasedrobot.py", line 15, in startCompetition
    super().startCompetition()
File "robot.py", line 18, in teleopPeriodic
    super().teleopPeriodic()
File "C:\Users\saama\Documents\HCRC\venv-robotpy2020beta\lib\site-packages\commandbased\commandbasedrobot.py", line 24, in commandPeriodic
    self.scheduler.run()
RuntimeError: Tried to call pure virtual function "CxxBase::_isFinished"

Lo16:07:45:828 WARNING : wpilib.ds           : Robots should not quit, but yours did!
op time of 0.020000s overrun

Error at frc::MotorSafety::Check [MotorSafety.cpp:103]: A timeout has been exceeded: DifferentialDrive... Output not updated often enough.
Robots should not quit, but yours did!
16:07:45:844 ERROR   : wpilib.ds           : The startCompetition() method (or methods called by it) should have handled the exception above.
The startCompetition() method (or methods called by it) should have handled the exception above.

Packages installed (pip list):

Package                  Version
------------------------ ----------
astroid                  2.3.3
atomicwrites             1.3.0
attrs                    19.3.0
bcrypt                   3.1.7
cffi                     1.13.2
colorama                 0.4.3
cryptography             2.8
importlib-metadata       1.4.0
isort                    4.3.21
lazy-object-proxy        1.4.3
mccabe                   0.6.1
more-itertools           8.1.0
packaging                20.0
paramiko                 2.7.1
Pint                     0.10.1
pip                      19.0.3
pluggy                   0.13.1
ptvsd                    4.3.2
py                       1.8.1
pycparser                2.19
pyfrc                    2020.0.0b1
pygame                   1.9.6
pylint                   2.4.4
PyNaCl                   1.3.0
pynetconsole             2.0.2
pynetworktables          2020.0.1
pyntcore                 2020.1.2.0
pyparsing                2.4.6
pytest                   5.3.2
robotpy-commands-v1      2020.1.2.0
robotpy-hal              2020.1.2.1
robotpy-halsim-gui       2020.1.2.1
robotpy-installer        2020.0.1
robotpy-wpilib-utilities 2020.0.1
robotpy-wpiutil          2020.1.2.1
setuptools               40.8.0
six                      1.13.0
typed-ast                1.4.1
wcwidth                  0.1.8
wpilib                   2020.1.2.2
wrapt                    1.11.2
zipp                     1.0.0
virtuald commented 4 years ago

I'll take a look in a bit.

virtuald commented 4 years ago

I don't have it set up to run on this laptop, but my guess is that you need to implement all of the virtual functions for every command. Prior versions of RobotPy didn't make you do this, so we can fix it at some point, but this would get you going for now.

Anything on this that says 'virtual' and =0... looks like only isFinished needs to be implemented. https://first.wpi.edu/FRC/roborio/release/docs/cpp/classfrc_1_1Command.html

picode98 commented 4 years ago

I tried adding the following definitions to all command classes (drive_immediate.py, drive_reserve.py):

def _isFinished(self):
    return False

def IsFinished(self):
    return False

def isCompleted(self):
    return False

The crash still occurs with all of these definitions present in both classes. Is there some other function that should be implemented?

virtuald commented 4 years ago

There are two issues.

One, you need to override the _isFinished function. We need to provide either a better error message or a default implementation like we did previously. I'm open to suggestions?

The other is that when we pass in commands to the scheduler, it doesn't retain a reference to them. Store them somewhere first, then pass it to the scheduler. We will fix this, but maybe not until later today.

virtuald commented 4 years ago

robotpy-commands-v1 2020.1.2.1 fixes the reference issue, and gives a mildly better error message when you forget to override something.

picode98 commented 4 years ago

I can confirm that this release fixes the issue; I appreciate the help. However, I also had to rename execute to _execute in both commands in order for these functions to be executed. This leads me to wonder which set of naming conventions are in use, as help(wpilib.command.Command) does not list either _isFinished or _execute as members.

virtuald commented 4 years ago
>>> import pprint
>>> pprint.pprint(dir(wpilib.command.Command))
['__Cancel',
 '__End',
 '__Execute',
 '__Initialize',
 '__Interrupted',
 '__class__',
 '__delattr__',
 '__dir__',
 '__doc__',
 '__eq__',
 '__format__',
 '__ge__',
 '__getattribute__',
 '__gt__',
 '__hash__',
 '__init__',
 '__init_subclass__',
 '__le__',
 '__lt__',
 '__module__',
 '__ne__',
 '__new__',
 '__reduce__',
 '__reduce_ex__',
 '__repr__',
 '__setattr__',
 '__sizeof__',
 '__str__',
 '__subclasshook__',
 '_assertUnlocked',
 '_clearRequirements',
 '_end',
 '_execute',
 '_initialize',
 '_interrupted',
 '_isFinished',
 '_isParented',
 '_isTimedOut',
 '_m_error',
 '_setParent',
 '_setTimeout',
 'cancel',
 'clearError',
 'clearGlobalErrors',
 'cloneError',
 'doesRequire',
 'getError',
 'getGlobalError',
 'getGlobalErrors',
 'getGroup',
 'getID',
 'getName',
 'getRequirements',
 'getSubsystem',
 'initSendable',
 'isCanceled',
 'isCompleted',
 'isInitialized',
 'isInterruptible',
 'isRunning',
 'requires',
 'run',
 'setErrnoError',
 'setError',
 'setErrorRange',
 'setGlobalError',
 'setGlobalWPIError',
 'setImaqError',
 'setInterruptible',
 'setName',
 'setRunWhenDisabled',
 'setSubsystem',
 'setWPIError',
 'start',
 'statusIsFatal',
 'timeSinceInitialized',
 'willRunWhenDisabled']

.. basically, anything that is 'protected' in C++ automatically gets an underscore before it, and anything with an underscore is automatically excluded from help. We should probably figure out the right way to deal with that.