View Single Post
  #3   Spotlight this post!  
Unread 12-12-2014, 11:23
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,715
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: (Java) Error calling subsystem method from command

Quote:
Originally Posted by Jaykus View Post
I'm having trouble calling methods from subsystems on Netbeans. When I call DriveSystem, it shows up fine and the preset methods show up, but whenever I try to call a method that I created myself it gives me an error saying "cannot find symbol method doNothing()". I tried different subsystems and commands, and even tried renaming them, but nothing seems to work and I can't find anything that might cause an error.

Command Code:
Code:
public class DriveDoNothing extends CommandBase {

    public DriveDoNothing() {
        requires(DriveSystem);
    }


    protected void execute() {
        DriveSystem.doNothing();

    }
}
Subsystem Code:
Code:
public class DriveSystem extends Subsystem {

    public void doNothing() {

         leftMotor.set(0.0);

        rightMotor.set(0.0);

    }
}
What you need to do is declare a static instance of your subsystem in your CommandBase class.

Code:
public class CommandBase {

     public static DriveSystem driveSystem = new DriveSystem();
...
}
Then you use this static instance of the dirve system in your command.

Code:
public class DriveDoNothing extends CommandBase {

    public DriveDoNothing() {
        requires(driveSystem);
    }


    protected void execute() {
        driveSystem.doNothing();

    }
}
If you'd like more details of why this works the way it does I'd be happy to expand my explanation for you.
Reply With Quote