Debugging problems

Every time I run the debugging program it creates what I think is an infinate loop and I have to stop the program

package org.usfirst.frc.team4284.robot;

import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.Jaguar;
import edu.wpi.first.wpilibj.buttons.JoystickButton;
import edu.wpi.first.wpilibj.buttons.Button;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.livewindow.LiveWindow;

/**

  • 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 Robot extends IterativeRobot {
    RobotDrive Drive;
    Joystick drivestick;
    Joystick xbox;
    int autoLoopCounter;

    /**

    • This function is run when the robot is first started up and should be
    • used for any initialization code.
      */
      public void robotInit() {
      Jaguar FL = new Jaguar (1);
      Jaguar BL = new Jaguar (2);
      Jaguar FR = new Jaguar (3);
      Jaguar BR = new Jaguar (4);
      Drive = new RobotDrive(FL,BL,FR,BR);
      drivestick = new Joystick(0);

    }

    /**

    • This function is run once each time the robot enters autonomous mode
      */
      public void autonomousInit() {
      autoLoopCounter = 0;
      }

    /**

    • This function is called periodically during autonomous
      */
      public void autonomousPeriodic() {
      /*if(autoLoopCounter < 100) //Check if we’ve completed 100 loops (approximately 2 seconds)
      {
      Drive.drive(-0.5, 0.0); // drive forwards half speed
      autoLoopCounter++;
      } else {
      Drive.drive(0.0, 0.0); // stop robot
      } */
      }

    /**

    • This function is called once each time the robot enters tele-operated mode
      */
      public void teleopInit(){

    }

    /**

    • This function is called periodically during operator control
      */
      public void teleopPeriodic() {
      Drive.arcadeDrive(drivestick);

      xbox = new Joystick(1);
      Button button1 = new JoystickButton(xbox, 1),
      button2 = new JoystickButton(xbox, 2),
      button3 = new JoystickButton(xbox, 3),
      button4 = new JoystickButton(xbox, 4),
      button5 = new JoystickButton(xbox, 5),
      button6 = new JoystickButton(xbox, 6),
      button7 = new JoystickButton(xbox, 7);

       button1.whenPressed(new ElevatorReverse());
       button2.whenPressed(new ElevatorOn());
       button3.whenPressed(new ElevatorOff());
       button4.whenPressed(new ArmsOut());
       button5.whenPressed(new ArmsIn());
       button6.whenPressed(new ArmsVerticalIn());
       button7.whenPressed(new ArmsVarticalOut());
      

    }

    /**

    • This function is called periodically during test mode
      */
      public void testPeriodic() {
      LiveWindow.run();
      }

}

I’m assuming the “debugging” program is the one you listed, not “when the program is ran in with the debugger”.

You didn’t state if the robot is in auton or teleop. Auton is written in IterativeRobot style and (at a quick glance) should work. The teleop section seems to be in command based style but is not correct. Most of the code in teleopPeriodic() should be in the teleopInit() so it is only called once.

There are a number of programming resources at http://wpilib.screenstepslive.com/s/4485/m/13809 and in particular, I would recommend the “Debugging a robot program” and learn how to set breakpoints and single-step through your code. A debugger is great for learning how your code is working and a tool every programmer should know how to use.