Go to Post Hallry's back! Tell a Friend! - Tyler Olds [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rating: Thread Rating: 3 votes, 5.00 average. Display Modes
  #1   Spotlight this post!  
Unread 24-02-2015, 19:50
Aero Aero is offline
consumes pizza, produces code
AKA: Ari Lotter
FRC #0865 (Warp7)
Team Role: Programmer
 
Join Date: May 2013
Rookie Year: 2013
Location: Toronto
Posts: 30
Aero is on a distinguished road
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   Spotlight this post!  
Unread 24-02-2015, 20:58
chsahit's Avatar
chsahit chsahit is offline
Lead Developer
AKA: Sahit C
FRC #0011 (MORT)
Team Role: Programmer
 
Join Date: Jul 2014
Rookie Year: 2013
Location: Mount Olive
Posts: 7
chsahit will become famous soon enoughchsahit will become famous soon enough
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   Spotlight this post!  
Unread 24-02-2015, 21:11
Aero Aero is offline
consumes pizza, produces code
AKA: Ari Lotter
FRC #0865 (Warp7)
Team Role: Programmer
 
Join Date: May 2013
Rookie Year: 2013
Location: Toronto
Posts: 30
Aero is on a distinguished road
Re: Can't get current from PDP, crashes.

Quote:
Originally Posted by chsahit View Post
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.
  #4   Spotlight this post!  
Unread 24-02-2015, 21:35
ozrien's Avatar
ozrien ozrien is offline
Omar Zrien
AKA: Omar
no team
Team Role: Mentor
 
Join Date: Sep 2006
Rookie Year: 2003
Location: Sterling Heights, MI
Posts: 549
ozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond repute
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   Spotlight this post!  
Unread 25-02-2015, 10:36
Cel Skeggs Cel Skeggs is offline
Robot Software Manager Alumnus
AKA: Previously known as Colby
FRC #1540 (The Flaming Chickens)
Team Role: Alumni
 
Join Date: Feb 2013
Rookie Year: 2009
Location: Portland, Oregon, USA
Posts: 107
Cel Skeggs is a glorious beacon of lightCel Skeggs is a glorious beacon of lightCel Skeggs is a glorious beacon of lightCel Skeggs is a glorious beacon of lightCel Skeggs is a glorious beacon of lightCel Skeggs is a glorious beacon of light
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)
__________________
Software manager alumnus. Developer of the CCRE, a powerful robot code framework based on dataflow and composibility.
Refer to as she/her/hers. Years of FRC: 2012, 2013, 2014, 2015, 2016. FLL for a few years beforehand.
Team 1540: The Flaming Chickens | Portland, Oregon | Twitter | Facebook

Last edited by Cel Skeggs : 25-02-2015 at 10:39.
  #6   Spotlight this post!  
Unread 25-02-2015, 11:00
virtuald's Avatar
virtuald virtuald is offline
RobotPy Guy
AKA: Dustin Spicuzza
FRC #1418 (), FRC #1973, FRC #4796, FRC #6367 ()
Team Role: Mentor
 
Join Date: Dec 2008
Rookie Year: 2003
Location: Boston, MA
Posts: 1,102
virtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant future
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
__________________
Maintainer of RobotPy - Python for FRC
Creator of pyfrc (Robot Simulator + utilities for Python) and pynetworktables/pynetworktables2js (NetworkTables for Python & Javascript)

2017 Season: Teams #1973, #4796, #6369
Team #1418 (remote mentor): Newton Quarterfinalists, 2016 Chesapeake District Champion, 2x Innovation in Control award, 2x district event winner
Team #1418: 2015 DC Regional Innovation In Control Award, #2 seed; 2014 VA Industrial Design Award; 2014 Finalists in DC & VA
Team #2423: 2012 & 2013 Boston Regional Innovation in Control Award


Resources: FIRSTWiki (relaunched!) | My Software Stuff
  #7   Spotlight this post!  
Unread 25-02-2015, 11:08
virtuald's Avatar
virtuald virtuald is offline
RobotPy Guy
AKA: Dustin Spicuzza
FRC #1418 (), FRC #1973, FRC #4796, FRC #6367 ()
Team Role: Mentor
 
Join Date: Dec 2008
Rookie Year: 2003
Location: Boston, MA
Posts: 1,102
virtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant future
Re: Can't get current from PDP, crashes.

Quote:
Originally Posted by Aero View Post
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.
__________________
Maintainer of RobotPy - Python for FRC
Creator of pyfrc (Robot Simulator + utilities for Python) and pynetworktables/pynetworktables2js (NetworkTables for Python & Javascript)

2017 Season: Teams #1973, #4796, #6369
Team #1418 (remote mentor): Newton Quarterfinalists, 2016 Chesapeake District Champion, 2x Innovation in Control award, 2x district event winner
Team #1418: 2015 DC Regional Innovation In Control Award, #2 seed; 2014 VA Industrial Design Award; 2014 Finalists in DC & VA
Team #2423: 2012 & 2013 Boston Regional Innovation in Control Award


Resources: FIRSTWiki (relaunched!) | My Software Stuff
  #8   Spotlight this post!  
Unread 25-02-2015, 11:19
virtuald's Avatar
virtuald virtuald is offline
RobotPy Guy
AKA: Dustin Spicuzza
FRC #1418 (), FRC #1973, FRC #4796, FRC #6367 ()
Team Role: Mentor
 
Join Date: Dec 2008
Rookie Year: 2003
Location: Boston, MA
Posts: 1,102
virtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant future
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.
__________________
Maintainer of RobotPy - Python for FRC
Creator of pyfrc (Robot Simulator + utilities for Python) and pynetworktables/pynetworktables2js (NetworkTables for Python & Javascript)

2017 Season: Teams #1973, #4796, #6369
Team #1418 (remote mentor): Newton Quarterfinalists, 2016 Chesapeake District Champion, 2x Innovation in Control award, 2x district event winner
Team #1418: 2015 DC Regional Innovation In Control Award, #2 seed; 2014 VA Industrial Design Award; 2014 Finalists in DC & VA
Team #2423: 2012 & 2013 Boston Regional Innovation in Control Award


Resources: FIRSTWiki (relaunched!) | My Software Stuff
  #9   Spotlight this post!  
Unread 25-02-2015, 17:48
virtuald's Avatar
virtuald virtuald is offline
RobotPy Guy
AKA: Dustin Spicuzza
FRC #1418 (), FRC #1973, FRC #4796, FRC #6367 ()
Team Role: Mentor
 
Join Date: Dec 2008
Rookie Year: 2003
Location: Boston, MA
Posts: 1,102
virtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant future
Re: Can't get current from PDP, crashes.

RobotPy 2015.0.14 has been released and should address this issue.
__________________
Maintainer of RobotPy - Python for FRC
Creator of pyfrc (Robot Simulator + utilities for Python) and pynetworktables/pynetworktables2js (NetworkTables for Python & Javascript)

2017 Season: Teams #1973, #4796, #6369
Team #1418 (remote mentor): Newton Quarterfinalists, 2016 Chesapeake District Champion, 2x Innovation in Control award, 2x district event winner
Team #1418: 2015 DC Regional Innovation In Control Award, #2 seed; 2014 VA Industrial Design Award; 2014 Finalists in DC & VA
Team #2423: 2012 & 2013 Boston Regional Innovation in Control Award


Resources: FIRSTWiki (relaunched!) | My Software Stuff
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 02:15.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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