mirror of
https://github.com/Team4388/2022NoWayHome.git
synced 2026-06-09 08:48:07 -06:00
Speedy regression + circle fitting for target track
This commit is contained in:
@@ -39,6 +39,8 @@ public class TrackTarget extends CommandBase {
|
|||||||
Pose2d pos = new Pose2d();
|
Pose2d pos = new Pose2d();
|
||||||
ArrayList<Point> points = new ArrayList<>();
|
ArrayList<Point> points = new ArrayList<>();
|
||||||
|
|
||||||
|
double m=0;
|
||||||
|
double b=0;
|
||||||
boolean isExecuted = false;
|
boolean isExecuted = false;
|
||||||
|
|
||||||
// public static Gains m_aimGains;
|
// public static Gains m_aimGains;
|
||||||
@@ -88,6 +90,14 @@ public class TrackTarget extends CommandBase {
|
|||||||
double distance = (VisionConstants.TARGET_HEIGHT - VisionConstants.LIME_HEIGHT) / Math.tan(y_rot);
|
double distance = (VisionConstants.TARGET_HEIGHT - VisionConstants.LIME_HEIGHT) / Math.tan(y_rot);
|
||||||
DesmosServer.putDouble("distance", distance);
|
DesmosServer.putDouble("distance", distance);
|
||||||
|
|
||||||
|
updateRegressionDesmos();
|
||||||
|
double regressedDistance = distanceRegression(distance);
|
||||||
|
DesmosServer.putDouble("distanceReg", regressedDistance);
|
||||||
|
|
||||||
|
//Vision odemetry circle fit based pose estimate
|
||||||
|
Point targetOffset = m_visionOdometry.getTargetOffset();
|
||||||
|
DesmosServer.putPoint("targetOff", targetOffset);
|
||||||
|
|
||||||
// isExecuted = true;
|
// isExecuted = true;
|
||||||
}
|
}
|
||||||
catch (Exception e){
|
catch (Exception e){
|
||||||
@@ -101,6 +111,15 @@ public class TrackTarget extends CommandBase {
|
|||||||
// m_turret.runshooterRotatePID(m_targetAngle);
|
// m_turret.runshooterRotatePID(m_targetAngle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final double distanceRegression(double distance) {
|
||||||
|
return m * distance + b;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateRegressionDesmos() {
|
||||||
|
m = DesmosServer.readDouble("m");
|
||||||
|
b = DesmosServer.readDouble("b");
|
||||||
|
}
|
||||||
|
|
||||||
// Called once the command ends or is interrupted.
|
// Called once the command ends or is interrupted.
|
||||||
@Override
|
@Override
|
||||||
public void end(boolean interrupted) {
|
public void end(boolean interrupted) {
|
||||||
|
|||||||
@@ -91,12 +91,7 @@ public class VisionOdometry extends SubsystemBase {
|
|||||||
m_camera.setLED(on ? VisionLEDMode.kOn : VisionLEDMode.kOff);
|
m_camera.setLED(on ? VisionLEDMode.kOn : VisionLEDMode.kOff);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Gets estimated odometry based on limelight data
|
public Point getTargetOffset() throws VisionObscuredException {
|
||||||
*
|
|
||||||
* @return The estimated odometry pose, including gyro rotation
|
|
||||||
* @throws VisionObscuredException
|
|
||||||
*/
|
|
||||||
public Pose2d getVisionOdometry() throws VisionObscuredException {
|
|
||||||
ArrayList<Point> screenPoints = getTargetPoints();
|
ArrayList<Point> screenPoints = getTargetPoints();
|
||||||
|
|
||||||
if(screenPoints.size() < 3)
|
if(screenPoints.size() < 3)
|
||||||
@@ -111,14 +106,25 @@ public class VisionOdometry extends SubsystemBase {
|
|||||||
guess = iterateGuess(guess, points);
|
guess = iterateGuess(guess, points);
|
||||||
}
|
}
|
||||||
|
|
||||||
guess = correctGuessForCenter(guess, m_shooter.getBoomBoomAngleDegrees());
|
return guess;
|
||||||
// guess = correctGuessForGyro(guess, m_drive.getRegGyro().getDegrees());
|
}
|
||||||
|
|
||||||
SmartDashboard.putNumber("Vision ODO x: ", guess.x);
|
/** Gets estimated odometry based on limelight data
|
||||||
SmartDashboard.putNumber("Vision ODO y: ", guess.y);
|
*
|
||||||
|
* @return The estimated odometry pose, including gyro rotation
|
||||||
|
* @throws VisionObscuredException
|
||||||
|
*/
|
||||||
|
public Pose2d getVisionOdometry() throws VisionObscuredException {
|
||||||
|
Point targetOffset = getTargetOffset();
|
||||||
|
|
||||||
|
targetOffset = correctGuessForCenter(targetOffset, m_shooter.getBoomBoomAngleDegrees());
|
||||||
|
targetOffset = correctGuessForGyro(targetOffset, m_drive.getRegGyro().getDegrees());
|
||||||
|
|
||||||
|
SmartDashboard.putNumber("Vision ODO x: ", targetOffset.x);
|
||||||
|
SmartDashboard.putNumber("Vision ODO y: ", targetOffset.y);
|
||||||
|
|
||||||
Rotation2d rotation = new Rotation2d(Math.toDegrees(m_drive.getRegGyro().getDegrees()));
|
Rotation2d rotation = new Rotation2d(Math.toDegrees(m_drive.getRegGyro().getDegrees()));
|
||||||
Pose2d odometryPose = new Pose2d(guess.x, guess.y, rotation);
|
Pose2d odometryPose = new Pose2d(targetOffset.x, targetOffset.y, rotation);
|
||||||
|
|
||||||
return odometryPose;
|
return odometryPose;
|
||||||
}
|
}
|
||||||
@@ -128,8 +134,7 @@ public class VisionOdometry extends SubsystemBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean getLEDs() {
|
public boolean getLEDs() {
|
||||||
if (m_camera.getLEDMode() == VisionLEDMode.kOff) return false;
|
return m_camera.getLEDMode() != VisionLEDMode.kOff;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateOdometryWithVision(){
|
public void updateOdometryWithVision(){
|
||||||
@@ -141,6 +146,7 @@ public class VisionOdometry extends SubsystemBase {
|
|||||||
err.printStackTrace();
|
err.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Reverse 3d projects target points from screen coordinates to 3d space
|
/** Reverse 3d projects target points from screen coordinates to 3d space
|
||||||
* <p>
|
* <p>
|
||||||
* Uses the known height of the target to project points
|
* Uses the known height of the target to project points
|
||||||
@@ -286,9 +292,8 @@ public class VisionOdometry extends SubsystemBase {
|
|||||||
* @return The angle corrected for the quadrent
|
* @return The angle corrected for the quadrent
|
||||||
*/
|
*/
|
||||||
public static final double correctQuadrent(double angle, Point guess, Point circlePoint) {
|
public static final double correctQuadrent(double angle, Point guess, Point circlePoint) {
|
||||||
if(circlePoint.x - guess.x < 0) {
|
if(circlePoint.x - guess.x < 0)
|
||||||
return angle - Math.PI;
|
return angle - Math.PI;
|
||||||
}
|
|
||||||
|
|
||||||
return angle;
|
return angle;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user