Skip to content

Commit

Permalink
Plots added
Browse files Browse the repository at this point in the history
  • Loading branch information
kubasaw committed Jan 15, 2020
1 parent df6b307 commit 2473531
Show file tree
Hide file tree
Showing 6 changed files with 248 additions and 68 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,7 @@ venv.bak/

# Test snippets
test*.py

# Log files
logs/
log.dat
6 changes: 4 additions & 2 deletions car/canListener.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from struct import unpack
from time import time

import serial
from PyQt5.QtCore import *
Expand Down Expand Up @@ -37,7 +38,7 @@ class myCan(QObject):
strSignal = pyqtSignal(str)
tupleSignal = pyqtSignal(tuple)

def __init__(self, serialPortName, strSlots=[], tupleSlots=[], loopTime=1):
def __init__(self, serialPortName, strSlots=[], tupleSlots=[], loopTime=1.0):
super().__init__()
self.__serialhandle = serial.Serial(serialPortName, 115200)
self.__serialhandle.reset_input_buffer()
Expand Down Expand Up @@ -119,10 +120,11 @@ def sendMsg(self, msg):
class canMsg():

def __init__(self, StdId, Data):
self.timestamp = time()
self.stdId = StdId
self.data = Data
self.dlc = len(Data)

def __str__(self):
if self.stdId == 19:
return "ID: {ID:#x}\t Data: {Data}".format(Data=unpack(
Expand Down
13 changes: 11 additions & 2 deletions car/motion.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def __init__(self, trackProfile):
super().__init__(trackProfile)
self.__length = max(pos[0] for pos in self.val)
self.__interpolant = interp1d([pos[0] for pos in self.val], [
pos[1] for pos in self.val], kind='cubic', bounds_error=True, copy=False, assume_sorted=False)
pos[1] for pos in self.val], kind='linear', bounds_error=True, copy=False, assume_sorted=False)

