com.ctre.phoenix.motorcontrol.ControlMode Java Examples

The following examples show how to use com.ctre.phoenix.motorcontrol.ControlMode. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Elevator.java    From FRC-2019-Public with MIT License 6 votes vote down vote up
@Override
public synchronized void writePeriodicOutputs() {
    if (mHoming) {
        if (atHomingLocation()) {
            zeroSensors();
            mMaster.overrideSoftLimitsEnable(true);
            System.out.println("Homed!!!");
            LED.getInstance().clearElevatorFault();
            mHoming = false;
        }

        if (mControlState == ControlState.OPEN_LOOP) {
            mMaster.set(ControlMode.PercentOutput, mPeriodicIO.demand, DemandType.ArbitraryFeedForward,
                    0.0);
        } else {
            mMaster.set(ControlMode.PercentOutput, 0.0, DemandType.ArbitraryFeedForward,
                    0.0);
        }
    } else {
        super.writePeriodicOutputs();
    }

}
 
Example #2
Source File: SubsystemMast.java    From PowerUp-2018 with GNU General Public License v3.0 6 votes vote down vote up
public Boolean dropIt(double speed) {
	if (lowerPinionLimit.get()) {
 	leftPinion.set(ControlMode.PercentOutput, leftPinionate(speed));
 	rightPinion.set(ControlMode.PercentOutput, rightPinionate(speed));
	} else {
		leftPinion.set(ControlMode.PercentOutput, 0);
 	rightPinion.set(ControlMode.PercentOutput, 0);
	}
	
	if (lowerScrewLimit.get()) {
		screw.set(ControlMode.PercentOutput, screwify(speed));
	} else {
		screw.set(ControlMode.PercentOutput, 0);
	}
	
	return (!lowerPinionLimit.get()) && (!lowerScrewLimit.get());
}
 
Example #3
Source File: SubsystemMast.java    From PowerUp-2018 with GNU General Public License v3.0 6 votes vote down vote up
/** raise the mast at RT-LR trigger speed */
  public void moveBySpeed(Joystick joy, double inhibitor) {
  	double dualAction = Xbox.RT(joy) - Xbox.LT(joy);
  	double screwSpeed = Xbox.LEFT_Y(joy) + dualAction;
  	double pinionSpeed = Xbox.RIGHT_Y(joy) + dualAction;
  	
if (!lowerPinionLimit.get() && pinionSpeed > 0)   { pinionSpeed = 0; }
if (!upperPinionLimit.get() && pinionSpeed < 0)   { pinionSpeed = 0; }
if (!lowerScrewLimit.get()  && screwSpeed  > 0)   { screwSpeed = 0;  }
if (!upperScrewLimit.get()  && screwSpeed  < 0)   { screwSpeed = 0;  }
	
  	publishSwitches();
  	if (!override) {
  		leftPinion.set(ControlMode.PercentOutput, leftPinionate(pinionSpeed));
      	rightPinion.set(ControlMode.PercentOutput, rightPinionate(pinionSpeed));
      	screw.set(ControlMode.PercentOutput, inhibitor * screwify(screwSpeed));
  	}
  }
 
Example #4
Source File: SubsystemManipulator.java    From PowerUp-2018 with GNU General Public License v3.0 6 votes vote down vote up
/** imitates an engine revving and idling */
public void rev(Joystick joy) {
	double intensity = Math.abs(Math.sqrt((Math.pow(Xbox.LEFT_X(joy), 2) + Math.pow(Xbox.LEFT_X(joy), 2)))); // intensity is 0.0-1.0, power of trigger
	
	int rpm = (int) ((((double) Constants.REDLINE - (double) Constants.IDLE) * intensity) + Constants.IDLE); // rpm is the rpm being imitated
	int miliseconds = (1 / rpm) * 60000; // length in miliseconds of each rev curve, based on rpm
	
	if (!revving) { redlineTime = System.currentTimeMillis(); revving = true; } // reset rev curve if not revving
		else if (System.currentTimeMillis() - redlineTime >= miliseconds) { revving = false; } // stop revving if time is up
	
	double speed = (System.currentTimeMillis() - redlineTime) / (double) miliseconds; // set speed to progress from 0.0-1.0 of the curve
	speed = speed > 1.0 ? 1.0 : speed; // quick concat the speed under 1.0
	
	speed = generateCurve(speed, 0, .25 * (intensity * .8 + .2), (intensity * .8 + .2)); // find y value on curve, given x and parameters
	
	armLeft.set(ControlMode.PercentOutput, leftArmify(speed));
	armRight.set(ControlMode.PercentOutput, rightArmify(speed));
}
 
