Servo motors not working

My team’s current robot requires the use of linear actuators. Looking at the documentation, the java doc has a separate class specifically servos. However, we found that when we set it to Servos, nothing would happen, thus we tried setting them as usual talons, and they functioned correctly, with -1.0 being fully retracted and 1.0 being fully extended.

The problem that I’m currently having is that the servos themselves won’t start whenever I press the button that it is assigned too.
Here is the OI.java class, with the commands in question being

c5.whenPressed(new pushGearOut());

and

c7.whenPressed(new pushGearIn()); 
package org.usfirst.frc.team3205.robot;

import org.usfirst.frc.team3205.robot.commands.cameraOneInit;
import org.usfirst.frc.team3205.robot.commands.cameraTwoInit;
import org.usfirst.frc.team3205.robot.commands.climber;
import org.usfirst.frc.team3205.robot.commands.climberReset;
import org.usfirst.frc.team3205.robot.commands.driveBaseSwitchDirections;
import org.usfirst.frc.team3205.robot.commands.dumpFlapClose;
import org.usfirst.frc.team3205.robot.commands.dumpFlapOpen;
import org.usfirst.frc.team3205.robot.commands.hopperUnCoil;
import org.usfirst.frc.team3205.robot.commands.intakeFlapClose;
import org.usfirst.frc.team3205.robot.commands.intakeFlapOpen;
import org.usfirst.frc.team3205.robot.commands.hopperCoil;
import org.usfirst.frc.team3205.robot.commands.pushGearIn;
import org.usfirst.frc.team3205.robot.commands.pushGearOut;
import org.usfirst.frc.team3205.robot.commands.visionSwitchCameras;

import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.buttons.Button;
import edu.wpi.first.wpilibj.buttons.JoystickButton;

//import org.usfirst.frc.team3205.robot.commands.ExampleCommand;

/**
 * This class is the glue that binds the controls on the physical operator
 * interface to the commands and command groups that allow control of the robot.
 */
public class OI {
	//// CREATING BUTTONS
	// One type of button is a joystick button which is any button on a
	//// joystick.
	// You create one by telling it which joystick it's on and which button
	// number it is.
	// Joystick stick = new Joystick(port);
	// Button button = new JoystickButton(stick, buttonNumber);

	// There are a few additional built in buttons you can use. Additionally,
	// by subclassing Button you can create custom triggers and bind those to
	// commands the same as any other Button.

	//// TRIGGERING COMMANDS WITH BUTTONS
	// Once you have a button, it's trivial to bind it to a button in one of
	// three ways:

	// Start the command when the button is pressed and let it run the command
	// until it is finished as determined by it's isFinished method.
	// button.whenPressed(new ExampleCommand());

	// Run the command while the button is being held down and interrupt it once
	// the button is released.
	// button.whileHeld(new ExampleCommand());

	// Start the command when the button is released and let it run the command
	// until it is finished as determined by it's isFinished method.
	// button.whenReleased(new ExampleCommand());

	public static Joystick right = new Joystick(0);
		Button r1 = new JoystickButton(right, 1);
		Button r2 = new JoystickButton(right, 2);
		Button r3 = new JoystickButton(right, 3);
		Button r4 = new JoystickButton(right, 4);
		Button r5 = new JoystickButton(right, 5);
		Button r6 = new JoystickButton(right, 6);
		Button r7 = new JoystickButton(right, 7);
		Button r8 = new JoystickButton(right, 8);
		Button r9 = new JoystickButton(right, 9);
		Button r10 = new JoystickButton(right, 10);
		Button r11 = new JoystickButton(right, 11);

	public static Joystick left = new Joystick(1);
		Button l1 = new JoystickButton(left, 1);
		Button l2 = new JoystickButton(left, 2);
		Button l3 = new JoystickButton(left, 3);
		Button l4 = new JoystickButton(left, 4);
		Button l5 = new JoystickButton(left, 5);
		Button l6 = new JoystickButton(left, 6);
		Button l7 = new JoystickButton(left, 7);
		Button l8 = new JoystickButton(left, 8);
		Button l9 = new JoystickButton(left, 9);
		Button l10 = new JoystickButton(left, 10);
		Button l11 = new JoystickButton(left, 11);
	public static Joystick controller = new Joystick(2);
		Button c1 = new JoystickButton(controller, 1);
		Button c2 = new JoystickButton(controller, 2);
		Button c3 = new JoystickButton(controller, 3);
		Button c4 = new JoystickButton(controller, 4);
		Button c5 = new JoystickButton(controller, 5);
		Button c6 = new JoystickButton(controller, 6);
		Button c7 = new JoystickButton(controller, 7);
		Button c8 = new JoystickButton(controller, 8);
		Button c9 = new JoystickButton(controller, 9);
		Button c10 = new JoystickButton(controller, 10);
		Button c11 = new JoystickButton(controller, 11);
		Button c12 = new JoystickButton(controller, 12);

	public static Joystick xbox = new Joystick(2);
		Button x1 = new JoystickButton(xbox, 1);
		Button x2 = new JoystickButton(xbox, 2);
		Button x3 = new JoystickButton(xbox, 3);
		Button x4 = new JoystickButton(xbox, 4);
		Button x5 = new JoystickButton(xbox, 5);
		Button x6 = new JoystickButton(xbox, 6);
		Button x7 = new JoystickButton(xbox, 7);
		Button x8 = new JoystickButton(xbox, 8);
		Button x9 = new JoystickButton(xbox, 9);
		Button x10 = new JoystickButton(xbox, 10);
		
	public OI(){
		//c6.whileHeld(new dumpFlapOpen());
		//c8.whileHeld(new dumpFlapClose()); 
		c9.whileHeld(new intakeFlapOpen());
		c10.whileHeld(new intakeFlapClose()); 
		
		c5.whenPressed(new pushGearOut());
		c7.whenPressed(new pushGearIn()); 
		
//		c5.whenActive(new pushGearOut());
//		c7.whenActive(new pushGearIn()); 
//		c5.toggleWhenPressed(new pushGearOut());
//	c7.toggleWhenPressed(new pushGearIn()); 
//
//		c5.whileHeld(new pushGearOut());
//		c7.whileHeld(new pushGearIn()); 
		c4.whileHeld(new hopperCoil());
		c3.whileHeld(new hopperUnCoil());
		c1.whileHeld(new climber());
		c2.whileHeld(new climberReset());
		c11.toggleWhenPressed(new cameraOneInit());
		c12.toggleWhenPressed(new cameraTwoInit());

		r1.toggleWhenPressed(new driveBaseSwitchDirections());
		l1.toggleWhenPressed(new visionSwitchCameras());
		//r1.whenPressed(new visionSwitchCameras());
//		l1.whenPressed(new visionSwitchCameras());
		//r1.whenActive(new visionSwitchCameras());
	}
}

Here is the gear subsystem:

package org.usfirst.frc.team3205.robot.subsystems;

import org.usfirst.frc.team3205.robot.RobotMap;
import org.usfirst.frc.team3205.robot.commands.pushGearOut;

import edu.wpi.first.wpilibj.DigitalInput;
import edu.wpi.first.wpilibj.Servo;
import edu.wpi.first.wpilibj.Talon;
import edu.wpi.first.wpilibj.command.Subsystem;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;

/**
 *
 */
public class Gear extends Subsystem {

	// Put methods for controlling this subsystem
	// here. Call these from Commands.
	private DigitalInput gearIn;
	private Talon gearOut;
	//private Servo gearOut;

	public Gear(){
		gearIn = new DigitalInput(RobotMap.IS_GEAR_IN); 
		//gearOut = new Servo(RobotMap.PUSH_EM_OUT); 
		gearOut = new Talon(RobotMap.PUSH_EM_OUT); 


	}
	// when the limit switch is pressed pull down the limit switch 
	public void initDefaultCommand() {
		// Set the default command for a subsystem here.
		//setDefaultCommand(new MySpecialCommand());
		setDefaultCommand(new pushGearOut()); 
	}

	public boolean isGearIn(){
		return gearIn.get(); 
	}

	public void pushOut(){ // this actually pulls in the gear 
		gearOut.set(0.8); 
		//gearOut.setAngle(45);
	}

	public void retract(){ // this actually puts out the gear 
		gearOut.set(-1.0);
		//gearOut.setAngle(10);
	}
//	public double getAngle(){
//		//return gearOut.getAngle(); 
//	}
	public void updateSmartDashboard(){
		SmartDashboard.putBoolean("Is Gear in", isGearIn());
	}
}


