Add code base
authorKevin Zhang <icestormf1@gmail.com>
Thu, 31 Dec 2015 03:54:55 +0000 (19:54 -0800)
committerKevin Zhang <icestormf1@gmail.com>
Thu, 31 Dec 2015 03:54:55 +0000 (19:54 -0800)
src/org/usfirst/frc/team3501/robot/Constants.java [new file with mode: 0644]
src/org/usfirst/frc/team3501/robot/MathLib.java [new file with mode: 0644]
src/org/usfirst/frc/team3501/robot/OI.java [new file with mode: 0644]
src/org/usfirst/frc/team3501/robot/Robot.java [new file with mode: 0644]
src/org/usfirst/frc/team3501/robot/subsystems/DriveTrain.java [new file with mode: 0644]

diff --git a/src/org/usfirst/frc/team3501/robot/Constants.java b/src/org/usfirst/frc/team3501/robot/Constants.java
new file mode 100644 (file)
index 0000000..021183a
--- /dev/null
@@ -0,0 +1,25 @@
+package org.usfirst.frc.team3501.robot;
+
+/**
+ * The Constants stores constant values for all subsystems. This includes the
+ * port values for motors and sensors, as well as important operational
+ * constants for subsystems such as max and min values.
+ */
+
+public class Constants {
+  public static class OI {
+    public final static int LEFT_STICK_PORT = 0;
+    public final static int RIGHT_STICK_PORT = 0;
+  }
+
+  public static class DriveTrain {
+    public static final int FRONT_LEFT = 0;
+    public static final int FRONT_RIGHT = 0;
+    public static final int REAR_LEFT = 0;
+    public static final int REAR_RIGHT = 0;
+  }
+
+  public static enum Direction {
+    LEFT, RIGHT, DOWN, UP, FORWARD, BACKWARD;
+  }
+}
diff --git a/src/org/usfirst/frc/team3501/robot/MathLib.java b/src/org/usfirst/frc/team3501/robot/MathLib.java
new file mode 100644 (file)
index 0000000..a57b5ce
--- /dev/null
@@ -0,0 +1,80 @@
+package org.usfirst.frc.team3501.robot;
+
+public class MathLib {
+
+  /***
+   * This method gives speed as a function of % distance covered so the speed
+   * forms a parabola starting and ending at minSpeed when you start and end and
+   * achieving maxSpeed exactly halfway.
+   *
+   * @param minSpeed
+   *          the starting and ending speed, in range [0, 1]
+   * @param maxSpeed
+   *          the max speed, achieved at percentComplete = 1/2.
+   * @param percentComplete
+   *          should be currentDistance / targetDistance
+   * @return the speed (motor value) to set motors to for smooth acceleration.
+   *         Note that since velocity is a parabola, acceleration is linear. It
+   *         may exceed the maximum value robot can accelerate without wheel
+   *         slipping.
+   */
+  public static double getSpeedForLinearAccel(double minSpeed, double maxSpeed,
+      double percentComplete) {
+    return 4 * (minSpeed - maxSpeed) * (percentComplete - 0.5)
+        * (percentComplete - 0.5) + maxSpeed;
+  }
+
+  /***
+   * This method gives speed as a function of % distance covered so the speed
+   * increases linearly from minSpeed to maxSpeed and then back down again.
+   *
+   * @param minSpeed
+   *          the starting and ending speed, in range [0, 1]
+   * @param maxSpeed
+   *          the max speed, achieved at percentComplete = 1/2.
+   * @param percentComplete
+   *          should be currentDistance / targetDistance
+   * @return the speed (motor value) to set motors to.
+   */
+  public static double getSpeedForConstantAccel(double minSpeed,
+      double maxSpeed, double percentComplete) {
+    return maxSpeed + 2 * (minSpeed - maxSpeed)
+        * Math.abs(percentComplete - 0.5);
+  }
+
+  /***
+   * Restricts an input value to the range [low, high]. If value > high it will
+   * be set to high. If value < low it will be set to low.
+   *
+   * This method is used for defensive programming for inputs to motors to
+   * restrict them to valid ranges.
+   *
+   * @param value
+   *          the value to restrict.
+   * @param low
+   *          the smallest acceptable value.
+   * @param high
+   *          the largest acceptable value.
+   * @return returns value restricted to be within the range [low, high].
+   */
+  public static double restrictToRange(double value, double low, double high) {
+    value = Math.max(value, low);
+    value = Math.min(value, high);
+    return value;
+  }
+
+  /***
+   * Returns true if val is in the range [low, high]
+   * 
+   * @param val
+   *          value to test
+   * @param low
+   *          low end of range
+   * @param high
+   *          high end of range
+   * @return boolean return true if val is in the range [low, high]
+   */
+  public static boolean inRange(double val, double low, double high) {
+    return (val <= high) && (val >= low);
+  }
+}
diff --git a/src/org/usfirst/frc/team3501/robot/OI.java b/src/org/usfirst/frc/team3501/robot/OI.java
new file mode 100644 (file)
index 0000000..997be71
--- /dev/null
@@ -0,0 +1,14 @@
+package org.usfirst.frc.team3501.robot;
+
+import edu.wpi.first.wpilibj.Joystick;
+
+public class OI {
+  public static Joystick leftJoystick;
+  public static Joystick rightJoystick;
+
+  public OI() {
+    leftJoystick = new Joystick(Constants.OI.LEFT_STICK_PORT);
+    rightJoystick = new Joystick(Constants.OI.RIGHT_STICK_PORT);
+
+  }
+}
diff --git a/src/org/usfirst/frc/team3501/robot/Robot.java b/src/org/usfirst/frc/team3501/robot/Robot.java
new file mode 100644 (file)
index 0000000..36ca70b
--- /dev/null
@@ -0,0 +1,36 @@
+package org.usfirst.frc.team3501.robot;
+
+import org.usfirst.frc.team3501.robot.Constants.DriveTrain;
+import edu.wpi.first.wpilibj.IterativeRobot;
+import edu.wpi.first.wpilibj.command.Scheduler;
+
+public class Robot extends IterativeRobot {
+  public static OI oi;
+  public static DriveTrain driveTrain;
+
+  @Override
+  public void robotInit() {
+    driveTrain = new DriveTrain();
+    oi = new OI();
+  }
+
+  @Override
+  public void autonomousInit() {
+  }
+
+  @Override
+  public void autonomousPeriodic() {
+    Scheduler.getInstance().run();
+
+  }
+
+  @Override
+  public void teleopInit() {
+  }
+
+  @Override
+  public void teleopPeriodic() {
+    Scheduler.getInstance().run();
+
+  }
+}
diff --git a/src/org/usfirst/frc/team3501/robot/subsystems/DriveTrain.java b/src/org/usfirst/frc/team3501/robot/subsystems/DriveTrain.java
new file mode 100644 (file)
index 0000000..54b0ce0
--- /dev/null
@@ -0,0 +1,21 @@
+package org.usfirst.frc.team3501.robot.subsystems;
+
+import org.usfirst.frc.team3501.robot.Constants;
+import edu.wpi.first.wpilibj.CANTalon;
+import edu.wpi.first.wpilibj.command.Subsystem;
+
+public class DriveTrain extends Subsystem {
+  private CANTalon frontLeft, frontRight, rearLeft, rearRight;
+
+  public DriveTrain() {
+    frontLeft = new CANTalon(Constants.DriveTrain.FRONT_LEFT);
+    frontRight = new CANTalon(Constants.DriveTrain.FRONT_RIGHT);
+    rearLeft = new CANTalon(Constants.DriveTrain.REAR_LEFT);
+    rearRight = new CANTalon(Constants.DriveTrain.REAR_RIGHT);
+  }
+
+  @Override
+  protected void initDefaultCommand() {
+  }
+
+}