|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||
|
||||
|
Relay Button Issue
We have two buttons that control one spike but in the code only one works if the other is commented out. How should we go about fixing this?
|
|
#2
|
|||
|
|||
|
Re: Relay Button Issue
Well, the first thing you could do is show us your code.
|
|
#3
|
||||
|
||||
|
Re: Relay Button Issue
Well, I coded an on/off switch recently and I came up with a one button toggle after a two button toggle.
Code:
public void teleopPeriodic()
{
boolean spikeToggle = false;
spike.set(Relay.Value.kOff);
if(joy1.getRawButton(BUTTON_NUM)) //set the button to activate motor for the joystick
{
if(spikeToggle == false) // if the toggle is off, set to true and activate motor
{
spikeToggle = true;
spike.set(Relay.Value.kOn);
}
Timer.delay(0.5); // cannot change the value within the first half second of activating, you can change value but it is here to have a safe toggle without toggling every millisecond
else if(spikeToggle == true) // if the motor is on, turn it off and it is set to false
{
spikeToggle = false;
spike.set(Relay.Value.kOff);
}
Timer.delay(0.5); // again it stalls the change for convenience and safety
}
}
If you have any questions and comments, just reply or post, etc. Happy Competitions! |
|
#4
|
|||
|
|||
|
Re: Relay Button Issue
So, what is the problem? I assume you fixed it? Regardless, you might want to create a separate thread in teleOp periodic since you have the 0.5s delays in there.
|
|
#5
|
||||
|
||||
|
Re: Relay Button Issue
Here is how I did one button with CommandBased
Use something like (its explained in the OI class): Code:
ButtonObject.whenPressed(new ToggleSpike()); Code:
private boolean state = false;
private boolean previousState = true;
public SetFeedBelt() {
// Use requires() here to declare subsystem dependencies
// eg. requires(chassis);
requires(feedBelt);
}
// Called just before this Command runs the first time
protected void initialize() {
}
// Called repeatedly when this Command is scheduled to run
protected void execute() {
state = !state;
feedBelt.setBelt(state);
}
// Make this return true when this Command no longer needs to run execute()
protected boolean isFinished() {
if(state != previousState) {
return true;
} else {
return false;
}
}
// Called once after isFinished returns true
protected void end() {
previousState = state;
}
Last edited by gixxy : 15-02-2012 at 10:55. Reason: Forgot info |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|