Go to Post Darn kids, how can they not be addicted to ChiefDelphi? - Kyle Love [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 11-02-2011, 21:21
Robototes2412's Avatar
Robototes2412 Robototes2412 is offline
1 * 4 != 14
FRC #2412 (Robototes)
Team Role: Programmer
 
Join Date: Jan 2010
Rookie Year: 2007
Location: Bellevue
Posts: 312
Robototes2412 is on a distinguished road
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?

Last edited by Robototes2412 : 11-02-2011 at 21:39. Reason: forgot LimitSwitch code
Reply With Quote
  #2   Spotlight this post!  
Unread 11-02-2011, 21:59
Robby Unruh's Avatar
Robby Unruh Robby Unruh is offline
*insert random dial-up tone here*
FRC #3266 (Robots R Us)
Team Role: Coach
 
Join Date: Feb 2010
Rookie Year: 2010
Location: Eaton, OH
Posts: 338
Robby Unruh will become famous soon enough
Re: This Code worked, then it didn't

Code:
public MinibotDeployment(int vicPort, int swiPort) {
?
__________________
[Robots R Us #3266]
2015: Georgia Southern Classic (Winners / Thanks 1319 & 1648!), Queen City
2014: Crossroads, Queen City
2013: Buckeye, Queen City, Crossroads
2012: Buckeye, Queen City

2011: Buckeye
2010: Buckeye
Reply With Quote
  #3   Spotlight this post!  
Unread 11-02-2011, 22:09
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

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 View Post

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.
Reply With Quote
  #4   Spotlight this post!  
Unread 11-02-2011, 22:10
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 Robby Unruh View Post
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.
Reply With Quote
  #5   Spotlight this post!  
Unread 12-02-2011, 12:23
Robototes2412's Avatar
Robototes2412 Robototes2412 is offline
1 * 4 != 14
FRC #2412 (Robototes)
Team Role: Programmer
 
Join Date: Jan 2010
Rookie Year: 2007
Location: Bellevue
Posts: 312
Robototes2412 is on a distinguished road
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
Reply With Quote
  #6   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
  #7   Spotlight this post!  
Unread 13-02-2011, 21:23
Robototes2412's Avatar
Robototes2412 Robototes2412 is offline
1 * 4 != 14
FRC #2412 (Robototes)
Team Role: Programmer
 
Join Date: Jan 2010
Rookie Year: 2007
Location: Bellevue
Posts: 312
Robototes2412 is on a distinguished road
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. >_<
__________________
Code:
class team2412(GP):
    def __init__(self):
        GP.__init__(self)
        self.coopertition = True
        self.info = {"name": "Robototes", "school": "Sammamish High School, Bellevue, WA"}
        assert self.kind_people == True
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 00:40.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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