initial commit
authorLogan Howard <logan@oflogan.com>
Fri, 17 Apr 2015 02:04:47 +0000 (19:04 -0700)
committerLogan Howard <logan@oflogan.com>
Fri, 17 Apr 2015 02:04:47 +0000 (19:04 -0700)
15 files changed:
.gitignore [new file with mode: 0644]
build.properties [new file with mode: 0644]
build.xml [new file with mode: 0644]
src/org/usfirst/frc/team3501/robot/Joystick.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/RobotMap.java [new file with mode: 0644]
src/org/usfirst/frc/team3501/robot/commands/CloseClaw.java [new file with mode: 0644]
src/org/usfirst/frc/team3501/robot/commands/CommandBase.java [new file with mode: 0644]
src/org/usfirst/frc/team3501/robot/commands/DriveForward.java [new file with mode: 0644]
src/org/usfirst/frc/team3501/robot/commands/DriveWithJoysticks.java [new file with mode: 0644]
src/org/usfirst/frc/team3501/robot/commands/OpenClaw.java [new file with mode: 0644]
src/org/usfirst/frc/team3501/robot/subsystems/Arm.java [new file with mode: 0644]
src/org/usfirst/frc/team3501/robot/subsystems/Claw.java [new file with mode: 0644]
src/org/usfirst/frc/team3501/robot/subsystems/Drivetrain.java [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..0369e1d
--- /dev/null
@@ -0,0 +1,41 @@
+*.pydevproject
+.metadata
+.gradle
+bin/
+tmp/
+*.tmp
+*.bak
+*.swp
+*~.nib
+local.properties
+.settings/
+.loadpath
+
+# Eclipse Core
+.project
+
+# External tool builders
+.externalToolBuilders/
+
+# Locally stored "Eclipse launch configurations"
+*.launch
+
+# CDT-specific
+.cproject
+
+# JDT-specific (Eclipse Java Development Tools)
+.classpath
+
+# PDT-specific
+.buildpath
+
+# sbteclipse plugin
+.target
+
+# TeXlipse plugin
+.texlipse
+
+# custom stuff that seems unnecessary
+build/
+dist/
+sysProps.xml
diff --git a/build.properties b/build.properties
new file mode 100644 (file)
index 0000000..a977dcd
--- /dev/null
@@ -0,0 +1,4 @@
+# Project specific information
+package=org.usfirst.frc.team3501.robot
+robot.class=${package}.Robot
+simulation.world.file=/usr/share/frcsim/worlds/GearsBotDemo.world
\ No newline at end of file
diff --git a/build.xml b/build.xml
new file mode 100644 (file)
index 0000000..2182d37
--- /dev/null
+++ b/build.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<project name="FRC Deployment" default="deploy">
+
+  <!--
+  The following properties can be defined to override system level
+  settings. These should not be touched unless you know what you're
+  doing. The primary use is to override the wpilib version when
+  working with older robots that can't compile with the latest
+  libraries.
+  -->
+
+  <!-- By default the system version of WPI is used -->
+  <!-- <property name="version" value=""/> -->
+
+  <!-- By default the system team number is used -->
+  <!-- <property name="team-number" value=""/> -->
+
+  <!-- By default the target is set to 10.TE.AM.2 -->
+  <!-- <property name="target" value=""/> -->
+
+  <!-- Any other property in build.properties can also be overridden. -->
+  
+  <property file="${user.home}/wpilib/wpilib.properties"/>
+  <property file="build.properties"/>
+  <property file="${user.home}/wpilib/java/${version}/ant/build.properties"/>
+  
+  <import file="${wpilib.ant.dir}/build.xml"/>
+
+</project> 
diff --git a/src/org/usfirst/frc/team3501/robot/Joystick.java b/src/org/usfirst/frc/team3501/robot/Joystick.java
new file mode 100644 (file)
index 0000000..c183c66
--- /dev/null
@@ -0,0 +1,28 @@
+package org.usfirst.frc.team3501.robot;
+
+import java.util.HashMap;
+import java.util.stream.IntStream;
+
+import edu.wpi.first.wpilibj.buttons.JoystickButton;
+import edu.wpi.first.wpilibj.command.Command;
+
+public class Joystick extends edu.wpi.first.wpilibj.Joystick {
+
+    private HashMap<Integer, JoystickButton> buttons;
+
+    public Joystick(int port) {
+        super(port);
+
+        IntStream.rangeClosed(1, 12).forEach((b) -> {
+            buttons.put(b, new JoystickButton(this, b));
+        });
+    }
+
+    public void whenPressed(int button, Command c) {
+        buttons.get(button).whenPressed(c);
+    }
+
+    public void whenReleased(int button, Command c) {
+        buttons.get(button).whenReleased(c);
+    }
+}
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..d6344b7
--- /dev/null
@@ -0,0 +1,23 @@
+package org.usfirst.frc.team3501.robot;
+
+import org.usfirst.frc.team3501.robot.commands.*;
+
+public class OI {
+    public Joystick left, right;
+
+    public OI() {
+        left  = new Joystick(RobotMap.LEFT_JOYSTICK_PORT);
+        right = new Joystick(RobotMap.RIGHT_JOYSTICK_PORT);
+
+        right.whenPressed(1, new CloseClaw());
+        right.whenReleased(1, new OpenClaw());
+    }
+
+    public double getForwardSpeed() {
+        return right.getY();
+    }
+
+    public double getTwistSpeed() {
+        return right.getTwist();
+    }
+}
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..68770bb
--- /dev/null
@@ -0,0 +1,55 @@
+
+package org.usfirst.frc.team3501.robot;
+
+import edu.wpi.first.wpilibj.IterativeRobot;
+import edu.wpi.first.wpilibj.command.Command;
+import edu.wpi.first.wpilibj.command.Scheduler;
+import edu.wpi.first.wpilibj.livewindow.LiveWindow;
+
+import org.usfirst.frc.team3501.robot.commands.*;
+import org.usfirst.frc.team3501.robot.subsystems.*;
+
+public class Robot extends IterativeRobot {
+
+       public static final Drivetrain drivetrain = new Drivetrain();
+       public static final Arm               arm = new Arm();
+       public static final Claw             claw = new Claw();
+
+       public static OI oi;
+
+    Command autonomousCommand;
+
+    public void robotInit() {
+               oi = new OI();
+
+               double time = 1.2;
+               double speed = 0.7;
+        autonomousCommand = new DriveForward(time, speed);
+    }
+
+       public void disabledPeriodic() {
+               Scheduler.getInstance().run();
+       }
+
+    public void autonomousInit() {
+        autonomousCommand.start();
+    }
+
+    public void autonomousPeriodic() {
+        Scheduler.getInstance().run();
+    }
+
+    public void teleopInit() {
+        autonomousCommand.cancel();
+    }
+
+    public void teleopPeriodic() {
+        Scheduler.getInstance().run();
+
+
+    }
+
+    public void testPeriodic() {
+        LiveWindow.run();
+    }
+}
diff --git a/src/org/usfirst/frc/team3501/robot/RobotMap.java b/src/org/usfirst/frc/team3501/robot/RobotMap.java
new file mode 100644 (file)
index 0000000..0525166
--- /dev/null
@@ -0,0 +1,18 @@
+package org.usfirst.frc.team3501.robot;
+
+import edu.wpi.first.wpilibj.DoubleSolenoid.Value;
+
+public class RobotMap {
+    public static final int LEFT_JOYSTICK_PORT = 0, RIGHT_JOYSTICK_PORT = 1;
+
+    public static final double MIN_DRIVE_JOYSTICK_INPUT = 0.1;
+
+    public static final int FRONT_LEFT_ADDRESS = 4, FRONT_RIGHT_ADDRESS = 5,
+                            REAR_LEFT_ADDRESS  = 3, REAR_RIGHT_ADDRESS  = 6;
+
+    public static final double MAX_DRIVE_SPEED = 0.7;
+
+    public static final int CLAW_FORWARD_CHANNEL = 0, CLAW_REVERSE_CHANNEL = 1;
+
+    public static final Value OPEN = Value.kForward, CLOSED = Value.kReverse;
+}
diff --git a/src/org/usfirst/frc/team3501/robot/commands/CloseClaw.java b/src/org/usfirst/frc/team3501/robot/commands/CloseClaw.java
new file mode 100644 (file)
index 0000000..3cf7125
--- /dev/null
@@ -0,0 +1,17 @@
+package org.usfirst.frc.team3501.robot.commands;
+
+public class CloseClaw extends CommandBase {
+
+    public CloseClaw() {
+        super("CloseClaw");
+        requires(claw);
+    }
+
+    protected void initialize() {
+        claw.close();
+    }
+
+    protected boolean isFinished() {
+        return true;
+    }
+}
diff --git a/src/org/usfirst/frc/team3501/robot/commands/CommandBase.java b/src/org/usfirst/frc/team3501/robot/commands/CommandBase.java
new file mode 100644 (file)
index 0000000..2fc4028
--- /dev/null
@@ -0,0 +1,34 @@
+package org.usfirst.frc.team3501.robot.commands;
+
+import org.usfirst.frc.team3501.robot.OI;
+import org.usfirst.frc.team3501.robot.Robot;
+import org.usfirst.frc.team3501.robot.subsystems.*;
+
+import edu.wpi.first.wpilibj.command.Command;
+
+public abstract class CommandBase extends Command {
+
+    protected static OI oi;
+
+    protected static Drivetrain drivetrain;
+    protected static Arm arm;
+    protected static Claw claw;
+
+    public CommandBase(String commandName) {
+        super(commandName);
+
+        oi = Robot.oi;
+
+        drivetrain = Robot.drivetrain;
+        arm        = Robot.arm;
+        claw       = Robot.claw;
+    }
+
+    protected void initialize() {}
+
+    protected void execute() {}
+
+    protected void end() {}
+
+    protected void interrupted() {}
+}
diff --git a/src/org/usfirst/frc/team3501/robot/commands/DriveForward.java b/src/org/usfirst/frc/team3501/robot/commands/DriveForward.java
new file mode 100644 (file)
index 0000000..0590b6b
--- /dev/null
@@ -0,0 +1,26 @@
+package org.usfirst.frc.team3501.robot.commands;
+
+public class DriveForward extends CommandBase {
+
+    private double speed;
+
+    public DriveForward(double time, double speed) {
+        super("DriveForward");
+        requires(drivetrain);
+
+        setTimeout(time);
+        this.speed = speed;
+    }
+
+    protected void execute() {
+        drivetrain.goForward(speed);
+    }
+
+    protected boolean isFinished() {
+        return isTimedOut();
+    }
+
+    protected void end() {
+        drivetrain.stop();
+    }
+}
diff --git a/src/org/usfirst/frc/team3501/robot/commands/DriveWithJoysticks.java b/src/org/usfirst/frc/team3501/robot/commands/DriveWithJoysticks.java
new file mode 100644 (file)
index 0000000..d1f3e50
--- /dev/null
@@ -0,0 +1,17 @@
+package org.usfirst.frc.team3501.robot.commands;
+
+public class DriveWithJoysticks extends CommandBase {
+
+    public DriveWithJoysticks() {
+        super("DriveWithJoysticks");
+        requires(drivetrain);
+    }
+
+    protected void execute() {
+        drivetrain.drive(oi.getForwardSpeed(), oi.getTwistSpeed());
+    }
+
+    protected boolean isFinished() {
+        return false;
+    }
+}
diff --git a/src/org/usfirst/frc/team3501/robot/commands/OpenClaw.java b/src/org/usfirst/frc/team3501/robot/commands/OpenClaw.java
new file mode 100644 (file)
index 0000000..a3aa3a2
--- /dev/null
@@ -0,0 +1,17 @@
+package org.usfirst.frc.team3501.robot.commands;
+
+public class OpenClaw extends CommandBase {
+
+    public OpenClaw() {
+        super("OpenClaw");
+        requires(claw);
+    }
+
+    protected void initialize() {
+        claw.open();
+    }
+
+    protected boolean isFinished() {
+        return true;
+    }
+}
diff --git a/src/org/usfirst/frc/team3501/robot/subsystems/Arm.java b/src/org/usfirst/frc/team3501/robot/subsystems/Arm.java
new file mode 100644 (file)
index 0000000..deffbdd
--- /dev/null
@@ -0,0 +1,18 @@
+package org.usfirst.frc.team3501.robot.subsystems;
+
+import edu.wpi.first.wpilibj.command.Subsystem;
+
+/**
+ *
+ */
+public class Arm extends Subsystem {
+    
+    // Put methods for controlling this subsystem
+    // here. Call these from Commands.
+
+    public void initDefaultCommand() {
+        // Set the default command for a subsystem here.
+        //setDefaultCommand(new MySpecialCommand());
+    }
+}
+
diff --git a/src/org/usfirst/frc/team3501/robot/subsystems/Claw.java b/src/org/usfirst/frc/team3501/robot/subsystems/Claw.java
new file mode 100644 (file)
index 0000000..aecab3e
--- /dev/null
@@ -0,0 +1,30 @@
+package org.usfirst.frc.team3501.robot.subsystems;
+
+import org.usfirst.frc.team3501.robot.RobotMap;
+import org.usfirst.frc.team3501.robot.commands.*;
+
+import edu.wpi.first.wpilibj.DoubleSolenoid;
+import edu.wpi.first.wpilibj.command.Subsystem;
+
+public class Claw extends Subsystem {
+
+    private final DoubleSolenoid piston;
+
+    public Claw() {
+        piston = new DoubleSolenoid(
+                RobotMap.CLAW_FORWARD_CHANNEL, RobotMap.CLAW_REVERSE_CHANNEL);
+    }
+
+    public void initDefaultCommand() {
+        setDefaultCommand(new CloseClaw());
+    }
+
+    public void open() {
+        piston.set(RobotMap.OPEN);
+    }
+
+    public void close() {
+        piston.set(RobotMap.CLOSED);
+    }
+}
+
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..5285956
--- /dev/null
@@ -0,0 +1,51 @@
+package org.usfirst.frc.team3501.robot.subsystems;
+
+import org.usfirst.frc.team3501.robot.RobotMap;
+
+import edu.wpi.first.wpilibj.CANJaguar;
+import edu.wpi.first.wpilibj.RobotDrive;
+import edu.wpi.first.wpilibj.command.Subsystem;
+
+public class Drivetrain extends Subsystem {
+
+    RobotDrive robotDrive;
+
+    public Drivetrain() {
+        CANJaguar frontLeft  = new CANJaguar(RobotMap.FRONT_LEFT_ADDRESS);
+        CANJaguar frontRight = new CANJaguar(RobotMap.FRONT_RIGHT_ADDRESS);
+        CANJaguar rearLeft   = new CANJaguar(RobotMap.REAR_LEFT_ADDRESS);
+        CANJaguar rearRight  = new CANJaguar(RobotMap.REAR_RIGHT_ADDRESS);
+
+        robotDrive = new RobotDrive(
+                frontLeft,  rearLeft,
+                frontRight, rearRight);
+    }
+
+    public void drive(double forward, double twist) {
+        if (Math.abs(forward) < RobotMap.MIN_DRIVE_JOYSTICK_INPUT)
+            forward = 0;
+        if (Math.abs(twist) < RobotMap.MIN_DRIVE_JOYSTICK_INPUT)
+            twist = 0;
+
+        robotDrive.arcadeDrive(
+                RobotMap.MAX_DRIVE_SPEED * adjust(forward),
+                RobotMap.MAX_DRIVE_SPEED * adjust(twist),
+                false);
+    }
+
+    public void goForward(double speed) {
+        robotDrive.arcadeDrive(speed, 0);
+    }
+
+    public void stop() {
+        robotDrive.arcadeDrive(0, 0);
+    }
+
+    // output is avg of `x` and `sqrt(x)`
+    private double adjust(double x) {
+        return (x + Math.signum(x) * Math.sqrt(Math.abs(x))) / 2;
+    }
+
+    public void initDefaultCommand() {}
+}
+