Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Can't get current from PDP, crashes. (http://www.chiefdelphi.com/forums/showthread.php?t=135145)

Aero 24-02-2015 19:50

Can't get current from PDP, crashes.
 
Hey guys, I'm experiencing a lil bit of trouble with the PDP's CAN stuff.
I'm trying to make our compressor disable once we're drawing a certain amount of amperage, just cause that current allowance could be better used.

For some reason, calling the PDP's getTotalCurrent method is causing our robot to crash with a "CTRE CAN Recieve Timeout"

Here's the code and full error:
Code:

from wpilib import Compressor, PowerDistributionPanel

class Pneumatics(object):
        AMPERAGE_THRESHOLD = 20

        def __init__(self):
                self.comp = Compressor()
                self.pdp = PowerDistributionPanel()

        def update(self):
                """
                Monitors the PDP for amp draw, and disables the compressor if amp draw is above a threshold to prevent brownouts.
                :return:
                """
                if self.pdp.getTotalCurrent() > self.AMPERAGE_THRESHOLD:
                        self.comp.stop()
                else:
                        self.comp.start()

Code:

ERROR Unhandled exception:
Traceback (most recent call last):
  File "/home/lvuser/py/robot.py", line 110, in <module>
    run(Drake)
  File "/usr/local/lib/python3.4/site-packages/wpilib/_impl/main.py", line 100, in run
    retval = options.cmdobj.run(options, robot_class, **kwargs)
  File "/usr/local/lib/python3.4/site-packages/hal/main.py", line 11, in run
    return robot_class.main(robot_class)
  File "/usr/local/lib/python3.4/site-packages/wpilib/robotbase.py", line 185, in main
    robot.startCompetition()
  File "/usr/local/lib/python3.4/site-packages/wpilib/samplerobot.py", line 162, in startCompetition
    self.operatorControl()
  File "/home/lvuser/py/robot.py", line 95, in operatorControl
    self.update()
  File "/home/lvuser/py/robot.py", line 102, in update
    component.update()
  File "/home/lvuser/py/components/pneumatics.py", line 16, in update
    if self.pdp.getTotalCurrent() > self.AMPERAGE_THRESHOLD:
  File "/usr/local/lib/python3.4/site-packages/wpilib/powerdistributionpanel.py", line 56, in getTotalCurrent
    return hal.getPDPTotalCurrent()
  File "/usr/local/lib/python3.4/site-packages/hal/functions.py", line 40, in outer
    raise HALError(getHALErrorMessage(status.value))
hal.exceptions.HALError: CTRE CAN Recieve Timeout


chsahit 24-02-2015 20:58

Re: Can't get current from PDP, crashes.
 
HAL means hardware abstraction layer. In my experience, if you see this there is probably a probably a mechanical/electrical issue. Not a problem with the code. Do you see the compressor as a node on the RoboRIO's web interface?

Aero 24-02-2015 21:11

Re: Can't get current from PDP, crashes.
 
Quote:

Originally Posted by chsahit (Post 1449470)
HAL means hardware abstraction layer. In my experience, if you see this there is probably a probably a mechanical/electrical issue. Not a problem with the code. Do you see the compressor as a node on the RoboRIO's web interface?

Yeah, should have mentioned; I can see the PDP fine in the RoboRIO's web interface. It has CAN ID 0, and it passes the self-test fine. It's weird, because the HAL is throwing the error, it's nowhere in RobotPy's WPIlib implementation.

ozrien 24-02-2015 21:35

Re: Can't get current from PDP, crashes.
 
EDIT : oops left editor open for too long....

That error occurs when you are trying to get signals from a CAN device you haven't received updates from. If possible you should catch that exception so it doesn't crash your app. Not sure how to do that in Py tho. Maybe someone else can recommend?

Is the PDP device ID the correct value, specified under "PDP CAN ID".
http://wpilib.screenstepslive.com/s/...ribution-panel

Does the PDP show up in the web-based config?
http://wpilib.screenstepslive.com/s/...ribution-panel

Cel Skeggs 25-02-2015 10:36

Re: Can't get current from PDP, crashes.
 
