11package org.firstinspires.ftc.teamcode
22
3- import com.andreidurlea.corecontrol.buttonsFeature.AnalogButton
3+ import com.andreidurlea.corecontrol.buttonsFeature.Button
44import com.andreidurlea.corecontrol.miscellaneous.telemetryEverywhere
55import com.andreidurlea.corecontrol.opModesFeature.CoreTeleOp
66import com.qualcomm.robotcore.eventloop.opmode.TeleOp
77import com.qualcomm.robotcore.hardware.DcMotor
8- import com.qualcomm.robotcore.hardware.DcMotorSimple
8+ import com.qualcomm.robotcore.hardware.DcMotor.ZeroPowerBehavior
99
10- @TeleOp(name = " Test Motor " , group = " Testing" )
10+ @TeleOp(name = " Test DcMotor " , group = " Testing" )
1111class TestDcMotor : CoreTeleOp () {
1212
13- lateinit var motor: DcMotor
13+ lateinit var motors: List <DcMotor >
14+ var currentMotorIndex = 0
15+ var direction = 1.0
1416
15- var motorName = " EDIT THIS TO CHOOSE YOUR SERVO NAME FROM THE CONFIG"
16- // you can find and edits configs in TeamCode/res/xml
17- // or in the Driver Station in the three dots menu > "configure robot"
17+ val reverseDirection = Button ({ gamepad1.right_bumper })
1818
19- val spin = AnalogButton ({ gamepad1.right_trigger })
20- val spinInReverse = AnalogButton ({ gamepad1.left_trigger })
19+ val nextMotor = Button ({ gamepad1.dpad_right })
20+ val prevMotor = Button ({ gamepad1.dpad_left })
2121
2222 override fun onInit () {
23- motor = hardwareMap[DcMotor ::class .java, motorName]
24- motor.direction = DcMotorSimple .Direction .FORWARD // Starts robot in forward (CW) direction
23+ motors = hardwareMap.getAll(DcMotor ::class .java)
24+ motors.forEach { it.zeroPowerBehavior = ZeroPowerBehavior .FLOAT }
25+ telemetryEverywhere.addLine(" To add a motor in your config, see the /TeamCode/res/xml folder" +
26+ " , or, tap the three dot menu on your driver station and select 'Configure robot'" )
2527 }
2628
2729 override fun onLoop () {
28- telemetryEverywhere.addLine(" Spin (Clowckwise) == Right Trigger (0-100%)" )
29- telemetryEverywhere.addLine(" Spin (Counterclockwise) == Left Trigger (0-100%)" )
30+ if (motors.isEmpty()) {
31+ telemetryEverywhere.addLine(" No DC motors found." )
32+ return
33+ }
3034
31- telemetryEverywhere.addData(" Currently testing" , motorName)
35+ val previousMotorIndex = currentMotorIndex
36+ if (nextMotor.wasPressed()) {
37+ currentMotorIndex = (currentMotorIndex + 1 ) % motors.size
38+ }
39+ if (prevMotor.wasPressed()) {
40+ currentMotorIndex = (currentMotorIndex - 1 + motors.size) % motors.size
41+ }
42+ if (previousMotorIndex != currentMotorIndex) {
43+ motors[previousMotorIndex].power = 0.0
44+ }
3245
33- motor.power = spin.value - spinInReverse.value
46+
47+ val currentMotor = motors[currentMotorIndex]
48+ val motorName = hardwareMap.getNamesOf(currentMotor).firstOrNull() ? : " Unknown"
49+
50+ if (reverseDirection.wasPressed()) {
51+ direction * = - 1.0
52+ }
53+
54+ telemetryEverywhere.addLine(" [INFO] This OpMode can find and test any motor in your config" )
55+ telemetryEverywhere.addLine(" [INFO] Control power with Right Trigger" )
56+ telemetryEverywhere.addLine(" [INFO] Reverse direction with Right Bumper" )
57+ telemetryEverywhere.addLine(" [INFO] Hold Left Bumper to brake the motor" )
58+ telemetryEverywhere.addLine(" [INFO] Cycle through motors in your config == D-Pad Left/Right" )
59+ telemetryEverywhere.addLine(" ====================================" )
60+ telemetryEverywhere.addData(" Currently testing" , " MOTOR ${currentMotorIndex + 1 } /${motors.size} , named ${motorName.uppercase()} " )
61+ telemetryEverywhere.addData(" Motor Power" , currentMotor.power)
62+ telemetryEverywhere.addData(" Motor Direction" ,
63+ if (direction > 0 ) " FORWARD (Positive power spins clockwise)"
64+ else " REVERSE (Negative power spins counter-clockwise)" )
65+ telemetryEverywhere.addLine(" ====================================" )
66+
67+ if (gamepad1.left_bumper) {
68+ currentMotor.power = 0.0
69+ currentMotor.zeroPowerBehavior = ZeroPowerBehavior .BRAKE
70+ } else {
71+ currentMotor.zeroPowerBehavior = ZeroPowerBehavior .FLOAT
72+ val power = gamepad1.right_trigger * direction
73+ if (power > 0.05 || power < - 0.05 ) {
74+ currentMotor.power = power
75+ } else {
76+ currentMotor.power = 0.0
77+ }
78+ }
3479 }
35- }
80+ }
0 commit comments