Skip to content

Commit

Permalink
Merge pull request #15 from nickschatz/master
Browse files Browse the repository at this point in the history
Add current limiting functions
  • Loading branch information
virtuald committed Sep 12, 2017
2 parents 447a047 + 14a82e9 commit fd3840f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
7 changes: 6 additions & 1 deletion ctre/_impl/cantalon_sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,9 @@ def __init__(self, deviceNumber, controlPeriodMs, enablePeriodMs):
'mp_btmBufferCnt': 0,
'mp_topBufferRem': 0,
'mp_zeroPos': 0,
'mp_outputEnable': TalonSRXConst.kMotionProfile_Disable
'mp_outputEnable': TalonSRXConst.kMotionProfile_Disable,

'current_limit_enable': False
})

hal_data['CAN'][deviceNumber] = self.hal_data
Expand Down Expand Up @@ -575,6 +577,9 @@ def SetRampThrottle(self, param):
def SetRevFeedbackSensor(self, param):
self.hal_data['rev_feedback_sensor'] = param

def SetCurrentLimEnable(self, param):
self.hal_data['current_limit_enable'] = param



#############################################################################
Expand Down
11 changes: 11 additions & 0 deletions ctre/cantalon.py
Original file line number Diff line number Diff line change
Expand Up @@ -1552,6 +1552,17 @@ def clearMotionProfileHasUnderrun(self):
"""
self.setParameter(param_t.eMotionProfileHasUnderrunErr, 0)

def setCurrentLimit(self, amps):
"""
:param amps:
:return:
"""
self.setParameter(param_t.eCurrentLimThreshold, amps)

def enableCurrentLimit(self, enable):
self.handle.SetCurrentLimEnable(enable)

def getDescription(self):
return "CANTalon ID %d" % self.deviceNumber

Expand Down
4 changes: 4 additions & 0 deletions tests/test_cantalon.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ def test_ct_basic(cantalon_and_data):

status = ctre.CANTalon.MotionProfileStatus()
ct.getMotionProfileStatus(status)

# test current threshold
ct.setCurrentLimit(30)
ct.enableCurrentLimit(True)



0 comments on commit fd3840f

Please sign in to comment.