And here are the pushGearOut() and pushGearIn() commands:

package org.usfirst.frc.team3205.robot.commands;

import org.usfirst.frc.team3205.robot.Robot;

import edu.wpi.first.wpilibj.command.Command;

/**
 *
 */
public class pushGearOut extends Command {

    public pushGearOut() {
        // Use requires() here to declare subsystem dependencies
        // eg. requires(chassis);
    	requires(Robot.gear); 
    }

    // Called just before this Command runs the first time
    protected void initialize() {
    	System.out.println(";alksdfja;lskjfl;aksdfj");
    	Robot.gear.pushOut(); 
    }

    // Called repeatedly when this Command is scheduled to run
    protected void execute() {
    	//Robot.gear.pushOut(); 

    }

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

    // Called once after isFinished returns true
    protected void end() {
    	Robot.gear.pushOut(); 

    }

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

package org.usfirst.frc.team3205.robot.commands;

import org.usfirst.frc.team3205.robot.Robot;

import edu.wpi.first.wpilibj.command.Command;

/**
 *
 */
public class pushGearIn extends Command {

    public pushGearIn() {
        // Use requires() here to declare subsystem dependencies
        // eg. requires(chassis);
    	requires(Robot.gear); 
    }

    // Called just before this Command runs the first time
    protected void initialize() {
    	System.out.println("why isnt this working");
    //	System.out.println(OI.c5.get());
    	Robot.gear.retract();

    }

    // Called repeatedly when this Command is scheduled to run
    protected void execute() {
    	//Robot.gear.retract();

    }

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

    // Called once after isFinished returns true
    protected void end() {
    	Robot.gear.retract();

    }

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

I know the servo works as it can run when a limit switch is triggered which I set to, however whenever I try executing the command through buttons nothing appears to happen.

Any help is appreciated.

I am wondering if creating two Joystick instances with the same port number is causing problems (both controllers and xbox are using port 2)?

Can you temporarily try moving your xbox controller to port 3 to see if it makes a difference?


	public static Joystick controller = new Joystick(2);
		Button c1 = new JoystickButton(controller, 1);
		Button c2 = new JoystickButton(controller, 2);
		Button c3 = new JoystickButton(controller, 3);
		Button c4 = new JoystickButton(controller, 4);
		Button c5 = new JoystickButton(controller, 5);
		Button c6 = new JoystickButton(controller, 6);
		Button c7 = new JoystickButton(controller, 7);
		Button c8 = new JoystickButton(controller, 8);
		Button c9 = new JoystickButton(controller, 9);
		Button c10 = new JoystickButton(controller, 10);
		Button c11 = new JoystickButton(controller, 11);
		Button c12 = new JoystickButton(controller, 12);

	public static Joystick xbox = new Joystick(3);
		Button x1 = new JoystickButton(xbox, 1);
		Button x2 = new JoystickButton(xbox, 2);
		Button x3 = new JoystickButton(xbox, 3);
		Button x4 = new JoystickButton(xbox, 4);
		Button x5 = new JoystickButton(xbox, 5);
		Button x6 = new JoystickButton(xbox, 6);
		Button x7 = new JoystickButton(xbox, 7);
		Button x8 = new JoystickButton(xbox, 8);
		Button x9 = new JoystickButton(xbox, 9);
		Button x10 = new JoystickButton(xbox, 10);

Temporarily, for debugging purposes, you can also add the following to your OI() constructor:


       SmartDashboard.putData("Push Gear In", new pushGearIn());
       SmartDashboard.putData("Push Gear Out", new pushGearOut());

That should let you test both commands from the driver station without having to press limit switches on the robot.

Like the guy above me said: There is a very big possibility that the problem is that you initialized 2 joysticks with the same port, it probably does not know what joystick to use. Try changing the port.
Plus, check if the controllers are in the right ports on the DriverStation (Go to USB devices and check if the numbers left to the joysticks match their corresponding port.).

I don’t believe it is the port numbers as when we switched the PWM ports of the servo with another motor that we’re using the motor ran fine using the same controls. I’ll try your suggestion though.