Skip to content

Commit

Permalink
Merge pull request #10 from Coconuts2486-FRC/Rebase
Browse files Browse the repository at this point in the history
Turret fully working including encoder override
  • Loading branch information
Diamond42474 authored Feb 29, 2020
2 parents 7ce2d58 + e408d24 commit eb6a91f
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 42 deletions.
Binary file modified FRC2020/.gradle/6.0.1/executionHistory/executionHistory.bin
Binary file not shown.
Binary file modified FRC2020/.gradle/6.0.1/executionHistory/executionHistory.lock
Binary file not shown.
Binary file modified FRC2020/.gradle/6.0.1/fileHashes/fileHashes.bin
Binary file not shown.
Binary file modified FRC2020/.gradle/6.0.1/fileHashes/fileHashes.lock
Binary file not shown.
Binary file modified FRC2020/.gradle/6.0.1/javaCompile/classAnalysis.bin
Binary file not shown.
Binary file modified FRC2020/.gradle/6.0.1/javaCompile/javaCompile.lock
Binary file not shown.
Binary file modified FRC2020/.gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
5 changes: 3 additions & 2 deletions FRC2020/src/main/java/frc/robot/Color_Wheel/Arm.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public class Arm{
public static boolean colorPistonActive = false;

public static void lift() {
/*
if (Map.Controllers.xbox.getRawButtonPressed(20)) {
if (!colorPistonActive) {
Map.ColorWheel.SensorLift.set(true);
Expand All @@ -18,9 +19,9 @@ public static void lift() {
}

}

*/

}

Expand Down
1 change: 1 addition & 0 deletions FRC2020/src/main/java/frc/robot/Map.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public static class controllers {
public static int manuelEncoderZeroer = 7;
public static int manuelSetAngle = 11; // Sets an angle for manuel mode
public static int manuelGoToAngle = 12; // Turns turret to preset angle
public static int manuelEncoderDisable = 9;
}
}

Expand Down
22 changes: 2 additions & 20 deletions FRC2020/src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

import com.ctre.phoenix.motorcontrol.NeutralMode;
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import frc.robot.Autonomous.AutoMissions;
import frc.robot.Cartridge.Conveyor;
import frc.robot.Cartridge.pistonlift;
import frc.robot.Cartridge.pixyDisplay;
import frc.robot.TeleOp.DriveTrain;
import frc.robot.Turret.TurretControl;
import frc.robot.Turret.TurretDisplay;
import frc.robot.Turret.TurretMotion;
Expand All @@ -23,13 +21,8 @@ public void robotInit() {
}

public void robotPeriodic() {
SmartDashboard.putString("Auto Mode", AutoMissions.CurrentAuto);
SmartDashboard.getNumber("Auto Selection", AutoMissions.SelectedAuto);
TurretDisplay.display();

if (Map.Controllers.xbox.getRawButtonPressed(Map.Turret.controllers.manuelEncoderZeroer)) {
Map.Turret.motors.rotation.setSelectedSensorPosition(0);
}
TurretControl.periodicRun();
}

@Override
Expand All @@ -44,7 +37,6 @@ public void autonomousInit() {
if (AutoMissions.SelectedAuto == 2) {
AutoMissions.GeneratorAuto();
}
Map.Turret.motors.rotation.setNeutralMode(NeutralMode.Brake);
}

