Skip to content

Commit

Permalink
preparing for driving the wheel
Browse files Browse the repository at this point in the history
  • Loading branch information
ProgramDragon64 committed Jun 30, 2022
1 parent 5a81ebc commit a394a79
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
19 changes: 19 additions & 0 deletions Larry/conversions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
import math
def convertDegreesToTalonFXUnits(num: float) -> float:
conversionFactor = 2048/360
num *= conversionFactor
return num

def sign(num) -> int:
if num > 0:
# positive
return 1
elif num < 0:
# negative
return -1
else:
# zero
return 0

def convertJoystickInputToDegrees(x: float, y: float):
return float(math.degrees(math.atan2(y, x)))

def deadband(value: float, band: float):
if math.fabs(value) <= band:
return 0
Expand Down
12 changes: 12 additions & 0 deletions Larry/subsystems/swerve_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
import ctre
from constants import *
import wpilib
from conversions import *

from conversions import convertDegreesToTalonFXUnits
class SwerveWheel(commands2.SubsystemBase):
def __init__(self) -> None:
super().__init__()
Expand Down Expand Up @@ -49,6 +52,15 @@ def turn(self, set_point: float):
self.directionMotor.set(ctre.TalonFXControlMode.MotionMagic, int(set_point))
wpilib.SmartDashboard.putNumber("Sensor - ", current_pos)

def translate(self, direction: float, speed: float):
# Before putting joystick input, make sure that the joystick is actually in use and not at rest.
# check for the closest angle (effeciency)
#ex) want to go -270, and +90 degrees is faster, so we would go to 90 degrees and make the wheel spin in the opposite direction
# convert angle to talon fx units
# go to closest angle
# check if the direction of the wheel needs to change
print()

def move(self, joystick_input: float):
self.speedMotor.set(ctre.TalonFXControlMode.PercentOutput, 0.1*joystick_input)

Expand Down

0 comments on commit a394a79

Please # to comment.