This Code worked, then it didn't

Hello, I have made code for my team’s minibot deployment system. It worked once, then never again

package com.robototes.abomasnow;

import edu.wpi.first.wpilibj.Jaguar;
import edu.wpi.first.wpilibj.Timer;

public class MinibotDeployment {
    Jaguar armSwingyMotor;
    LimitSwitch thePole;

    MinibotDeployment(int vicPort, int swiPort) {
        //the thing that sets crap up
        this.armSwingyMotor = new Jaguar(4, vicPort);
        this.thePole = new LimitSwitch(swiPort, 14);
    }

    void hitThePole(Driver robot) {
        robot.stop();
        double time = Timer.getFPGATimestamp();
        while ((Timer.getFPGATimestamp() < time + 5.0f) && this.thePole.getLeftWays()) {
            System.out.println(';');
            this.armSwingyMotor.set(0.25);
        }
        this.armSwingyMotor.set(0);
    }

    void resetArm() {
        
    }
}

Limitswitch:

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.robototes.abomasnow;

import edu.wpi.first.wpilibj.DigitalInput;

public class LimitSwitch {
    DigitalInput one;
    DigitalInput two;

    LimitSwitch(int port, int otherPort) {
        one = new DigitalInput(4, port);
        two = new DigitalInput(4, otherPort);
    }

    boolean getLeftWays() {
        return this.one.get();
    }

    boolean getRightWays() {
        return this.two.get();
    }

    boolean] get() {
        boolean] foo = {this.getLeftWays(), this.getRightWays()};
        return foo;
    }
}

resetArm is supposed to be blank.

Where did I screw up?

**public** MinibotDeployment(int vicPort, int swiPort) {

?

It appears that the robot read your comment and didn’t like it!

JK

Is there a better way to do this?

If you use the loop but never reach the limit what happens to the rest of the robot code?

P.S. what “didn’t” work?

Did the robot stop working? If so it appears that you tripped the watchdog.

I do agree that it should be public but I’m thinking he is saying that he ran the code once and it worked but didn’t work after that.

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


while ((Timer.getFPGATimestamp() < time + 5.0f) && this.thePole.getLeftWays()) {
            System.out.println(';');
            this.armSwingyMotor.set(0.25);
        }
        this.armSwingyMotor.set(0);

To something like

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

ok, thanks for the code. We found that the problem was a freaking pwm cable dying on us. >_<