Skip to content

Tank Drive!! #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,20 @@ def includeDesktopSupport = false

// Maven central needed for JUnit
repositories {
maven { url "https://jitpack.io" }
mavenCentral()
}

// Defining my dependencies. In this case, WPILib (+ friends), and vendor libraries.
// Also defines JUnit 4.
dependencies {
compile 'com.github.WilliamAHartman:Jamepad:1.3.2'
compile wpi.deps.wpilib()
compile wpi.deps.vendor.java()
nativeZip wpi.deps.vendor.jni(wpi.platforms.roborio)
nativeDesktopZip wpi.deps.vendor.jni(wpi.platforms.desktop)
testCompile 'junit:junit:4.12'

}

// Setting up my Jar File. In this case, adding all libraries into the main jar ('fat jar')
Expand Down
Empty file modified gradlew
100644 → 100755
Empty file.
48 changes: 13 additions & 35 deletions src/main/java/frc/robot/OI.java
Original file line number Diff line number Diff line change
@@ -1,42 +1,20 @@
/*----------------------------------------------------------------------------*/
/* 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 frc.robot;
import com.studiohartman.jamepad.ControllerManager;

/**
* This class is the glue that binds the controls on the physical operator
* interface to the commands and command groups that allow control of the robot.
*/
public class OI {
//// CREATING BUTTONS
// One type of button is a joystick button which is any button on a
//// joystick.
// You create one by telling it which joystick it's on and which button
// number it is.
// Joystick stick = new Joystick(port);
// Button button = new JoystickButton(stick, buttonNumber);

// There are a few additional built in buttons you can use. Additionally,
// by subclassing Button you can create custom triggers and bind those to
// commands the same as any other Button.

//// TRIGGERING COMMANDS WITH BUTTONS
// Once you have a button, it's trivial to bind it to a button in one of
// three ways:
import edu.wpi.first.wpilibj.Joystick;

// Start the command when the button is pressed and let it run the command
// until it is finished as determined by it's isFinished method.
// button.whenPressed(new ExampleCommand());
public class OI {
private Joystick driverController = new Joystick(RobotMap.DRIVER_CONTROLLER);
private static ControllerManager controller = new ControllerManager();
public double GetDriverRawAxis(int axis){
return driverController.getRawAxis(axis);

// Run the command while the button is being held down and interrupt it once
// the button is released.
// button.whileHeld(new ExampleCommand());
}


// Start the command when the button is released and let it run the command
// until it is finished as determined by it's isFinished method.
// button.whenReleased(new ExampleCommand());
public OI(){
controller.initSDLGamepad();
}
}

21 changes: 14 additions & 7 deletions src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@

package frc.robot;

//import com.ctre.phoenix.motorcontrol.can.WPI_TalonSRX;

import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj.command.Command;
import edu.wpi.first.wpilibj.command.Scheduler;
import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import frc.robot.commands.ExampleCommand;
import frc.robot.subsystems.DriveTrain;
import frc.robot.subsystems.ExampleSubsystem;

//import frc.robot.subsystems.DriveTrain;


/**
* The VM is configured to automatically run this class, and to call the
Expand All @@ -24,22 +27,26 @@
* project.
*/
public class Robot extends TimedRobot {
public static ExampleSubsystem m_subsystem = new ExampleSubsystem();
public static DriveTrain driveTrain = new DriveTrain();
public static OI m_oi;
public static DriveTrain drivetrain;
//public static WPI_TalonSRX leftMotor1 = new WPI_TalonSRX(RobotMap.leftMotor1);
//public static WPI_TalonSRX leftMotor12 = new WPI_TalonSRX(RobotMap.leftMotor2);
//public static WPI_TalonSRX rightMotor1 = new WPI_TalonSRX(RobotMap.rightMotor1);
//public static WPI_TalonSRX rightMotor2 = new WPI_TalonSRX(RobotMap.rightMotor2);
//public static DriveTrain drivetrain;


Command m_autonomousCommand;
SendableChooser<Command> m_chooser = new SendableChooser<>();

/**
* This function is run when the robot is first started up and should be
* used for any initialization code.
*/
@Override
public void robotInit() {
drivetrain = new DriveTrain();
//drivetrain = new DriveTrain();
m_oi = new OI();
m_chooser.setDefaultOption("Default Auto", new ExampleCommand());

// chooser.addOption("My Auto", new MyAutoCommand());
SmartDashboard.putData("Auto mode", m_chooser);
//robot initialization goes here. YAY
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/frc/robot/RobotMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,19 @@ public class RobotMap {
// number and the module. For example you with a rangefinder:
// public static int rangefinderPort = 1;
// public static int rangefinderModule = 1;
public static final int Motor_Left_1_ID = 1;
public static final int Motor_Left_2_ID = 3;
public static final int Motor_Right_1_ID = 2;
public static final int Motor_Right_2_ID = 4;
public static final int DRIVER_CONTROLLER = 0;
public static final int LEFT_STICK_Y = 1;
public static final int LEFT_STICK_X = 2;
public static final int RIGHT_STICK_Y = 5;

public static final int ONLY_STICKY = 0;
public static final int ONLY_STICKX = 0;
public static final int RIGHT_STICK_X = 0;
public static final int JOYSTICK_CONTROLLER = 0;


}
60 changes: 60 additions & 0 deletions src/main/java/frc/robot/commands/Arcade_Drive.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*----------------------------------------------------------------------------*/
/* 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 frc.robot.commands;

import edu.wpi.first.wpilibj.command.Command;
import frc.robot.Robot;
import frc.robot.RobotMap;

public class Arcade_Drive extends Command {
public Arcade_Drive() {
// Use requires() here to declare subsystem dependencies

requires(Robot.driveTrain);
}

// Called just before this Command runs the first time
@Override
protected void initialize() {
}

// Called repeatedly when this Command is scheduled to run
@Override
protected void execute() {
double leftstickY = Robot.m_oi.GetDriverRawAxis(RobotMap.LEFT_STICK_Y);
double leftstickX = Robot.m_oi.GetDriverRawAxis(RobotMap.RIGHT_STICK_X);
Robot.driveTrain.setLeftMotors(leftstickY*0.5);
Robot.driveTrain.setRightMotors(leftstickY*0.5);
if (leftstickX < 0){
Robot.driveTrain.setLeftMotors(leftstickY*0.5);
Robot.driveTrain.setRightMotors(leftstickY*0.1);
if (leftstickX > 0){
Robot.driveTrain.setRightMotors(leftstickY*0.5);
Robot.driveTrain.setLeftMotors(leftstickY*0.1);
}
}
}
// 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() {
Robot.driveTrain.setLeftMotors(0);
Robot.driveTrain.setRightMotors(0);
}

// Called when another command which requires one or more of the same
// subsystems is scheduled to run
@Override
protected void interrupted() {
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */
/* 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. */
Expand All @@ -9,14 +9,12 @@

import edu.wpi.first.wpilibj.command.Command;
import frc.robot.Robot;
import frc.robot.RobotMap;

/**
* An example command. You can replace me with your own command.
*/
public class ExampleCommand extends Command {
public ExampleCommand() {
public class TankDrive extends Command {
public TankDrive() {
// Use requires() here to declare subsystem dependencies
requires(Robot.m_subsystem);
requires(Robot.driveTrain);
}

// Called just before this Command runs the first time
Expand All @@ -27,6 +25,11 @@ protected void initialize() {
// Called repeatedly when this Command is scheduled to run
@Override
protected void execute() {
double leftstickY = Robot.m_oi.GetDriverRawAxis(RobotMap.LEFT_STICK_Y);
double rightstickY = Robot.m_oi.GetDriverRawAxis(RobotMap.RIGHT_STICK_Y);

Robot.driveTrain.setLeftMotors(leftstickY*0.5);
Robot.driveTrain.setRightMotors(rightstickY*0.5);
}

// Make this return true when this Command no longer needs to run execute()
Expand All @@ -38,11 +41,15 @@ protected boolean isFinished() {
// Called once after isFinished returns true
@Override
protected void end() {

Robot.driveTrain.setLeftMotors(0);
Robot.driveTrain.setRightMotors(0);
}

// Called when another command which requires one or more of the same
// subsystems is scheduled to run
@Override
protected void interrupted() {
this.end();
}
}
68 changes: 16 additions & 52 deletions src/main/java/frc/robot/subsystems/DriveTrain.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,68 +12,32 @@
import com.ctre.phoenix.motorcontrol.can.VictorSPX;

import edu.wpi.first.wpilibj.command.Subsystem;
import frc.robot.RobotMap;
import frc.robot.commands.Arcade_Drive;

/**
* Add your docs here.
*/
public class DriveTrain extends Subsystem {
// Put methods for controlling this subsystem
// here. Call these from Commands.
TalonSRX rightMotor1;
VictorSPX rightMotor2;
TalonSRX leftMotor1;
VictorSPX leftMotor2;

private double leftSpeed;
private double rightSpeed;

public DriveTrain(){
rightMotor1 = new TalonSRX(1);
rightMotor2 = new VictorSPX(2);
leftMotor1 = new TalonSRX(30);
leftMotor2 = new VictorSPX(4);
}

public void tankDrive(double left, double right){

if(left > 1){
left = 1;
} else if(left < -1){
left = -1;
} else {
// these are valid inputs. do we want to change them?
if(left < 0){
left = -left*left;
}else {
left = left*left;
}
}
if(right > 1){
right = 1;
} else if(right < -1){
right = -1;
} else {
// these are valid inputs. do we want to change them?
if(right < 0){
right = -right*right;
}else {
right = right*right;
}
}

leftSpeed = left;
rightSpeed = right;

rightMotor1.set(ControlMode.PercentOutput, rightSpeed);
rightMotor2.set(ControlMode.PercentOutput, rightSpeed);
leftMotor1.set(ControlMode.PercentOutput, leftSpeed);
leftMotor2.set(ControlMode.PercentOutput, leftSpeed);

}
private TalonSRX motorLeft1 = new TalonSRX(RobotMap.Motor_Left_1_ID);
private VictorSPX motorLeft2 = new VictorSPX(RobotMap.Motor_Left_2_ID);
private TalonSRX motorRight1 = new TalonSRX(RobotMap.Motor_Right_1_ID);
private VictorSPX motorRight2 = new VictorSPX(RobotMap.Motor_Right_2_ID);

@Override
public void initDefaultCommand() {
// Set the default command for a subsystem here.
// setDefaultCommand(new MySpecialCommand());
setDefaultCommand(new Arcade_Drive());
}

public void setLeftMotors(double speed){
motorLeft1.set(ControlMode.PercentOutput, speed);
motorLeft2.set(ControlMode.PercentOutput, speed);
}
public void setRightMotors(double speed){
motorRight1.set(ControlMode.PercentOutput, -speed);
motorRight2.set(ControlMode.PercentOutput, -speed);
}
}