def getSlopeSine(self, point, positionInterval=2):
"""Compute track slope sine
Expand Down Expand Up @@ -217,6 +217,10 @@ def setThrottle(self, throttle):
except:
raise ValueError(
"Throttle value have to be choosen from unit interval [0-1]")

if (self.__throttle <= 0 and temp >= 0):
self.__state[2] += self.param.get("r0")

self.__throttle = temp

def setTimestep(self, dt):
Expand Down Expand Up @@ -295,7 +299,6 @@ def carDynamics(t, x, throttle):
self.__state = solve_ivp(lambda t, x: carDynamics(t, x, self.__throttle), (t0, __nextSwitch),
self.__state, t_eval=[__nextSwitch])['y'].flatten()
if (self.__throttle <= 0):
self.__state[2] += self.param.get("r0")
self.setThrottle(1)
else:
self.setThrottle(0)
Expand All @@ -306,6 +309,12 @@ def carDynamics(t, x, throttle):
else:
self.__state = solve_ivp(lambda t, x: carDynamics(t, x, self.__throttle), (t0, tf),
self.__state, t_eval=[tf])['y'].flatten()
if(__nextSwitch == tf):
if (self.__throttle <= 0):
self.setThrottle(1)
else:
self.setThrottle(0)

self.__time = tf

return self.__state
75 changes: 49 additions & 26 deletions gui/mainWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Form implementation generated from reading ui file 'mainWindow.ui'
#
# Created by: PyQt5 UI code generator 5.13.0
# Created by: PyQt5 UI code generator 5.14.1
#
# WARNING! All changes made in this file will be lost!

Expand Down Expand Up @@ -51,33 +51,11 @@ def setupUi(self, MainWindow):
self.Simulation = QtWidgets.QWidget()
self.Simulation.setObjectName("Simulation")
self.gridLayoutWidget = QtWidgets.QWidget(self.Simulation)
self.gridLayoutWidget.setGeometry(QtCore.QRect(10, 10, 317, 99))
self.gridLayoutWidget.setGeometry(QtCore.QRect(10, 10, 317, 128))
self.gridLayoutWidget.setObjectName("gridLayoutWidget")
self.gridLayout = QtWidgets.QGridLayout(self.gridLayoutWidget)
self.gridLayout.setContentsMargins(0, 0, 0, 0)
self.gridLayout.setObjectName("gridLayout")
self.speedField = QtWidgets.QLineEdit(self.gridLayoutWidget)
self.speedField.setReadOnly(True)
self.speedField.setObjectName("speedField")
self.gridLayout.addWidget(self.speedField, 1, 2, 1, 1)
self.timeField = QtWidgets.QLineEdit(self.gridLayoutWidget)
self.timeField.setReadOnly(True)
self.timeField.setObjectName("timeField")
self.gridLayout.addWidget(self.timeField, 1, 0, 1, 1)
self.engineLabel = QtWidgets.QLabel(self.gridLayoutWidget)
self.engineLabel.setAlignment(QtCore.Qt.AlignCenter)
self.engineLabel.setObjectName("engineLabel")
self.gridLayout.addWidget(self.engineLabel, 0, 4, 1, 1)
self.makeStepButton = QtWidgets.QPushButton(self.gridLayoutWidget)
self.makeStepButton.setObjectName("makeStepButton")
self.gridLayout.addWidget(self.makeStepButton, 2, 0, 1, 5)
self.engineField = QtWidgets.QLineEdit(self.gridLayoutWidget)
self.engineField.setObjectName("engineField")
self.gridLayout.addWidget(self.engineField, 1, 4, 1, 1)
self.positionLabel = QtWidgets.QLabel(self.gridLayoutWidget)
self.positionLabel.setAlignment(QtCore.Qt.AlignCenter)
self.positionLabel.setObjectName("positionLabel")
self.gridLayout.addWidget(self.positionLabel, 0, 1, 1, 1)
self.fuelField = QtWidgets.QLineEdit(self.gridLayoutWidget)
self.fuelField.setReadOnly(True)
self.fuelField.setObjectName("fuelField")
Expand All @@ -86,14 +64,32 @@ def setupUi(self, MainWindow):
self.fuelLabel.setAlignment(QtCore.Qt.AlignCenter)
self.fuelLabel.setObjectName("fuelLabel")
self.gridLayout.addWidget(self.fuelLabel, 0, 3, 1, 1)
self.engineLabel = QtWidgets.QLabel(self.gridLayoutWidget)
self.engineLabel.setAlignment(QtCore.Qt.AlignCenter)
self.engineLabel.setObjectName("engineLabel")
self.gridLayout.addWidget(self.engineLabel, 0, 4, 1, 1)
self.positionLabel = QtWidgets.QLabel(self.gridLayoutWidget)
self.positionLabel.setAlignment(QtCore.Qt.AlignCenter)
self.positionLabel.setObjectName("positionLabel")
self.gridLayout.addWidget(self.positionLabel, 0, 1, 1, 1)
self.timeLabel = QtWidgets.QLabel(self.gridLayoutWidget)
self.timeLabel.setAlignment(QtCore.Qt.AlignCenter)
self.timeLabel.setObjectName("timeLabel")
self.gridLayout.addWidget(self.timeLabel, 0, 0, 1, 1)
self.speedField = QtWidgets.QLineEdit(self.gridLayoutWidget)
self.speedField.setReadOnly(True)
self.speedField.setObjectName("speedField")
self.gridLayout.addWidget(self.speedField, 1, 2, 1, 1)
self.engineField = QtWidgets.QLineEdit(self.gridLayoutWidget)
self.engineField.setObjectName("engineField")
self.gridLayout.addWidget(self.engineField, 1, 4, 1, 1)
self.positionField = QtWidgets.QLineEdit(self.gridLayoutWidget)
self.positionField.setReadOnly(True)
self.positionField.setObjectName("positionField")
self.gridLayout.addWidget(self.positionField, 1, 1, 1, 1)
self.makeStepButton = QtWidgets.QPushButton(self.gridLayoutWidget)
self.makeStepButton.setObjectName("makeStepButton")
self.gridLayout.addWidget(self.makeStepButton, 2, 0, 1, 5)
self.speedLabel = QtWidgets.QLabel(self.gridLayoutWidget)
self.speedLabel.setAlignment(QtCore.Qt.AlignCenter)
self.speedLabel.setObjectName("speedLabel")
Expand All @@ -102,6 +98,31 @@ def setupUi(self, MainWindow):
self.simulationStart.setCheckable(True)
self.simulationStart.setObjectName("simulationStart")
self.gridLayout.addWidget(self.simulationStart, 3, 0, 1, 5)
self.timeField = QtWidgets.QLineEdit(self.gridLayoutWidget)
self.timeField.setReadOnly(True)
self.timeField.setObjectName("timeField")
self.gridLayout.addWidget(self.timeField, 1, 0, 1, 1)
self.resetSimulationButton = QtWidgets.QPushButton(self.gridLayoutWidget)
self.resetSimulationButton.setObjectName("resetSimulationButton")
self.gridLayout.addWidget(self.resetSimulationButton, 4, 0, 1, 5)
self.gridLayoutWidget_2 = QtWidgets.QWidget(self.Simulation)
self.gridLayoutWidget_2.setGeometry(QtCore.QRect(329, 9, 631, 301))
self.gridLayoutWidget_2.setObjectName("gridLayoutWidget_2")
self.chartsGrid = QtWidgets.QGridLayout(self.gridLayoutWidget_2)
self.chartsGrid.setContentsMargins(0, 0, 0, 0)
self.chartsGrid.setObjectName("chartsGrid")
self.fuelChartW = QChartView(self.gridLayoutWidget_2)
self.fuelChartW.setObjectName("fuelChartW")
self.chartsGrid.addWidget(self.fuelChartW, 1, 0, 1, 1)
self.positionChartW = QChartView(self.gridLayoutWidget_2)
self.positionChartW.setObjectName("positionChartW")
self.chartsGrid.addWidget(self.positionChartW, 0, 0, 1, 1)
self.engineChartW = QChartView(self.gridLayoutWidget_2)
self.engineChartW.setObjectName("engineChartW")
self.chartsGrid.addWidget(self.engineChartW, 1, 1, 1, 1)
self.speedChartW = QChartView(self.gridLayoutWidget_2)
self.speedChartW.setObjectName("speedChartW")
self.chartsGrid.addWidget(self.speedChartW, 0, 1, 1, 1)
self.tabWidget.addTab(self.Simulation, "")
self.Settings = QtWidgets.QWidget()
self.Settings.setObjectName("Settings")
Expand Down Expand Up @@ -154,13 +175,14 @@ def retranslateUi(self, MainWindow):
self.refreshAvailablePorts.setText(_translate("MainWindow", "Refresh"))
self.connectPort.setText(_translate("MainWindow", "Connect"))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.Connection), _translate("MainWindow", "Connection"))
self.fuelLabel.setText(_translate("MainWindow", "Fuel"))
self.engineLabel.setText(_translate("MainWindow", "Engine"))
self.makeStepButton.setText(_translate("MainWindow", "Make Simulation &Step!"))
self.positionLabel.setText(_translate("MainWindow", "Position"))
self.fuelLabel.setText(_translate("MainWindow", "Fuel"))
self.timeLabel.setText(_translate("MainWindow", "Time"))
self.makeStepButton.setText(_translate("MainWindow", "Make Simulation &Step!"))
self.speedLabel.setText(_translate("MainWindow", "Speed"))
self.simulationStart.setText(_translate("MainWindow", "Start Simulation!"))
self.resetSimulationButton.setText(_translate("MainWindow", "Reset Simulation!"))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.Simulation), _translate("MainWindow", "Simulation"))
self.langSelectorLabel.setText(_translate("MainWindow", "Language"))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.Settings), _translate("MainWindow", "Settings"))
Expand All @@ -170,6 +192,7 @@ def retranslateUi(self, MainWindow):
self.actionAbout.setText(_translate("MainWindow", "About"))
self.actionImport_Settings.setText(_translate("MainWindow", "Import Settings"))
self.actionExport_Settings.setText(_translate("MainWindow", "Export Settings"))
from PyQt5.QtChart import QChartView


if __name__ == "__main__":
Expand Down
107 changes: 73 additions & 34 deletions gui/mainWindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -132,21 +132,24 @@
<x>10</x>
<y>10</y>
<width>317</width>
<height>99</height>
<height>128</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="2">
<widget class="QLineEdit" name="speedField">
<item row="1" column="3">
<widget class="QLineEdit" name="fuelField">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLineEdit" name="timeField">
<property name="readOnly">
<bool>true</bool>
<item row="0" column="3">
<widget class="QLabel" name="fuelLabel">
<property name="text">
<string>Fuel</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
Expand All @@ -160,16 +163,6 @@
</property>
</widget>
</item>
<item row="2" column="0" colspan="5">
<widget class="QPushButton" name="makeStepButton">
<property name="text">
<string>Make Simulation &amp;Step!</string>
</property>
</widget>
</item>
<item row="1" column="4">
<widget class="QLineEdit" name="engineField"/>
</item>
<item row="0" column="1">
<widget class="QLabel" name="positionLabel">
<property name="text">
Expand All @@ -180,23 +173,6 @@
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QLineEdit" name="fuelField">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QLabel" name="fuelLabel">
<property name="text">
<string>Fuel</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="timeLabel">
<property name="text">
Expand All @@ -207,13 +183,30 @@
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QLineEdit" name="speedField">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="4">
<widget class="QLineEdit" name="engineField"/>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="positionField">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="0" colspan="5">
<widget class="QPushButton" name="makeStepButton">
<property name="text">
<string>Make Simulation &amp;Step!</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLabel" name="speedLabel">
<property name="text">
Expand All @@ -234,6 +227,44 @@
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLineEdit" name="timeField">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="4" column="0" colspan="5">
<widget class="QPushButton" name="resetSimulationButton">
<property name="text">
<string>Reset Simulation!</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="gridLayoutWidget_2">
<property name="geometry">
<rect>
<x>329</x>
<y>9</y>
<width>631</width>
<height>301</height>
</rect>
</property>
<layout class="QGridLayout" name="chartsGrid">
<item row="1" column="0">
<widget class="QChartView" name="fuelChartW" native="true"/>
</item>
<item row="0" column="0">
<widget class="QChartView" name="positionChartW" native="true"/>
</item>
<item row="1" column="1">
<widget class="QChartView" name="engineChartW" native="true"/>
</item>
<item row="0" column="1">
<widget class="QChartView" name="speedChartW" native="true"/>
</item>
</layout>
</widget>
</widget>
Expand Down Expand Up @@ -321,6 +352,14 @@
</property>
</action>
</widget>
<customwidgets>
<customwidget>
<class>QChartView</class>
<extends>QWidget</extends>
<header>PyQt5.QtChart</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>
Expand Down
Loading

0 comments on commit 2473531

Please sign in to comment.