|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
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() {
}
}
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;
}
}
Where did I screw up? Last edited by Robototes2412 : 11-02-2011 at 21:39. Reason: forgot LimitSwitch code |
|
#2
|
|||||
|
|||||
|
Re: This Code worked, then it didn't
Code:
public MinibotDeployment(int vicPort, int swiPort) {
|
|
#3
|
|||
|
|||
|
Re: This Code worked, then it didn't
It appears that the robot read your comment and didn't like it!
JK Quote:
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. |
|
#4
|
|||
|
|||
|
Re: This Code worked, then it didn't
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.
|
|
#5
|
||||
|
||||
|
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 |
|
#6
|
|||
|
|||
|
Re: This Code worked, then it didn't
Quote:
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);
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);
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. |
|
#7
|
||||
|
||||
|
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. >_<
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|