Go to Post "Don't worry, it's just a prototype." - Newo95 [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 14-02-2012, 18:33
Thundrio Thundrio is offline
Dedicated Racer
FRC #3673
 
Join Date: Feb 2011
Rookie Year: 2010
Location: The Internet
Posts: 67
Thundrio is on a distinguished road
Need some quick advice

We are doing a demonstration at the halftime show of a school basketball game in a few hours, and I am trying to code up a button to make it easier on us.

Last night we tested and it works fine, but I do not have an intuitive control system set up. Our robot uses a belt to raise the ball to our shooter, and then we run the shooter, and fire a pneumatic kicker to kick the ball into the shooter. the main problem is with people forgetting to retract the kicker, which will stop the belt if you forget (I have done this many times), so I want it to automatically retract.

I want to use the simple .get() button command to run the program, and this is what I would like it to do in pseudocode.

if (joystickbutton.get()){//runs the program when button is held down
if (programrun? = false){//will run program if has not been run before
shootermotors.set(1);//turns on the shooter
wait (untilshootersatmaxspeed);//usually about 3-4 seconds
solenoid.extend;//kicks the ball into the shooter
wait (untilsolenoidisextended);//waits until the solenoid is kicked fully
solenoid.retract;//puts the solenoid back in position
shootermotors.set(0);//turns off the motors
programrun = true;//sets it so the program doesnt run more than once
}
}
else{
programrun = false;//so that when i take finger off button program can be run again
}

here is my actual code which does not work as intended, I have declared everything before.

if (zero.get()){//if joystick is held down
if (MYVAL = false){//if program hasnt been run
topshoot.set(1);//sets speed of top part of shooter
bottomshoot.set(-1);//sets speed of bottom part of shooter
Timer.delay(4);//waits im assuming 4 seconds
s1.set(true);//sets the solenoid to the right value to extend
s2.set(false);//sets the solenoid to the right value to extend
Timer.delay(3);//waits im assuming 3 seconds
s1.set(false);//sets the solenoid to the right value to retract
s2.set(true);//sets the solenoid to the right value to retract
topshoot.set(0);//turns off the top motor
bottomshoot.set(0);//turns off the bottom motor
MYVAL = true;//makes it so program cant be run more than once
}
}
else{

MYVAL = false;//sets it so the program can be run again
}


any quick ideas about what could be wrong would be appreciated.

tyvm in advance
__________________
Interested in a new way of playing old games?
visit http://www.speedrunslive.com for a way to make single player games multiplayer!
visit http://www.zeldaspeedruns.com to open up a new world for zelda lovers!
pm me here or at zsr for more information!
Reply With Quote
  #2   Spotlight this post!  
Unread 14-02-2012, 19:30
shank948 shank948 is offline
VP of Programming - 948
AKA: Stephen Shank
FRC #0948 (NRG (Newport Robotics Group))
Team Role: Alumni
 
Join Date: Feb 2010
Rookie Year: 2009
Location: Bellevue, Wa
Posts: 21
shank948 is an unknown quantity at this point
Re: Need some quick advice

Quote:
Originally Posted by Thundrio View Post
Timer.delay(4);//waits im assuming 4 seconds
First, Timer.delay(x) waits for x milliseconds.
Second, I can see a lot of potential for watchdog errors with this code, since it is written like normal, top-to-bottom code as opposed to the looping thread that is used for FRC.
I'm not the best at articulating my ideas so feel free to ask any other questions.
Your simplest bet would be to make a button/control for each aspect(belts, kicker,shooter), even though that may be harder for the driver to remember.
Reply With Quote
  #3   Spotlight this post!  
Unread 14-02-2012, 20:48
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: Need some quick advice

Quote:
Originally Posted by shank948 View Post
First, Timer.delay(x) waits for x milliseconds.
Second, I can see a lot of potential for watchdog errors with this code, since it is written like normal, top-to-bottom code as opposed to the looping thread that is used for FRC.
I'm not the best at articulating my ideas so feel free to ask any other questions.
Your simplest bet would be to make a button/control for each aspect(belts, kicker,shooter), even though that may be harder for the driver to remember.
By the way, x is not for milliseconds, it is for seconds. The robot will delay without anything happening, besides spikes, if something is implemented with this as a wait statement.

Just a tip.
__________________
Team 1369
Senior
Head Programmer (Java)
Head Electrician
Reply With Quote
  #4   Spotlight this post!  
Unread 17-02-2012, 22:28
Ginto8's Avatar
Ginto8 Ginto8 is offline
Programming Lead
AKA: Joe Doyle
FRC #2729 (Storm)
Team Role: Programmer
 
Join Date: Oct 2010
Rookie Year: 2010
Location: Marlton, NJ
Posts: 174
Ginto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of light
Re: Need some quick advice

Sounds to me like this is a job for... a Command with a state machine!
Since you want it to work easily with a .get() (presumably without hanging your robot or killing the watchdog, the poor beast), I'd use a StartCommand to initialize a Command in .get(). This command should have some sort of member determining which "state" it's in (raising belt, extending piston, retracting piston, etc.), and each execute() it should act upon this state (by continuing to do something like raising the belt, or possibly doing nothing), then check to see if it's complete (enough time has gone by, another sensor has been tripped, etc.). If the current state is complete, it advances to the next state, and if there are no more states, it either starts over (returning to its initial state) or finishes (which I think is the better choice in this situation). If you set up your command like a state machine, it can perform actions in sequence without getting in the way of the rest of the robot.

Just as a possible example of a state machine, I have some code I wrote early in the season which runs a sequence of Commands (feel free to use it if it suits your needs):
Code:
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package commands;

import edu.wpi.first.wpilibj.command.Command;

/**
 *
 * @author Ginto8
 */
public class CommandSequence extends Command {
    Command[] commands_;
    int current_;

    public CommandSequence(Command[] commands) {
        commands_ = commands;
    }

    protected void initialize() {
        if(commands_ == null || commands_.length == 0)
            current_ = -1;
        else
            current_ = 0;
    }

    protected void execute() {
        if(!commands_[current_].isRunning()) {
            ++current_;
            if(!isFinished())
                commands_[current_].start();
        }
    }

    protected boolean isFinished() {
        return current_ >= 0 && current_ <= commands_.length;
    }

    protected void end() {
        current_ = -1;
    }

    protected void interrupted() {
        end();
    }

}
In this case, the member variable current_ is my state, selecting which Command should be run.
Reply With Quote
  #5   Spotlight this post!  
Unread 18-02-2012, 18:28
jesusrambo jesusrambo is offline
Self-Proclaimed Programmer Messiah
AKA: JD Russo
FRC #2035 (Robo Rockin' Bots)
Team Role: Programmer
 
Join Date: Feb 2012
Rookie Year: 2010
Location: Carmel, CA
Posts: 114
jesusrambo is an unknown quantity at this point
Re: Need some quick advice

in OI:

Code:
JoystickButton doStuff = new JoystickButton(joysticknumber, buttonnumber);

doStuff.whenReleased(new Shoot());
Make a command called Shoot
Code:
package edu.wpi.first.wpilibj.templates.commands;

/**
 *
 * @author Thundrio
 */
public class ExampleCommand extends CommandBase {
Timer t = new Timer();


    protected void initialize() {
        shooterMotors.set(1);
        t.reset();
        t.start();
    }

    protected void execute() {
        shooterMotors.set(1);
        if (t.get() >= 1)
            solenoid.extend();
    }

    protected boolean isFinished() {
        if (solenoid.isExtended())
            return true;
        else
            return false;
    }

    protected void end() {
        shooterMotors.set(0);
    }
}
Something like that. Replace the placeholder stuff with your own commands and subsystems obviously, and add a constructor and all.
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:45.

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