diff --git a/Java/CommandBased/.classpath b/Java/CommandBased/.classpath new file mode 100644 index 0000000..ac37fb2 --- /dev/null +++ b/Java/CommandBased/.classpath @@ -0,0 +1,5 @@ + + + + + diff --git a/Java/CommandBased/.project b/Java/CommandBased/.project new file mode 100644 index 0000000..5fad685 --- /dev/null +++ b/Java/CommandBased/.project @@ -0,0 +1,17 @@ + + + CommandBased + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/Java/jankCenterSwitch/.classpath b/Java/jankCenterSwitch/.classpath new file mode 100644 index 0000000..9d41f0e --- /dev/null +++ b/Java/jankCenterSwitch/.classpath @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/Java/jankCenterSwitch/.project b/Java/jankCenterSwitch/.project new file mode 100644 index 0000000..ff471d0 --- /dev/null +++ b/Java/jankCenterSwitch/.project @@ -0,0 +1,18 @@ + + + jankCenterSwitch + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + edu.wpi.first.wpilib.plugins.core.nature.FRCProjectNature + + diff --git a/Java/jankCenterSwitch/bin/.gitignore b/Java/jankCenterSwitch/bin/.gitignore new file mode 100644 index 0000000..cf1db2e --- /dev/null +++ b/Java/jankCenterSwitch/bin/.gitignore @@ -0,0 +1 @@ +/org/ diff --git a/Java/jankCenterSwitch/build.properties b/Java/jankCenterSwitch/build.properties new file mode 100644 index 0000000..03cea2b --- /dev/null +++ b/Java/jankCenterSwitch/build.properties @@ -0,0 +1,4 @@ +# Project specific information +package=org.usfirst.frc.team1665.robot +robot.class=${package}.Robot +simulation.world.file=/usr/share/frcsim/worlds/GearsBotDemo.world \ No newline at end of file diff --git a/Java/jankCenterSwitch/build.xml b/Java/jankCenterSwitch/build.xml new file mode 100644 index 0000000..76fd29a --- /dev/null +++ b/Java/jankCenterSwitch/build.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Java/jankCenterSwitch/src/org/usfirst/frc/team1665/robot/Drivetrain.java b/Java/jankCenterSwitch/src/org/usfirst/frc/team1665/robot/Drivetrain.java new file mode 100644 index 0000000..7ff186d --- /dev/null +++ b/Java/jankCenterSwitch/src/org/usfirst/frc/team1665/robot/Drivetrain.java @@ -0,0 +1,33 @@ +package org.usfirst.frc.team1665.robot; + +import edu.wpi.first.wpilibj.SpeedControllerGroup; +import edu.wpi.first.wpilibj.VictorSP; +import edu.wpi.first.wpilibj.drive.DifferentialDrive; + +public class Drivetrain{ + + // Initializing left drivetrain controllers + public static VictorSP driveControllerLeft1 = new VictorSP(1); + public static VictorSP driveControllerLeft2 = new VictorSP(2); + public static SpeedControllerGroup driveControllersLeft = new SpeedControllerGroup(driveControllerLeft1, + driveControllerLeft2); + + // Initializing right drivetrain controllers + public static VictorSP driveControllerRight1 = new VictorSP(2); + public static VictorSP driveControllerRight2 = new VictorSP(3); + public static SpeedControllerGroup driveControllersRight = new SpeedControllerGroup(driveControllerRight1, + driveControllerRight2); + + // Initializing drivetrain + public static DifferentialDrive drivetrain = new DifferentialDrive(driveControllersLeft, driveControllersRight); + + + public Drivetrain() { + } + + //Split stick arcade drive + public void drive(double Throttle, double Turn) { + drivetrain.arcadeDrive(Throttle,Turn); + } + +} diff --git a/Java/jankCenterSwitch/src/org/usfirst/frc/team1665/robot/Robot.java b/Java/jankCenterSwitch/src/org/usfirst/frc/team1665/robot/Robot.java new file mode 100644 index 0000000..0e1e6e2 --- /dev/null +++ b/Java/jankCenterSwitch/src/org/usfirst/frc/team1665/robot/Robot.java @@ -0,0 +1,133 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + +package org.usfirst.frc.team1665.robot; + +import edu.wpi.first.wpilibj.Timer; +import edu.wpi.first.networktables.NetworkTable; +import edu.wpi.first.networktables.NetworkTableInstance; +import edu.wpi.first.wpilibj.DriverStation; +import edu.wpi.first.wpilibj.DriverStation.Alliance; + +import edu.wpi.first.wpilibj.IterativeRobot; +import edu.wpi.first.wpilibj.smartdashboard.SendableChooser; +import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; + +/** + * The VM is configured to automatically run this class, and to call the + * functions corresponding to each mode, as described in the IterativeRobot + * documentation. If you change the name of this class or the package after + * creating this project, you must also update the build.properties file in the + * project. + */ +public class Robot extends IterativeRobot { + private Drivetrain drivetrain = new Drivetrain(); + + /** + * This function is run when the robot is first started up and should be + * used for any initialization code. + */ + @Override + public void robotInit() { + } + + /** + * This autonomous (along with the chooser code above) shows how to select + * between different autonomous modes using the dashboard. The sendable + * chooser code works with the Java SmartDashboard. If you prefer the + * LabVIEW Dashboard, remove all of the chooser code and uncomment the + * getString line to get the auto name from the text box below the Gyro + * + *

