|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||
|
||||
|
Motor Programming
Okay - I want to have a motor that - when button 4 is pressed on the joystick the motor moves in one direction until he button is released - when button 5 is pressed the motor moves in the other direction until the button is released.
Here is the code I wrote: Subsystem for the "ForkMotor": Quote:
Command to move motor in one direction. Quote:
Quote:
THANKS for the help! |
|
#2
|
||||
|
||||
|
Re: Motor Programming
In the constructor for each of your commands, you should pass the instance variable from CommandBase instead of the Subsystem class name:
Code:
public LiftForks() {
// Use requires() here to declare subsystem dependencies
// eg. requires(chassis);
requires(forkMotor); // or whatever you named the instance variable
}
Code:
public LiftForks() {
// Use requires() here to declare subsystem dependencies
// eg. requires(chassis);
requries(ForkMotor);
}
Last edited by Domenic Rodriguez : 24-01-2014 at 22:45. Reason: Grammar |
|
#3
|
||||
|
||||
|
Re: Motor Programming
My Subsystem name is the same as the name in commandbase.
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. Right now I am not having any issues with it - I haven't been able to test it though because I am having DS issues. THANKS! |
|
#4
|
||||
|
||||
|
Re: Motor Programming
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:
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();
}
}
|
|
#5
|
||||
|
||||
|
Re: Motor Programming
Okay - yeah your right - THANKS a ton!
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|