From b07c0a5491b8f046b3016774350a136f13678456 Mon Sep 17 00:00:00 2001 From: Elliott Chen <37708746+Elioc997472@users.noreply.github.com> Date: Fri, 18 Jan 2019 14:45:07 -0800 Subject: [PATCH] Code to test LEDs When Y is pressed on the controller, the LEDs cycle through 3 modes. Just meant to test LEDs; final will probably be controlled differently. --- 2019robot/build.gradle | 2 +- .../java/org/usfirst/frc4388/robot/OI.java | 3 +- .../org/usfirst/frc4388/robot/RobotMap.java | 11 +--- .../frc4388/robot/commands/LedSwitch.java | 59 +++++++++++++++++++ .../usfirst/frc4388/robot/subsystems/LED.java | 36 +++++++++++ 5 files changed, 100 insertions(+), 11 deletions(-) create mode 100644 2019robot/src/main/java/org/usfirst/frc4388/robot/commands/LedSwitch.java create mode 100644 2019robot/src/main/java/org/usfirst/frc4388/robot/subsystems/LED.java diff --git a/2019robot/build.gradle b/2019robot/build.gradle index f15e84c..86010b5 100644 --- a/2019robot/build.gradle +++ b/2019robot/build.gradle @@ -1,6 +1,6 @@ plugins { id "java" - id "edu.wpi.first.GradleRIO" version "2019.1.1" + id "edu.wpi.first.GradleRIO" version "2019.2.1" } def ROBOT_MAIN_CLASS = "org.usfirst.frc4388.robot.Main" diff --git a/2019robot/src/main/java/org/usfirst/frc4388/robot/OI.java b/2019robot/src/main/java/org/usfirst/frc4388/robot/OI.java index 4fc1133..173d622 100644 --- a/2019robot/src/main/java/org/usfirst/frc4388/robot/OI.java +++ b/2019robot/src/main/java/org/usfirst/frc4388/robot/OI.java @@ -60,7 +60,8 @@ public class OI JoystickButton shiftDown = new JoystickButton(m_driverXbox.getJoyStick(), XboxController.LEFT_BUMPER_BUTTON); shiftDown.whenPressed(new DriveSpeedShift(false)); // shiftDown.whenPressed(new LEDIndicators(false)); - + + ledSwitch.whenPressed(new LedSwitch()); //Operator Xbox /* diff --git a/2019robot/src/main/java/org/usfirst/frc4388/robot/RobotMap.java b/2019robot/src/main/java/org/usfirst/frc4388/robot/RobotMap.java index 64e015f..1ae047a 100644 --- a/2019robot/src/main/java/org/usfirst/frc4388/robot/RobotMap.java +++ b/2019robot/src/main/java/org/usfirst/frc4388/robot/RobotMap.java @@ -17,15 +17,8 @@ public class RobotMap { public static final int DRIVETRAIN_RIGHT_MOTOR1_CAN_ID = 4; public static final int DRIVETRAIN_RIGHT_MOTOR2_CAN_ID = 5; - //carriage motors - public static final int CARRIAGE_LEFT_MOTOR_CAN_ID = 8; - public static final int CARRIAGE_RIGHT_MOTOR_CAN_ID = 9; - - //Elevator Motors - public static final int ELEVATOR_MOTOR1_ID = 6; - public static final int ELEVATOR_MOTOR2_ID = 7; - public static final int CLIMBER_CAN_ID = 10; - + // LED + public static final int LED_DRIVER = 0; // Pneumatics public static final int DRIVETRAIN_SPEEDSHIFT_PCM_ID = 0; diff --git a/2019robot/src/main/java/org/usfirst/frc4388/robot/commands/LedSwitch.java b/2019robot/src/main/java/org/usfirst/frc4388/robot/commands/LedSwitch.java new file mode 100644 index 0000000..4598ec4 --- /dev/null +++ b/2019robot/src/main/java/org/usfirst/frc4388/robot/commands/LedSwitch.java @@ -0,0 +1,59 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 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.frc4388.robot.commands; + +import edu.wpi.first.wpilibj.command.Command; + +public class LedSwitch extends Command { + public LedSwitch() { + requires(LED); + } + + // Called just before this Command runs the first time + @Override + protected void initialize() { + float lastTime = System.currentTimeMillis; + LED.mode1(); + } + + /** + * Called repeatedly when this Command is scheduled to run. Cycles through 3 LED modes + * before returning to begining + */ + @Override + protected void execute() { + if(System.currentTimeMillis>lastTime+30000){ //After 30 seconds + LED.mode1(); + float lastTime = System.currentTimeMillis; + } + else if(System.currentTimeMillis>lastTime+20000){//After 20 seconds + LED.mode3(); + } + else if( System.currentTimeMillis>lastTime+10000){//After 10 seconds + LED.mode2(); + } + + } + + // Make this return true when this Command no longer needs to run execute() + @Override + protected boolean isFinished() { + return false; + } + + // Called once after isFinished returns true + @Override + protected void end() { + } + + // Called when another command which requires one or more of the same + // subsystems is scheduled to run + @Override + protected void interrupted() { + } +} diff --git a/2019robot/src/main/java/org/usfirst/frc4388/robot/subsystems/LED.java b/2019robot/src/main/java/org/usfirst/frc4388/robot/subsystems/LED.java new file mode 100644 index 0000000..24527aa --- /dev/null +++ b/2019robot/src/main/java/org/usfirst/frc4388/robot/subsystems/LED.java @@ -0,0 +1,36 @@ +package org.usfirst.frc4388.robot.subsystems; + +import org.usfirst.frc.team2848.robot.RobotMap; + +import edu.wpi.first.wpilibj.AnalogInput; +import edu.wpi.first.wpilibj.DigitalInput; +import edu.wpi.first.wpilibj.Spark; +import edu.wpi.first.wpilibj.command.Subsystem; + +/** + * + */ +public class LED extends Subsystem { + + //LED Spark controller + public Spark LED1 = new Spark(RobotMap.LED_DRIVER); + + + //public void initDefaultCommand() {} + + //LED mode 1 + public void mode1() { ///TODO: name the modes + LED1.set(-.57); + } + + //LED mode 2 + public void mode2() { + LED1.set(.32); + } + + //LED mode 3 + public void mode3() { + LED1.set(-.69); + } + +} \ No newline at end of file