Example #5
Source File: Intake.java    From FRC-2018-Public with MIT License 6 votes vote down vote up
private Intake() {
    mCloseSolenoid = Constants.makeSolenoidForId(Constants.kIntakeCloseSolenoid);
    mClampSolenoid = Constants.makeSolenoidForId(Constants.kIntakeClampSolenoid);

    mLeftMaster = TalonSRXFactory.createDefaultTalon(Constants.kIntakeLeftMasterId);
    mLeftMaster.set(ControlMode.PercentOutput, 0);
    mLeftMaster.setInverted(true);
    mLeftMaster.configVoltageCompSaturation(12.0, Constants.kLongCANTimeoutMs);
    mLeftMaster.enableVoltageCompensation(true);

    mRightMaster = TalonSRXFactory.createDefaultTalon(Constants.kIntakeRightMasterId);
    mRightMaster.set(ControlMode.PercentOutput, 0);
    mRightMaster.setInverted(false);
    mRightMaster.configVoltageCompSaturation(12.0, Constants.kLongCANTimeoutMs);
    mRightMaster.enableVoltageCompensation(true);
}
 
Example #6
Source File: SubsystemDrive.java    From PowerUp-2018 with GNU General Public License v3.0 6 votes vote down vote up
public boolean driveDistance(double leftIn, double rightIn) {
    double leftGoal = (leftIn2Mag(leftIn));
    double rightGoal = (rightIn2Mag(rightIn));
    leftMaster.set(ControlMode.Position, leftify(leftGoal));
		leftSlave.follow(leftMaster);
    rightMaster.set(ControlMode.Position, rightify(rightGoal));
		rightSlave.follow(rightMaster);

    boolean leftInRange =
            pid.getLeftInches() > leftify(leftGoal) - DISTANCE_ALLOWABLE_ERROR &&
                    pid.getLeftInches() < leftify(leftGoal) + DISTANCE_ALLOWABLE_ERROR;
    boolean rightInRange =
            pid.getRightInches() > rightify(rightGoal) - DISTANCE_ALLOWABLE_ERROR &&
                    pid.getRightInches() < rightify(rightGoal) + DISTANCE_ALLOWABLE_ERROR;
    return leftInRange && rightInRange;
}
 
Example #7
Source File: SubsystemDrive.java    From PowerUp-2018 with GNU General Public License v3.0 6 votes vote down vote up
/**
     * simple rocket league drive code (not actually rocket league)
     * independent rotation and acceleration
     */
    public void driveRLTank(Joystick joy, double ramp, double inhibitor) {
        double adder = Xbox.RT(joy) - Xbox.LT(joy);
        double left = adder + (Xbox.LEFT_X(joy) / 1.333333);
        double right = adder - (Xbox.LEFT_X(joy) / 1.333333);
        left = (left > 1.0 ? 1.0 : (left < -1.0 ? -1.0 : left));
        right = (right > 1.0 ? 1.0 : (right < -1.0 ? -1.0 : right));
        setRamps(ramp);

//        if (getYAngle() > Constants.TILT_ANGLE ) {
//            leftMaster.set(ControlMode.PercentOutput, -1*Constants.RECOVERY_SPEED);
//            rightMaster.set(ControlMode.PercentOutput, -1*Constants.RECOVERY_SPEED);
//        } else if (getYAngle() < -1*Constants.TILT_ANGLE){
//            leftMaster.set(ControlMode.PercentOutput, Constants.RECOVERY_SPEED);
//            rightMaster.set(ControlMode.PercentOutput, Constants.RECOVERY_SPEED);
//        } else {
            leftMaster.set(ControlMode.PercentOutput, leftify(left));
            rightMaster.set(ControlMode.PercentOutput, rightify(right));
//        }
    }
 
