I agree with Jared that you should apply a timer to your timed functions (as mentioned previously). Your idea of starting another thread for the watchdog is interesting, but I'm not sure if it will work as the watchdog is attached to your RobotBase which is extended by IterativeRobot and SimpleRobot. It is, in general, ok to disable the watchdog to test problems, but the robot should be up on blocks. You cannot disable a runaway robot that is no longer listening to controls, which is the reason why the watchdog is there. Here is how we handle our kick timer (in stripped down code)
Code:
public class IRobot extends IterativeRobot
{
Timer robotTime = new Timer();
Joystick js_right = new Joystick(1);
Joystick js_left = new Joystick(2);
Solenoid latch = new Solenoid(1);
Solenoid unlatch = new Solenoid(2);
Solenoid kick1 = new Solenoid(3);
Solenoid unkick1 = new Solenoid(4);
public void robotInit()
{
this.getWatchdog().setEnabled(true);
this.getWatchdog().setExpiration(.2);
this.getWatchdog().feed();
robotTime.reset();
robotTime.stop();
}
public void disabledPeriodic()
{
this.getWatchdog().feed();
/**
* This function is called periodically during operator control
*/
public void teleopPeriodic()
{
//***************Kicker Controls*****************
if (!kicking && js_left.getTrigger())
{
kicking = true;
}
if (kicking)
{
kickTimer();
}
}
public boolean kickTimer()
{
if (robotTime.get() == 0)
{
// KICK
latch.set(false);
unlatch.set(true);
robotTime.start();
} else if (robotTime.get() >= 0.5)
{
// RETRACT
latch.set(true);
unlatch.set(false);
kick1.set(false);
unkick1.set(true);
}
if (robotTime.get() >= 4)
{
// GET READY TO KICK AGAIN
kick1.set(true);
unkick1.set(false);
kicking = false;
robotTime.stop();
robotTime.reset();
}
return kicking;
}
It should be noted that the Timer object here is the one defined by the WPI library and NOT the one defined by java.util.