Under Java (and probably C++), there's a distinction in the HAL between errors and warnings. In this case, this is a warning, and the Java WPILib would generally just log a warning instead of throwing an exception. Though, in reality, the Java implementation ignores all errors and warnings from the HAL about the PDP, possibly for this exact reason:

Code:

        /**
        * Query the current of a single channel of the PDP
        * @return The current of one of the PDP channels (channels 0-15) in Amperes
        */
        public double getCurrent(int channel) {
                ByteBuffer status = ByteBuffer.allocateDirect(4);
                status.order(ByteOrder.LITTLE_ENDIAN);

                double current = PDPJNI.getPDPChannelCurrent((byte)channel, status.asIntBuffer());

                checkPDPChannel(channel);

                return current;
        }

For those of you not well versed in the WPILibJ source, there is a conspicuous lack of a HALUtil status check:
Code:

HALUtil.checkStatus(status.asIntBuffer());
Without this check, warnings and errors from the PDP part of the HAL are not checked.

This may be a bug in the python implementation: it likely should log these as warnings, or ignore them altogether.

We ran into the same problem in Java with our custom wrappers (that would log warnings properly, even for PDP accesses) - randomly, the PDP would have chunks of time where it reported this warning on every access. Most of the time, it would work just fine. An example of this from our logs: (the time at the left is in milliseconds from startup)

Code:

[238266 WARNING] (Common.java:68) HAL Warning: CTRE CAN Recieve Timeout[1] in ccre.igneous.direct.DirectPDP.getCurrent(DirectPDP.java:42)
[238283 WARNING] (Common.java:68) HAL Warning: CTRE CAN Recieve Timeout[1] in ccre.igneous.direct.DirectPDP.getCurrent(DirectPDP.java:42)
[238285 WARNING] (Common.java:68) HAL Warning: CTRE CAN Recieve Timeout[1] in ccre.igneous.direct.DirectPDP.getCurrent(DirectPDP.java:42)
[238289 WARNING] (Common.java:68) HAL Warning: CTRE CAN Recieve Timeout[1] in ccre.igneous.direct.DirectPDP.getCurrent(DirectPDP.java:42)
[238304 WARNING] (Common.java:68) HAL Warning: CTRE CAN Recieve Timeout[1] in ccre.igneous.direct.DirectPDP.getCurrent(DirectPDP.java:42)
[238306 WARNING] (Common.java:68) HAL Warning: CTRE CAN Recieve Timeout[1] in ccre.igneous.direct.DirectPDP.getCurrent(DirectPDP.java:42)
[238311 WARNING] (Common.java:68) HAL Warning: CTRE CAN Recieve Timeout[1] in ccre.igneous.direct.DirectPDP.getCurrent(DirectPDP.java:42)


virtuald 25-02-2015 11:00

Re: Can't get current from PDP, crashes.
 
This does appear to be a RobotPy HAL bug, as Colby points out. I've filed a bug to track this at https://github.com/robotpy/robotpy-wpilib/issues/143.

Aero, if you could subscribe to that bug, I'll be pushing a possible fix for it in a few minutes. I won't be able to test it -- but presumably you can :)

virtuald 25-02-2015 11:08

Re: Can't get current from PDP, crashes.
 
Quote:

Originally Posted by Aero (Post 1449480)
Yeah, should have mentioned; I can see the PDP fine in the RoboRIO's web interface. It has CAN ID 0, and it passes the self-test fine. It's weird, because the HAL is throwing the error, it's nowhere in RobotPy's WPIlib implementation.

Also, it should be noted that the python library has two pieces (well.. three), one is a WPILib piece, and the other is a HAL piece. The HAL piece is just an abstraction, with two concrete implementations -- one for simulation, one for the actual roboRIO C++ hal wrapper.

It works pretty well, because we can run the same WPILib code for simulation/testing and on the real robot, unlike how the simulation stuff is implemented for Java. Hopefully they'll use our model next year. :)

virtuald 25-02-2015 11:19

Re: Can't get current from PDP, crashes.
 
Fix posted at https://github.com/robotpy/robotpy-wpilib/pull/144, Aero please try it out and leave a comment to let me know if it works for you.

virtuald 25-02-2015 17:48

Re: Can't get current from PDP, crashes.
 
RobotPy 2015.0.14 has been released and should address this issue.


All times are GMT -5. The time now is 01:43.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi