Quote:
Originally Posted by RufflesRidge
The operatorControl function is only called a single time so your code runs once, using one set of joystick info then does nothing for a long time.
You should surround the code you currently have in the operatorControl method with a loop:
while(isOperatorControl() && isEnabled())
{
}
|
Instead of using a while loop for your entire code, you could try using "iterative robot". You can do this by clicking the "new project" icon in the top left-ish area (it looks like a cardboard box). Then click "FRC Java" entry in the left pane, and the "IterativeRobotTemplateProject" in the right hand pane. Click "Next". The next step should have 5 text fields you can edit. I recommend editing the top, which is the Project Name. I leave the rest alone. Click finish.
It's pretty much the same thing as using the simple robot project, and a while loop, however with iterative robot, your "RobotTemplate" class is looped at a speed which is controlled by the robot. It loops at about 20 times per second if i remember correctly.
This is what robot template should look like:
Code:
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.templates;
import edu.wpi.first.wpilibj.IterativeRobot;
/**
* The VM is configured to automatically run this class, and to call the
* functions corresponding to each mode, as described in the IterativeRobot
* documentation. If you change the name of this class or the package after
* creating this project, you must also update the manifest file in the resource
* directory.
*/
public class RobotTemplate extends IterativeRobot {
/**
* This function is run when the robot is first started up and should be
* used for any initialization code.
*/
public void robotInit() {
}
/**
* This function is called periodically during autonomous
*/
public void autonomousPeriodic() {
}
/**
* This function is called periodically during operator control
*/
public void teleopPeriodic() {
}
}
At this point I would make separate classes for your teleoperated, and your autonomous code, and call them under the "teleopPeriodic()" and the "autonomousPeriodic()" methods respectively.
Hope this helps!