|
Re: Help with Test Robot program (NetBeans)
Updated code:
[code]package edu.wpi.first.wpilibj.templates;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.GenericHID;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.Victor;
//import edu.wpi.first.wpilibj.PWM;
import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.SpeedController;
import edu.wpi.first.wpilibj.Timer;
/**
* 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 TestRobot extends IterativeRobot {
private static RobotDrive driveTrain;
private static GenericHID leftJoystick;
private static GenericHID rightJoystick;
private SpeedController leftVictor;
private SpeedController rightVictor;
//private static PWM rightPWM;
//private static PWM leftPWM;
private boolean m_robotMainOverridden;
/**
* This function is run when the robot is first started up and should be
* used for any initialization code.
*/
public void robotInit() {
leftJoystick = new Joystick(2);
leftVictor = new Victor (1);
//leftPWM = new PWM (2);
rightJoystick = new Joystick(1);
rightVictor = new Victor (1);
//rightPWM = new PWM (1);
driveTrain = new RobotDrive(leftVictor, rightVictor);
}
/**
* This function is called periodically during autonomous
*/
public void autonomousPeriodic() {
}
/**
* This function is called periodically during operator control
*/
public void teleopPeriodic() {
getWatchdog().setEnabled(true);
getWatchdog().setExpiration(0.2);
while (isOperatorControl() && isEnabled()) {
//driveTrain.arcadeDrive(rightJoystick);
driveTrain.tankDrive(leftJoystick, rightJoystick);
if(leftJoystick.getTrigger())
{
leftVictor.set(0.7);
}
else
{
leftVictor.set(0.0);
}
if(rightJoystick.getTrigger())
{
rightVictor.set(0.7);
}
else
{
rightVictor.set(0.0);
}
}
getWatchdog().feed();
}
public void robotMain() { // supplied default robotMain
System.out.println("Information: No user-supplied robotMain()");
m_robotMainOverridden = false;
}
public void autonomous() { // supplied default autonomous()
System.out.println("Provided Autonomous() method running");
}
public void operatorControl() { // suppled default operatorControl()
System.out.println("Provided OperatorControl() method running");
}
public void startCompetition() {
robotMain();
if (!m_robotMainOverridden) {
while(true) {
// Wait for robot to be enabled
while (isDisabled()) {
Timer.delay(.01);
}
// Now enabled - check if we should run Autonomous code
if (isAutonomous()) {
autonomous();
while (isAutonomous() && !isDisabled()) {
Timer.delay(.01);
}
} else {
operatorControl(); // run the operator control method
while (isOperatorControl() && !isDisabled()) {
Timer.delay(.01);
}
}
}
}
}
}[code]
|