Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   This Code worked, then it didn't (http://www.chiefdelphi.com/forums/showthread.php?t=91546)

Robototes2412 11-02-2011 21:21

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

Code:

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:
Code:

/*
 * 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?

Robby Unruh 11-02-2011 21:59

Re: This Code worked, then it didn't
 
Code:

public MinibotDeployment(int vicPort, int swiPort) {
?

drakesword 11-02-2011 22:09

Re: This Code worked, then it didn't
 
Quote:

Originally Posted by Robototes2412 (Post 1020922)

Code:

--SNIP--
        //the thing that sets crap up


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

JK
Quote:

Originally Posted by Robototes2412 (Post 1020922)

Code:

        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);
    }


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.

drakesword 11-02-2011 22:10

Re: This Code worked, then it didn't
 
Quote:

Originally Posted by Robby Unruh (Post 1020945)
Code:

public MinibotDeployment(int vicPort, int swiPort) {
?

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.

Robototes2412 12-02-2011 12:23

Re: This Code worked, then it didn't
 
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

drakesword 13-02-2011 20:46

Re: This Code worked, then it didn't
 
Quote:

Originally Posted by Robototes2412 (Post 1021286)
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

Robototes2412 13-02-2011 21:23

Re: This Code worked, then it didn't
 
ok, thanks for the code. We found that the problem was a freaking pwm cable dying on us. >_<


All times are GMT -5. The time now is 22:18.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi