From b449387d8a410c4d224b9ebca4cbe6b6689ff26b Mon Sep 17 00:00:00 2001 From: Logan Howard Date: Thu, 16 Apr 2015 19:04:47 -0700 Subject: [PATCH] initial commit --- .gitignore | 41 ++++++++++++++ build.properties | 4 ++ build.xml | 30 ++++++++++ .../usfirst/frc/team3501/robot/Joystick.java | 28 ++++++++++ src/org/usfirst/frc/team3501/robot/OI.java | 23 ++++++++ src/org/usfirst/frc/team3501/robot/Robot.java | 55 +++++++++++++++++++ .../usfirst/frc/team3501/robot/RobotMap.java | 18 ++++++ .../team3501/robot/commands/CloseClaw.java | 17 ++++++ .../team3501/robot/commands/CommandBase.java | 34 ++++++++++++ .../team3501/robot/commands/DriveForward.java | 26 +++++++++ .../robot/commands/DriveWithJoysticks.java | 17 ++++++ .../frc/team3501/robot/commands/OpenClaw.java | 17 ++++++ .../frc/team3501/robot/subsystems/Arm.java | 18 ++++++ .../frc/team3501/robot/subsystems/Claw.java | 30 ++++++++++ .../team3501/robot/subsystems/Drivetrain.java | 51 +++++++++++++++++ 15 files changed, 409 insertions(+) create mode 100644 .gitignore create mode 100644 build.properties create mode 100644 build.xml create mode 100644 src/org/usfirst/frc/team3501/robot/Joystick.java create mode 100644 src/org/usfirst/frc/team3501/robot/OI.java create mode 100644 src/org/usfirst/frc/team3501/robot/Robot.java create mode 100644 src/org/usfirst/frc/team3501/robot/RobotMap.java create mode 100644 src/org/usfirst/frc/team3501/robot/commands/CloseClaw.java create mode 100644 src/org/usfirst/frc/team3501/robot/commands/CommandBase.java create mode 100644 src/org/usfirst/frc/team3501/robot/commands/DriveForward.java create mode 100644 src/org/usfirst/frc/team3501/robot/commands/DriveWithJoysticks.java create mode 100644 src/org/usfirst/frc/team3501/robot/commands/OpenClaw.java create mode 100644 src/org/usfirst/frc/team3501/robot/subsystems/Arm.java create mode 100644 src/org/usfirst/frc/team3501/robot/subsystems/Claw.java create mode 100644 src/org/usfirst/frc/team3501/robot/subsystems/Drivetrain.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0369e1d --- /dev/null +++ b/.gitignore @@ -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 index 0000000..a977dcd --- /dev/null +++ b/build.properties @@ -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 index 0000000..2182d37 --- /dev/null +++ b/build.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/org/usfirst/frc/team3501/robot/Joystick.java b/src/org/usfirst/frc/team3501/robot/Joystick.java new file mode 100644 index 0000000..c183c66 --- /dev/null +++ b/src/org/usfirst/frc/team3501/robot/Joystick.java @@ -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 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 index 0000000..d6344b7 --- /dev/null +++ b/src/org/usfirst/frc/team3501/robot/OI.java @@ -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 index 0000000..68770bb --- /dev/null +++ b/src/org/usfirst/frc/team3501/robot/Robot.java @@ -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 index 0000000..0525166 --- /dev/null +++ b/src/org/usfirst/frc/team3501/robot/RobotMap.java @@ -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 index 0000000..3cf7125 --- /dev/null +++ b/src/org/usfirst/frc/team3501/robot/commands/CloseClaw.java @@ -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 index 0000000..2fc4028 --- /dev/null +++ b/src/org/usfirst/frc/team3501/robot/commands/CommandBase.java @@ -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 index 0000000..0590b6b --- /dev/null +++ b/src/org/usfirst/frc/team3501/robot/commands/DriveForward.java @@ -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 index 0000000..d1f3e50 --- /dev/null +++ b/src/org/usfirst/frc/team3501/robot/commands/DriveWithJoysticks.java @@ -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 index 0000000..a3aa3a2 --- /dev/null +++ b/src/org/usfirst/frc/team3501/robot/commands/OpenClaw.java @@ -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 index 0000000..deffbdd --- /dev/null +++ b/src/org/usfirst/frc/team3501/robot/subsystems/Arm.java @@ -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 index 0000000..aecab3e --- /dev/null +++ b/src/org/usfirst/frc/team3501/robot/subsystems/Claw.java @@ -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 index 0000000..5285956 --- /dev/null +++ b/src/org/usfirst/frc/team3501/robot/subsystems/Drivetrain.java @@ -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() {} +} + -- 2.30.2