Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   Packages/Importing problem with FRC Java (http://www.chiefdelphi.com/forums/showthread.php?t=132282)

TeamMarcies 06-01-2015 20:14

Packages/Importing problem with FRC Java
 
So currently I am trying to use the following VALID java statement:

public Executor executor = Executors.newSingleThreadExecutor();

It requires these two imports:

import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

which require this package:

package java.util.concurrent;

Which isn't found according to Netbeans but is found when I am working with a default java project.

Is this simply not allowed to be used?
I am wanting to use threads in autonomous mode and through that, use Executors that will allow threads to be placed in queue so I can have them executed in the order I have threads be executed in.

Also, are threads allowed to be used?

Ben Wolsieffer 06-01-2015 20:17

Re: Packages/Importing problem with FRC Java
 
Is this code for the roboRIO, and if so, how did you set up your project for Netbeans. If you manually set up the project for Netbeans that might have something to do with it.

TeamMarcies 06-01-2015 20:24

Re: Packages/Importing problem with FRC Java
 
We are using the new 2015 roboRIO.

I've been programming for the team for 2 years and I've just decided to go ahead and clean up our messy code and start using threads to make things easier.

I have set up the project properly.

File -> New Project - > Java FRC -> IterativeRobot

I know it's working because it's recognizing the FRC java API which I am knees deep in with the code. It's just this problem where I can't seem to import a java utility I need for threads.

Team3266Spencer 06-01-2015 20:43

Re: Packages/Importing problem with FRC Java
 
Just use the command-based template. No reason to rewrite the wheel.

Ben Wolsieffer 06-01-2015 20:45

Re: Packages/Importing problem with FRC Java
 
Are you using Netbeans? Netbeans is not officially supported anymore, so I suspect you are either trying to use the 2014 plugins or you have something wrong with how you tried to integrate the 2015 API into Netbeans.

I would try using Eclipse to test and make sure your code works in the official environment.

Ben Wolsieffer 06-01-2015 20:51

Re: Packages/Importing problem with FRC Java
 
Quote:

Originally Posted by Team3266Spencer (Post 1423223)
Just use the command-based template. No reason to rewrite the wheel.

I also recommend using the command-based system. It gives you a lot of the advantages of multithreaded code without worrying about race conditions, deadlocks and other threading weirdness. You will also be able to get more help from other teams.

TeamMarcies 06-01-2015 20:52

Re: Packages/Importing problem with FRC Java
 
Alright, thanks!

I'll start transitioning to Eclipse and let you know the results.

Ben Wolsieffer 06-01-2015 20:54

Re: Packages/Importing problem with FRC Java
 
You've probably already seen this, but in case you haven't, this will help with the installation and setup: http://wpilib.screenstepslive.com/s/...eclipse-c-java

TeamMarcies 06-01-2015 23:09

Re: Packages/Importing problem with FRC Java
 
Yep! Eclipse did the trick. Thanks guys. I'll be sure to check out the command-based programming - it seems neat.

Just one quick question: Am I able to do a while(true) loop in a thread and have it persistently be doing something or will it crash the network/roboRIO?

Basically what I'm doing here:

Code:

public void run() {
        R.autonomousCounter = 0;
        while (true) {
            if ((Math.floor(R.autonomousCounter / loopsPerSecond)) < seconds) {
                if (forward) {
                    theRobot.drive(-robotDriveSpeed, gyro.getAngle() * gyroModifierSpeed);
                }else if (!forward) {
                    theRobot.drive(robotDriveSpeed, gyro.getAngle() * gyroModifierSpeed);
                }
            }else{
                break;
            }
        }
        theRobot.drive(0.0, 0.0);
    }


Team3266Spencer 06-01-2015 23:16

Re: Packages/Importing problem with FRC Java
 
Quote:

Originally Posted by TeamMarcies (Post 1423307)
Yep! Eclipse did the trick. Thanks guys. I'll be sure to check out the command-based programming - it seems neat.

Just one quick question: Am I able to do a while(true) loop in a thread and have it persistently be doing something or will it crash the network/roboRIO?

Basically what I'm doing here:

Code:

public void run() {
        R.autonomousCounter = 0;
        while (true) {
            if ((Math.floor(R.autonomousCounter / loopsPerSecond)) < seconds) {
                if (forward) {
                    theRobot.drive(-robotDriveSpeed, gyro.getAngle() * gyroModifierSpeed);
                }else if (!forward) {
                    theRobot.drive(robotDriveSpeed, gyro.getAngle() * gyroModifierSpeed);
                }
            }else{
                break;
            }
        }
        theRobot.drive(0.0, 0.0);
    }


Just do it this way:

Code:

public void run() {
        R.autonomousCounter = 0;
        while ((Math.floor(R.autonomousCounter / loopsPerSecond)) < seconds) {
            if (forward) {
                theRobot.drive(-robotDriveSpeed, gyro.getAngle() * gyroModifierSpeed);
            }else if (!forward) {
                theRobot.drive(robotDriveSpeed, gyro.getAngle() * gyroModifierSpeed);
            }
        }
        theRobot.drive(0.0, 0.0);
    }

I still wouldn't be worrying with threads though.

cgmv123 06-01-2015 23:17

Re: Packages/Importing problem with FRC Java
 
Quote:

Originally Posted by TeamMarcies (Post 1423307)
Am I able to do a while(true) loop in a thread and have it persistently be doing something or will it crash the network/roboRIO?

Add
Code:

Timer.delay(0.005);
at the end of your loop and you should be fine.

TeamMarcies 06-01-2015 23:46

Re: Packages/Importing problem with FRC Java
 
Greatly appreciate the help guys, thanks!


All times are GMT -5. The time now is 11:20.

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