View Single Post
  #21   Spotlight this post!  
Unread 13-06-2010, 03:18
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: no control of bot when kicker is operating

I'm not sure if Java has the same thing, but in C++ another easy way to do something like this (without having to worry about yielding, since it does it for you automatically) in a different thread is via the Notifier class. It calls a function every N seconds (we specified 0.0025 seconds) on a different thread. Then you just have your state machine in a single function and have it do the right thing (ie, operate the right switches and such) every time the function gets called. And as the other poster said, you have a different function that gets called by the main thread that touches the state variables.

Of course, a key thing when dealing with multiple threads is to make sure you deal with potential synchronization problems, by using the appropriate locking mechanisms. In C++, you can use the Synchronized class to do that.

I've attached our Kicker code in C++. The full version of our 2010 code is at http://www.virtualroadside.com/FRC/
Attached Files
File Type: h Kicker.h (7.5 KB, 21 views)
__________________
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