LFRobotics
24-01-2014, 22:11
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":
package edu.wpi.first.LFRobot2014.subsystems;
import edu.wpi.first.LFRobot2014.RobotMap;
import edu.wpi.first.wpilibj.Jaguar;
import edu.wpi.first.wpilibj.SpeedController;
import edu.wpi.first.wpilibj.command.Subsystem;
/**
*
* @author FrankyMonezz
*/
public class ForkMotor extends Subsystem {
// Put methods for controlling this subsystem
// here. Call these from Commands.
SpeedController motor = new Jaguar(RobotMap.ForkMotorPort);
public void initDefaultCommand() {
// Set the default command for a subsystem here.
//setDefaultCommand(new MySpecialCommand());
}
public void up() {
motor.set(1);
}
public void down() {
motor.set(-1);
}
}
Command to move motor in one direction.
package edu.wpi.first.LFRobot2014.commands;
/**
*
* @author FrankyMonezz
*/
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() {
}
// Called when another command which requires one or more of the same
// subsystems is scheduled to run
protected void interrupted() {
}
}
Command to move the motor in the other direction:
package edu.wpi.first.LFRobot2014.commands;
/**
*
* @author FrankyMonezz
*/
public class LowerForks extends CommandBase {
public LowerForks() {
// 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.down();
}
// 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() {
}
// Called when another command which requires one or more of the same
// subsystems is scheduled to run
protected void interrupted() {
}
}
All ports are already set correctly in RobotMap and buttons are correctly assigned using whileHeld() in OI - noting this will the above code work?
THANKS for the help!
Here is the code I wrote:
Subsystem for the "ForkMotor":
package edu.wpi.first.LFRobot2014.subsystems;
import edu.wpi.first.LFRobot2014.RobotMap;
import edu.wpi.first.wpilibj.Jaguar;
import edu.wpi.first.wpilibj.SpeedController;
import edu.wpi.first.wpilibj.command.Subsystem;
/**
*
* @author FrankyMonezz
*/
public class ForkMotor extends Subsystem {
// Put methods for controlling this subsystem
// here. Call these from Commands.
SpeedController motor = new Jaguar(RobotMap.ForkMotorPort);
public void initDefaultCommand() {
// Set the default command for a subsystem here.
//setDefaultCommand(new MySpecialCommand());
}
public void up() {
motor.set(1);
}
public void down() {
motor.set(-1);
}
}
Command to move motor in one direction.
package edu.wpi.first.LFRobot2014.commands;
/**
*
* @author FrankyMonezz
*/
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() {
}
// Called when another command which requires one or more of the same
// subsystems is scheduled to run
protected void interrupted() {
}
}
Command to move the motor in the other direction:
package edu.wpi.first.LFRobot2014.commands;
/**
*
* @author FrankyMonezz
*/
public class LowerForks extends CommandBase {
public LowerForks() {
// 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.down();
}
// 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() {
}
// Called when another command which requires one or more of the same
// subsystems is scheduled to run
protected void interrupted() {
}
}
All ports are already set correctly in RobotMap and buttons are correctly assigned using whileHeld() in OI - noting this will the above code work?
THANKS for the help!