Skip to content

Commit

Permalink
temp
Browse files Browse the repository at this point in the history
  • Loading branch information
maxspier committed Dec 14, 2023
1 parent 24fc7b7 commit 7ffa69e
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 34 deletions.
8 changes: 8 additions & 0 deletions src/main/deploy/ShooterValueDataGenerated.dfa
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
0.5
0.26309475799897647
1.0
0.3598490045176868
1.5
0.6206778576674324
2.0
0.9494694075016604
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.team766.ViSIONbase;

import com.team766.framework.AprilTagErrorCode;
import com.team766.framework.Context;
import com.team766.robot.Robot;
import edu.wpi.first.math.geometry.Transform3d;
import edu.wpi.first.wpilibj.Filesystem;
Expand Down Expand Up @@ -144,7 +145,7 @@ public double shootAndCalculate() {

}
powersTried.add(power);
Robot.shooter.shoot(power); //TODO: Make sure this runs for ample time so ball can actually be shot
//Robot.shooter.shoot(power); //TODO: Make sure this runs for ample time so ball can actually be shot


return power;
Expand Down Expand Up @@ -269,7 +270,7 @@ public double thisHappenedWithShot(boolean wentIn, boolean wasLong){
powersTried.clear();
wasTooLong.clear();
first = true;
return -1;
return 0;
} else {
ballWentIn = false;

Expand Down
49 changes: 47 additions & 2 deletions src/main/java/com/team766/robot/OI.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,56 @@ public void run(final Context context) {


if(joystick2.getButton(1)){
Robot.shooter.shoot(1, 1);
//Robot.shooter.shoot(1, 1);
try {
Robot.shooter.testS(context);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}else{
Robot.shooter.shoot(0,0);
//Robot.shooter.shoot(0,0);
}

if(joystick2.getButtonPressed(2)){
try {
Robot.shooter.startNewCalibrationDistanceSession(context);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

if(joystick2.getButtonPressed(3)){
try {
Robot.shooter.inputDataFromShot(false, true, context);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

if(joystick2.getButtonPressed(4)){
try {
Robot.shooter.inputDataFromShot(false, false, context);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

if(joystick2.getButtonPressed(5)){
try {
Robot.shooter.inputDataFromShot(true, false, context);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

if(joystick2.getButtonPressed(6)){
Robot.shooter.resetCalibrationAndStoreDataInFine();
}


}
Expand Down
46 changes: 46 additions & 0 deletions src/main/java/com/team766/robot/mechanisms/Shooter.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package com.team766.robot.mechanisms;

import java.util.ArrayList;
import javax.swing.text.AbstractDocument.Content;
import com.team766.ViSIONbase.AutomaticShooterPowerCalibration;
import com.team766.framework.Context;
import com.team766.framework.Mechanism;
import com.team766.hal.MotorController;
import com.team766.hal.RobotProvider;
import com.team766.robot.procedures.ShootPower;

public class Shooter extends Mechanism {

Expand All @@ -11,8 +16,14 @@ public class Shooter extends Mechanism {
private MotorController leftShooterMotor;
private MotorController rightShooterMotor;




static AutomaticShooterPowerCalibration calibration;

private double lastSpeed = 0;
public Shooter(){
calibration = new AutomaticShooterPowerCalibration(1);
topShooterMotor = RobotProvider.instance.getMotor("shooter.topMotor");

leftShooterMotor = RobotProvider.instance.getMotor("shooter.leftMotor");
Expand All @@ -38,6 +49,7 @@ public void shoot(double speedSides, double speedTop){
}

public void shoot(double speed){
checkContextOwnership();
topShooterMotor.set(speed);
lastSpeed = speed;
//TODO: Check to see if this is the correct direction
Expand All @@ -48,5 +60,39 @@ public void shoot(double speed){
public double getLastSpeed(){
return lastSpeed;
}

public void testS(Context context) throws InterruptedException{
shootForFiveSeconds(0.8, context);

shoot(0,0);
System.out.println("iyrueajil;k");
}

public void startNewCalibrationDistanceSession(Context context) throws InterruptedException{
context.yield();
//Context contexta = new Context();
//context.startAsync(shootForFiveSeconds(ab, context));

double ab = calibration.shootAndCalculate();
context.startAsync(new ShootPower(ab));
log("ab: " + ab);
}

public void inputDataFromShot(boolean wentIn, boolean wasLong, Context context) throws InterruptedException{
double ab = calibration.thisHappenedWithShot(wentIn, wasLong);
context.startAsync(new ShootPower(ab));
}

public void resetCalibrationAndStoreDataInFine(){
calibration.reset();
}

public void shootForFiveSeconds(double power, Context context) throws InterruptedException{
shoot(power);
context.yield();
context.waitForSeconds(5);
}


}

29 changes: 0 additions & 29 deletions src/main/java/com/team766/robot/mechanisms/ShooterCalibrator.java

This file was deleted.

18 changes: 18 additions & 0 deletions src/main/java/com/team766/robot/procedures/ShootPower.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.team766.robot.procedures;

import com.team766.framework.Context;
import com.team766.framework.Procedure;
import com.team766.robot.Robot;

public class ShootPower extends Procedure {
private double power;
public ShootPower(double power){
this.power = power;
}
public void run(Context context){
context.takeOwnership(Robot.shooter);
Robot.shooter.shoot(power);
context.waitForSeconds(5);
Robot.shooter.shoot(0);
}
}
2 changes: 1 addition & 1 deletion src/test/java/com/team766/shooter/ShooterTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class ShooterTestCase {
public static void setUp() throws Exception {


calibration = new AutomaticShooterPowerCalibration(3);
calibration = new AutomaticShooterPowerCalibration(1);

//The powers we get back should model y = 0.15(2.5)^x
distancesToTest.add(0.5);
Expand Down

0 comments on commit 7ffa69e

Please sign in to comment.