public final static int TOGGLE_FLYWHEEL_PORT = 0;
public final static int TOGGLE_INDEXWHEEL_PORT = 0;
+
+ public final static int HALL_EFFECT_PORT = 4;
}
public static class DriveTrain {
import org.usfirst.frc.team3501.robot.subsystems.DriveTrain;
import org.usfirst.frc.team3501.robot.subsystems.Intake;
import org.usfirst.frc.team3501.robot.subsystems.Shooter;
+import org.usfirst.frc.team3501.robot.utils.HallEffectSensor;
import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.command.Scheduler;
private static Shooter shooter;
private static OI oi;
private static Intake intake;
+ private HallEffectSensor hallEffect;
@Override
public void robotInit() {
shooter = Shooter.getShooter();
intake = Intake.getIntake();
+ hallEffect = Shooter.getHallEffectSensor();
}
public static DriveTrain getDriveTrain() {
@Override
public void teleopPeriodic() {
Scheduler.getInstance().run();
-
+ System.out.println("Hall Effect Period: " + hallEffect.getCounterPeriod());
}
}
// Called repeatedly when this Command is scheduled to run
protected void execute() {
double shooterSpeed = this.wheelController
- .calcPID(this.shooter.getShooterSpeed());
+ .calcPID(this.shooter.getShooterRPM());
this.shooter.setFlyWheelMotorVal(shooterSpeed);
}
// Called repeatedly when this Command is scheduled to run
protected void execute() {
double shooterSpeed = this.wheelController
- .calcPID(this.shooter.getShooterSpeed());
+ .calcPID(this.shooter.getShooterRPM());
this.shooter.setFlyWheelMotorVal(shooterSpeed);
}
package org.usfirst.frc.team3501.robot.subsystems;
import org.usfirst.frc.team3501.robot.Constants;
+import org.usfirst.frc.team3501.robot.utils.HallEffectSensor;
import com.ctre.CANTalon;
public class Shooter extends Subsystem {
public double wheelP = 0, wheelI = 0, wheelD = -0;
private static Shooter shooter;
+ private static HallEffectSensor hallEffect;
private final CANTalon flyWheel, indexWheel;
public static final double DEFAULT_INDEXING_SPEED = 0;
flyWheel = new CANTalon(Constants.Shooter.FLY_WHEEL);
indexWheel = new CANTalon(Constants.Shooter.INDEX_WHEEL);
+ hallEffect = new HallEffectSensor(Constants.Shooter.HALL_EFFECT_PORT, 1);
+ }
+
+ public static HallEffectSensor getHallEffectSensor() {
+ return hallEffect;
}
/**
}
- public double getShooterSpeed() {
- return 0.0;
+ public double getShooterRPM() {
+ return hallEffect.getRPM();
}
}
--- /dev/null
+package org.usfirst.frc.team3501.robot.utils;
+
+import edu.wpi.first.wpilibj.Counter;
+
+public class HallEffectSensor {
+ private Counter counter;
+
+ public HallEffectSensor(int port, int bufferLength) {
+ counter = new Counter(port);
+ counter.setSamplesToAverage(bufferLength);
+ }
+
+ /**
+ * Returns rotations per second(buffered) of hall effect sensor counter
+ *
+ * @return rotations per second of hall effect counter
+ */
+ public double getRPS() {
+ return 1.0 / counter.getPeriod();
+ }
+
+ /**
+ * Get the period of the most recent count.
+ *
+ * @return period of latest count in seconds
+ */
+ public double getCounterPeriod() {
+ return counter.getPeriod();
+ }
+
+ /**
+ * Returns rotations per minute(buffered) of hall effect sensor counter
+ *
+ * @return rotations per minute of hall effect sensor
+ */
+ public double getRPM() {
+ return this.getRPS() * 60;
+ }
+
+}