Example #8
Source File: SubsystemDrive.java    From PowerUp-2018 with GNU General Public License v3.0 5 votes vote down vote up
/**
     * drive code where rotation is dependent on acceleration
     * @param radius 0.00-1.00, 1 being zero radius and 0 being driving in a line
     */
    public void driveForza(Joystick joy, double ramp, double radius, double inhibitor) {
        double left = 0,
                right = 0;
        double acceleration = Xbox.RT(joy) - Xbox.LT(joy);

        setRamps(ramp);
//        if (getYAngle() > Constants.TILT_ANGLE ) {
//            leftMaster.set(ControlMode.PercentOutput, -1 * Constants.RECOVERY_SPEED);
//            rightMaster.set(ControlMode.PercentOutput, -1 * Constants.RECOVERY_SPEED);
//        } else if (getYAngle() < -1 * Constants.TILT_ANGLE){
//            leftMaster.set(ControlMode.PercentOutput, Constants.RECOVERY_SPEED);
//            rightMaster.set(ControlMode.PercentOutput, Constants.RECOVERY_SPEED);
//        } else {

            if (!reversing ? Xbox.LEFT_X(joy) < 0 : Xbox.LEFT_X(joy) > 0) {
                right = acceleration;
                left = (acceleration * ((2 * (1 - Math.abs(Xbox.LEFT_X(joy)))) - 1)) / radius;
            } else if (!reversing ? Xbox.LEFT_X(joy) > 0 : Xbox.LEFT_X(joy) < 0) {
                left = acceleration;
                right = (acceleration * ((2 * (1 - Math.abs(Xbox.LEFT_X(joy)))) - 1)) / radius;
            } else {
                left = acceleration;
                right = acceleration;
            }
//        }][\
        left = (left > 1.0 ? 1.0 : (left < -1.0 ? -1.0 : left));
        right = (right > 1.0 ? 1.0 : (right < -1.0 ? -1.0 : right));
        leftMaster.set(ControlMode.PercentOutput, leftify(left) * inhibitor * (reversing ? -1.0 : 1.0));
        rightMaster.set(ControlMode.PercentOutput, rightify(right) * inhibitor * (reversing ? -1.0 : 1.0));

        SmartDashboard.putString("Left Master", "Left Master Voltage: " + leftMaster.getBusVoltage());
        SmartDashboard.putString("Right Master", "Right Master Voltage: " + rightMaster.getBusVoltage());
    }
 
Example #9
Source File: SubsystemMast.java    From PowerUp-2018 with GNU General Public License v3.0 5 votes vote down vote up
public void adjustScrew(Position direction){
   	if (direction == Position.UP){
   		while (!upperScrewLimit.get()){
   			screw.set(ControlMode.PercentOutput, screwify(1));
		}
	} else if (direction == Position.DOWN){
   		while (!lowerScrewLimit.get()){
   			screw.set(ControlMode.PercentOutput, screwify(-1));
		}
	}
}
 
Example #10
Source File: SubsystemMast.java    From PowerUp-2018 with GNU General Public License v3.0 5 votes vote down vote up
public void adjustPinion(Position direction){

    	if (direction == Position.UP) {
			while (!upperPinionLimit.get()) {
				rightPinion.set(ControlMode.PercentOutput, rightPinionate(1));
				leftPinion.set(ControlMode.PercentOutput, leftPinionate(1));
			}
		} else if (direction == Position.DOWN) {
			while (!lowerPinionLimit.get()) {
				rightPinion.set(ControlMode.PercentOutput, rightPinionate(-1));
				leftPinion.set(ControlMode.PercentOutput, leftPinionate(-1));
			}
		}
	}
 
Example #11
Source File: SubsystemManipulator.java    From PowerUp-2018 with GNU General Public License v3.0 5 votes vote down vote up
public void spinByJoystick(Joystick joy) {
	int speed = 0;
	speed += joy.getRawButton(Xbox.RB) ? 1d : 0d;
	speed -= joy.getRawButton(Xbox.LB) ? 1d : 0d;
	armLeft.set(ControlMode.PercentOutput, leftArmify(speed));
	armRight.set(ControlMode.PercentOutput, rightArmify(speed));
}
 
Example #12
Source File: LazyTalonSRX.java    From FRC-2018-Public with MIT License 5 votes vote down vote up
@Override
public void set(ControlMode mode, double value) {
    if (value != mLastSet || mode != mLastControlMode) {
        mLastSet = value;
        mLastControlMode = mode;
        super.set(mode, value);
    }
}
 
Example #13
Source File: Intake.java    From FRC-2018-Public with MIT License 5 votes vote down vote up
private synchronized void updateActuatorFromState(IntakeState state) {
    mLeftMaster.set(ControlMode.PercentOutput, state.leftMotor);
    mRightMaster.set(ControlMode.PercentOutput, state.rightMotor);
    setJaw(state.jawState);

    mLED.setIntakeLEDState(state.ledState);
}
 
