From 08c633e01bdf00b24f8239e3d2b08367ae3b7d3f Mon Sep 17 00:00:00 2001 From: iris Date: Fri, 21 Jun 2024 01:45:59 -0500 Subject: [PATCH] WORKING PIDS --- REVHubInterface/REVMotor.py | 10 +--------- REVHubInterface/__main__.py | 12 +++++++----- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/REVHubInterface/REVMotor.py b/REVHubInterface/REVMotor.py index cf17149..3e1bb78 100644 --- a/REVHubInterface/REVMotor.py +++ b/REVHubInterface/REVMotor.py @@ -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 @@ -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 @@ -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) @@ -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): @@ -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) diff --git a/REVHubInterface/__main__.py b/REVHubInterface/__main__.py index 90f619c..0a60c96 100644 --- a/REVHubInterface/__main__.py +++ b/REVHubInterface/__main__.py @@ -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 = [ @@ -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 = [ @@ -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 = [ @@ -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) @@ -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))