Go to Post Has FIRST ever made a game that was easy to do? - Koko Ed [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 06-12-2013, 11:08
katsauga's Avatar
katsauga katsauga is offline
Lead Programmer
AKA: Marshall Baskin
no team
Team Role: Programmer
 
Join Date: Jan 2013
Rookie Year: 2011
Location: Mora, MN
Posts: 86
katsauga has a little shameless behaviour in the past
Help with buttons and timed sequences

I have finally figured out how to add a button in java. Now though, I am not sure how to make a timed sequence or how to add a motor that the button activates. Do I create a new subsystem? Or is it just certain commands?
__________________
If life gives you lemons,Make grape juice and sit back and watch the world wonder how you did it
Reply With Quote
  #2   Spotlight this post!  
Unread 06-12-2013, 11:32
Jon Stratis's Avatar
Jon Stratis Jon Stratis is offline
Mentor, LRI, MN RPC
FRC #2177 (The Robettes)
Team Role: Mentor
 
Join Date: Feb 2007
Rookie Year: 2006
Location: Minnesota
Posts: 3,835
Jon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond repute
Re: Help with buttons and timed sequences

Are you coming to the MN Splash tomorrow? A couple members of my team will be giving a comprehensive overview of how to do everything in Java that would probably answer all of your questions. The presentation contains just about all of the main parts of our code from last year, and would show you exactly how to get everything started, set up your subsystems, set up commands to act on those subsystems, and link all of that to your OI.

If you can't make it to Splash (it looks like you're a bit far north), contact us at 2177@therobettes.com, and our lead programmer can get you the presentation, and possibly set up a skype chat to walk through it at some point.
__________________
2007 - Present: Mentor, 2177 The Robettes
LRI: North Star 2012-2016; Lake Superior 2013-2014; MN State Tournament 2013-2014, 2016; Galileo 2016; Iowa 2017
2015: North Star Regional Volunteer of the Year
2016: Lake Superior WFFA
Reply With Quote
  #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: 443
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
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:42.

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