Instantiate hall effect sensor inside runFlyWheel() method
authorshainachen <shaina.sierra@gmail.com>
Wed, 25 Jan 2017 05:16:08 +0000 (21:16 -0800)
committershainachen <shaina.sierra@gmail.com>
Fri, 3 Feb 2017 03:05:19 +0000 (19:05 -0800)
src/org/usfirst/frc/team3501/robot/commands/shooter/RunFlyWheel.java
src/org/usfirst/frc/team3501/robot/subsystems/HallEffectBuffer.java

index 203f9dce79a4eb3088eb1155e9e67dfa1fbac036..3900b57122ed5bbf0f1e604b6a33fe015f572e06 100644 (file)
@@ -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
index 47f6a4486ca6a41701bbe94e11ec75111704ad3b..88161568f6a990a7fe32cab210f1b247f22310ca 100644 (file)
@@ -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;
   }
 }