Skip to content

Commit

Permalink
WORKING PIDS
Browse files Browse the repository at this point in the history
  • Loading branch information
Iris-TheRainbow committed Jun 21, 2024
1 parent 1412e92 commit 08c633e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
10 changes: 1 addition & 9 deletions REVHubInterface/REVMotor.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ def resetMotorEncoder(commObj, destination, motorChannel):


def setMotorConstantPower(commObj, destination, motorChannel, powerLevel):
print('setpower')
setMotorConstantPowerMsg = REVMsg.SetMotorConstantPower()
setMotorConstantPowerMsg.payload.motorChannel = motorChannel
setMotorConstantPowerMsg.payload.powerLevel = powerLevel
Expand Down Expand Up @@ -183,8 +182,6 @@ def __init__(self, commObj, channel, destinationModule):
self.destinationModule = destinationModule
self.commObj = commObj
self.motorCurrent = REVADC.ADCPin(self.commObj, 8 + channel, self.destinationModule)
self.targetPositon = None
self.targetVeolcity = None

def setDestination(self, destinationModule):
self.destinationModule = destinationModule
Expand Down Expand Up @@ -224,8 +221,7 @@ def resetEncoder(self):
resetMotorEncoder(self.commObj, self.destinationModule, self.channel)

def setPower(self, powerLevel):
if self.targetPositon and self.targetVelocity is None:
setMotorConstantPower(self.commObj, self.destinationModule, self.channel, powerLevel)
setMotorConstantPower(self.commObj, self.destinationModule, self.channel, powerLevel)

def getPower(self):
return getMotorConstantPower(self.commObj, self.destinationModule, self.channel)
Expand All @@ -243,7 +239,6 @@ def getTargetVelocity(self):
return getMotorTargetVelocity(self.commObj, self.destinationModule, self.channel)

def setTargetPosition(self, position, tolerance):
self.targetPositon = position
setMotorTargetPosition(self.commObj, self.destinationModule, self.channel, position, tolerance)

def getTargetPosition(self):
Expand Down Expand Up @@ -290,9 +285,6 @@ def getPositionPID(self):

def getBulkPIDData(self):
return getBulkPIDData(self.commObj, self.destinationModule, self.channel)
def disablePIDs(self):
self.targetPositon = None
self.targetVeolcity = None

def init(self):
self.setMode(0, 1)
Expand Down
12 changes: 7 additions & 5 deletions REVHubInterface/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,9 +688,10 @@ def send_all_KA(self):
module.getStatus()

def speedMotorSlider(self, speed, moduleNumber, motorNumber, *args):
self.repetitiveFunctions = []
self.Motor_packs[moduleNumber * 4 + motorNumber].Java_entry.delete(0, END)
self.Motor_packs[moduleNumber * 4 + motorNumber].Java_entry.insert(0, '%.2f' % (float(speed) / 32000))
self.REVModules[moduleNumber].motors[motorNumber].disablePIDs()
self.REVModules[moduleNumber].motors[motorNumber].setMode(0, 1)
self.REVModules[moduleNumber].motors[motorNumber].setPower(float(speed))
self.REVModules[moduleNumber].motors[motorNumber].enable()
self.repetitiveFunctions = [
Expand All @@ -700,10 +701,11 @@ def speedMotorSlider(self, speed, moduleNumber, motorNumber, *args):

def zeroMotorSpeed(self, motorNumber, moduleNumber, *args):
speed = 0
self.repetitiveFunctions = []
self.REVModules[moduleNumber].motors[motorNumber].setMode(0, 1)
self.Motor_packs[moduleNumber * 4 + motorNumber].Speed_slider.set(speed)
self.Motor_packs[moduleNumber * 4 + motorNumber].Java_entry.delete(0, END)
self.Motor_packs[moduleNumber * 4 + motorNumber].Java_entry.insert(0, '%.2f' % float(speed / 32000))
self.REVModules[moduleNumber].motors[motorNumber].disablePIDs()
self.REVModules[moduleNumber].motors[motorNumber].setPower(float(speed))
self.REVModules[moduleNumber].motors[motorNumber].enable()
self.repetitiveFunctions = [
Expand All @@ -717,10 +719,9 @@ def javaMotorEntry(self, motorNumber, moduleNumber, *args):
except ValueError:
print('Invalid speed entered: ' + self.Motor_packs[moduleNumber * 4 + motorNumber].Java_entry.get())
return False

self.repetitiveFunctions = []
self.Motor_packs[moduleNumber * 4 + motorNumber].Speed_slider.set(speed * 32000)
self.REVModules[moduleNumber].motors[motorNumber].setMode(0, 1)
self.REVModules[moduleNumber].motors[motorNumber].disablePIDs()
self.REVModules[moduleNumber].motors[motorNumber].setPower(float(speed * 32000))
self.REVModules[moduleNumber].motors[motorNumber].enable()
self.repetitiveFunctions = [
Expand All @@ -729,6 +730,7 @@ def javaMotorEntry(self, motorNumber, moduleNumber, *args):
return True

def javaTargetEntry(self, motorNumber, moduleNumber, *args):
self.repetitiveFunctions = []
self.zeroMotorSpeed(motorNumber, moduleNumber)
target = int(self.pid_packs[moduleNumber * 4 + motorNumber].Java_entry.get())
self.REVModules[moduleNumber].motors[motorNumber].setTargetPosition(target, 1)
Expand Down Expand Up @@ -1021,7 +1023,7 @@ def on_connect_button_callback(self):
frame.grid(row=motorNumber, column=moduleNumber, sticky=(N, S, E, W))
self.Motor_packs.append(
dc_motor(frame, partial(self.speedMotorSlider, motorNumber=motorNumber, moduleNumber=moduleNumber),
partial(self.speedMotorEntry, motorNumber=motorNumber, moduleNumber=moduleNumber),
partial(self.zeroMotorSpeed, motorNumber=motorNumber, moduleNumber=moduleNumber),
partial(self.javaMotorEntry, motorNumber=motorNumber, moduleNumber=moduleNumber)))
self.Motor_packs[-1].Motor_pack.config(
text='Module: ' + str(moduleNumber) + ' Motors: ' + str(motorNumber))
Expand Down

0 comments on commit 08c633e

Please sign in to comment.