|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||
|
||||
|
Re: Rookie Java FRC programming buttons
When using joysticks, I generally use the Joystick#getRawButton() method as opposed to the specialized methods. You might want to try using:
Code:
...
if (driveStick.getRawButton(1)) // '== true' is not necessary in an if statement for a boolean
{
...
You may have already done this, but you should check the lights on top of the solenoid module while the code runs to ensure that you indeed have a code issue. Quote:
(Protip: if you wrap your code in [code][/code] tags, it will format nicer.) |
|
#2
|
||||
|
||||
|
Re: Rookie Java FRC programming buttons
Quote:
As a form of troubleshooting, why don't you use a Button instead to test and see if the Trigger is causing the issue? In other news, I don't think the code you have there will do exactly what you want. When the trigger is pushed you will enter that for{} loop, but every 0.2001 seconds you will be re-entering that loop until the finger is taken off the trigger. I assume you want to just toggle the valves 3 times and that's it when the button is pushed? If so, you'll need to add a little logic that checks whether the button has just been pressed. For example: boolean triggered=false; if(driveStick.getTrigger() && !triggered){ triggered=true; for{} loop;} else if(!driveStick.getTrigger()){ triggered=false;} In other news, avoid using local for and while loops in SimpleRobot. While that loop is running, you will not get any Drive updates. For just 0.2 seconds maybe you can get away with it, but not good practice in general. Instead, you can either create a separate thread (See Thread class), or what I like to do is create a function that will track its own timing when called repeatedly and return a true or false boolean to indicate when it's done (use the Timer class) Last edited by seg9585 : 12-02-2014 at 11:16. |
|
#3
|
|||
|
|||
|
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. Last edited by aweso_meme : 12-02-2014 at 17:22. |
|
#4
|
||||
|
||||
|
Re: Rookie Java FRC programming buttons
Quote:
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()){.... |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|