@Override
Expand All @@ -53,7 +45,6 @@ public void autonomousPeriodic() {

@Override
public void teleopInit() {
Map.Turret.motors.rotation.setNeutralMode(NeutralMode.Brake);
}

@Override
Expand All @@ -63,17 +54,8 @@ public void teleopPeriodic() {
pixyDisplay.display();
// pixyControl.run(); // Runs pixy homing automation
//DriveTrain.drive();
//pistonlift.run();
pistonlift.run();
Conveyor.run();
if(Map.Controllers.xbox.getRawButtonPressed(8)){
if(!colorwheel){
colorwheel = true;
Map.Cartridge.ColorWheel.SensorLift.set(true);
}else{
colorwheel = false;
Map.Cartridge.ColorWheel.SensorLift.set(false);
}
}
}

@Override
Expand Down
50 changes: 44 additions & 6 deletions FRC2020/src/main/java/frc/robot/Turret/TurretControl.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class TurretControl {
private static double manuelLargeAdjusterDivision = 2; // how much the large adjuster is divided by
public static boolean firing = false;
public static boolean autoIsTracking = true;
public static boolean encoderDisabled = false;

public static void run() {
if (Map.Controllers.xbox.getRawButtonPressed(Map.Turret.controllers.manuelMode)) {
Expand Down Expand Up @@ -55,14 +56,34 @@ public static void run() {
} else {
// Manuel Mode
// Turning
if(Map.Controllers.xbox.getRawButtonPressed(Map.Turret.controllers.manuelEncoderDisable)){
if(encoderDisabled){
encoderDisabled = false;
}else{
encoderDisabled = true;
}
}
double large = Math.abs(Map.Controllers.xbox.getRawAxis(Map.Turret.controllers.manuelRotateLarge));
double small = Math.abs(Map.Controllers.xbox.getRawAxis(Map.Turret.controllers.manuelRotateSmall));
if (large > small) {
TurretMotion.Rotation.turn(Map.Controllers.xbox.getRawAxis(Map.Turret.controllers.manuelRotateLarge)
/ manuelLargeAdjusterDivision);
} else {
TurretMotion.Rotation.turn(Map.Controllers.xbox.getRawAxis(Map.Turret.controllers.manuelRotateSmall)
/ manuelSmallAdjusterDivision);
if(encoderDisabled){
if (large > small) {
TurretMotion.Rotation.overrideTurn(Map.Controllers.xbox.getRawAxis(Map.Turret.controllers.manuelRotateLarge)
/ manuelLargeAdjusterDivision);
} else {
TurretMotion.Rotation.overrideTurn(Map.Controllers.xbox.getRawAxis(Map.Turret.controllers.manuelRotateSmall)
/ manuelSmallAdjusterDivision);
}
if (Map.Controllers.xbox.getRawButtonPressed(Map.Turret.controllers.manuelEncoderZeroer)) {
Map.Turret.motors.rotation.setSelectedSensorPosition(0);
}
}else{
if (large > small) {
TurretMotion.Rotation.turn(Map.Controllers.xbox.getRawAxis(Map.Turret.controllers.manuelRotateLarge)
/ manuelLargeAdjusterDivision);
} else {
TurretMotion.Rotation.turn(Map.Controllers.xbox.getRawAxis(Map.Turret.controllers.manuelRotateSmall)
/ manuelSmallAdjusterDivision);
}
}
// LED config
if (Map.Controllers.xbox.getRawButtonPressed(1)) {
Expand Down Expand Up @@ -116,4 +137,21 @@ public static void run() {
}
}
}
public static void periodicRun(){

if (Map.Controllers.xbox.getRawButtonPressed(Map.Turret.controllers.manuelEncoderZeroer)) {
Map.Turret.motors.rotation.setSelectedSensorPosition(0);
}
/*
double large = Math.abs(Map.Controllers.xbox.getRawAxis(Map.Turret.controllers.manuelRotateLarge));
double small = Math.abs(Map.Controllers.xbox.getRawAxis(Map.Turret.controllers.manuelRotateSmall));
if (large > small) {
TurretMotion.Rotation.overrideTurn(Map.Controllers.xbox.getRawAxis(Map.Turret.controllers.manuelRotateLarge)
/ manuelLargeAdjusterDivision);
} else {
TurretMotion.Rotation.overrideTurn(Map.Controllers.xbox.getRawAxis(Map.Turret.controllers.manuelRotateSmall)
/ manuelSmallAdjusterDivision);
}
*/
}
}
18 changes: 4 additions & 14 deletions FRC2020/src/main/java/frc/robot/Turret/TurretMotion.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import com.ctre.phoenix.motorcontrol.ControlMode;
import com.ctre.phoenix.motorcontrol.FeedbackDevice;
import com.ctre.phoenix.motorcontrol.NeutralMode;

import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import frc.robot.Map;

/**
Expand All @@ -16,7 +14,7 @@ public static void init() {
Map.Turret.motors.follower.follow(Map.Turret.motors.launcher);
Map.Turret.motors.rotation.configSelectedFeedbackSensor(FeedbackDevice.CTRE_MagEncoder_Relative, 0, 10);
Map.Turret.motors.launcher.configSelectedFeedbackSensor(FeedbackDevice.CTRE_MagEncoder_Relative, 0, 10);
Map.Turret.motors.rotation.setNeutralMode(NeutralMode.Coast);
Map.Turret.motors.rotation.setNeutralMode(NeutralMode.Brake);
Map.Turret.motors.launcher.setNeutralMode(NeutralMode.Coast);
Map.Turret.motors.rotation.setInverted(true);
Map.Turret.motors.follower.setInverted(true);
Expand Down Expand Up @@ -65,7 +63,6 @@ public void run(){
while(goTo&&abserror>errorRange){
abserror = Math.abs(pos-getDegrees());
error = pos-getDegrees();
SmartDashboard.putNumber("Error: ", error);
if(abserror>slopePoint){
if(error>0){
turn(topSpeed);
Expand All @@ -75,11 +72,6 @@ public void run(){
}else{
turn((error/slopePoint)*topSpeed);
}
/*
abserror = Math.abs(pos-getDegrees());
error = pos-getDegrees();
turn(error/maxDeg);
*/
}
turn(0);
goTo = false;
Expand All @@ -89,10 +81,6 @@ public void run(){
//Map.Turret.motors.rotation.set(ControlMode.Position, degreesToTicks(pos));
}

private static int degreesToTicks(double degrees) {
return (int) ((degrees / 360) * ticksInrevolution);
}

public static double getPosition() {
// Gets current position in motor ticks
return -Map.Turret.motors.rotation.getSelectedSensorPosition();
Expand All @@ -102,7 +90,9 @@ public static double getDegrees() {
// Gets current position in Degrees
return (getPosition() / ticksInrevolution) * 360;
}

public static void overrideTurn(double pwr){
Map.Turret.motors.rotation.set(ControlMode.PercentOutput, pwr);
}
public static void turn(double pwr) {
// Turns turret using pwr as input (-1 to 1)
// Map.Turret.motors.rotation.set(ControlMode.PercentOutput, pwr);
Expand Down

0 comments on commit eb6a91f

Please sign in to comment.