Skip to content

Commit 470f9f8

Browse files
committed
Add CANCoder initialization
1 parent cd45259 commit 470f9f8

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "swervepy"
3-
version = "1.5.0"
3+
version = "1.5.1"
44
description = "Swerve drive library for FRC"
55
authors = ["Ethan Wall <[email protected]>"]
66
license = "MIT"

swervepy/impl/sensor.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111

1212
class AbsoluteCANCoder(AbsoluteEncoder):
13-
def __init__(self, id_: int | tuple[int, str]):
13+
def __init__(self, id_: int | tuple[int, str], invert: bool = False):
1414
super().__init__()
1515

1616
# Construct the CANCoder from either a tuple of motor ID and CAN bus ID or just a motor ID
@@ -19,7 +19,14 @@ def __init__(self, id_: int | tuple[int, str]):
1919
except TypeError:
2020
self._encoder = phoenix5.sensors.CANCoder(id_)
2121

22-
self._encoder.configAbsoluteSensorRange(phoenix5.sensors.AbsoluteSensorRange.Unsigned_0_to_360)
22+
config = phoenix5.sensors.CANCoderConfiguration()
23+
config.absoluteSensorRange = phoenix5.sensors.AbsoluteSensorRange.Unsigned_0_to_360
24+
config.sensorDirection = invert
25+
config.initializationStrategy = phoenix5.sensors.SensorInitializationStrategy.BootToAbsolutePosition
26+
config.sensorTimeBase = phoenix5.sensors.SensorTimeBase.PerSecond
27+
28+
self._encoder.configFactoryDefault()
29+
self._encoder.configAllSettings(config)
2330

2431
wpilib.SmartDashboard.putData(f"Absolute CANCoder {id_}", self)
2532

0 commit comments

Comments
 (0)