You can add additional auto modes by adding additional comparisons to + * the switch structure below with additional strings. If using the + * SendableChooser make sure to add them to the chooser code above as well. + */ + // Variables for auto modes + private Timer driveTimer = new Timer(); + int autoState; + + NetworkTable table; + String gameData; + Boolean allianceColorRed; + int allianceNumber; + Boolean goesLeft = true; + + + public void drive(double throttle, double turn) { + drivetrain.drive(throttle, turn); + } + + @Override + public void autonomousInit() { + // rest timer + driveTimer.reset(); + // Start timer + driveTimer.start(); + + gameData = DriverStation.getInstance().getGameSpecificMessage(); + allianceColorRed = DriverStation.getInstance().getAlliance() == DriverStation.Alliance.Red; + allianceNumber = DriverStation.getInstance().getLocation(); + + + goesLeft = (gameData.charAt(0) == 'L'); + } + + + + /** + * This function is called periodically during autonomous. + */ + @Override + public void autonomousPeriodic() { + autoState = 0; + switch (autoState) { + case 0: // Drive forward a tiny bit + drive(1, 0); + if (driveTimer.get() > 1000) { + driveTimer.reset(); + autoState++; + } + break; + case 1: // Turn to angle + // use game data + double turnSpeed = 0.5; + if(goesLeft) { turnSpeed = -1*turnSpeed; } + drive(0, turnSpeed); + if (driveTimer.get() > 500) { + driveTimer.reset(); + autoState++; + } + break; + case 2: // Drive to Switch + drive(1, 0); + if (driveTimer.get() > 2500) { + drive(0, 0); + driveTimer.reset(); + autoState++; + } + break; + case 3: // SCOREEEEEEE + + // spit out here + break; + } + } + + /** + * This function is called periodically during operator control. + */ + @Override + public void teleopPeriodic() { + } + + /** + * This function is called periodically during test mode. + */ + @Override + public void testPeriodic() { + } +} diff --git a/Java/jankCenterSwitch/src/org/usfirst/frc/team1665/robot/Robot2.java b/Java/jankCenterSwitch/src/org/usfirst/frc/team1665/robot/Robot2.java new file mode 100644 index 0000000..e237ead --- /dev/null +++ b/Java/jankCenterSwitch/src/org/usfirst/frc/team1665/robot/Robot2.java @@ -0,0 +1,100 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + +package org.usfirst.frc.team1665.robot; + +import edu.wpi.first.wpilibj.Timer; +import edu.wpi.first.wpilibj.command.Command; +import edu.wpi.first.wpilibj.command.Scheduler; +import edu.wpi.first.networktables.NetworkTable; +import edu.wpi.first.networktables.NetworkTableInstance; +import edu.wpi.first.wpilibj.DriverStation; +import edu.wpi.first.wpilibj.DriverStation.Alliance; + +import edu.wpi.first.wpilibj.IterativeRobot; +import edu.wpi.first.wpilibj.smartdashboard.SendableChooser; +import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; + +/** + * The VM is configured to automatically run this class, and to call the + * functions corresponding to each mode, as described in the IterativeRobot + * documentation. If you change the name of this class or the package after + * creating this project, you must also update the build.properties file in the + * project. + */ +public class Robot2 extends IterativeRobot { + private Drivetrain drivetrain = new Drivetrain(); + + /** + * This function is run when the robot is first started up and should be + * used for any initialization code. + */ + @Override + public void robotInit() { + } + + /** + * This autonomous (along with the chooser code above) shows how to select + * between different autonomous modes using the dashboard. The sendable + * chooser code works with the Java SmartDashboard. If you prefer the + * LabVIEW Dashboard, remove all of the chooser code and uncomment the + * getString line to get the auto name from the text box below the Gyro + * + *

