From: Kevin Zhang Date: Thu, 31 Dec 2015 03:54:55 +0000 (-0800) Subject: Add code base X-Git-Url: http://challenge-bot.com/repos/?p=3501%2Fstronghold-2016;a=commitdiff_plain;h=38a404b33adc222b57179884470913cb4c0a011d Add code base --- diff --git a/src/org/usfirst/frc/team3501/robot/Constants.java b/src/org/usfirst/frc/team3501/robot/Constants.java new file mode 100644 index 00000000..021183a8 --- /dev/null +++ b/src/org/usfirst/frc/team3501/robot/Constants.java @@ -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 index 00000000..a57b5ce7 --- /dev/null +++ b/src/org/usfirst/frc/team3501/robot/MathLib.java @@ -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 index 00000000..997be71c --- /dev/null +++ b/src/org/usfirst/frc/team3501/robot/OI.java @@ -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 index 00000000..36ca70bc --- /dev/null +++ b/src/org/usfirst/frc/team3501/robot/Robot.java @@ -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 index 00000000..54b0ce01 --- /dev/null +++ b/src/org/usfirst/frc/team3501/robot/subsystems/DriveTrain.java @@ -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() { + } + +}