Skip to content

Commit

Permalink
Add feed_enable to simulation periodic
Browse files Browse the repository at this point in the history
  • Loading branch information
CoryNessCTR committed Dec 18, 2023
1 parent 1299ff6 commit 0ae051a
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 5 deletions.
8 changes: 7 additions & 1 deletion python/ArcadeDrive/robot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
This is a demo program for arcade drive in Python with Phoenix 6
"""
import wpilib
from phoenix6 import hardware, controls
from phoenix6 import hardware, controls, unmanaged


class MyRobot(wpilib.TimedRobot):
Expand Down Expand Up @@ -46,6 +46,12 @@ def teleopPeriodic(self):
self.front_left_motor.set_control(self.left_out.with_output(throttle + wheel))
self.front_right_motor.set_control(self.right_out.with_output(throttle - wheel))

def simulationPeriodic(self):
""""""
# If the driver station is enabled, then feed enable for phoenix devices
if wpilib.DriverStation.isEnabled():
unmanaged.feed_enable(100)


if __name__ == "__main__":
wpilib.run(MyRobot)
9 changes: 8 additions & 1 deletion python/CANcoder/robot.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"""
import wpilib
from wpilib import Timer
from phoenix6 import hardware
from phoenix6 import hardware, unmanaged

class MyRobot(wpilib.TimedRobot):
"""
Expand All @@ -25,6 +25,7 @@ def teleopPeriodic(self):
"""Every 100ms, print the status of the StatusSignal"""

if self.timer.hasElapsed(0.1):
self.timer.reset()
# get_position automatically calls refresh(), no need to manually refresh.
#
# StatusSignals also implement the str dunder to provide a useful print of the signal
Expand All @@ -39,5 +40,11 @@ def teleopPeriodic(self):

print("")

def simulationPeriodic(self):
""""""
# If the driver station is enabled, then feed enable for phoenix devices
if wpilib.DriverStation.isEnabled():
unmanaged.feed_enable(100)

if __name__ == "__main__":
wpilib.run(MyRobot)
9 changes: 8 additions & 1 deletion python/PositionClosedLoop/robot.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"""
import wpilib
from wpilib import Timer, XboxController
from phoenix6 import hardware, controls, configs
from phoenix6 import hardware, controls, configs, unmanaged

class MyRobot(wpilib.TimedRobot):
"""
Expand Down Expand Up @@ -42,6 +42,7 @@ def teleopPeriodic(self):
self.talonfx.set_control(self.position_request.with_position(self.joystick.getLeftY() * 10))

if self.timer.hasElapsed(0.1):
self.timer.reset()
# Print the position & velocity to see what they are
pos = self.talonfx.get_position()
vel = self.talonfx.get_velocity()
Expand All @@ -51,5 +52,11 @@ def teleopPeriodic(self):

print("")

def simulationPeriodic(self):
""""""
# If the driver station is enabled, then feed enable for phoenix devices
if wpilib.DriverStation.isEnabled():
unmanaged.feed_enable(100)

if __name__ == "__main__":
wpilib.run(MyRobot)
8 changes: 8 additions & 0 deletions python/StatusSignals/robot.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
controls,
SignalLogger,
BaseStatusSignal,
unmanaged
)


Expand Down Expand Up @@ -47,6 +48,7 @@ def teleopPeriodic(self):
"""Every 100ms, print the status of the StatusSignal"""

if self.timer.hasElapsed(0.1):
self.timer.reset()
BaseStatusSignal.refresh_all(self.pos, self.vel)

pos_timestamp = self.pos.all_timestamps.get_device_timestamp().time
Expand All @@ -57,6 +59,12 @@ def teleopPeriodic(self):
)
print(f"Latency compensated position is {latency_compensated_pos}")

def simulationPeriodic(self):
""""""
# If the driver station is enabled, then feed enable for phoenix devices
if wpilib.DriverStation.isEnabled():
unmanaged.feed_enable(100)


if __name__ == "__main__":
wpilib.run(MyRobot)
16 changes: 14 additions & 2 deletions python/TalonFX/robot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
This is a demo program for TalonFX usage in Phoenix 6
"""
import wpilib
from wpilib import Timer
from phoenix6 import hardware
from wpilib import Timer, XboxController
from phoenix6 import hardware, unmanaged, controls

class MyRobot(wpilib.TimedRobot):
"""
Expand All @@ -17,14 +17,20 @@ def robotInit(self):

# Keep a reference to all the motor controllers used
self.talonfx = hardware.TalonFX(1, "canivore")
self.control = controls.DutyCycleOut(0)

self.timer = Timer()
self.timer.start()

self.joystick = XboxController(0)

def teleopPeriodic(self):
"""Every 100ms, print the status of the StatusSignal"""

self.talonfx.set_control(self.control.with_output(self.joystick.getLeftY()))

if self.timer.hasElapsed(0.1):
self.timer.reset()
# get_position automatically calls refresh(), no need to manually refresh.
#
# StatusSignals also implement the str dunder to provide a useful print of the signal
Expand All @@ -39,5 +45,11 @@ def teleopPeriodic(self):

print("")

def _simulationPeriodic(self):
""""""
# If the driver station is enabled, then feed enable for phoenix devices
if wpilib.DriverStation.isEnabled():
unmanaged.feed_enable(100)

if __name__ == "__main__":
wpilib.run(MyRobot)

0 comments on commit 0ae051a

Please sign in to comment.