Skip to content

Commit

Permalink
Merge pull request #4 from ThePinkAlliance/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
devsamuelv authored Jun 30, 2022
2 parents 9fcf42a + 8447017 commit 082be1c
Show file tree
Hide file tree
Showing 19 changed files with 398 additions and 166 deletions.
4 changes: 2 additions & 2 deletions ThePinkAlliance.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"fileName": "ThePinkAlliance.json",
"name": "ThePinkAlliance",
"version": "2.0.12",
"version": "2.0.14",
"uuid": "9619F7EA-7F96-4236-9D94-02338DFED572",
"mavenUrls": [
"https://jitpack.io",
Expand All @@ -13,7 +13,7 @@
{
"groupId": "com.github.ThePinkAlliance",
"artifactId": "core",
"version": "2.0.12"
"version": "2.0.14"
}
],
"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.12'
version = '2.0.14'

sourceCompatibility = JavaVersion.VERSION_11 // java 11
targetCompatibility = JavaVersion.VERSION_11
Expand All @@ -16,13 +16,17 @@ repositories {
}
maven { url = uri('https://maven.revrobotics.com/') }
maven { url = uri('https://devsite.ctr-electronics.com/maven/release/') }
maven {
url = uri("https://plugins.gradle.org/m2/")
}
}

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.shuffleboard:api: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'
Expand All @@ -32,6 +36,7 @@ dependencies {
implementation 'com.revrobotics.frc:REVLib-java:2022.1.1'
}


