Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Ericxiyinyang committed Dec 5, 2024
2 parents 7b5f076 + 35c48af commit 2914c6a
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 5 deletions.
Binary file added .DS_Store
Binary file not shown.
5 changes: 4 additions & 1 deletion constants.py
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@

ARM_MOTOR_ID = 1
arm_radius = 1
arm_speed = 1
arm_gear_ratio = 1
5 changes: 1 addition & 4 deletions robot_systems.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@
import sensors
import wpilib


class Robot:
pass

arm = subsystem.Arm()

class Pneumatics:
pass


class Sensors:
pass

Expand Down
1 change: 1 addition & 0 deletions subsystem/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from subsystem.arm import Arm
43 changes: 43 additions & 0 deletions subsystem/arm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import config
import constants

from units.SI import radians
from toolkit.motors.ctre_motors import TalonFX
from toolkit.subsystem import Subsystem

class Arm(Subsystem):

# Initialize class
def __init__(self):
super().__init__()
self.arm_motor = TalonFX(can_id=constants.ARM_MOTOR_ID, config=config.arm_config)
self.arm_motor_follower = TalonFX(can_id=constants.ARM_MOTOR_ID, inverted=True, config=config.arm_config)

self.zeroed = False
self.arm_moving = False

# Start motors
def init(self) -> None:
self.arm_motor.init()
self.arm_motor_follower.init()
self.arm_motor_follower.follow(self.arm_motor)

# Zero the arm
def zero(self) -> None:
self.arm_motor.set_target_position(self.arm_motor.get_sensor_position() * constants.arm_gear_ratio)
self.zeroed = True

# Extends arm to an radians
def extend(self, radians: radians) -> None:
self.arm_motor.set_target_position(radians * constants.arm_gear_ratio)
self.arm_moving = True

# Checks if extended
def isExtended(self, radians: radians) -> bool:

# Compare current sensor position with target position
if self.arm_moving and round((self.arm_motor.get_sensor_position() / constants.arm_gear_ratio), 2) == round(radians, 2):
self.arm_moving = False
return True
else:
return False

0 comments on commit 2914c6a

Please sign in to comment.