View Single Post
  #4   Spotlight this post!  
Unread 25-01-2014, 07:13
Domenic Rodriguez's Avatar
Domenic Rodriguez Domenic Rodriguez is offline
Registered User
FRC #0316 (LuNaTeCs)
Team Role: College Student
 
Join Date: Sep 2010
Rookie Year: 2011
Location: Grove City, PA
Posts: 213
Domenic Rodriguez has a spectacular aura aboutDomenic Rodriguez has a spectacular aura aboutDomenic Rodriguez has a spectacular aura about
Re: Motor Programming

Quote:
Originally Posted by LFRobotics View Post
My Subsystem name is the same as the name in commandbase.
I would recommend against using the same capitalization for the class name and the instance variable; it creates ambiguity as to which you are referring to. Common practice is to use headless camel case for variable names:
Code:
ForkMotor forkMotor = new ForkMotor();
Quote:
Originally Posted by LFRobotics View Post
I did not end the command because I will use the button.whileHeld(new command) and should it shut the motor/command down when I release the button so I don't have to tell it to stop...
Correct me if I'm wrong (it's been a while since I've worked with the command-based robot template), but just because your command is canceled doesn't mean the motor will shut off by itself. You need to explicitly tell it to stop moving with "motor.set(0)", otherwise it will just keep moving at the previous value it received (in your case either 1.0 or -1.0). This is why I recommend adding a ForkMotor#stop() method that get's called when your commands exit:

Code:
public class ForkMotor extends Subsystem {
    ....
    // Existing subsystem code
    ...

    public void stop() {
        motor.set(0.0);
    }
}
Code:
public class LiftForks extends CommandBase {
    public LiftForks() {
        // Use requires() here to declare subsystem dependencies
        // eg. requires(chassis);
        requires(ForkMotor);
    }

    // Called just before this Command runs the first time
    protected void initialize() {
    }

    // Called repeatedly when this Command is scheduled to run
    protected void execute() {
        ForkMotor.up();
    }

    // Make this return true when this Command no longer needs to run execute()
    protected boolean isFinished() {
        return false;
    }

    // Called once after isFinished returns true
    protected void end() {
        ForkMotor.stop();
    }

    // Called when another command which requires one or more of the same
    // subsystems is scheduled to run
    protected void interrupted() {
        end();
    }
}
__________________

LuNaTeCs - Learning Under Nurturing Adults Teaching Engineering Concepts and Skills - Small and Mighty!

FRC 316 LuNaTeCs - Student (2011-2014), Lead Programmer (2011-2014), Team Captain (2013-2014), Operator (2013), Drive Coach (2014), Mentor (2015-????)
'11 Philly Regional Finalists, '13 Chestnut Hill Finalists, '13 Lenape Champions, '13 Archimedes Division, '14 Chestnut Hill Champions, '14 Lenape Champions
FTC 7071 EngiNerds - Founding Advisor (2013-2014) | FRC 5420 Velocity - Founding Advisor (2015)
Grove City College Class of '18, Electrical/Computer Engineering (B.S.E.E)

Reply With Quote