Go to Post Sorry, during my fluid mechanics lectures on drag I must have been designing a gearbox in my mind. FRC season will do that. - sanddrag [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 30-01-2014, 17:40
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
Issue with Servo and Motor Program

I am a beginner, first year programmer and I wrote a couple programs in CommandBase java and they have a few errors. I do have the robot driving.

One of them was supposed to have two commands defined by a subsystem - one command would move a servo 45 degrees away from its default location and the second one would move the servo back to its default location. When I press the buttons assigned to complete these tasks nothing happens.

Here it is:


Subsystem(called LaunchServo):

Quote:
package edu.wpi.first.LFRobot2014.subsystems;

import edu.wpi.first.LFRobot2014.RobotMap;
import edu.wpi.first.wpilibj.Servo;
import edu.wpi.first.wpilibj.command.Subsystem;

/**
*
* @author FrankyMonezz
*/
public class LaunchServo extends Subsystem {
// Put methods for controlling this subsystem
// here. Call these from Commands.

Servo servo = new Servo(RobotMap.LaunchServoPort);

public void initDefaultCommand() {
// Set the default command for a subsystem here.
//setDefaultCommand(new MySpecialCommand());
}

public void setPos(double pos){
servo.set(pos);
}

public double getPos(){
double pos = servo.get();
return pos;
}}
Command to Move it to 45(called PrepBall):

Quote:
package edu.wpi.first.LFRobot2014.commands;

/**
*
* @author FrankyMonezz
*/
public class PrepBall extends CommandBase {

public PrepBall() {
// Use requires() here to declare subsystem dependencies
// eg. requires(chassis);
requires(launchservo);
}

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

// Called repeatedly when this Command is scheduled to run
protected void execute() {
//move servo to 45 degrees
launchservo.setPos(45);
}

// Make this return true when this Command no longer needs to run execute()
protected boolean isFinished() {
if(launchservo.getPos() == 45){

return true;
}
else {
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 back to Default(called PrepBall2):

Quote:
package edu.wpi.first.LFRobot2014.commands;

/**
*
* @author FrankyMonezz
*/
public class PrepBall2 extends CommandBase {

public PrepBall2() {
// Use requires() here to declare subsystem dependencies
// eg. requires(chassis);
requires(launchservo);
}

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

// Called repeatedly when this Command is scheduled to run
protected void execute() {
//move servo back to default location
launchservo.setPos(0);
}

// Make this return true when this Command no longer needs to run execute()
protected boolean isFinished() {
if(launchservo.getPos() == 0){
return true;
}
else {
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:

Quote:
public static final int
LaunchServoPort = 5;
CommandBase(subsystem is called LaunchServo):

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(PrepBall - moves it to 45 -- PrepBall2 - moves it to default):


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;
}

}
The other one had two 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

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);
setTimeout(.5);
}

// 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 isTimedOut();
}

// 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();
}
}


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);
setTimeout(.5);
}

// 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 isTimedOut();
}

// 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();
}
}



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!
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 12:45.

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