generated from Choate-Robotics/7407-DriveCode-Template-v2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feat/arm' of https://github.com/Choate-Robotics/7407-Dr…
…iveCode-Crescendo-Offseason into feat/arm
- Loading branch information
Showing
5 changed files
with
49 additions
and
5 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
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 |
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 @@ | ||
from subsystem.arm import Arm |
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,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 |