Skip to content

Commit

Permalink
Added LogitechController to OI
Browse files Browse the repository at this point in the history
  • Loading branch information
briansemrau committed Feb 10, 2018
1 parent f8eef54 commit bf6d59e
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 7 deletions.
82 changes: 82 additions & 0 deletions src/org/usfirst/frc/team4737/lib/LogitechController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package org.usfirst.frc.team4737.lib;

import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.buttons.JoystickButton;

public class LogitechController {

public class Axis {
private final Joystick controller;
private final int axis;

private double deadzone;

public Axis(Joystick controller, int axis) {
this.controller = controller;
this.axis = axis;
}

public void setDeadzone(double radius) {
if (radius < 0) throw new IllegalArgumentException("Deadzone cannot be less than 0.");
this.deadzone = radius;
}

public double getRaw() {
return controller.getRawAxis(axis);
}

public double get() {
double raw = getRaw();
if (raw < -deadzone) {
return scale(raw, -1, -deadzone, -1, 0);
} else if (raw > deadzone) {
return scale(raw, deadzone, 1, 0, 1);
} else {
return 0;
}
}

private double scale(double val, double valLow, double valHigh, double newLow, double newHigh) {
double reduced = (val - valLow) / (valHigh - valLow);
return reduced * (newHigh - newLow) + newLow;
}
}

public class Thumbstick {
public final Axis X, Y;

public Thumbstick(Joystick controller, int axisX, int axisY) {
X = new Axis(controller, axisX);
Y = new Axis(controller, axisY);
}
}

public final Joystick controller;
public final JoystickButton A;
public final JoystickButton B;
public final JoystickButton X;
public final JoystickButton Y;
public final JoystickButton RB;
public final JoystickButton LB;
public final Thumbstick LS;
public final Thumbstick RS;
public final Axis LT;
public final Axis RT;

public LogitechController(int usbPort) {
controller = new Joystick(usbPort);
A = new JoystickButton(controller, -1); // TODO map the correct button IDs
B = new JoystickButton(controller, -1);
X = new JoystickButton(controller, -1);
Y = new JoystickButton(controller, -1);
RB = new JoystickButton(controller, -1);
LB = new JoystickButton(controller, -1);
LS = new Thumbstick(controller, -1, -1);
RS = new Thumbstick(controller, -1, -1);
LT = new Axis(controller, -1);
RT = new Axis(controller, -1);
}

// TODO add rumble if possible

}
15 changes: 10 additions & 5 deletions src/org/usfirst/frc/team4737/robot/OI.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@

package org.usfirst.frc.team4737.robot;

import edu.wpi.first.wpilibj.Joystick;
import org.usfirst.frc.team4737.lib.LogitechController;
import org.usfirst.frc.team4737.robot.commands.ReverseIntake;
import org.usfirst.frc.team4737.robot.commands.RunIntake;


/**
* This class is the glue that binds the controls on the physical operator
Expand Down Expand Up @@ -42,12 +45,14 @@ public class OI {
// until it is finished as determined by it's isFinished method.
// button.whenReleased(new ExampleCommand());

public Joystick leftJoystick;
public Joystick rightJoystick;
public LogitechController controller;

public OI() {
leftJoystick = new Joystick(0);
rightJoystick = new Joystick(1);
controller = new LogitechController(0);

controller.A.whileHeld(new RunIntake());
controller.B.whileHeld(new ReverseIntake());

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ protected void initialize() {
// Called repeatedly when this Command is scheduled to run
protected void execute() {
Robot.DRIVETRAIN.tankDrive(
Robot.OI.leftJoystick.getRawAxis(1),
Robot.OI.rightJoystick.getRawAxis(1));
Robot.OI.controller.LS.Y.get(),
Robot.OI.controller.RS.Y.get());
}

// Make this return true when this Command no longer needs to run execute()
Expand Down

0 comments on commit bf6d59e

Please sign in to comment.