Go to Post I might be a nerd, but I am definitely a pi freak! - Courtneyb1023 [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 12-02-2012, 19:48
Gnome2013's Avatar
Gnome2013 Gnome2013 is offline
Gnomies
FRC #2013 (Cyber Gnomes)
 
Join Date: Jan 2012
Rookie Year: 2006
Location: Canada
Posts: 26
Gnome2013 is an unknown quantity at this point
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?
Reply With Quote
  #2   Spotlight this post!  
Unread 12-02-2012, 21:09
Patrick Chiang Patrick Chiang is offline
Programming
FRC #3070 (Team Pronto)
Team Role: Mentor
 
Join Date: Feb 2009
Rookie Year: 2009
Location: Seattle
Posts: 162
Patrick Chiang is a name known to allPatrick Chiang is a name known to allPatrick Chiang is a name known to allPatrick Chiang is a name known to allPatrick Chiang is a name known to allPatrick Chiang is a name known to all
Re: Relay Button Issue

Well, the first thing you could do is show us your code.
Reply With Quote
  #3   Spotlight this post!  
Unread 12-02-2012, 21:25
NS_Radication's Avatar
NS_Radication NS_Radication is offline
Student
AKA: Marco Schoener
FRC #1369 (Minotaur)
Team Role: Programmer
 
Join Date: Jan 2012
Rookie Year: 2009
Location: Tampa
Posts: 88
NS_Radication is an unknown quantity at this point
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
    }
}
Two buttons were crazy, but if you want two buttons, just replace the else if with the if statement and add it to the second button loop. Hope this helped.

If you have any questions and comments, just reply or post, etc.

Happy Competitions!
__________________
Team 1369
Senior
Head Programmer (Java)
Head Electrician
Reply With Quote
  #4   Spotlight this post!  
Unread 14-02-2012, 19:55
BurtGummer BurtGummer is offline
Electrical/Mechanical/Programming
FRC #3020
Team Role: Engineer
 
Join Date: Feb 2009
Rookie Year: 2009
Location: Southern CA
Posts: 89
BurtGummer will become famous soon enoughBurtGummer will become famous soon enough
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.
__________________
I'm a mentor looking for a home in Southern California! I know Java, C++, electrical and mechanical.

Need Java or C++ help? Send me a PM!
Reply With Quote
  #5   Spotlight this post!  
Unread 15-02-2012, 10:50
gixxy's Avatar
gixxy gixxy is offline
Programming and Arduino Mentor
AKA: Gustave Michel III
FRC #3946 (Tiger Robotics)
Team Role: Mentor
 
Join Date: Nov 2011
Rookie Year: 2012
Location: Ruston, LA
Posts: 207
gixxy is on a distinguished road
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());
then inside the command my code:

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;
    }
So with two buttons make it two button.whenPressed(new onOrOffCommand()); and two commands, and if they require the spike subsystem it will handle the interrupts for you.

Last edited by gixxy : 15-02-2012 at 10:55. Reason: Forgot info
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 12:37.

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