View Single Post
  #8   Spotlight this post!  
Unread 22-02-2015, 17:20
notmattlythgoe's Avatar
notmattlythgoe notmattlythgoe is offline
Flywheel Police
AKA: Matthew Lythgoe
FRC #2363 (Triple Helix)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: Newport News, VA
Posts: 1,717
notmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond repute
Re: Passing in variables into a command via command group

Quote:
Originally Posted by defied View Post
Yes.
Great, there are a couple of things going on that are easy to fix.

First, you have done a good job of passing the value into the AutoDrive command. Now that it is in the command you need to actually do something with it. First off, we need a global place to store it so it is accessible out side of the constructor. I would also suggest naming the parameter something meaningful like power, or drivePower. It will make your code more readable in the future when you go back to it.

Code:
private double power;

public AutoDrive(double x) {
...
Now that you have a place to store it you need to store the passed in value in the new variable.

Code:
private double power;

public AutoDrive(double x) {
     power = x;
}
You now have access to this value to use in execute(). But, your execute method is going to cause you problems. In the Command Base structure you want to avoid using long executing loops of any kind. Instead, you want to use isFinished() to determine with the command should finish.

Your execute() should look like this:

Code:
protected void execute() {
     Robot.driveWithJoystick.mecanumDrive_Cartesian123(0,0,0,0);
}
Then your isFinished() should look like this, this will stop the command once both encoders are reporting values greater than 1500:

Code:
protected boolean isFinished() {
     return RobotMap.frontLeftEnc.get() > 1500 && RobotMap.frontRightEnc.get() > 1500;
This should fix most of your problems. Make those changes and post your updated code. Let me know if you have any questions.
Reply With Quote