mirror of
https://github.com/Team4388/2023WayOfTheRobot.git
synced 2026-06-09 00:37:59 -06:00
code review
This commit is contained in:
@@ -22,7 +22,7 @@ import edu.wpi.first.wpilibj2.command.CommandScheduler;
|
|||||||
import frc4388.utility.RobotTime;
|
import frc4388.utility.RobotTime;
|
||||||
|
|
||||||
import frc4388.robot.subsystems.Location;
|
import frc4388.robot.subsystems.Location;
|
||||||
|
import frc4388.robot.subsystems.Apriltags.Tag;
|
||||||
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
|
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -71,12 +71,9 @@ public class Robot extends TimedRobot {
|
|||||||
// block in order for anything in the Command-based framework to work.
|
// block in order for anything in the Command-based framework to work.
|
||||||
CommandScheduler.getInstance().run();
|
CommandScheduler.getInstance().run();
|
||||||
|
|
||||||
// Call position and rotation reorder
|
final Tag pos = location.getPosRot();
|
||||||
location.reoderPrio();
|
|
||||||
|
|
||||||
final Object[] pos = location.getPosition();
|
|
||||||
if (pos != null) {
|
if (pos != null) {
|
||||||
SmartDashboard.putNumber("name", (Double) pos[0]);
|
SmartDashboard.putNumber("x position", pos.x);
|
||||||
}
|
}
|
||||||
|
|
||||||
//ystem.out.print(apriltagPos[0]);
|
//ystem.out.print(apriltagPos[0]);
|
||||||
|
|||||||
@@ -9,41 +9,28 @@ import edu.wpi.first.networktables.NetworkTableInstance;
|
|||||||
|
|
||||||
public class Apriltags {
|
public class Apriltags {
|
||||||
public static class Tag {
|
public static class Tag {
|
||||||
boolean visible = true;
|
public boolean visible = true;
|
||||||
double x, y, z = 0;
|
public double x, y, z = 0;
|
||||||
}
|
public double ry, rp, rr = 0;
|
||||||
|
|
||||||
public Object[] getApriltagPosition() {
|
|
||||||
final var tagTable = NetworkTableInstance.getDefault().getTable("apriltag");
|
|
||||||
final var tag = new Tag();
|
|
||||||
// integrate the tag system
|
|
||||||
|
|
||||||
// return new Object[] {true,
|
|
||||||
// tagTable.getEntry("TagPosX"),
|
|
||||||
// tagTable.getEntry("TagPosY"),
|
|
||||||
// tagTable.getEntry("TagPosZ")
|
|
||||||
// };
|
|
||||||
|
|
||||||
return new Object[] {true,
|
|
||||||
1,
|
|
||||||
2,
|
|
||||||
3
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object[] getApriltagRotation() {
|
public Tag getTagPosRot() {
|
||||||
final var tagTable = NetworkTableInstance.getDefault().getTable("apriltag");
|
final var tagTable = NetworkTableInstance.getDefault().getTable("apriltag");
|
||||||
|
|
||||||
return new Object[] {true,
|
final Tag tag = new Tag();
|
||||||
tagTable.getEntry("TagRotY"),
|
tag.visible = isAprilTag();
|
||||||
tagTable.getEntry("TagRotP"),
|
tag.x = tagTable.getEntry("TagPosX").getDouble(0);
|
||||||
tagTable.getEntry("TagRotR")
|
tag.y = tagTable.getEntry("TagPosY").getDouble(0);
|
||||||
};
|
tag.z = tagTable.getEntry("TagPosZ").getDouble(0);
|
||||||
|
tag.ry = tagTable.getEntry("TagRotY").getDouble(0);
|
||||||
|
tag.rp = tagTable.getEntry("TagRotP").getDouble(0);
|
||||||
|
tag.rr = tagTable.getEntry("TagRotR").getDouble(0);
|
||||||
|
|
||||||
|
return tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAprilTag() {
|
public boolean isAprilTag() {
|
||||||
final var tagTable = NetworkTableInstance.getDefault().getTable("apriltag");
|
final var tagTable = NetworkTableInstance.getDefault().getTable("apriltag");
|
||||||
// return tagTable.getEntry("IsTag").getBoolean(false);
|
return tagTable.getEntry("IsTag").getBoolean(false);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,40 +1,27 @@
|
|||||||
package frc4388.robot.subsystems;
|
package frc4388.robot.subsystems;
|
||||||
|
|
||||||
import frc4388.robot.subsystems.Apriltags;
|
import frc4388.robot.subsystems.Apriltags.Tag;
|
||||||
|
|
||||||
public class Location {
|
public class Location {
|
||||||
final Apriltags Apriltag = new Apriltags();
|
final Apriltags apriltag = new Apriltags();
|
||||||
|
|
||||||
private boolean isLimelight = false;
|
private boolean isLimelight = false;
|
||||||
private boolean isApriltag = false;
|
private boolean isApriltag = false;
|
||||||
|
|
||||||
//Determines which source to get pos and rot from and also resets
|
//Determines which source to get pos and rot from and also resets
|
||||||
public void reoderPrio(){
|
private void reoderPrio(){
|
||||||
isLimelight = false; //If limelight gets position and if within a certain range of poles
|
isLimelight = false; //If limelight gets position and if within a certain range of poles
|
||||||
isApriltag = Apriltag.isAprilTag();
|
isApriltag = apriltag.isAprilTag();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object[] getPosition() {
|
public Tag getPosRot() {
|
||||||
if(isLimelight){
|
reoderPrio();
|
||||||
//Return Limelight Position
|
if(isApriltag){
|
||||||
}else if(isApriltag){
|
return apriltag.getTagPosRot();
|
||||||
return Apriltag.getApriltagPosition();
|
} else if (isLimelight) {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object[] getRotation() {
|
|
||||||
Object[] Rotation = {};
|
|
||||||
|
|
||||||
if(isLimelight){
|
|
||||||
//Return Limelight Rotation
|
|
||||||
}else if(isApriltag){
|
|
||||||
return Apriltag.getApriltagRotation();
|
|
||||||
}else{
|
|
||||||
//Return odometry Rotation, last resort
|
|
||||||
}
|
|
||||||
|
|
||||||
return Rotation;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user