Skip to content

Commit 4d5727b

Browse files
committed
Use target distance instead of time for drive to target in auto mode
1 parent 444e85f commit 4d5727b

1 file changed

Lines changed: 41 additions & 47 deletions

File tree

  • TeamCode/src/main/java/org/firstinspires/ftc/teamcode/IntoTheDeep24_25/auto/test

TeamCode/src/main/java/org/firstinspires/ftc/teamcode/IntoTheDeep24_25/auto/test/autoTemplate2.java

Lines changed: 41 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88
import com.qualcomm.robotcore.hardware.HardwareMap;
99
import com.qualcomm.robotcore.hardware.Servo;
1010
import com.qualcomm.robotcore.util.ElapsedTime;
11+
1112
import org.firstinspires.ftc.teamcode.IntoTheDeep24_25.pidMaybe;
1213
import org.firstinspires.ftc.teamcode.TemplateJanx;
1314

1415
@Disabled
15-
public class autoTemplate2 extends TemplateJanx{
16+
public class autoTemplate2 extends TemplateJanx {
1617
private ElapsedTime runtime = new ElapsedTime();
1718
static final double COUNTS_PER_MOTOR_REV = 288; // 288- core hex motor
1819
static final double DRIVE_GEAR_REDUCTION = 1.0; // No External Gearing.
@@ -29,7 +30,7 @@ public autoTemplate2(HardwareMap h) {
2930
super(h);
3031
this.h = h;
3132
runtime.reset();
32-
pid = new pidMaybe(0.004,0.0001,0.15);
33+
pid = new pidMaybe(0.004, 0.0001, 0.15);
3334
}
3435

3536
public void armInit(String a, String e, String c) {
@@ -59,69 +60,64 @@ public void wheelInit(String frontRight, String backRight, String backleft, Stri
5960
fl.setMode(DcMotor.RunMode.RUN_TO_POSITION);
6061
}
6162

62-
public void drive(double speed, double leftInches, double rightInches,int timeOuts) {
63+
public void drive(double speed, double leftInches, double rightInches, int timeOuts) {
6364
int flTarget = fl.getCurrentPosition() + (int) (leftInches * COUNTS_PER_INCH);
6465
int blTarget = bl.getCurrentPosition() + (int) (leftInches * COUNTS_PER_INCH);
6566
int brTarget = br.getCurrentPosition() + (int) (rightInches * COUNTS_PER_INCH);
6667
int frTarget = fr.getCurrentPosition() + (int) (rightInches * COUNTS_PER_INCH);
67-
while (runtime.seconds() < timeOuts){
68+
while (fl.getCurrentPosition() < flTarget && fr.getCurrentPosition() < frTarget) {
6869
fl.setTargetPosition(flTarget);
69-
fr.setTargetPosition(frTarget);
70-
bl.setTargetPosition(blTarget);
71-
br.setTargetPosition(brTarget);
72-
73-
fr.setMode(DcMotor.RunMode.RUN_TO_POSITION);
74-
br.setMode(DcMotor.RunMode.RUN_TO_POSITION);
75-
bl.setMode(DcMotor.RunMode.RUN_TO_POSITION);
76-
fl.setMode(DcMotor.RunMode.RUN_TO_POSITION);
77-
78-
fr.setPower(1);
79-
br.setPower(1);
80-
bl.setPower(1);
81-
fl.setPower(1);
82-
}
70+
fr.setTargetPosition(frTarget);
71+
bl.setTargetPosition(blTarget);
72+
br.setTargetPosition(brTarget);
73+
74+
fr.setMode(DcMotor.RunMode.RUN_TO_POSITION);
75+
br.setMode(DcMotor.RunMode.RUN_TO_POSITION);
76+
bl.setMode(DcMotor.RunMode.RUN_TO_POSITION);
77+
fl.setMode(DcMotor.RunMode.RUN_TO_POSITION);
78+
79+
fr.setPower(1);
80+
br.setPower(1);
81+
bl.setPower(1);
82+
fl.setPower(1);
83+
}
8384
fr.setPower(0);
8485
br.setPower(0);
8586
bl.setPower(0);
8687
fl.setPower(0);
8788
}
88-
public void turn(boolean right)
89-
{
89+
90+
public void turn(boolean right) {
9091
int turn = 33;
91-
if(right)
92-
{
93-
drive(400,-turn,turn,3);
94-
}
95-
else
96-
{
97-
drive(400,turn,-turn,3);
92+
if (right) {
93+
drive(400, -turn, turn, 3);
94+
} else {
95+
drive(400, turn, -turn, 3);
9896
}
9997
}
10098

101-
public void moveArm(int targetPos)
102-
{
103-
arm.setTargetPosition(targetPos);
104-
//double power = pid.calculatePower(targetPos, arm.getCurrentPosition(),time);
105-
arm.setMode(DcMotor.RunMode.RUN_TO_POSITION);
106-
arm.setPower(1);
107-
// arm.setPower(power);
99+
public void moveArm(int targetPos) {
100+
arm.setTargetPosition(targetPos);
101+
//double power = pid.calculatePower(targetPos, arm.getCurrentPosition(),time);
102+
arm.setMode(DcMotor.RunMode.RUN_TO_POSITION);
103+
arm.setPower(1);
104+
// arm.setPower(power);
108105
}
109106

110-
public void open()
111-
{
112-
while(runtime.seconds()<2) {
107+
public void open() {
108+
while (runtime.seconds() < 2) {
113109
claw.setPosition(0);
114110
}
115111
}
116-
public void close()
117-
{
118-
while(runtime.seconds()<2) {
112+
113+
public void close() {
114+
while (runtime.seconds() < 2) {
119115
claw.setPosition(1);
120116
}
121117
}
122-
public void claw(boolean open,int time)
123-
{
124-
while(runtime.seconds()<time) {
118+
119+
public void claw(boolean open, int time) {
120+
while (runtime.seconds() < time) {
125121
if (open) {
126122
claw.setPosition(0);
127123
}
@@ -172,10 +168,8 @@ public void claw(boolean open,int time)
172168
bl.setPower(0);
173169
fl.setPower(0);
174170
*/
175-
public void strafe(boolean left)
176-
{
177-
if(left)
178-
{
171+
public void strafe(boolean left) {
172+
if (left) {
179173

180174
}
181175
}

0 commit comments

Comments
 (0)