Skip to content

Commit

Permalink
Added total axis torque output to fx graph
Browse files Browse the repository at this point in the history
  • Loading branch information
Ultrawipf committed Nov 21, 2023
1 parent 191d496 commit ae6c2a6
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
### Changes this version:
- Added basic translation function
- Fixed CS selection in SPI buttons
- Added axis output torque to FX live graph

### Changes in 1.14.x:
- Added TMC space vector PWM checkbox
Expand Down
61 changes: 56 additions & 5 deletions effects_graph_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ def __init__(self, dlg=None):
self.start_time = 0
self.chart_last_x = 0

self.axis = None
self.axistorque_enabled = False
self.totaltorqe_line = None

self.axis = 0
self.spinBox_axis.valueChanged.connect(self.setAxis)

# Chart setup
Expand Down Expand Up @@ -62,6 +65,11 @@ def __init__(self, dlg=None):
self.chart_yaxis_forces, PyQt6.QtCore.Qt.AlignmentFlag.AlignLeft
)

# Output axis
self.chart_yaxis_output = PyQt6.QtCharts.QValueAxis()
self.chart_yaxis_output.setMin(-10)
self.chart_yaxis_output.setMax(10)

self.chart.legend().setLabelBrush(
PyQt6.QtWidgets.QApplication.instance().palette().text()
)
Expand Down Expand Up @@ -100,7 +108,7 @@ def __init__(self, dlg=None):
PyQt6.QtGui.QColorConstants.Red,
PyQt6.QtGui.QColorConstants.Green,
PyQt6.QtGui.QColorConstants.Yellow,
PyQt6.QtGui.QColorConstants.Black,
PyQt6.QtGui.QColorConstants.Gray,
]
self.lines = []
for i in range(12):
Expand All @@ -116,12 +124,39 @@ def __init__(self, dlg=None):
self.timer = PyQt6.QtCore.QTimer(self)
self.timer.timeout.connect(self.update_timer) # pylint: disable=no-value-for-parameter

def set_total_output_display(self,enable: bool):
"""Enable or disable the axis torque line"""
if enable and self.totaltorqe_line == None:
self.axistorque_enabled = enable
self.chart.addAxis(
self.chart_yaxis_output, PyQt6.QtCore.Qt.AlignmentFlag.AlignRight
)
q_line = PyQt6.QtCharts.QLineSeries()
q_line.setColor(PyQt6.QtGui.QColorConstants.Svg.coral)
q_line.setName("Output torque (Y2)")
self.totaltorqe_line = q_line
self.chart.addSeries(q_line)
q_line.attachAxis(self.chart_yaxis_output)
q_line.attachAxis(self.chart_xaxis)
elif not enable and self.totaltorqe_line != None:
self.chart.removeSeries(self.totaltorqe_line)
self.chart.removeAxis(self.chart_yaxis_output)
del self.totaltorqe_line
self.totaltorqe_line = None

def set_output_axis_range(self,val: int):
"""Changes the right Y axis scaling"""
self.chart_yaxis_output.setMin(-val)
self.chart_yaxis_output.setMax(val)

def reset(self):
# Clear
self.start_time = PyQt6.QtCore.QTime.currentTime()
self.chart_last_x = 0
for i in range(12):
self.lines[i].clear()
if self.totaltorqe_line != None:
self.totaltorqe_line.clear()

def setAxis(self,axis):
# Reset
Expand Down Expand Up @@ -149,6 +184,16 @@ def hideEvent(self, event): # pylint: disable=invalid-name, unused-argument
def update_timer(self):
"""Call the board to get instant data."""
self.get_value_async("fx", "effectsForces", self.display_data,adr=self.axis)
if self.totaltorqe_line != None:
self.get_value_async("axis","curtorque",callback=self.axistorque_cb,instance=self.axis,conversion=int)

def axistorque_cb(self,val):
if not self.totaltorqe_line != None:
return
self.add_data_to_series(self.totaltorqe_line,val)
maxval = abs(max(list(self.totaltorqe_line.points()),key=lambda v:abs(v.y())).y())
self.set_output_axis_range(max(10,maxval)) # Autorange


def display_data(self, data):
"""Decode the data received."""
Expand Down Expand Up @@ -185,6 +230,11 @@ def update_effect_stats(self,dat):
self.spinBox_11.setValue(dat[10])
self.spinBox_12.setValue(dat[11])

def add_data_to_series(self,line,val):
line.append(self.chart_last_x, val)
if line.count() > self.max_datapoints:
line.remove(0)

def update_current(self, forces):
"""Display on graph the response of the board."""
try:
Expand All @@ -193,9 +243,7 @@ def update_current(self, forces):
)
index = 0
for i in forces:
self.lines[index].append(self.chart_last_x, forces[index])
if self.lines[index].count() > self.max_datapoints:
self.lines[index].remove(0)
self.add_data_to_series(self.lines[index],forces[index])
index += 1

self.chart_xaxis.setMax(self.chart_last_x)
Expand Down Expand Up @@ -238,3 +286,6 @@ def display(self):
self.show()
self.raise_()
self.activateWindow()

def set_total_output_display(self,enabled: bool):
self.graph_ui.set_total_output_display(enabled)
2 changes: 2 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ def reset_tabs(self):

self.effects_monitor_dlg.setEnabled(False)
self.effects_graph_dlg.setEnabled(False)
self.effects_graph_dlg.set_total_output_display(False)
self.actionEffectsMonitor.setEnabled(False)
self.actionEffects_forces.setEnabled(False)
self.axes = 0
Expand Down Expand Up @@ -466,6 +467,7 @@ def update_tabs_cb(active):
self.profile_ui.set_save_btn(True)
self.axes = max(self.axes,classe.axis)
self.maxaxischanged.emit(self.axes)
self.effects_graph_dlg.set_total_output_display(True)
elif classe_active["id"] == 0x81 or classe_active["id"] == 0x82 or \
classe_active["id"] == 0x83:
classe = tmc4671_ui.TMC4671Ui(main=self, unique=classe_active["unique"])
Expand Down

0 comments on commit ae6c2a6

Please sign in to comment.