Go to Post Life has its Ups and Downs, you can stay down or push yourself. - Mike Schroeder [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Spotlight this post!  
Unread 02-02-2014, 10:42
LFRobotics's Avatar
LFRobotics LFRobotics is offline
Registered User
FRC #4623
 
Join Date: Jan 2014
Location: Little Falls, MN
Posts: 95
LFRobotics is on a distinguished road
whileHeld() Motor Program Issue

Okay - I am programming a command based java and wrote a couple of commands defined by a subsystem called ForkMotor. One command was supposed to move a motor forward(1) while a button was pressed. The other was supposed to move a motor backwards(-1) while a button is pressed. When I hold the button down that is supposed to move it forward the motor glitches off and on but does stop when I let go - the motor is fine I tested it. The button that SHOULD turn it in the other direction doesn't work at all. If anyone knows how to fix this that would be AWESOME.

Here it is:

Subsystem(called ForkMotor):


Quote:
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);
}

public void stop(){
motor.set(0);
}
}
First Command(to move it forward -- called LiftForks):

Quote:
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() {
}
}

Second Command(to move it in reverse -- called LowerForks):


Quote:
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() {
}
}
Port Assignment(called ForkMotorPort):

Quote:
public static final int
leftMotorPort = 1,
rightMotorPort = 2,
ArmMotorPort = 3,
ForkMotorPort = 4;
CommandBase(called ForkMotor):

Quote:
public abstract class CommandBase extends Command {

public static OI oi;
// Create a single static instance of all of your subsystems
public static ForkMotor forkmotor = new ForkMotor();
public static ArmMotor armmotor = new ArmMotor();
public static Chassis chassis = new Chassis();
public static LaunchServo launchservo = new LaunchServo();
Button Assignments(LiftForks - moves it forward(1) -- LowerForks - moves it in reverse(-1):


Quote:
public Joystick
rightStick,
leftStick;

private final Button ForksDown, ForksUp, prepball, prepball2, motor1, motor2; //add Auto



public OI() {

rightStick = new Joystick(RobotMap.rightJoystickPort);
leftStick = new Joystick(RobotMap.leftJoystickPort);
ForksDown = new JoystickButton(rightStick, 5);
ForksUp = new JoystickButton(rightStick, 4);
prepball = new JoystickButton(leftStick, 4);
prepball2 = new JoystickButton(leftStick, 5);
motor1 = new JoystickButton(rightStick, 2);
motor2 = new JoystickButton(rightStick, 3);

//Auto = new JoystickButton(leftStick, 4);

ForksUp.whileHeld(new LiftForks());
ForksDown.whileHeld(new LowerForks());
prepball.whenPressed(new PrepBall());
prepball2.whenPressed(new PrepBall2());
motor1.whenPressed(new ArmLauncher());
motor2.whenPressed(new ReleaseTension());
//Auto.whenPressed(new AutoCommandGroup());
}

public Joystick getRightStick() {
return rightStick;
}

public Joystick getLeftStick() {
return leftStick;
}

}
ANY help WILL be appreciated - THANKS!

Last edited by LFRobotics : 02-02-2014 at 17:03.
Reply With Quote
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 09:31.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi