View Single Post
  #6   Spotlight this post!  
Unread 03-06-2012, 19:02
Djur's Avatar
Djur Djur is offline
WPILib
AKA: Sam Carlberg
no team
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2009
Location: Massachusetts
Posts: 182
Djur will become famous soon enough
Re: Java Robot Template

You would be better off creating a new class for the "Shooter" object and have that contain such methods as "shoot()" and "aim()". For example:

Code:
public class Shooter {

    public Shooter() {
        //initialization code goes here
    }

    public void shoot() {
        //code goes here
    }

    public void aim() {
        //code goes here
    }

}
Then in your main class:
Code:
public class Main extends RobotMain {

    Shooter shooter;

    public void robotInit() {
        shooter = new Shooter();
    }

    public void teleopPeriodic() {
        shooter.aim();
        shooter.shoot();
    }

}
Calling a method in teleopInit() is not recommended because it is only called once, when the robot enters teleop period. You would be better off calling it in teleopPeriodic, which updates about every 50 ms, or in teleopContinuous, which updates as fast as possible.

You should also take a look at the Java tutorials Oracle has on their website to learn the basics of Java.
__________________
WPILib dev (RobotBuilder, SmartDashboard, GRIP)

Last edited by Djur : 03-06-2012 at 19:54. Reason: Oracle tutorials
Reply With Quote