|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools |
Rating:
|
Display Modes |
|
#1
|
|||
|
|||
|
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
|
|
#2
|
||||
|
||||
|
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?
|
|
#3
|
|||
|
|||
|
Re: Can't get current from PDP, crashes.
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.
|
|
#4
|
||||
|
||||
|
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 |
|
#5
|
|||
|
|||
|
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;
}
Code:
HALUtil.checkStatus(status.asIntBuffer()); 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) Last edited by Cel Skeggs : 25-02-2015 at 10:39. |
|
#6
|
||||
|
||||
|
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 ![]() |
|
#7
|
||||
|
||||
|
Re: Can't get current from PDP, crashes.
Quote:
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. ![]() |
|
#8
|
||||
|
||||
|
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.
|
|
#9
|
||||
|
||||
|
Re: Can't get current from PDP, crashes.
RobotPy 2015.0.14 has been released and should address this issue.
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|