From: shainachen Date: Wed, 25 Jan 2017 05:16:08 +0000 (-0800) Subject: Instantiate hall effect sensor inside runFlyWheel() method X-Git-Url: http://challenge-bot.com/repos/?a=commitdiff_plain;h=6d1b404a1c4a5ee358435163c2abc32a326c4736;p=3501%2F2017steamworks Instantiate hall effect sensor inside runFlyWheel() method --- diff --git a/src/org/usfirst/frc/team3501/robot/commands/shooter/RunFlyWheel.java b/src/org/usfirst/frc/team3501/robot/commands/shooter/RunFlyWheel.java index 203f9dc..3900b57 100644 --- a/src/org/usfirst/frc/team3501/robot/commands/shooter/RunFlyWheel.java +++ b/src/org/usfirst/frc/team3501/robot/commands/shooter/RunFlyWheel.java @@ -1,7 +1,9 @@ package org.usfirst.frc.team3501.robot.commands.shooter; import org.usfirst.frc.team3501.robot.Robot; +import org.usfirst.frc.team3501.robot.subsystems.HallEffectSensor; +import edu.wpi.first.wpilibj.Counter; import edu.wpi.first.wpilibj.Timer; import edu.wpi.first.wpilibj.command.Command; @@ -13,8 +15,12 @@ import edu.wpi.first.wpilibj.command.Command; */ public class RunFlyWheel extends Command { Timer timer; + HallEffectSensor hallSource; + Counter hall; private double motorVal; private double time; + private int bufferLength = 15; + private int hallChannel = 0; // hallChannel=DIO channeL /** * See JavaDoc comment in class for details @@ -30,6 +36,11 @@ public class RunFlyWheel extends Command { timer = new Timer(); this.motorVal = motorVal; this.time = time; + + hall = new Counter(hallChannel); + hall.setMaxPeriod(1); + + hallSource = new HallEffectSensor(hall, bufferLength); } // Called just before this Command runs the first time @@ -42,6 +53,8 @@ public class RunFlyWheel extends Command { // Called repeatedly when this Command is scheduled to run @Override protected void execute() { + double rotVel = hallSource.getRPS(); + } // Called once after isFinished returns true diff --git a/src/org/usfirst/frc/team3501/robot/subsystems/HallEffectBuffer.java b/src/org/usfirst/frc/team3501/robot/subsystems/HallEffectBuffer.java index 47f6a44..8816156 100644 --- a/src/org/usfirst/frc/team3501/robot/subsystems/HallEffectBuffer.java +++ b/src/org/usfirst/frc/team3501/robot/subsystems/HallEffectBuffer.java @@ -17,11 +17,16 @@ public class HallEffectBuffer { } } + /** + * Gets average buffer value from array of existing buffer vals + * + * @return average buffered speed + */ public double getAverage() { double total = 0; - for (int i = 0; i < bufferVals.length; i++) { + for (int i = 0; i < index; i++) { total += bufferVals[i]; } - return total / bufferVals.length; + return total / index + 1; } }