Skip to content

Commit

Permalink
added sensor stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
alexl1239 committed Sep 1, 2024
1 parent 42313c9 commit 3e08b53
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
2 changes: 1 addition & 1 deletion constants.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from math import pi

arm_min_rotation: float = 10*(pi/180) #placeholders
arm_min_rotation: float = 11*(pi/180)
arm_max_rotation: float = 200*(pi/180)

arm_gear_ratio = 48
30 changes: 20 additions & 10 deletions subsystem/arm.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from toolkit.subsystem import Subsystem
from toolkit.motors.ctre_motors import TalonFX, TalonConfig

class arm(Subsystem):
class Arm(Subsystem):
def __init__(self):
super().__init__()

Expand All @@ -27,25 +27,35 @@ def __init__(self):
self.target_angle: radians = 0

def init(self):
self.motor.init()
self.motor_follower.init()
self.motor.init()
self.motor_follower.init()

self.motor_follower.follow(self.motor, True)
self.motor_follower.follow(self.motor, True)

def raise_arm(self):
self.motor.set_target_velocity(config.arm_speed)
self.motor.set_target_velocity(config.arm_speed)

def lower_arm(self):
self.motor.set_target_velocity(-config.arm_speed)
self.motor.set_target_velocity(-config.arm_speed)

def stop_arm(self):
self.motor.set_target_velocity(0)
self.motor.set_target_velocity(0)

def get_current(self) -> float:
return self.motor.get_motor_current()

def set_sensor_position(self, position: float):
self.motor.set_sensor_position(position)

def reset_sensor_position(self):
current_position = self.motor.get_sensor_position()
self.set_sensor_position(current_position)

def get_arm_angle(self):
return (
(self.motor.get_sensor_position() / constants.arm_gear_ratio)
* pi
* 2
(self.motor.get_sensor_position() / constants.arm_gear_ratio)
* pi
* 2
)

def limit_angle(self, angle: radians) -> radians:
Expand Down

0 comments on commit 3e08b53

Please sign in to comment.