Skip to content

Commit b2828c7

Browse files
committed
Add velocity measurement configuration
1 parent 3409be9 commit b2828c7

File tree

8 files changed

+62
-32
lines changed

8 files changed

+62
-32
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ plugins {
44
id "idea"
55
}
66

7-
version = "19.0.0"
7+
version = "19.1.0"
88

99
repositories {
1010
jcenter()

src/main/kotlin/org/strykeforce/thirdcoast/command/Command.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ interface Command {
4141
"menu" -> createMenuCommand(parent, key, toml)
4242
"talon.select" -> SelectTalonsCommand(parent, key, toml)
4343
"talon.mode" -> SelectControlModeCommand(parent, key, toml)
44-
"talon.brake" -> SelectBrakeModeCommand(parent, key, toml)
44+
"talon.brake" -> SelectVelocityMeasurmentPeriodCommand(parent, key, toml)
4545
"talon.run" -> RunTalonsCommand(parent, key, toml)
4646
"talon.status" -> TalonsStatusCommand(parent, key, toml)
4747
"talon.slot.select" -> SelectSlotCommand(parent, key, toml)
@@ -51,6 +51,7 @@ interface Command {
5151
"talon.sensor.position" -> SetSensorPositionCommand(parent, key, toml)
5252
"talon.hard.source" -> SelectHardLimitSourceCommand(parent, key, toml)
5353
"talon.hard.normal" -> SelectHardLimitNormalCommand(parent, key, toml)
54+
"talon.velocity.period" -> SelectVelocityMeasurmentPeriodCommand(parent, key, toml)
5455
"servo.select" -> SelectServosCommand(parent, key, toml)
5556
"servo.run" -> RunServosCommand(parent, key, toml)
5657
"digital_output.select" -> SelectDigitalOutputsCommand(parent, key, toml)

src/main/kotlin/org/strykeforce/thirdcoast/talon/SelectBrakeModeCommand.kt

Lines changed: 0 additions & 30 deletions
This file was deleted.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package org.strykeforce.thirdcoast.talon
2+
3+
import com.ctre.phoenix.motorcontrol.VelocityMeasPeriod
4+
import com.ctre.phoenix.motorcontrol.VelocityMeasPeriod.*
5+
import net.consensys.cava.toml.TomlTable
6+
import org.koin.standalone.inject
7+
import org.strykeforce.thirdcoast.command.AbstractSelectCommand
8+
import org.strykeforce.thirdcoast.command.Command
9+
import org.strykeforce.thirdcoast.device.TalonService
10+
11+
class SelectVelocityMeasurmentPeriodCommand(
12+
parent: Command?,
13+
key: String,
14+
toml: TomlTable
15+
) : AbstractSelectCommand<VelocityMeasPeriod>(
16+
parent,
17+
key,
18+
toml,
19+
listOf(Period_1Ms, Period_2Ms, Period_5Ms, Period_10Ms, Period_20Ms, Period_50Ms, Period_100Ms),
20+
listOf("1 ms", "2 ms", "5 ms", "10 ms", "20 ms", "50 ms", "100 ms")
21+
) {
22+
private val talonService: TalonService by inject()
23+
override val activeIndex
24+
get() = values.indexOf(talonService.activeConfiguration.velocityMeasurementPeriod)
25+
26+
override fun setActive(index: Int) {
27+
val period = values[index]
28+
talonService.active.forEach { it.configVelocityMeasurementPeriod(period, talonService.timeout) }
29+
talonService.activeConfiguration.velocityMeasurementPeriod = period
30+
}
31+
}

src/main/kotlin/org/strykeforce/thirdcoast/talon/TalonParameter.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class TalonParameter(command: Command, toml: TomlTable, val enum: Enum) : Abstra
4747
SOFT_LIMIT_ENABLE_REVERSE,
4848
SOFT_LIMIT_THRESHOLD_FORWARD,
4949
SOFT_LIMIT_THRESHOLD_REVERSE,
50+
VELOCITY_MEASUREMENT_WINDOW,
5051
FACTORY_DEFAULTS,
5152
}
5253

src/main/kotlin/org/strykeforce/thirdcoast/talon/TalonParameterCommand.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class TalonParameterCommand(
6565
SOFT_LIMIT_ENABLE_REVERSE -> formatMenu(config.reverseSoftLimitEnable)
6666
SOFT_LIMIT_THRESHOLD_FORWARD -> formatMenu(config.forwardSoftLimitThreshold)
6767
SOFT_LIMIT_THRESHOLD_REVERSE -> formatMenu(config.reverseSoftLimitThreshold)
68+
VELOCITY_MEASUREMENT_WINDOW -> formatMenu(config.velocityMeasurementWindow)
6869
FACTORY_DEFAULTS -> tomlMenu
6970
else -> TODO("${param.enum} not implemented")
7071
}
@@ -215,6 +216,10 @@ class TalonParameterCommand(
215216
talon.configReverseSoftLimitThreshold(value, timeout)
216217
config.reverseSoftLimitThreshold = value
217218
}
219+
VELOCITY_MEASUREMENT_WINDOW -> configIntParam(config.velocityMeasurementWindow) { talon, value ->
220+
talon.configVelocityMeasurementWindow(value, timeout)
221+
talonService.dirty = true // let the talon round down the number to a legal value
222+
}
218223
FACTORY_DEFAULTS -> configBooleanParam(false) { talon, value ->
219224
if (value) talon.configFactoryDefault(timeout)
220225
}

src/main/resources/commands.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,19 @@ type = "menu"
197197
order = 90
198198
menu = "neutral deadband"
199199
param = "NEUTRAL_DEADBAND"
200+
[talon.velocity_measurement]
201+
type = "menu"
202+
order = 26
203+
menu = "configure velocity measurement"
204+
[talon.velocity_measurement.period]
205+
type = "talon.velocity.period"
206+
order = 10
207+
menu = "velocity measurement period"
208+
[talon.velocity_measurement.window]
209+
type = "talon.param"
210+
order = 20
211+
menu = "velocity measurement window"
212+
param = "VELOCITY_MEASUREMENT_WINDOW"
200213
[talon.voltage_compensation]
201214
type = "menu"
202215
order = 27

src/main/resources/talon.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,15 @@
9090
type = "INTEGER"
9191
help = "Number of samples in the rolling average of voltage measurement."
9292

93+
#
94+
# velocity measurement
95+
#
96+
[VELOCITY_MEASUREMENT_WINDOW]
97+
name = "Velocity Measurement Window"
98+
type = "INTEGER"
99+
range = [1.0, 32.0]
100+
help = "Sets the number of velocity samples used in the rolling average velocity measurement."
101+
93102
#
94103
# PID slots
95104
#

0 commit comments

Comments
 (0)