jar {
def env = System.getenv("JITPACK")

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.ThePinkAlliance.core.annotations;

import java.lang.annotation.ElementType;

public @interface Untested {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.ThePinkAlliance.core.ctre.talon;

public abstract class TalonUtils {

public static double FULL_TALON_ROTATION_TICKS = 2048;
}
23 changes: 23 additions & 0 deletions src/main/java/com/ThePinkAlliance/core/joystick/Joystick.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@ public enum Buttons {
}
}

public enum POV_TYPE {
NORTH(0),
EAST(90),
WEST(270),
SOUTH(180);

int id = 0;

POV_TYPE(int id) {
this.id = id;
}
}

public enum Axis {
LEFT_X(JoystickMap.LEFT_X_AXIS),
LEFT_Y(JoystickMap.LEFT_Y_AXIS),
Expand Down Expand Up @@ -55,4 +68,14 @@ public JoystickButton getButton(Buttons button) {
public JoystickAxis getAxis(Axis axis) {
return new JoystickAxis(this, axis);
}

public boolean povActivated(POV_TYPE type) {
int pov = this.joy.getPOV();

if (pov == type.id) {
return true;
} else {
return false;
}
}
}
73 changes: 9 additions & 64 deletions src/main/java/com/ThePinkAlliance/core/joystick/JoystickAxis.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,87 +2,32 @@

import com.ThePinkAlliance.core.joystick.Joystick.Axis;
import com.ThePinkAlliance.core.joystick.Joystick.Buttons;
import com.ThePinkAlliance.core.util.joystick.JoystickUtils;
import java.util.function.Supplier;

public class JoystickAxis {

private Joystick joystick;
private Axis axis;
private double axis_limit;

private boolean cube = false;
private boolean deadband = false;

private double deadbandSetpoint = 0.05;

public JoystickAxis(Joystick joystick, Axis axis) {
this.joystick = joystick;
this.axis = axis;
this.axis_limit = 1;
}

public JoystickAxis clearDeadband() {
this.deadband = false;

return this;
public Supplier<Double> getInvertedSupplier() {
return () -> (this.joystick.getJoystick().getRawAxis(this.axis.id) * -1);
}

public JoystickAxis clearCubing() {
this.cube = false;

return this;

public double getInverted() {
return this.joystick.getJoystick().getRawAxis(this.axis.id) * -1;
}

public JoystickAxis withLimit(double max) {
this.axis_limit = max / 100;

return this;
public Supplier<Double> getSuppliedValue() {
return () -> this.joystick.getJoystick().getRawAxis(this.axis.id);
}

public Supplier<Double> invert() {
double x =
(this.joystick.getJoystick().getRawAxis(this.axis.id) * -1) * axis_limit;

return () -> modAxis(x);
}

public JoystickAxis withAxisCubed() {
this.cube = true;

return this;
}

public JoystickAxis withDeadband() {
this.deadband = true;

return this;
}

public JoystickAxis withDeadband(double deadband) {
this.deadband = true;
this.deadbandSetpoint = deadband;

return this;
}

public Supplier<Double> getSuppliedValue() {
double x =
this.joystick.getJoystick().getRawAxis(this.axis.id) * axis_limit;

return () -> modAxis(x);
}

private double modAxis(double x) {
if (cube) {
x = Math.copySign(x * x * x, x);
}

if (deadband) {
x = JoystickUtils.deadband(x, deadbandSetpoint);
}

return x;
public double get() {
return this.joystick.getJoystick().getRawAxis(this.axis.id);
}

public JoystickButton getJoystickButton() {
Expand Down
152 changes: 152 additions & 0 deletions src/main/java/com/ThePinkAlliance/core/limelight/Limelight.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
package com.ThePinkAlliance.core.limelight;

import edu.wpi.first.networktables.NetworkTable;
import edu.wpi.first.networktables.NetworkTableEntry;
import edu.wpi.first.networktables.NetworkTableInstance;

public class Limelight {

public enum LED_MODE {
BLINK(2),
ON(3),
OFF(1),
PIPELINE(0);

private int mode;

LED_MODE(int mode) {
this.mode = mode;
}

public int get() {
return mode;
}
}

public enum GAME_TARGET_HEIGHTS {
RAPID_REACT_TOP_HUB(102.375);

private double height;

GAME_TARGET_HEIGHTS(double height) {
this.height = height;
}

public double get() {
return height;
}
}

LED_MODE CURRENT_LED_MODE;

double HEIGHT_FROM_FLOOR;
double MOUNTED_ANGLE;
double REFLECTED_TAPE_HEIGHT;
double HORIZONTAL_OFFSET;

NetworkTable table;
NetworkTableEntry ty;
NetworkTableEntry tx;
NetworkTableEntry tv;
NetworkTableEntry ledMode;

/**
* @param height_from_floor The limelight lens height from the floor in inches.
* @param mounted_angle The current pitch angle of the limelight on its mount.
*/
public Limelight(double height_from_floor, double mounted_angle) {
this.HEIGHT_FROM_FLOOR = height_from_floor;
this.MOUNTED_ANGLE = mounted_angle;
this.REFLECTED_TAPE_HEIGHT = GAME_TARGET_HEIGHTS.RAPID_REACT_TOP_HUB.get();
this.HORIZONTAL_OFFSET = 0;

configureLimelight();
}

/**
* @param height_from_floor The limelight lens height from the floor in inches.
* @param mounted_angle The current pitch angle of the limelight on its mount.
* @param horizontal_offset The angluar offset of the limelight from the center of the robot.
*/
public Limelight(
double height_from_floor,
double mounted_angle,
double horizontal_offset
) {
this.HEIGHT_FROM_FLOOR = height_from_floor;
this.MOUNTED_ANGLE = mounted_angle;
this.REFLECTED_TAPE_HEIGHT = GAME_TARGET_HEIGHTS.RAPID_REACT_TOP_HUB.get();
this.HORIZONTAL_OFFSET = horizontal_offset;

configureLimelight();
}

private void configureLimelight() {
this.CURRENT_LED_MODE = LED_MODE.OFF;

this.table = NetworkTableInstance.getDefault().getTable("limelight");
this.ty = this.table.getEntry("ty");
this.tx = this.table.getEntry("tx");

this.ledMode = this.table.getEntry("ledMode");
this.tv = this.table.getEntry("tv");

// Configure the limelight led's, camera mode and pipeline
this.ledMode.setNumber(this.CURRENT_LED_MODE.get());
this.table.getEntry("camMode").setNumber(0);
this.table.getEntry("pipeline").setNumber(0);
}

/**
*
* @param targetHeight The height of the reflective tape in inches.
*/
public void configureTargetHeight(double targetHeight) {
this.REFLECTED_TAPE_HEIGHT = targetHeight;
}

/**
*
* @param targetHeight The height of the reflective tape in inches.
*/
public void configureTargetHeight(GAME_TARGET_HEIGHTS targetHeight) {
this.configureTargetHeight(targetHeight.get());
}

public double calculateAngleOffset() {
return tx.getDouble(0) + HORIZONTAL_OFFSET;
}

/**
*
* @return if any valid targets are found.
*/
public boolean foundTarget() {
return tv.getDouble(0) > 0;
}

/**
*
* @return amount of valid targets are found.
*/
public double foundTargets() {
return tv.getDouble(0);
}

/**
* Returns the horizontal difference from the center of the detected target.
*/
public double getHorizontalDiff() {
return this.tx.getDouble(0);
}

public double calculateDistance() {
double verticalOffset = ty.getDouble(0);
double targetAngleDeg = MOUNTED_ANGLE + verticalOffset;

return (
(REFLECTED_TAPE_HEIGHT - HEIGHT_FROM_FLOOR) /
Math.tan(Math.toRadians(targetAngleDeg))
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.ThePinkAlliance.core.limelight;

public class LimelightConstants {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.ThePinkAlliance.core.math;

import edu.wpi.first.math.interpolation.TimeInterpolatableBuffer.InterpolateFunction;

public class InterpolatingTimestamp implements InterpolateFunction<Double> {

@Override
public Double interpolate(Double start, Double end, double t) {
return null;
}
}
Loading

0 comments on commit 082be1c

Please sign in to comment.