You can add additional auto modes by adding additional comparisons to + * the switch structure below with additional strings. If using the + * SendableChooser make sure to add them to the chooser code above as well. + */ + // Variables for auto modes + NetworkTable table; + String gameData; + Boolean allianceColorRed; + int allianceNumber; + Boolean goesLeft = true; + + Command autonomousCommand; + + + @Override + public void autonomousInit() { + + gameData = DriverStation.getInstance().getGameSpecificMessage(); + + goesLeft = (gameData.charAt(0) == 'L'); + + // put real drivetrain command here + autonomousCommand = new centerSwitchAuto(Drivetrain,goesLeft); + + // Schedule the autonomous command (example) + if (autonomousCommand != null) { + autonomousCommand.start(); + } + } + + + + /** + * This function is called periodically during autonomous. + */ + @Override + public void autonomousPeriodic() { + Scheduler.getInstance().run(); + } + + /** + * This function is called periodically during operator control. + */ + @Override + public void teleopPeriodic() { + } + + /** + * This function is called periodically during test mode. + */ + @Override + public void testPeriodic() { + } +} diff --git a/Java/jankCenterSwitch/src/org/usfirst/frc/team1665/robot/centerSwitchAuto.java b/Java/jankCenterSwitch/src/org/usfirst/frc/team1665/robot/centerSwitchAuto.java new file mode 100644 index 0000000..5ae5721 --- /dev/null +++ b/Java/jankCenterSwitch/src/org/usfirst/frc/team1665/robot/centerSwitchAuto.java @@ -0,0 +1,87 @@ +package org.usfirst.frc.team1665.robot; + +import edu.wpi.first.wpilibj.Spark; +import edu.wpi.first.wpilibj.Timer; +import edu.wpi.first.wpilibj.command.Command; +import edu.wpi.first.wpilibj.command.Subsystem; + +public class centerSwitchAuto extends Command{ + // Variables for auto modes + private Timer driveTimer = new Timer(); + int autoState; + Boolean goesLeft; + + private Drivetrain drivetrain = new Drivetrain(); + + public centerSwitchAuto(Subsystem requiredSubsystem, Boolean goesLeft) { + this.goesLeft = goesLeft; + requires(requiredSubsystem); + } + + public void drive(double throttle, double turn) { + drivetrain.drive(throttle, turn); + } + + protected void initialize() { + // rest timer + driveTimer.reset(); + // Start timer + driveTimer.start(); + + autoState = 0; + + } + + // Called repeatedly when this Command is scheduled to run + protected void execute() { + autoState = 0; + switch (autoState) { + case 0: // Drive forward a tiny bit + drive(1, 0); + if (driveTimer.get() > 1000) { + driveTimer.reset(); + autoState++; + } + break; + case 1: // Turn to angle + // use game data + double turnSpeed = 0.5; + if(goesLeft) { turnSpeed = -1*turnSpeed; } + drive(0, turnSpeed); + if (driveTimer.get() > 500) { + driveTimer.reset(); + autoState++; + } + break; + case 2: // Drive to Switch + drive(1, 0); + if (driveTimer.get() > 2500) { + drive(0, 0); + driveTimer.reset(); + autoState++; + } + break; + case 3: // SCOREEEEEEE + + // spit out here + break; + } + } + + // Make this return true when this Command no longer needs to run execute() + protected boolean isFinished() { + return false; + } + + // Called once after isFinished returns true + protected void end() { + drive(0,0); + } + + // Called when another command which requires one or more of the same + // subsystems is scheduled to run + protected void interrupted() { + end(); + } + +} diff --git a/LabVIEW/AutoDrive.png b/LabVIEW/AutoDrive.png new file mode 100644 index 0000000..6d5a260 Binary files /dev/null and b/LabVIEW/AutoDrive.png differ diff --git a/LabVIEW/AutoDrive.vi b/LabVIEW/AutoDrive.vi new file mode 100644 index 0000000..bf8c870 Binary files /dev/null and b/LabVIEW/AutoDrive.vi differ diff --git a/LabVIEW/Implementation Example.vi b/LabVIEW/Implementation Example.vi new file mode 100644 index 0000000..a456fad Binary files /dev/null and b/LabVIEW/Implementation Example.vi differ diff --git a/LabVIEW/Implementation_Exampled.png b/LabVIEW/Implementation_Exampled.png new file mode 100644 index 0000000..9c1bf13 Binary files /dev/null and b/LabVIEW/Implementation_Exampled.png differ diff --git a/LabVIEW/README.md b/LabVIEW/README.md new file mode 100644 index 0000000..f5768ef --- /dev/null +++ b/LabVIEW/README.md @@ -0,0 +1,20 @@ +# LabVIEW auto examples +Author: Max Westwater - 5254 + +Implementation examples are shown. For the AutoDrive function things are broken down into the code that goes in both +Begin.vi and 'Autonomous Independent.vi'. There are also two examples in the implementation example file which are the +defaults from NI for both normal and command and control. All methods should work. 5254 used the code style of AutoDrive.vi + +AutoDrive.vi +- Can simply be dragged into Autonomous Independent.vi +- Set parameters for function + - String of the robot drive motor refnum name (taken from Begin.vi) + - Time (in ms) to wait before driving + - Speed to drive at + - Time (in ms) to drive forward + +## Implementation Example +![alt text](https://raw.githubusercontent.com/FRC5254/auto-for-everyone/master/LabVIEW/Implementation_Exampled.png) +## Auto Drive +![alt text](https://raw.githubusercontent.com/FRC5254/auto-for-everyone/master/LabVIEW/AutoDrive.png) + diff --git a/LabVIEW/add_labview_autos_here.txt b/LabVIEW/add_labview_autos_here.txt deleted file mode 100644 index e69de29..0000000