Skip to content

Commit

Permalink
Added JoystickUtils, Created a wrapper for neo 550
Browse files Browse the repository at this point in the history
  • Loading branch information
devsamuelv committed Apr 20, 2022
1 parent 14eac30 commit 1086153
Show file tree
Hide file tree
Showing 9 changed files with 150 additions and 34 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/gradle-wrapper-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ name: "Validate Gradle Wrapper"
on:
push:
branches:
- master
- main
pull_request:
branches:
- master
- main

jobs:
validation:
Expand Down
4 changes: 2 additions & 2 deletions ThePinkAlliance.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"fileName": "ThePinkAlliance.json",
"name": "ThePinkAlliance",
"version": "2.0.8",
"version": "2.0.9",
"uuid": "9619F7EA-7F96-4236-9D94-02338DFED572",
"mavenUrls": ["https://jitpack.io"],
"jsonUrl": "https://raw.githubusercontent.com/ThePinkAlliance/core/main/ThePinkAlliance.json",
"javaDependencies": [
{
"groupId": "com.github.ThePinkAlliance",
"artifactId": "core",
"version": "2.0.8"
"version": "2.0.9"
}
],
"jniDependencies": [],
Expand Down
7 changes: 6 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'java-library'
apply plugin: 'maven-publish'

group = 'com.ThePinkAlliance.core'
version = '2.0.8'
version = '2.0.9'

sourceCompatibility = JavaVersion.VERSION_11 // java 11
targetCompatibility = JavaVersion.VERSION_11
Expand All @@ -12,17 +12,22 @@ repositories {
maven {
url = uri('https://frcmaven.wpi.edu/artifactory/release/')
}
maven { url = uri('https://maven.revrobotics.com/') }
maven { url = uri('https://devsite.ctr-electronics.com/maven/release/') }
}

dependencies {
implementation 'com.google.guava:guava:29.0-jre'

implementation 'edu.wpi.first.wpilibj:wpilibj-java:2022.4.1'
implementation 'edu.wpi.first.shuffleboard:shuffleboard:2022.4.1'
implementation 'edu.wpi.first.wpilibNewCommands:wpilibNewCommands-java:2022.4.1'
implementation 'edu.wpi.first.wpiutil:wpiutil-java:2022.4.1'
implementation 'edu.wpi.first.cscore:cscore-java:2022.4.1'
implementation 'edu.wpi.first.ntcore:ntcore-java:2022.4.1'
implementation 'edu.wpi.first.wpimath:wpimath-java:2022.4.1'

implementation 'com.revrobotics.frc:REVLib-java:2022.1.0'
}

java {
Expand Down
37 changes: 37 additions & 0 deletions src/main/java/com/ThePinkAlliance/core/logger/CommandLogger.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.ThePinkAlliance.core.logger;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.sql.Timestamp;
import java.util.Date;

public class CommandLogger {

private String commandName;
private String filename;
private String directory = "/home/lvuser/pink/logger/";

public CommandLogger(String commandName) {
this.commandName = commandName;
this.filename = commandName + ".command.csv";
}

public void recordWithTime(String[] rows, Object... objects) {
String timestamp = new Timestamp(new Date().getTime()).toString();
File file = new File(
directory + commandName + "-" + timestamp + ".command.csv"
);
FileWriter writer;

try {
writer = new FileWriter(file);

if (!file.exists()) {
file.createNewFile();
}
} catch (IOException err) {
err.printStackTrace();
}
}
}
16 changes: 16 additions & 0 deletions src/main/java/com/ThePinkAlliance/core/rev/RevNeo550.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.ThePinkAlliance.core.rev;

import com.revrobotics.CANSparkMax;
import com.revrobotics.CANSparkMaxLowLevel;

public class RevNeo550 extends CANSparkMax {

/**
* This will configure a rev neo with amperage limit's by default.
* @param channel
*/
public RevNeo550(final int channel) {
super(channel, CANSparkMaxLowLevel.MotorType.kBrushless);
this.setSmartCurrentLimit(20);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.ThePinkAlliance.core.shooter;

public interface TargetPackage {
public double kP = 0;
public double kFF = 0;
public double rpm = 0;
public double hoodPosition = 0;
public double getKP();

public double getKFF();

public double getRpm();

public double getHoodPosition();
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.ThePinkAlliance.core.shooter;

public class TargetPackageHelper {

public TargetPackage create(
double ff,
double kP,
double rpm,
double hoodPosition
) {
return new TargetPackage() {
@Override
public double getKFF() {
return ff;
}

@Override
public double getKP() {
return kP;
}

@Override
public double getRpm() {
return rpm;
}

@Override
public double getHoodPosition() {
return hoodPosition;
}
};
}
}
47 changes: 47 additions & 0 deletions src/main/java/com/ThePinkAlliance/core/util/JoystickUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.ThePinkAlliance.core.util;

public class JoystickUtils {

public static double deadband(double value, double deadband) {
if (Math.abs(value) > deadband) {
if (value > 0.0) {
return (value - deadband) / (1.0 - deadband);
} else {
return (value + deadband) / (1.0 - deadband);
}
} else {
return 0.0;
}
}

/**
* Apply deadband to the joystick input and Cube the output
* @param value is the raw joystick input
* @return the filtered joystick input
*/
public static double modifyAxisCubed(double value) {
// Deadband
value = deadband(value, 0.05);

// Cubing due to raw power until robot reaches competition weight.
value = Math.copySign(value * value * value, value);

return value;
}

/**
* Apply deadband to the joystick input and Cube the output
* @param value is the raw joystick input
* @param deadband is the wanted deadband applied
* @return the filtered joystick input
*/
public static double modifyAxisCubed(double value, double deadband) {
// Deadband
value = deadband(value, deadband);

// Cubing due to raw power until robot reaches competition weight.
value = Math.copySign(value * value * value, value);

return value;
}
}

0 comments on commit 1086153

Please sign in to comment.