-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c68bf47
commit 55a5130
Showing
22 changed files
with
208 additions
and
35 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.
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
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
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
10 changes: 10 additions & 0 deletions
10
ftc/src/main/java/com/rowanmcalpin/nextftc/ftc/hardware/controllables/Controllable.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,10 @@ | ||
package com.rowanmcalpin.nextftc.ftc.hardware.controllables | ||
|
||
/** | ||
* An item that has a position and a power. | ||
*/ | ||
interface Controllable { | ||
var currentPosition: Double | ||
var velocity: Double | ||
var power: Double | ||
} |
29 changes: 29 additions & 0 deletions
29
ftc/src/main/java/com/rowanmcalpin/nextftc/ftc/hardware/controllables/MotorEx.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,29 @@ | ||
package com.rowanmcalpin.nextftc.ftc.hardware.controllables | ||
|
||
import com.qualcomm.robotcore.hardware.DcMotor | ||
import com.qualcomm.robotcore.hardware.DcMotorEx | ||
import com.rowanmcalpin.nextftc.ftc.OpModeData | ||
|
||
/** | ||
* Wrapper class for motors that implements controllable (and can therefore be used with RunToPosition | ||
* commands). | ||
*/ | ||
class MotorEx(private val motor: DcMotorEx): Controllable { | ||
|
||
constructor(name: String): this(OpModeData.hardwareMap.get(DcMotorEx::class.java, name)) | ||
|
||
override var currentPosition: Double | ||
get() = motor.currentPosition.toDouble() | ||
set(value) { } | ||
|
||
override var velocity: Double | ||
get() = motor.velocity | ||
set(value) { } | ||
|
||
override var power: Double | ||
get() = motor.power | ||
set(value) { | ||
motor.mode = DcMotor.RunMode.RUN_WITHOUT_ENCODER | ||
motor.power = value | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
ftc/src/main/java/com/rowanmcalpin/nextftc/ftc/hardware/controllables/MotorGroup.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,50 @@ | ||
package com.rowanmcalpin.nextftc.ftc.hardware.controllables | ||
|
||
/** | ||
* A MotorGroup is a collection of [MotorEx]s that are all controlled by a single encoder (connected | ||
* to the leader motor) | ||
* | ||
* @param leader the [MotorEx] with the encoder that will be used | ||
* @param followers any other motors to control | ||
*/ | ||
class MotorGroup(val leader: MotorEx, vararg val followers: MotorEx): Controllable { | ||
|
||
constructor(vararg names: String): this( | ||
MotorEx(names[0]), | ||
*createMotors(names) | ||
) | ||
|
||
override var currentPosition: Double | ||
get() = leader.currentPosition | ||
set(value) { } | ||
|
||
override var velocity: Double | ||
get() = leader.velocity | ||
set(value) { } | ||
|
||
override var power: Double | ||
get() = leader.power | ||
set(value) { | ||
leader.power = value | ||
followers.forEach { | ||
it.power = value | ||
} | ||
} | ||
|
||
companion object { | ||
fun createMotors(names: Array<out String>): Array<out MotorEx> { | ||
val list = mutableListOf<MotorEx>() | ||
if (names.isEmpty()) { | ||
throw NotEnoughMotorsException() | ||
} | ||
|
||
for (i in 1..names.size) { | ||
list += MotorEx(names[i]) | ||
} | ||
|
||
return list.toTypedArray() | ||
} | ||
} | ||
} | ||
|
||
class NotEnoughMotorsException(): Exception("You must supply at least one motor to a MotorGroup.") |
27 changes: 27 additions & 0 deletions
27
ftc/src/main/java/com/rowanmcalpin/nextftc/ftc/hardware/controllables/RunToPosition.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,27 @@ | ||
package com.rowanmcalpin.nextftc.ftc.hardware.controllables | ||
|
||
import com.rowanmcalpin.nextftc.core.Subsystem | ||
import com.rowanmcalpin.nextftc.core.command.Command | ||
import com.rowanmcalpin.nextftc.core.control.controllers.Controller | ||
import kotlin.math.abs | ||
|
||
/** | ||
* This implements a [Controller] to drive a [Controllable] to a specified target position | ||
*/ | ||
class RunToPosition @JvmOverloads constructor(val controllable: Controllable, val target: Double, val controller: Controller, | ||
override val subsystems: Set<Subsystem> = setOf()): Command() { | ||
override val isDone: Boolean | ||
get() = controller.atTarget(controllable.currentPosition) | ||
|
||
override fun start() { | ||
controller.target = target | ||
controller.reset() | ||
} | ||
|
||
override fun update() { | ||
val calculatedPower = controller.calculate(controllable.currentPosition) | ||
if (abs(controllable.power - calculatedPower) > 0.01) { | ||
controllable.power = calculatedPower | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
ftc/src/main/java/com/rowanmcalpin/nextftc/ftc/hardware/controllables/RunToVelocity.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,35 @@ | ||
package com.rowanmcalpin.nextftc.ftc.hardware.controllables | ||
|
||
import com.rowanmcalpin.nextftc.core.Subsystem | ||
import com.rowanmcalpin.nextftc.core.command.Command | ||
import com.rowanmcalpin.nextftc.core.control.controllers.Controller | ||
import kotlin.math.abs | ||
|
||
/** | ||
* This implements a PID controller to drive a motor to a specified target velocity. | ||
* | ||
* @param controllable the [Controllable] to control | ||
* @param targetVelocity the target velocity | ||
* @param controller the [Controller] to implement | ||
* @param subsystems the list of [Subsystem]s this command interacts with (should be whatever | ||
* subsystem holds this command) | ||
* @param outCondition will be evaluated every update, and the command will stop once it returns true | ||
*/ | ||
class RunToVelocity @JvmOverloads constructor(val controllable: Controllable, val targetVelocity: Double, | ||
val controller: Controller, override val subsystems: Set<Subsystem> = setOf(), | ||
val outCondition: () -> Boolean = { abs(controllable.velocity)-targetVelocity < 10 }): Command() { | ||
override val isDone: Boolean | ||
get() = outCondition.invoke() | ||
|
||
override fun start() { | ||
controller.target = targetVelocity | ||
controller.reset() | ||
} | ||
|
||
override fun update() { | ||
val calculatedPower = controller.calculate(controllable.velocity) | ||
if (abs(controllable.power - calculatedPower) > 0.01) { | ||
controllable.power = calculatedPower | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
ftc/src/main/java/com/rowanmcalpin/nextftc/ftc/hardware/controllables/SetPower.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,21 @@ | ||
package com.rowanmcalpin.nextftc.ftc.hardware.controllables | ||
|
||
import com.rowanmcalpin.nextftc.core.Subsystem | ||
import com.rowanmcalpin.nextftc.core.command.Command | ||
|
||
/** | ||
* Sets a controllable to a specific power without any internal feedback | ||
* | ||
* @param controllable the [Controllable] to control | ||
* @param power the power to set the [Controllable] to | ||
* @param subsystems the [Subsystem]s this command interacts with (should be whatever | ||
* subsystem holds this command) | ||
*/ | ||
class SetPower @JvmOverloads constructor(val controllable: Controllable, val power: Double, | ||
override val subsystems: Set<Subsystem> = setOf()): Command() { | ||
override val isDone = true | ||
|
||
override fun start() { | ||
controllable.power = power | ||
} | ||
} |
6 changes: 0 additions & 6 deletions
6
ftc/src/main/java/com/rowanmcalpin/nextftc/ftc/hardware/motors/Controllable.kt
This file was deleted.
Oops, something went wrong.
17 changes: 0 additions & 17 deletions
17
ftc/src/main/java/com/rowanmcalpin/nextftc/ftc/hardware/motors/MotorEx.kt
This file was deleted.
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
Submodule maven.rowanmcalpin.com
updated
75 files