Go to Post You inspire your way. I'll inspire my way. - Andrew Schreiber [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 03-02-2017, 18:49
Coach Seb's Avatar
Coach Seb Coach Seb is offline
Registered User
AKA: Sebastien Cournoyer
FRC #5860 (Full Metal Muskrats)
Team Role: Coach
 
Join Date: Sep 2015
Rookie Year: 2015
Location: Algonac, MI
Posts: 123
Coach Seb is an unknown quantity at this point
Java Command Based Command

New to Command Based... We are about to start coding the commands for each subsystem and before we get too far, we need the following info on how to handle multiple commands...

For example, we have a feeder motor... we want a command to FeederOn(clockwise), FeederOnRev(counterclockwise) and FeederOff...

We created a Feeder_Command class...

Code:
public class TeleopFeederOn_Command extends Command{
	@Override
	protected void execute(){
		while(Robot.oi.getOperatorJoystick().getRawButton(4) ==true){
			Robot.fuelFeederSubsystem.FeederOn();
		}
		Robot.fuelFeederSubsystem.FeederOff();	
	}
	@Override
	protected boolean isFinished() {
		// TODO Auto-generated method stub
		return false;
	}
	@Override
	protected void end() {
		Robot.fuelFeederSubsystem.FeederOff();
	}
	@Override
	protected void interrupted(){
		end();
	}	
}
That should take care of our FeederOn command using button 4. Now should we build a new command class for FeederOnRev (button5) or do we want to add the command to this class?
Reply With Quote
  #2   Spotlight this post!  
Unread 03-02-2017, 22:27
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: 446
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: Java Command Based Command

If you want a button to execute a command you should be doing this in the OI class.
See here for an example: https://wpilib.screenstepslive.com/s...joystick-input

Basically:
  • create a command for each of your actions (or one that takes in a parameter for the "speed" to pass on to the motors).
  • In OI, you link the command to execute to a Joystick action on a button (e.g. WhenPressed, WhileHeld, etc.).
  • the execute method of your command is just going to call in to the subsystem it requires and call the right setter method that ultimately calls someMotorName.set(speed).

To specifically address your code example, get rid of everything except "Robot.fuelFeederSubsystem.FeederOn();" in the execute method. Then add something like the following to the OI class:
Code:
Joystick myJoystick = new Joystick(0);
Button aButton = new JoystickButton(myJoystick, 5);

...

aButton.whileHeld(new TeleopFeederOn_Command());
Check the Javadoc for Button to see understand what the different methods for button presses (whileHeld, whenPressed...) do.

The guides for command based programming on screensteps live are pretty good. You could also use RobotBuilder to generate some example code to see what the "right" way to do it is. And there's also lots of example code out there to pull from.
__________________
http://team2168.org

Last edited by otherguy : 03-02-2017 at 22:34.
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 13:15.

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