Skip to content

Commit

Permalink
fixed select command bug
Browse files Browse the repository at this point in the history
 - added inline reversed function for motors
 - added overloads for functional commands
 - copied latest roadrunner Tank PIDVA follower
  • Loading branch information
amarcolini committed Nov 19, 2021
1 parent 0953768 commit bcb0b8f
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ repositories {
maven { url 'https://jitpack.io' }
}
dependencies {
implementation "com.github.amarcolini.joos:$module:0.1.2-alpha"
implementation "com.github.amarcolini.joos:$module:0.1.3-alpha"
}
```
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
buildscript {
ext {
kotlin_version = "1.5.31"
lib_version = "v0.1.2-alpha"
lib_version = "v0.1.3-alpha"
}

repositories {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ class FunctionalCommand @JvmOverloads constructor(
override var isInterruptable: Boolean = true,
override var requirements: Set<Component> = emptySet()
) : Command() {
@JvmOverloads
constructor(
init: () -> Unit = {},
execute: () -> Unit = {},
end: (Boolean) -> Unit = {},
isFinished: () -> Boolean = { false },
init: Runnable = Runnable {},
execute: Runnable = Runnable {},
end: Consumer<Boolean> = Consumer {},
isFinished: BooleanSupplier = BooleanSupplier { false },
isInterruptable: Boolean = true,
vararg requirements: Component
) : this(init, execute, end, isFinished, isInterruptable, requirements.toSet())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class SelectCommand @JvmOverloads constructor(

override fun init() {
selected = command.get()
selected.init()
}

override fun execute() {
Expand All @@ -32,5 +33,5 @@ class SelectCommand @JvmOverloads constructor(
override val isInterruptable: Boolean
get() = selected.isInterruptable

override fun isFinished(): Boolean = selected.isInterruptable
override fun isFinished(): Boolean = selected.isFinished()
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class SequentialCommand @JvmOverloads constructor(
private var index = -1

override fun init() {
commands.forEach { it.scheduler = scheduler }
index = 0
commands[index].init()
}
Expand Down
23 changes: 19 additions & 4 deletions command/src/main/kotlin/com/amarcolini/joos/hardware/Motor.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.amarcolini.joos.hardware

import com.amarcolini.joos.command.Command
import com.amarcolini.joos.command.CommandScheduler
import com.amarcolini.joos.command.Component
import com.amarcolini.joos.control.FeedforwardCoefficients
import com.amarcolini.joos.control.PIDCoefficients
Expand All @@ -10,7 +9,9 @@ import com.amarcolini.joos.util.NanoClock
import com.qualcomm.robotcore.hardware.DcMotor
import com.qualcomm.robotcore.hardware.DcMotorSimple
import com.qualcomm.robotcore.hardware.HardwareMap
import kotlin.math.*
import kotlin.math.PI
import kotlin.math.abs
import kotlin.math.sign


/**
Expand Down Expand Up @@ -272,8 +273,14 @@ class Motor @JvmOverloads constructor(
field = value
}

/**
* Whether this motor is reversed.
*/
var reversed: Boolean = false
@JvmName("reversed")
/**
* Sets whether the direction of this motor is reversed.
*/
@JvmName("setReversed")
set(value) {
motors.forEach {
it.direction =
Expand All @@ -282,7 +289,7 @@ class Motor @JvmOverloads constructor(
}
field = value
}
@JvmName("reversed")
@JvmName("isReversed")
get() = motors[0].direction == DcMotorSimple.Direction.REVERSE

/**
Expand Down Expand Up @@ -314,6 +321,14 @@ class Motor @JvmOverloads constructor(
*/
val maxTPS: Double = CPR * (maxRPM / 60)

/**
* Reverses the direction of this motor.
*/
fun reversed(): Motor {
reversed = !reversed
return this
}

/**
* Sets the speed of the motor.
*
Expand Down
2 changes: 1 addition & 1 deletion gui/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ javafx {

shadowJar {
destinationDirectory.set(buildDir)
archiveBaseName.set("gui")
archiveBaseName.set("$rootProject.name-gui")
archiveClassifier.set("all")
archiveVersion.set(project.version)
}
Expand Down
2 changes: 1 addition & 1 deletion navigation/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ compileKotlin {

shadowJar {
destinationDirectory.set(buildDir)
archiveBaseName.set("navigation")
archiveBaseName.set("$rootProject.name-navigation")
archiveClassifier.set("all")
archiveVersion.set(project.version)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class TankPIDVAFollower @JvmOverloads constructor(

// note: feedforward is processed at the wheel level
val axialCorrection = axialController.update(0.0, currentRobotVel?.x)
val headingCorrection = sign(targetVel.vec() dot currentPose.vec()) *
val headingCorrection = sign(targetVel.vec() dot currentPose.headingVec()) *
crossTrackController.update(0.0, currentRobotVel?.y)

val correctedVelocity = targetRobotVel + Pose2d(
Expand Down

0 comments on commit bcb0b8f

Please sign in to comment.