forked from FIRST-Tech-Challenge/FtcRobotController
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
+ *rename* Loq => SharedResource because the multithreading parallels are kinda cringe idk + Add a bunch of `@JvmField` and `@JvmOverloads` annotations + Add RobotConfiguration abstract class + MotorPowers: normalization, operator functions + SharedResource and Scheduler panic()s (cleanup functions) + Deprecate RobotLocks.kt object + Delete commented code in Task.kt + Claw now takes lock as constructor argument
- Loading branch information
1 parent
da607ec
commit 78169e4
Showing
15 changed files
with
232 additions
and
125 deletions.
There are no files selected for viewing
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
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
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
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
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
115 changes: 74 additions & 41 deletions
115
TeamCode/src/main/java/org/firstinspires/ftc/teamcode/configurations/NeoRobot1.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 |
---|---|---|
@@ -1,50 +1,83 @@ | ||
package org.firstinspires.ftc.teamcode.configurations; | ||
package org.firstinspires.ftc.teamcode.configurations | ||
|
||
import com.qualcomm.robotcore.hardware.DcMotor; | ||
import com.qualcomm.robotcore.hardware.DcMotorSimple; | ||
import com.qualcomm.robotcore.hardware.HardwareMap; | ||
import com.qualcomm.robotcore.hardware.DcMotor | ||
import com.qualcomm.robotcore.hardware.DcMotorSimple | ||
import com.qualcomm.robotcore.hardware.HardwareMap | ||
import com.qualcomm.robotcore.hardware.Servo | ||
import dev.aether.collaborative_multitasking.SharedResource | ||
import org.firstinspires.ftc.teamcode.utility.MotorSet | ||
import org.firstinspires.ftc.teamcode.utility.typedGet | ||
|
||
import org.firstinspires.ftc.teamcode.utility.MotorSet; | ||
class NeoRobot1(map: HardwareMap) : RobotConfiguration() { | ||
@JvmField | ||
var frontLeft // 0 | ||
: DcMotor = map.typedGet("frontLeft") | ||
|
||
public class NeoRobot1 { | ||
public DcMotor frontLeft; // 0 | ||
public DcMotor frontRight; // 1 | ||
public DcMotor backLeft; // 2 | ||
public DcMotor backRight; // 3 | ||
@JvmField | ||
var frontRight // 1 | ||
: DcMotor = map.typedGet("frontRight") | ||
|
||
public DcMotor slideLeft; // 0 | ||
public DcMotor slideRight; // 1 | ||
@JvmField | ||
var backLeft // 2 | ||
: DcMotor = map.typedGet("backLeft") | ||
|
||
private static void reverse(DcMotor target) { | ||
target.setDirection(DcMotorSimple.Direction.REVERSE); | ||
} | ||
private static void brake(DcMotor ...targets) { | ||
for (DcMotor target : targets ) target.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE); | ||
} | ||
@JvmField | ||
var backRight // 3 | ||
: DcMotor = map.typedGet("backRight") | ||
|
||
@JvmField | ||
var liftLeftB // 0 | ||
: DcMotor = map.typedGet("slideLeft") | ||
|
||
@JvmField | ||
var liftRightB // 1 | ||
: DcMotor = map.typedGet("slideRight") | ||
|
||
@JvmField | ||
var clawGrabB | ||
: Servo = map.typedGet("clawGrab") | ||
|
||
public NeoRobot1(HardwareMap map) { | ||
frontLeft = map.get(DcMotor.class, "frontLeft"); | ||
reverse(frontLeft); | ||
frontRight = map.get(DcMotor.class, "frontRight"); | ||
backLeft = map.get(DcMotor.class, "backLeft"); | ||
reverse(backLeft); | ||
backRight = map.get(DcMotor.class, "backRight"); | ||
brake(frontLeft, frontRight, backLeft, backRight); | ||
|
||
slideLeft = map.get(DcMotor.class, "slideLeft"); | ||
slideLeft.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER); | ||
slideLeft.setTargetPosition(0); | ||
slideLeft.setPower(1); | ||
slideLeft.setMode(DcMotor.RunMode.RUN_TO_POSITION); | ||
slideRight = map.get(DcMotor.class, "slideRight"); | ||
slideRight.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER); | ||
slideRight.setTargetPosition(0); | ||
slideRight.setPower(1); | ||
slideRight.setMode(DcMotor.RunMode.RUN_TO_POSITION); | ||
reverse(slideRight); | ||
@JvmField | ||
var clawRotateB | ||
: Servo = map.typedGet("clawRotate") | ||
|
||
|
||
override val driveMotors: MotorSet = MotorSet(frontLeft, frontRight, backLeft, backRight) | ||
override val driveMotorLock: SharedResource | ||
get() = SharedResource("driveMotors") { | ||
driveMotors.setAll( | ||
0.0 | ||
) | ||
} | ||
override val clawGrab: Servo get() = clawGrabB | ||
override val clawRotate: Servo get() = clawRotateB | ||
override val clawLock: SharedResource = SharedResource("claw") | ||
override val liftLeft: DcMotor get() = liftLeftB | ||
override val liftRight: DcMotor get() = liftRightB | ||
|
||
init { | ||
setReverse(frontLeft) | ||
setReverse(backLeft) | ||
enableBrakes(frontLeft, frontRight, backLeft, backRight) | ||
|
||
liftLeftB.mode = DcMotor.RunMode.STOP_AND_RESET_ENCODER | ||
liftLeftB.targetPosition = 0 | ||
liftLeftB.power = 1.0 | ||
liftLeftB.mode = DcMotor.RunMode.RUN_TO_POSITION | ||
liftRightB.mode = DcMotor.RunMode.STOP_AND_RESET_ENCODER | ||
liftRightB.targetPosition = 0 | ||
liftRightB.power = 1.0 | ||
liftRightB.mode = DcMotor.RunMode.RUN_TO_POSITION | ||
setReverse(liftRightB) | ||
} | ||
|
||
public MotorSet getMotorSet() { | ||
return new MotorSet(frontLeft, frontRight, backLeft, backRight); | ||
companion object { | ||
private fun setReverse(target: DcMotor) { | ||
target.direction = DcMotorSimple.Direction.REVERSE | ||
} | ||
|
||
private fun enableBrakes(vararg targets: DcMotor) { | ||
for (target in targets) target.zeroPowerBehavior = DcMotor.ZeroPowerBehavior.BRAKE | ||
} | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
TeamCode/src/main/java/org/firstinspires/ftc/teamcode/configurations/RobotConfiguration.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.configurations | ||
|
||
import com.qualcomm.robotcore.hardware.DcMotor | ||
import com.qualcomm.robotcore.hardware.HardwareMap | ||
import com.qualcomm.robotcore.hardware.Servo | ||
import dev.aether.collaborative_multitasking.SharedResource | ||
import org.firstinspires.ftc.teamcode.utility.MotorSet | ||
|
||
abstract class RobotConfiguration { | ||
companion object { | ||
@JvmStatic | ||
fun currentConfiguration(): (HardwareMap) -> RobotConfiguration = ::NeoRobot1 | ||
} | ||
|
||
protected abstract val driveMotors: MotorSet? | ||
fun driveMotors(): MotorSet = driveMotors ?: throw NullPointerException("Robot configuration has no drive motors but they were requested") | ||
|
||
abstract val driveMotorLock: SharedResource | ||
|
||
protected abstract val clawGrab: Servo? | ||
fun clawGrab(): Servo = clawGrab ?: throw NullPointerException("Robot configuration has no claw grab servo but it was requested") | ||
protected abstract val clawRotate: Servo? | ||
fun clawRotate(): Servo = clawRotate ?: throw NullPointerException("Robot configuration has no claw rotate servo but it was requested") | ||
abstract val clawLock: SharedResource | ||
|
||
protected abstract val liftLeft: DcMotor? | ||
fun liftLeft(): DcMotor = liftLeft ?: throw NullPointerException("Robot configuration has no left lift motor but it was requested") | ||
protected abstract val liftRight: DcMotor? | ||
fun liftRight(): DcMotor = liftRight ?: throw NullPointerException("Robot configuration has no right lift motor but it was requested") | ||
} |
8 changes: 3 additions & 5 deletions
8
TeamCode/src/main/java/org/firstinspires/ftc/teamcode/configurations/RobotLocks.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 |
---|---|---|
@@ -1,10 +1,8 @@ | ||
package org.firstinspires.ftc.teamcode.configurations | ||
|
||
import dev.aether.collaborative_multitasking.Loq | ||
import dev.aether.collaborative_multitasking.SharedResource | ||
|
||
object RobotLocks { | ||
val driveMotors = Loq("driveMotors") | ||
val liftLeft = Loq("driveMotors") | ||
val liftRight = Loq("driveMotors") | ||
val claw = Loq("claw") | ||
@Deprecated("Use a RobotConfiguration's locks for panic support.") | ||
val driveMotors = SharedResource("driveMotors") | ||
} |
Oops, something went wrong.