-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from strykeforce/mwitcpalek/talonFX
Mwitcpalek/talon fx
- Loading branch information
Showing
31 changed files
with
1,958 additions
and
189 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
kotlin.code.style=official |
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,5 +1,6 @@ | ||
#Sat Jan 18 13:27:09 EST 2020 | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-all.zip | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=permwrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=permwrapper/dists | ||
zipStoreBase=GRADLE_USER_HOME |
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
33 changes: 33 additions & 0 deletions
33
src/main/kotlin/org/strykeforce/thirdcoast/device/PigeonService.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,33 @@ | ||
package org.strykeforce.thirdcoast.device | ||
|
||
import com.ctre.phoenix.sensors.PigeonIMU | ||
import com.ctre.phoenix.sensors.PigeonIMU_StatusFrame | ||
import org.strykeforce.thirdcoast.telemetry.item.PigeonIMUItem | ||
import mu.KotlinLogging | ||
import org.strykeforce.thirdcoast.telemetry.TelemetryService | ||
|
||
private val logger = KotlinLogging.logger {} | ||
|
||
private const val DEFAULT_TEMP_COMP = false | ||
|
||
|
||
class PigeonService(private val telemetryService: TelemetryService, factory: (id: Int) -> PigeonIMU) : | ||
AbstractDeviceService<PigeonIMU>(factory) { | ||
|
||
val timeout = 10 | ||
var tempCompensation = DEFAULT_TEMP_COMP | ||
|
||
|
||
override fun activate(ids: Collection<Int>): Set<Int> { | ||
val new = super.activate(ids) | ||
telemetryService.stop() | ||
active.forEach {telemetryService.register(PigeonIMUItem(it)) } | ||
active.forEach { | ||
it.setTemperatureCompensationDisable(tempCompensation) | ||
} | ||
|
||
telemetryService.start() | ||
return new | ||
} | ||
|
||
} |
73 changes: 73 additions & 0 deletions
73
src/main/kotlin/org/strykeforce/thirdcoast/device/TalonFxService.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,73 @@ | ||
package org.strykeforce.thirdcoast.device | ||
|
||
import com.ctre.phoenix.motorcontrol.ControlMode | ||
import com.ctre.phoenix.motorcontrol.NeutralMode | ||
import com.ctre.phoenix.motorcontrol.StatusFrame | ||
import com.ctre.phoenix.motorcontrol.StatusFrameEnhanced | ||
import com.ctre.phoenix.motorcontrol.can.SlotConfiguration | ||
import com.ctre.phoenix.motorcontrol.can.TalonFX | ||
import com.ctre.phoenix.motorcontrol.can.TalonFXConfiguration | ||
import mu.KotlinLogging | ||
import org.strykeforce.thirdcoast.telemetry.TelemetryService | ||
import java.lang.IllegalStateException | ||
import kotlin.math.log | ||
|
||
private val logger = KotlinLogging.logger {} | ||
|
||
private val CONTROL_MODE_DEFAULT = ControlMode.PercentOutput | ||
private const val ACTIVE_SLOT_DEFAULT = 0 | ||
private val NEUTRAL_MODE_DEFAULT = NeutralMode.EEPROMSetting | ||
private const val VOLTAGE_COMPENSATION_ENABLED_DEFAULT = true | ||
private const val CURRENT_LIMIT_ENABLED_DEFAULT = false | ||
private const val SENSOR_PHASE_INVERTED_DEFAULT = false | ||
private const val OUTPUT_INVERTED_DEFAULT = false | ||
|
||
|
||
class TalonFxService(private val telemetryService: TelemetryService, factory: (id:Int) -> TalonFX ): | ||
AbstractDeviceService<TalonFX>(factory) { | ||
|
||
val timeout = 10 | ||
var dirty = true | ||
var neutralMode = NEUTRAL_MODE_DEFAULT | ||
var controlMode = CONTROL_MODE_DEFAULT | ||
var voltageCompensation = VOLTAGE_COMPENSATION_ENABLED_DEFAULT | ||
var sensorPhase = SENSOR_PHASE_INVERTED_DEFAULT | ||
var activeSlotIndex: Int = ACTIVE_SLOT_DEFAULT | ||
|
||
var activeConfiguration = TalonFXConfiguration() | ||
get() { | ||
if(!dirty) return field | ||
active.firstOrNull()?.getAllConfigs(field,timeout)?: logger.debug("no active talon fx's, returning default config") | ||
dirty = false | ||
return field | ||
} | ||
|
||
val activeSlot: SlotConfiguration | ||
get() = when(activeSlotIndex){ | ||
0 -> activeConfiguration.slot0 | ||
1 -> activeConfiguration.slot1 | ||
2 -> activeConfiguration.slot2 | ||
3 -> activeConfiguration.slot3 | ||
else -> throw IllegalStateException("invalid slot: $activeSlotIndex") | ||
} | ||
|
||
val outputInverted: Boolean | ||
get() = active.firstOrNull()?.inverted?: OUTPUT_INVERTED_DEFAULT | ||
|
||
override fun activate(ids: Collection<Int>): Set<Int> { | ||
dirty = true | ||
|
||
val new = super.activate(ids) | ||
telemetryService.stop() | ||
active.filter { new.contains(it.deviceID) }.forEach(){ | ||
it.setNeutralMode(neutralMode) | ||
it.selectProfileSlot(activeSlotIndex,0) | ||
it.enableVoltageCompensation(voltageCompensation) | ||
it.setSensorPhase(sensorPhase) | ||
it.setInverted(OUTPUT_INVERTED_DEFAULT) | ||
telemetryService.register(it) | ||
} | ||
telemetryService.start() | ||
return new | ||
} | ||
} |
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
38 changes: 38 additions & 0 deletions
38
src/main/kotlin/org/strykeforce/thirdcoast/gyro/PigeonParameter.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,38 @@ | ||
package org.strykeforce.thirdcoast.gyro | ||
|
||
import net.consensys.cava.toml.TomlTable | ||
import org.strykeforce.thirdcoast.command.AbstractParameter | ||
import org.strykeforce.thirdcoast.command.Command | ||
import org.strykeforce.thirdcoast.parseResource | ||
import org.strykeforce.thirdcoast.talon.TalonParameter | ||
|
||
class PigeonParameter(command: Command, toml: TomlTable, val enum: PigeonParameter.Enum) : AbstractParameter(command, toml) { | ||
|
||
enum class Enum { | ||
ACCUM_Z_ANGLE, | ||
FUSED_HEADING, | ||
TEMP_COMP_DISABLE, | ||
YAW, | ||
GENERAL_STATUS, | ||
SIX_DEG_STATUS, | ||
FUSED_STATUS, | ||
GYRO_ACCUM_STATUS, | ||
GEN_COMPASS_STATUS, | ||
GEN_ACCEL_STATUS, | ||
SIX_QUAT_STATUS, | ||
MAG_STATUS, | ||
BIAS_GYRO_STATUS, | ||
BIAS_MAG_STATUS, | ||
BIAS_ACCEL_STATUS, | ||
FACTORY_DEFAULT, | ||
} | ||
|
||
companion object { | ||
private val tomlTable by lazy { parseResource("/pigeon.toml") } | ||
|
||
fun create(command: Command, param: String): PigeonParameter { | ||
val toml = tomlTable.getTable(param) ?: throw java.lang.IllegalArgumentException("missing param: $param") | ||
return PigeonParameter(command, toml, Enum.valueOf(param)) | ||
} | ||
} | ||
} |
Oops, something went wrong.