Go to Post What no one knows is that I’m actually wearing fishnet stockings under this gown… as soon as they finish taking all of these darn photos I’m going to show Dave and Amanda who really has the best legs in FIRST!!! - MissInformation [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

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #3   Spotlight this post!  
Unread 07-12-2013, 16:50
otherguy's Avatar
otherguy otherguy is offline
sparkE
AKA: James
FRC #2168 (The Aluminum Falcons)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: CT
Posts: 429
otherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to behold
Re: Help with buttons and timed sequences

If you're still looking for help on this, there are some good resources online.

It sounds like you're using the Command Based robot project.
If so, you're typically going to want your commands to start/stop conditionally. Typically this starts/stops based on sensor statuses (switches/encoders/etc.) or operator inputs (button presses. (based on sensor input). Alternatively you could have time stop a command as well (See below).

General info on the command based robot project: here
How to associate a command with a joystick button: here


To answer your question specifically...
Quote:
I am not sure how to make a timed sequence or how to add a motor that the button activates.I am not sure how to make a timed sequence or how to add a motor that the button activates.
First you're going to want to create a subsystem which has methods to control the motors on the subsystem in question. So if for example you have a frisbee shooter with two wheels on it... you might have some thing like this for subsystem code:
Code:
public class Shooter extends Subsystem {
        Victor shooterVictorFwd;
        Victor shooterVictorAft;

        public Shooter() {
            shooterVictorAft = new Victor(RobotMap.shooterMotorAft);
            shooterVictorFwd = new Victor(RobotMap.shooterMotorFwd);
        }
        

        public void initDefaultCommand() {
             //Choose a command that should be the default.
             // In this case, probably something that sets the wheels to not spin.
             setDefaultCommand(new DriveShooterWithConstant(0,0));
        }
   

        public void driveShooterWheels(double aftWheelSpeed, double fwdWheelSpeed) {
            shooterVictorFwd.set(fwdWheelSpeed);
            shooterVictorAft.set(aftWheelSpeed);
        }
}
And the command for the shooter could be something like this:
Code:
public class DriveShooterWithConstant extends CommandBase {
        
        private double myAftWheelSpeed;
        private double myFwdWheelSpeed;
        
        /*
         * Method allows you to drive shooter with constant speed
         */
        public DriveShooterWithConstant(double aftWheelSpeed, double fwdWheelSpeed){
                requires(shooter);
                
                myAftWheelSpeed = aftWheelSpeed;
                my.FwdWheelSpeed = fwdWheelSpeed;
        }

        
        protected void end() {
            // Nothing needed here in this case
        }

        
        protected void execute() {
            shooter.driveShooterWheels(aftWheelSpeed,fwdWheelSpeed);
        }

        
        protected void initialize() {
            // Nothing needed here in this case
        }
 
        
        protected void interrupted() {
            // Nothing needed here in this case
        }

        
        protected boolean isFinished() {
                return false;
        }

}
In our code, if we want to have a command run for a duration, we call it with a timeout specified.

Code:
public class RunShooterTimed extends CommandGroup {
        public RunShooterTimed() {
                //this will run the command, and if it doesn't complete in 10 seconds, will kill it
                addSequential(new DriveShooterWithConstant(1.0,1.0), 10.0);                
        }
}

Then you would just link the command group "RunShoterTimed" to a button on the joystick.

Hopefully there aren't too many bugs in the code, I just threw the example above together, it's not tested, but should be mostly correct.

Hope that helps.
__________________
http://team2168.org
Reply With Quote
 


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 09:31.

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