-
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 #1 from Thierry-Lachance/main
added function file for arm/elevator/drivetrain
- Loading branch information
Showing
11 changed files
with
175 additions
and
135 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
14 changes: 14 additions & 0 deletions
14
TeamCode/src/main/java/org/firstinspires/ftc/teamcode/ArmFunction.kt
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,14 @@ | ||
package org.firstinspires.ftc.teamcode | ||
|
||
import com.qualcomm.robotcore.hardware.AnalogInput | ||
|
||
class ArmFunction { | ||
companion object { | ||
@JvmStatic | ||
fun moveArm(power: Double, armSensor: AnalogInput): Double { | ||
return if (power >= 0 && armSensor.voltage < 0.75) power | ||
else if (power >= 0 && armSensor.voltage > 2.55) power | ||
else 0.0 | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
TeamCode/src/main/java/org/firstinspires/ftc/teamcode/DrivetrainFunction.kt
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,30 @@ | ||
package org.firstinspires.ftc.teamcode | ||
|
||
import kotlin.math.abs | ||
|
||
class DrivetrainFunction { | ||
|
||
companion object { | ||
@JvmStatic | ||
fun calculateTicks(Cm: Double): Double { | ||
|
||
val COUNTS_PER_MOTOR_REV = 536.6 | ||
|
||
val WHEEL_DIAMETER_CM = 10.0 | ||
|
||
val COUNTS_PER_Cm = COUNTS_PER_MOTOR_REV / (WHEEL_DIAMETER_CM * 3.1415) | ||
return COUNTS_PER_Cm * Cm | ||
} | ||
|
||
@JvmStatic | ||
fun calculatePower(targetPos: Double, currentPos: Double): Double { | ||
return if (abs(targetPos - currentPos) > 50) { | ||
if (abs(currentPos - targetPos) < 100) 0.25 | ||
else if (abs(currentPos - targetPos) < 500) 0.50 | ||
else if (abs(currentPos - targetPos) < 1000) 0.75 | ||
else 1.0 | ||
} else 0.0 | ||
|
||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
TeamCode/src/main/java/org/firstinspires/ftc/teamcode/ElevatorFunction.kt
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,18 @@ | ||
package org.firstinspires.ftc.teamcode | ||
|
||
import com.qualcomm.robotcore.hardware.DigitalChannel | ||
|
||
class ElevatorFunction { | ||
companion object { | ||
@JvmStatic | ||
fun moveElevator( | ||
power: Double, | ||
elevatorIn: DigitalChannel, | ||
elevatorOut: DigitalChannel | ||
): Double { | ||
return if (elevatorIn.state && power >= 0) power | ||
else if (elevatorOut.state && power >= 0) power | ||
else 0.0 | ||
} | ||
} | ||
} |
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
65 changes: 65 additions & 0 deletions
65
TeamCode/src/main/java/org/firstinspires/ftc/teamcode/autoTemplate.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,65 @@ | ||
package org.firstinspires.ftc.teamcode; | ||
|
||
import com.qualcomm.robotcore.eventloop.opmode.Autonomous; | ||
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode; | ||
import com.qualcomm.robotcore.hardware.DcMotor; | ||
import com.qualcomm.robotcore.hardware.DcMotorSimple; | ||
|
||
|
||
@Autonomous | ||
public class autoTemplate extends LinearOpMode { | ||
|
||
DcMotor frontLeftMotor; | ||
DcMotor backLeftMotor; | ||
DcMotor frontRightMotor; | ||
DcMotor backRightMotor; | ||
|
||
@Override | ||
public void runOpMode() throws InterruptedException { | ||
frontLeftMotor = hardwareMap.dcMotor.get("frontLeft"); | ||
backLeftMotor = hardwareMap.dcMotor.get("backLeft"); | ||
frontRightMotor = hardwareMap.dcMotor.get("frontRight"); | ||
backRightMotor = hardwareMap.dcMotor.get("backRight"); | ||
|
||
|
||
frontRightMotor.setDirection(DcMotorSimple.Direction.REVERSE); | ||
backRightMotor.setDirection(DcMotorSimple.Direction.REVERSE); | ||
|
||
frontLeftMotor.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER); | ||
frontLeftMotor.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER); | ||
frontRightMotor.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER); | ||
frontRightMotor.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER); | ||
backLeftMotor.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER); | ||
backLeftMotor.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER); | ||
backRightMotor.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER); | ||
backRightMotor.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER); | ||
|
||
waitForStart(); | ||
|
||
while (opModeIsActive()) { | ||
double targetFL = DrivetrainFunction.calculateTicks(60.0); | ||
double targetFR = DrivetrainFunction.calculateTicks(60.0); | ||
double targetBL = DrivetrainFunction.calculateTicks(60.0); | ||
double targetBR = DrivetrainFunction.calculateTicks(60.0); | ||
encoderDrive(targetFL, targetFR, targetBL, targetBR); | ||
|
||
} | ||
} | ||
|
||
public void encoderDrive(double targetFL, double targetFR, double targetBL, double targetBR) { | ||
while (DrivetrainFunction.calculatePower(targetFL, frontLeftMotor.getCurrentPosition()) != 0 | ||
&& DrivetrainFunction.calculatePower(targetFR, frontRightMotor.getCurrentPosition()) != 0 | ||
&& DrivetrainFunction.calculatePower(targetBL, backLeftMotor.getCurrentPosition()) != 0 | ||
&& DrivetrainFunction.calculatePower(targetBR, backRightMotor.getCurrentPosition()) != 0) { | ||
frontLeftMotor.setPower(DrivetrainFunction.calculatePower(targetFL, frontLeftMotor.getCurrentPosition())); | ||
frontRightMotor.setPower(DrivetrainFunction.calculatePower(targetFR, frontRightMotor.getCurrentPosition())); | ||
backLeftMotor.setPower(DrivetrainFunction.calculatePower(targetBL, backLeftMotor.getCurrentPosition())); | ||
backRightMotor.setPower(DrivetrainFunction.calculatePower(targetBR, backRightMotor.getCurrentPosition())); | ||
} | ||
|
||
|
||
} | ||
|
||
|
||
} | ||
|
3 changes: 2 additions & 1 deletion
3
TeamCode/src/main/java/org/firstinspires/ftc/teamcode/autoTest.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
Oops, something went wrong.