Go to Post if we aren't here for some wisdom...what are we here for? - Molten [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, 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
  #2   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
  #3   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