-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from ftc16072/DR4b
Dr4b
- Loading branch information
Showing
3 changed files
with
103 additions
and
2 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
...e/src/main/java/org/firstinspires/ftc/teamcode/ftc16072/Mechanisms/DoubleReverse4Bar.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package org.firstinspires.ftc.teamcode.ftc16072.Mechanisms; | ||
|
||
import com.qualcomm.robotcore.hardware.DcMotor; | ||
import com.qualcomm.robotcore.hardware.DcMotorSimple; | ||
import com.qualcomm.robotcore.hardware.HardwareMap; | ||
|
||
import org.firstinspires.ftc.teamcode.ftc16072.Tests.QQTest; | ||
import org.firstinspires.ftc.teamcode.ftc16072.Tests.TestTwoMotors; | ||
import org.firstinspires.ftc.teamcode.ftc16072.Util.PIDFController; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
public class DoubleReverse4Bar extends QQMechanism{ | ||
public static final double TEST_SPEED = 0.2; | ||
DcMotor leftMotor; | ||
DcMotor rightMotor; | ||
public static double kP = 0.001; | ||
public static double kI = 0.0; | ||
public static double kD = 0.0; | ||
public static double kF = 0.0; | ||
public static double max = 0.8; | ||
public static double min = 0.0; | ||
|
||
int currentPos; | ||
int desiredPos; | ||
|
||
|
||
PIDFController pidfController = new PIDFController(kP,kI,kD,kF,max,min); | ||
|
||
public int INTAKE_POS = 0;//TODO: make real | ||
|
||
public int PLACE_POS = 600; //TODO: make real :) | ||
|
||
@Override | ||
public void init(HardwareMap hwMap) { | ||
leftMotor = hwMap.get(DcMotor.class, "left_4bar_motor"); | ||
rightMotor = hwMap.get(DcMotor.class, "right_4bar_motor"); | ||
leftMotor.setDirection(DcMotorSimple.Direction.REVERSE); | ||
leftMotor.setMode(DcMotor.RunMode.RUN_USING_ENCODER); | ||
rightMotor.setMode(DcMotor.RunMode.RUN_USING_ENCODER); | ||
leftMotor.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE); | ||
rightMotor.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE); | ||
} | ||
|
||
public void setPosition(int desiredPos){ | ||
this.desiredPos = desiredPos; | ||
} | ||
public void manualPositionChange(int changeAmount){ | ||
desiredPos += changeAmount; | ||
} | ||
@Override | ||
public void update(){ | ||
currentPos = (leftMotor.getCurrentPosition() + rightMotor.getCurrentPosition())/2;//average left and right speeds | ||
double motorPower = pidfController.calculate(desiredPos,currentPos); | ||
leftMotor.setPower(motorPower); | ||
rightMotor.setPower(motorPower); | ||
} | ||
|
||
@Override | ||
public List<QQTest> getTests() { | ||
return Arrays.asList(new TestTwoMotors("fourbar", TEST_SPEED,leftMotor,rightMotor)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
TeamCode/src/main/java/org/firstinspires/ftc/teamcode/ftc16072/Tests/TestTwoMotors.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package org.firstinspires.ftc.teamcode.ftc16072.Tests; | ||
|
||
import com.qualcomm.robotcore.hardware.DcMotor; | ||
|
||
import org.firstinspires.ftc.robotcore.external.Telemetry; | ||
|
||
public class TestTwoMotors extends QQTest{ | ||
DcMotor leftMotor; | ||
DcMotor rightMotor; | ||
double speed; | ||
public TestTwoMotors(String name, double speed, DcMotor leftMotor, DcMotor rightMotor){ | ||
super(name); | ||
this.speed = speed; | ||
this.leftMotor = leftMotor; | ||
this.rightMotor = rightMotor; | ||
} | ||
@Override | ||
public void run(boolean on, Telemetry telemetry) { | ||
telemetry.addData("encoder position",leftMotor.getCurrentPosition()); | ||
telemetry.addData("encoder position",rightMotor.getCurrentPosition()); | ||
if(on){ | ||
leftMotor.setPower(speed); | ||
rightMotor.setPower(speed); | ||
|
||
}else{ | ||
leftMotor.setPower(0); | ||
rightMotor.setPower(0); | ||
|
||
} | ||
|
||
} | ||
|
||
} |