Example #14
Source File: Turret.java    From FRC-2019-Public with MIT License 5 votes vote down vote up
@Override
public synchronized void writePeriodicOutputs() {
    if (mHoming) {
        if (atHomingLocation()) {
            if (mPeriodicIO.demand > 0) {
                mMaster.setSelectedSensorPosition((int) unitsToTicks(-2.0));
            } else {
                mMaster.setSelectedSensorPosition((int) unitsToTicks(0.26));
            }
            mMaster.overrideSoftLimitsEnable(true);
            System.out.println("Homed!!!");
            LED.getInstance().clearTurretFault();
            mHoming = false;
        }

        if (mControlState == ControlState.OPEN_LOOP) {
            mMaster.set(ControlMode.PercentOutput, mPeriodicIO.demand, DemandType.ArbitraryFeedForward,
                    0.0);
        } else {
            mMaster.set(ControlMode.PercentOutput, 0.0, DemandType.ArbitraryFeedForward,
                    0.0);
        }
    } else {
        super.writePeriodicOutputs();
    }

}
 
Example #15
Source File: Vacuum.java    From FRC-2019-Public with MIT License 5 votes vote down vote up
@Override
public synchronized void stop() {
    mOn = false;

    // Make sure the vacuum is off
    mMaster.set(ControlMode.PercentOutput, 0.0);
}
 
Example #16
Source File: Vacuum.java    From FRC-2019-Public with MIT License 5 votes vote down vote up
@Override
public synchronized void writePeriodicOutputs() {
    double output = 0.0;
    if (mOn) {
        if (mPeriodicIO.thresholdState == ThresholdState.BELOW || mPeriodicIO.thresholdState == ThresholdState.BETWEEN) {
            output = kFullSetpoint;
        } else { // ABOVE
            output = kSteadySetpoint;
        }
    }
    mMaster.set(ControlMode.PercentOutput, output);
}
 
Example #17
Source File: LazyTalonSRX.java    From FRC-2019-Public with MIT License 5 votes vote down vote up
@Override
public void set(ControlMode mode, double value) {
    if (value != mLastSet || mode != mLastControlMode) {
        mLastSet = value;
        mLastControlMode = mode;
        super.set(mode, value);
    }
}
 
Example #18
Source File: TalonSRXChecker.java    From FRC-2019-Public with MIT License 4 votes vote down vote up
@Override
protected void setMotorOutput(TalonSRX motor, double output) {
    motor.set(ControlMode.PercentOutput, output);
}
 
Example #19
Source File: SubsystemDrive.java    From PowerUp-2018 with GNU General Public License v3.0 4 votes vote down vote up
public void driveDirect(double left, double right) {
    left = (left > 1.0 ? 1.0 : (left < -1.0 ? -1.0 : left));
    right = (right > 1.0 ? 1.0 : (right < -1.0 ? -1.0 : right));
    leftMaster.set(ControlMode.PercentOutput, leftify(left));
    rightMaster.set(ControlMode.PercentOutput, rightify(right));
}
 
Example #20
Source File: SubsystemManipulator.java    From PowerUp-2018 with GNU General Public License v3.0 4 votes vote down vote up
/** eat the power cube */
public void eat() {
	armLeft.set(ControlMode.PercentOutput, leftArmify(-1));
	armRight.set(ControlMode.PercentOutput, rightArmify(-1));
}
 
Example #21
Source File: SubsystemManipulator.java    From PowerUp-2018 with GNU General Public License v3.0 4 votes vote down vote up
/** spit out the power cube */
public void spit() {
	armLeft.set(ControlMode.PercentOutput, leftArmify(1));
	armRight.set(ControlMode.PercentOutput, rightArmify(1));
}
 
Example #22
Source File: SubsystemManipulator.java    From PowerUp-2018 with GNU General Public License v3.0 4 votes vote down vote up
/** STOP SPINNING ME RIGHT ROUND, BABY RIGHT ROUND */
public void stopSpinning() {
	armLeft.set(ControlMode.PercentOutput, 0);
	armRight.set(ControlMode.PercentOutput, 0);
}
 
Example #23
Source File: StingerRoller.java    From FRC-2019-Public with MIT License 4 votes vote down vote up
public synchronized void setOpenLoop(double output) {
    mMaster.set(ControlMode.PercentOutput, output);
}