View Single Post
  #5   Spotlight this post!  
Unread 13-02-2011, 20:46
drakesword drakesword is offline
Registered User
AKA: Bryant
FRC #0346 (Robohawks)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2004
Location: USA
Posts: 200
drakesword is on a distinguished road
Re: This Code worked, then it didn't

Quote:
Originally Posted by Robototes2412 View Post
Everything in my code is mono-package by design.

the minibot deployment is called as

MinibotDeployment rusty = new MinibotDeployment(3,5);

The robot gets stuck in the loop and no PWM values are set
Easy answer don't use loops. When you trip the watchdog it cuts output.

You should look at possibly using a state machine or schedule a TimerTask to complete your operations. As is its preventing communications with the driver station and/or the rest of the code.

Example

change
Code:
while ((Timer.getFPGATimestamp() < time + 5.0f) && this.thePole.getLeftWays()) {
            System.out.println(';');
            this.armSwingyMotor.set(0.25);
        }
        this.armSwingyMotor.set(0);
To something like
Code:
final double time = Timer.getFPGATimestamp();
java.util.Timer timer = new java.util.Timer();
timer.schedule( new TimerTask() 
{
    public void run()
    {
        if((Timer.getFPGATimestamp() < time + 5.0f) && this.thePole.getLeftWays()) {
            System.out.println(';');
            this.armSwingyMotor.set(0.25);
        }
        else
        {
            this.armSwingyMotor.set(0);
            this.cancel();
        }
    }
}, 0, 50);
This will call the run method every 50 ms starting immediately.
Why call a timer to set the motor to .25 instead of setting the motor to 0.25 then creating a timer to stop the motor? To avoid the motor safety shutting it off

Last edited by drakesword : 13-02-2011 at 21:05.
Reply With Quote