Skip to content

Commit

Permalink
Added tmc debug openloop test mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Ultrawipf committed Jul 25, 2024
1 parent 727cca9 commit eb1ab77
Show file tree
Hide file tree
Showing 4 changed files with 265 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
### Changes this version:
- Added TMC debug openloop test mode

### Changes in 1.15.x:
- Added permanent inertia and friction effect sliders
- Added position save toggle for ODrive
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
import activetasks

# This GUIs version
VERSION = "1.15.0"
VERSION = "1.15.1"

# Minimal supported firmware version.
# Major version of firmware must match firmware. Minor versions must be higher or equal
Expand Down
181 changes: 180 additions & 1 deletion res/tmcdebug.ui
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,187 @@
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_3">
<property name="title">
<string>Test mode</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Warning: Openloop mode does NOT use current sensors. You are manually applying a PWM value. Carefully check the currents.&lt;br/&gt;High currents may DAMAGE the motor, driver, connected devices or cause INJURY.&lt;br/&gt;&lt;br/&gt;Set up motor before enabling this.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_openloop">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Yes i know what i am doing. Enable openloop mode.</string>
</property>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_openlooptest">
<property name="enabled">
<bool>false</bool>
</property>
<property name="title">
<string>Openloop test</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="3" column="1">
<widget class="QProgressBar" name="progressBar_power">
<property name="maximum">
<number>28000</number>
</property>
<property name="value">
<number>0</number>
</property>
<property name="invertedAppearance">
<bool>false</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>PWM</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Speed</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSlider" name="horizontalSlider_speed">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="tickPosition">
<enum>QSlider::NoTicks</enum>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSlider" name="horizontalSlider_pwm">
<property name="maximum">
<number>20000</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QSpinBox" name="spinBox_pwm">
<property name="frame">
<bool>false</bool>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
<property name="buttonSymbols">
<enum>QAbstractSpinBox::NoButtons</enum>
</property>
<property name="keyboardTracking">
<bool>false</bool>
</property>
<property name="suffix">
<string>%</string>
</property>
<property name="maximum">
<number>99</number>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Current</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QSpinBox" name="spinBox_speed">
<property name="frame">
<bool>false</bool>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
<property name="buttonSymbols">
<enum>QAbstractSpinBox::NoButtons</enum>
</property>
<property name="keyboardTracking">
<bool>false</bool>
</property>
<property name="suffix">
<string> rpm</string>
</property>
</widget>
</item>
<item row="3" column="2">
<widget class="QSpinBox" name="spinBox_current">
<property name="frame">
<bool>false</bool>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
<property name="buttonSymbols">
<enum>QAbstractSpinBox::NoButtons</enum>
</property>
<property name="keyboardTracking">
<bool>false</bool>
</property>
<property name="suffix">
<string>/32787</string>
</property>
<property name="maximum">
<number>40000</number>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QCheckBox" name="checkBox_reverse">
<property name="text">
<string>Reverse</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
<connections>
<connection>
<sender>horizontalSlider_speed</sender>
<signal>valueChanged(int)</signal>
<receiver>spinBox_speed</receiver>
<slot>setValue(int)</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>391</y>
</hint>
<hint type="destinationlabel">
<x>611</x>
<y>391</y>
</hint>
</hints>
</connection>
</connections>
</ui>
83 changes: 81 additions & 2 deletions tmcdebug_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,95 @@
from PyQt6.QtCore import QTimer
import main
from base_ui import WidgetUI
from base_ui import CommunicationHandler

class TMCDebugUI(WidgetUI):
class TMCDebugUI(WidgetUI,CommunicationHandler):

def __init__(self, main=None, unique=1):
WidgetUI.__init__(self, main,'tmcdebug.ui')
self.main = main #type: main.MainUi
self.timer = QTimer(self)
self.timer_slow = QTimer(self)

self.pwm = 0
self.speed = 0
self.axis = 0
self.openloopenabled = False
self.adc_to_amps = 0

self.timer.timeout.connect(self.updateTimer)
self.timer_slow.timeout.connect(self.updateTimerSlow)

self.register_callback("tmc","acttrq",self.updateCurrent,self.axis,str)
self.register_callback("tmc","state",self.stateCb,self.axis,str,typechar='?')
self.register_callback("tmc","iScale",self.setCurrentScaler,self.axis,float)

self.horizontalSlider_speed.valueChanged.connect(self.speedchanged)
self.horizontalSlider_pwm.valueChanged.connect(self.pwmchanged)
self.pushButton_openloop.clicked.connect(lambda : self.set_openloop(True))
self.checkBox_reverse.stateChanged.connect(lambda : self.speedchanged(self.speed))
self.init_ui()


def init_ui(self):
pass
self.send_commands("tmc",["state","iScale"],self.axis)

def updateTimer(self):
self.send_command("tmc","acttrq",self.axis)

def updateTimerSlow(self):
self.send_command("tmc","state",self.axis)

def stateCb(self,state):
intstate = int(state)
if(intstate == 3 or intstate == 2):
self.set_ready(True)

def hideEvent(self,event):
self.timer.stop()
self.timer_slow.stop()

def showEvent(self,event):
self.init_ui()
self.timer.start(100)
self.timer_slow.start(1000)

def set_ready(self,ready):
self.pushButton_openloop.setEnabled(ready)

def set_openloop(self,enable):
self.openloopenabled = enable
self.groupBox_openlooptest.setEnabled(enable)
self.send_value("main","openloopspeed",instance=self.axis,val=0,adr=0)
self.horizontalSlider_speed.setValue(0)
self.horizontalSlider_pwm.setValue(0)

def setCurrentScaler(self,x):
if x != self.adc_to_amps:
self.adc_to_amps = x
if x != 0:
self.spinBox_current.setSuffix("mA")
else:
self.spinBox_current.setSuffix("/32787")


def updateCurrent(self,torqueflux):
tflist = [(int(v)) for v in torqueflux.split(":")]
torque = abs(tflist[0])
flux = tflist[1]
currents = complex(torque,flux)
self.progressBar_power.setValue(int(abs(currents)))
if self.adc_to_amps != 0:
self.spinBox_current.setValue(int(abs(currents*self.adc_to_amps*1000)))
else:
self.spinBox_current.setValue(int(abs(currents)))

def speedchanged(self,speed):
self.speed = speed
newspeed = -self.speed if self.checkBox_reverse.isChecked() else self.speed
self.send_value("main","openloopspeed",instance=self.axis,val=newspeed,adr=self.pwm)

def pwmchanged(self,pwm):
self.pwm = pwm
self.spinBox_pwm.setValue(int(pwm/200))
self.send_value("main","openloopspeed",instance=self.axis,val=self.speed,adr=self.pwm)

0 comments on commit eb1ab77

Please sign in to comment.