View Single Post
  #4   Spotlight this post!  
Unread 12-07-2014, 10:34
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,043
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: Python Multi Processing

Well, we run our main loop at 15ms, so that sounds reasonable to achieve with polling.

Now that your code is formatted, the error is easy to spot. It's good to remember that FRC code on the cRio runs in the kernel, and not in userspace like it does on the desktop. As a consequence of vxWorks being a real time operating system, what's happening is you're never yielding to other threads using something like sleep() (or even doing some I/O would do the trick), so vxWorks is just running your thread infinitely and eating 100% CPU, and none of the other threads (like your main loop) ever get activated. You should be able to verify this by sticking a print statement at the beginning of the calcValue function (you can use NetConsole to view the output. RobotPy ships with a netconsole.py which also implements the functionality). Stick a wpilib.Wait() in there, and your other threads should start working again.

This type of problem is very easily avoided by never using threads directly. Alternatively, you can use the wpilib.Notifier object, which will call a function continuously at a specified interval.

Also, I wonder if GetAverageVoltage() would work better for you instead of just GetVoltage().

Additionally, if you care about uniform performance, I would just deal with the divide by zero case and make sure the exception never happens. Exceptions are relatively expensive in python, or at least expensive enough if you care about jitter in your calculations.
__________________
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
Reply With Quote