Skip to content

Commit

Permalink
[#166] create class LightningController
Browse files Browse the repository at this point in the history
undo previous changes

create LightningController

- use controller
- use shuffleboard when enabled
  • Loading branch information
Vilok1 committed Apr 22, 2024
1 parent 103bc7c commit 75a5082
Show file tree
Hide file tree
Showing 2 changed files with 249 additions and 10 deletions.
37 changes: 27 additions & 10 deletions filter/XboxControllerFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import edu.wpi.first.math.MathUtil;
import edu.wpi.first.math.geometry.Rotation2d;
import edu.wpi.first.wpilibj.XboxController;
import frc.thunder.shuffleboard.LightningController;

public class XboxControllerFilter extends XboxController{
public class XboxControllerFilter extends LightningController{

private filterMode mode;

Expand Down Expand Up @@ -35,6 +35,23 @@ public XboxControllerFilter(int port, double deadBand, double minPower, double m
this.maxPower = maxPower;
}

/**
* Constructor for XboxControllerFilter
* @param port Port of controller
* @param deadBand Deadband to apply to controller
* @param minPower Minimum power to apply to controller
* @param maxPower Maximum power to apply to controller
* @param mode Filter mode to apply to controller
* @param name Name of controller for sim
*/
public XboxControllerFilter(int port, double deadBand, double minPower, double maxPower, filterMode mode, String name) {
super(name, port);
this.mode = mode;
this.deadband = deadBand;
this.minPower = minPower;
this.maxPower = maxPower;
}

/**
* Get the filtered left X value
* @return Get the filtered left X value
Expand Down Expand Up @@ -102,17 +119,17 @@ private double[] filter(double X, double Y) {
}
}

if (xOutput > 1){
xOutput = 1;
if (xOutput > maxPower){
xOutput = maxPower;
}
if (yOutput > 1){
yOutput = 1;
if (yOutput > maxPower){
yOutput = maxPower;
}
if (xOutput < -1){
xOutput = -1;
if (xOutput < minPower){
xOutput = minPower;
}
if (yOutput < -1){
yOutput = -1;
if (yOutput < minPower){
yOutput = minPower;
}


Expand Down
222 changes: 222 additions & 0 deletions shuffleboard/LightningController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
package frc.thunder.shuffleboard;

import edu.wpi.first.wpilibj.XboxController;

public class LightningController extends XboxController{

String name;

public LightningController(String name, int port){
super(port);
this.name = name;
}

public LightningController(int port){
super(port);
this.name = "Controller " + port + " ";
}

public boolean simController(){
return LightningShuffleboard.getBool(name, name + "simController", false);

}

/**
* @return the leftX value from the controller/shuffleboard
*/
public double getLeftX(){
if (simController()){
return LightningShuffleboard.getDouble(name, name + "LeftX", 0d);
} else {
return super.getLeftX();
}
}

/**
* @return the leftY value from the controller/shuffleboard
*/
public double getLeftY(){
if (simController()){
return LightningShuffleboard.getDouble(name, name + "LeftY", 0d);
} else {
return super.getLeftY();
}
}

/**
* @return the rightX value from the controller/shuffleboard
*/
public double getRightX(){
if (simController()){
return LightningShuffleboard.getDouble(name, name + "RightX", 0d);
} else {
return super.getRightX();
}
}

/**
* @return the rightY value from the controller/shuffleboard
*/
public double getRightY(){
if (simController()){
return LightningShuffleboard.getDouble(name, name + "RightY", 0d);
} else {
return super.getRightY();
}
}

/**
* @return the leftTriggerAxis value from the controller/shuffleboard
*/
public double getLeftTriggerAxis(){
if (simController()){
return LightningShuffleboard.getDouble(name, name + "LeftTriggerAxis", 0d);
} else {
return super.getLeftTriggerAxis();
}
}

/**
* @return the rightTriggerAxis value from the controller/shuffleboard
*/
public double getRightTriggerAxis(){
if (simController()){
return LightningShuffleboard.getDouble(name, name + "RightTriggerAxis", 0d);
} else {
return super.getRightTriggerAxis();
}
}

/**
* @return the leftBumper value from the controller/shuffleboard
*/
public boolean getLeftBumper(){
if (simController()){
return LightningShuffleboard.getBool(name, name + "LeftBumper", false);
} else {
return super.getLeftBumper();
}
}

/**
* @return the rightBumper value from the controller/shuffleboard
*/
public boolean getRightBumper(){
if (simController()){
return LightningShuffleboard.getBool(name, name + "RightBumper", false);
} else {
return super.getRightBumper();
}
}

/**
* @return the leftStickButton value from the controller/shuffleboard
*/
public boolean getLeftStickButton(){
if (simController()){
return LightningShuffleboard.getBool(name, name + "LeftStickButton", false);
} else {
return super.getLeftStickButton();
}
}

/**
* @return the rightStickButton value from the controller/shuffleboard
*/
public boolean getRightStickButton(){
if (simController()){
return LightningShuffleboard.getBool(name, name + "RightStickButton", false);
} else {
return super.getRightStickButton();
}
}

/**
* @return the AButton value from the controller/shuffleboard
*/
public boolean getAButton(){
if (simController()){
return LightningShuffleboard.getBool(name, name + "AButton", false);
} else {
return super.getAButton();
}
}

/**
* @return the BButton value from the controller/shuffleboard
*/
public boolean getBButton(){
if (simController()){
return LightningShuffleboard.getBool(name, name + "BButton", false);
} else {
return super.getBButton();
}
}

/**
* @return the XButton value from the controller/shuffleboard
*/
public boolean getXButton(){
if (simController()){
return LightningShuffleboard.getBool(name, name + "XButton", false);
} else {
return super.getXButton();
}
}

/**
* @return the YButton value from the controller/shuffleboard
*/
public boolean getYButton(){
if (simController()){
return LightningShuffleboard.getBool(name, name + "YButton", false);
} else {
return super.getYButton();
}
}

/**
* @return the backButton value from the controller/shuffleboard
*/
public boolean getBackButton(){
if (simController()){
return LightningShuffleboard.getBool(name, name + "BackButton", false);
} else {
return super.getBackButton();
}
}

/**
* @return the startButton value from the controller/shuffleboard
*/
public boolean getStartButton(){
if (simController()){
return LightningShuffleboard.getBool(name, name + "StartButton", false);
} else {
return super.getStartButton();
}
}

/**
* Initializes all the values for the controller on shuffleboard
*/
public void initValues(){
LightningShuffleboard.getBool(name, name + "simController", false);
LightningShuffleboard.getDouble(name, name + "LeftX", 0d);
LightningShuffleboard.getDouble(name, name + "LeftY", 0d);
LightningShuffleboard.getDouble(name, name + "RightX", 0d);
LightningShuffleboard.getDouble(name, name + "RightY", 0d);
LightningShuffleboard.getDouble(name, name + "LeftTriggerAxis", 0d);
LightningShuffleboard.getDouble(name, name + "RightTriggerAxis", 0d);
LightningShuffleboard.getBool(name, name + "LeftBumper", false);
LightningShuffleboard.getBool(name, name + "RightBumper", false);
LightningShuffleboard.getBool(name, name + "LeftStickButton", false);
LightningShuffleboard.getBool(name, name + "RightStickButton", false);
LightningShuffleboard.getBool(name, name + "AButton", false);
LightningShuffleboard.getBool(name, name + "BButton", false);
LightningShuffleboard.getBool(name, name + "XButton", false);
LightningShuffleboard.getBool(name, name + "YButton", false);
LightningShuffleboard.getBool(name, name + "BackButton", false);
LightningShuffleboard.getBool(name, name + "StartButton", false);
}
}

0 comments on commit 75a5082

Please sign in to comment.