Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subsystem Checking #27

Merged
merged 12 commits into from
Sep 28, 2018
2 changes: 1 addition & 1 deletion .project
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>frc_3452_2018_java_master</name>
<name>frc_3452_2018_JAVA</name>
<comment>Project f created by Buildship.</comment>
<projects>
</projects>
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/frc/robot/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
*/

public class Constants {
public class kLoop {
public static final double LOOP_SPEED = .02;
public static final double ENCODER_CHECKER_SPEED = .1;
}

public class kAuton {
public static final int COMMAND_ARRAY_SIZE = 41;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package frc.robot.util;
package frc.robot;

import java.util.ArrayList;

import edu.wpi.first.wpilibj.RobotController;
import frc.robot.Constants;
import frc.robot.Robot;
import frc.robot.util.Util;

public class GZLog {

Expand All @@ -24,6 +23,15 @@ public void update() {
}
};

LogItem left_encoder_valid = new LogItem("L-ENC-PRSNT")
{
@Override
public void update()
{
this.mValue = Robot.drive.mIO.leftEncoderValid.toString();
}
};

LogItem right_speed = new LogItem("R-RPM")
{
@Override
Expand All @@ -33,6 +41,15 @@ public void update()
}
};

LogItem right_encoder_valid = new LogItem("R-ENC-PRSNT")
{
@Override
public void update()
{
this.mValue = Robot.drive.mIO.rightEncoderValid.toString();
}
};

LogItem l1_amp = new LogItem("L1-AMP")
{
@Override
Expand Down Expand Up @@ -217,6 +234,15 @@ public void update()
}
};

LogItem elev_encoder_present = new LogItem("ELEV-ENC-PRSNT")
{
@Override
public void update()
{
this.mValue = Robot.elevator.mIO.encoderValid.toString();
}
};

LogItem elev_rotations = new LogItem("ELEV-ROT"){
@Override
public void update()
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,18 @@ public class Robot extends TimedRobot {
@Override
public void robotInit() {
allSubsystems.construct();

files.fillLogger();
auton.fillAutonArray();
health.generateHealth();

// TODO ISSUE #14
// allSubsystems.startLooping();

health.generateHealth();
}

@Override
public void robotPeriodic() {
allSubsystems.loop();

}

@Override
Expand Down
86 changes: 40 additions & 46 deletions src/main/java/frc/robot/subsystems/Climber.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package frc.robot.subsystems;

import edu.wpi.first.wpilibj.Spark;
import frc.robot.Constants.kClimber;
import frc.robot.Constants.kPDP;
import frc.robot.Robot;
import frc.robot.util.GZSubsystem;

import edu.wpi.first.wpilibj.Spark;

public class Climber extends GZSubsystem {

private Spark climber_1;
Expand All @@ -20,12 +19,11 @@ public class Climber extends GZSubsystem {
// Construction
public Climber() {
}

public synchronized void construct()
{

public synchronized void construct() {
climber_1 = new Spark(kClimber.CLIMBER_1);
climber_1.setInverted(kClimber.CLIMBER_1_INVERT);

climber_1.setSubsystem(Climber.class.getName());
climber_1.setName("climber_1");
}
Expand Down Expand Up @@ -57,21 +55,6 @@ public synchronized void loop() {
handleStates();
in();
out();

switch (mState) {

case MANUAL:
mIO.climber_output = mIO.climber_desired_output;
break;

case NEUTRAL:
mIO.climber_output = 0;
break;

default:
System.out.println("WARNING: Incorrect climber state " + mState + " reached.");
break;
}
}

public static class IO {
Expand All @@ -84,13 +67,12 @@ public static class IO {
public Double climber_desired_output = 0.0;
}

public void runClimber(double percentage)
{
public void runClimber(double percentage) {
if (climbCounter > 3)
manual(percentage);
else
stop();

}

private void manual(double percentage) {
Expand All @@ -106,11 +88,26 @@ protected synchronized void in() {

@Override
protected synchronized void out() {

switch (mState) {

case MANUAL:
mIO.climber_output = mIO.climber_desired_output;
break;

case NEUTRAL:
mIO.climber_output = 0;
break;

default:
System.out.println("WARNING: Incorrect climber state " + mState + " reached.");
break;
}
climber_1.set(Math.abs(mIO.climber_output));
}

public enum ClimberState {
NEUTRAL, MANUAL,
NEUTRAL, MANUAL;
}

@Override
Expand All @@ -121,33 +118,30 @@ public synchronized void stop() {
public synchronized void setWantedState(ClimberState wantedState) {
this.mWantedState = wantedState;
}

public synchronized void checkHealth()
{

}

private synchronized void handleStates() {

//if trying to disable or run demo mode while not connected to field
if (((this.isDisabed() || Robot.auton.isDemo()) && !Robot.gzOI.isFMS())
|| mWantedState == ClimberState.NEUTRAL) {

if (stateNot(ClimberState.NEUTRAL)) {
onStateExit(mState);
mState = ClimberState.NEUTRAL;
onStateStart(mState);
}

} else if (mState != mWantedState) {
private void switchToState(ClimberState s) {
if (mState != s) {
onStateExit(mState);
mState = mWantedState;
mState = s;
onStateStart(mState);
}
}

private synchronized boolean stateNot(ClimberState state) {
return mState != state;
private synchronized void handleStates() {
boolean neutral = false;
neutral |= (this.isDisabed() || Robot.auton.isDemo()) && !Robot.gzOI.isFMS();
neutral |= mWantedState == ClimberState.NEUTRAL;

// if trying to disable or run demo mode while not connected to field
if (neutral) {

switchToState(ClimberState.NEUTRAL);

} else {

switchToState(mWantedState);

}
}

public String getStateString() {
Expand Down
Loading