|
Re: Rookie Java FRC programming buttons
Quote:
Originally Posted by aweso_meme
So what would be the code for creating a Thread class?
Do I need to create a new class inside my current package, and then in the main class call Loop xyz = new Loop();, or do i need a certain constructor? Also, with xyz.start(); I read on the internet that these threads have precedence. Does this mean I can have the main class running at the same time or no?
EDIT: Also, If I do need to make a new class, what methods do I need to define and how do I call them in the tele-op method?
Thanks again.
|
You need to create a new Java file, with the name the same as your new class (this is the case for any class -- which you can call by adding to your project and creating an object of your new Class name.
For a "Thread" example:
class YourNewClass extends Thread {
YourNewClass(int x) {
//This is the constructor
}
public void run() {
//Put a while() loop in here
. . .
}
}
from your teleop class:
YourNewClass triggeraction = new YourNewClass();
triggeraction.setPriority(1); //The lower the priority, the thread will be executed last in the computing cycles. teleOp is top priority
triggeraction.run();
while(isEnabled()){....
__________________
My FIRST legacy:
Team 204 Student 2001, 2002 (Voorhees, NJ)
Team 1493 College Mentor 2006 - 2008 (Troy, NY)
Team 2150 Intern/Professional Mentor 2007, 2009 (Palos Verdes)
Team 4123 Lead Engineering Mentor 2012 (Bellflower, CA)
Team 4276 Engineering Mentor 2012-2016 (Huntington Beach, CA)
|