How to make a "Custom VI" in Java?

Hello all,

In the past, our team has used LABView to program our robots. This year, we have switched over to Java. In LV, I could make custom vi’s to do, for example, ramping. I have a small understanding of the concepts needed to do this in java, but it is very, very hazy, so if anyone could point me to a tutorial or other documentation on how to do this, I would much appreciate it.


Not a tutorial, but a “custom VI” in Java would essentially be a method/function. Further, you can spread your methods across several classes to group them (such as a ‘shooter’ class, or a ‘vision targeting’ class).

Hope this points you in a helpful direction (too close to bed to find a good tutorial for you).

You can take a look at the WPI site:

Another resource is the samples that are installed with NetBeans. In NetBeans, go to:
File -> New Project -> Samples -> FRC Java

There are three basic “styles” of programming a robot in Java: BasicRobot, IterativeRobot, and CommandBased. I will let you read about the differences elsewhere, but I thought you should know that there are three different paradigms.

Finally, if you do a search on ChiefDelphi, you will find other teams that link to tutorials on their sites.

Good luck!

Here’s a rate limiter we had in our code from last year.

         * A simple rate limiter.
         * @param input the input value (speed from command/joystick)
         * @param speed the speed currently being traveled at
         * @param posRateLimit the rate limit for accelerating
         * @param negRateLimit the rate limit for decelerating
         * @return the new output speed (rate limited)
        public static double rateLimit(double input, double speed,
                        double posRateLimit, double negRateLimit) {
                if (input > 0) {
                        if (input > (speed + posRateLimit)) {
                          //Accelerating positively
                          speed = speed + posRateLimit;
                        } else if (input < (speed - negRateLimit)) {
                          //Decelerating positively 
                          speed = speed - negRateLimit;
                        } else {
                          speed = input;
                } else {
                        if (input < (speed - posRateLimit)) {
                          //Accelerating negatively
                          speed = speed - posRateLimit;
                        } else if (input > (speed + negRateLimit)) {
                           //Decelerating negatively
                          speed = speed + negRateLimit;
                        } else {
                          speed = input;
                return speed;

You would/could call it like this:

newLeftSpeed = rateLimit(newLeftSpeed, currentLeftSpeed, 0.15, 0.15);
newRightSpeed = rateLimit(newRightSpeed, currentRightSpeed, 0.15, 0.15);

drivetrain.tankDrive(newLeftSpeed, newRightSpeed);

Where the current and new variables used above are class variables used to keep track of speed between loop iterations, and the tank drive just passes the values it receives on to the motor controllers for each side of the drivetrain. The new speed variables could be coming right off your joysticks if using this code in teleop.

Also note, that the code uses the term speed to refer to the commanded value sent out to the motor controller (between 1.0 and -1.0). This is really just the voltage the motor controller will be commanded to output and doesn’t have any direct correlation to the speed of travel of the robot. This code doesn’t, and isn’t intended to, make use of any sensor values in the rate limiter.

If you can post what type of java project you’re working in (Simple Robot, Iterative Robot, or Command Based) we could help suggest how to integrate the code a little better.

Thanks for all the responses! Since this is our first year with java, we figured we should start with SimpleRobot and learn iterative or command-based during the off-season.