Skip to content

Commit

Permalink
several bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
micromouseonline committed Jan 8, 2023
1 parent 45feb71 commit c559cf9
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 31 deletions.
10 changes: 5 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def set_speed(self, speed):
:param speed: The speed throughout the turn
:return: modifies acceleration
'''
self.current_params.max_speed = speed
self.current_params.speed = speed
acceleration = self.path.get_turn_acceleration(self.current_profile, self.current_params)
self.set_safely(self.ui.accelerationSpinBox, int(acceleration))
self.re_calculate()
Expand Down Expand Up @@ -255,7 +255,7 @@ def set_acceleration(self, acceleration):
self.current_params.acceleration = acceleration
radius = self.ui.radiusSpinBox.value()
speed = math.sqrt(acceleration * radius)
self.current_params.max_speed = speed
self.current_params.speed = speed
self.set_safely(self.ui.turnSpeedSpinBox, int(speed))
self.re_calculate()

Expand Down Expand Up @@ -339,8 +339,8 @@ def show_summary(self):
self.ui.textEdit.append(f" Wheel Accel'n: {wheel_acc:5.0f} mm/s/s")
self.ui.textEdit.append(f" Max alpha: {max_alpha:5.0f} deg/s/s")
self.ui.textEdit.append(f" Max omega: {self.path.get_max_omega():5.0f} deg/s")
self.ui.textEdit.append(f" Exit X: {end_x:5.1f} mm")
self.ui.textEdit.append(f" Exit Y: {end_y:5.1f} mm")
self.ui.textEdit.append(f"Profile Exit X: {end_x:5.1f} mm")
self.ui.textEdit.append(f"Profile Exit Y: {end_y:5.1f} mm")
self.ui.textEdit.append(f" Overshoot X: {slip_comp_x:5.1f} mm")
self.ui.textEdit.append(f" Undershoot Y: {slip_comp_y:5.1f} mm")
self.ui.textEdit.append(f" Exit Speed: {self.path.trajectory.speed:5.0f} mm/s")
Expand All @@ -365,7 +365,7 @@ def plot_data(self):
lot of that is just clearing the axes
'''
now = perf_counter()
axes = self.ui.mpl_widget.axes
axes = self.ui.pg_widget.axes
title_style = {'color': 'cyan', 'size': '12px'}
interval = self.path.trajectory.delta_t
path_time = self.path.trajectory.time
Expand Down
10 changes: 5 additions & 5 deletions path.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def calculate(self, profile_type: ProfileType, params: TurnParameters, startx, s
else:
profile = Trapezoid()
self.trajectory.set_profiler(profile)
params.speed = params.max_speed
# params.speed = params.max_speed
self.trajectory.set_params(params)
self.trajectory.set_start_xy(startx,starty)
self.trajectory.calculate()
Expand All @@ -176,12 +176,12 @@ def calculate(self, profile_type: ProfileType, params: TurnParameters, startx, s
def get_turn_acceleration(self, profile_type: ProfileType, params: TurnParameters):
acc = 0
if profile_type == ProfileType.TRAPEZOID:
acc = params.max_speed * params.max_speed / params.arc_radius
acc = params.speed * params.speed / params.arc_radius
elif profile_type == ProfileType.QUADRATIC:
acc = params.max_speed * params.max_speed / params.arc_radius
acc = params.speed * params.speed / params.arc_radius
elif profile_type == ProfileType.SINUSOID:
acc = params.max_speed * params.max_speed / params.arc_radius
acc = params.speed * params.speed / params.arc_radius
elif profile_type == ProfileType.CUBIC:
acc = 6 * params.max_speed * params.max_speed * math.radians(params.angle) / 4 / params.cubic_length
acc = 6 * params.speed * params.speed * math.radians(params.angle) / 4 / params.cubic_length

return acc
20 changes: 10 additions & 10 deletions profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ def __init__(self):

def setup(self, params : TurnParameters):
self.params = params
self.arc_omega = np.degrees(params.max_speed / params.arc_radius)
self.transition_angle = params.delta * self.arc_omega / (2.0 * params.max_speed)
self.arc_omega = np.degrees(params.speed / params.arc_radius)
self.transition_angle = params.delta * self.arc_omega / (2.0 * params.speed)
self.arc_angle = params.angle - 2 * self.transition_angle
self.arc_length = params.max_speed * self.arc_angle / self.arc_omega
self.arc_length = params.speed * self.arc_angle / self.arc_omega
self.length = 2 * params.delta + self.arc_length

def get_omega(self,p,speed):
Expand All @@ -67,10 +67,10 @@ def __init__(self):

def setup(self, params : TurnParameters):
self.params = params
self.arc_omega = np.degrees(params.max_speed / params.radius)
self.transition_angle = params.delta * self.arc_omega / (3.0 * params.max_speed)
self.arc_omega = np.degrees(params.speed / params.radius)
self.transition_angle = params.delta * self.arc_omega / (3.0 * params.speed)
self.arc_angle = params.angle - 2 * self.transition_angle
self.arc_length = params.max_speed * self.arc_angle / self.arc_omega
self.arc_length = params.speed * self.arc_angle / self.arc_omega
self.length = 2 * params.delta + self.arc_length

def get_omega(self,p,speed):
Expand All @@ -94,10 +94,10 @@ def __init__(self):

def setup(self, params : TurnParameters):
self.params = params
self.arc_omega = np.degrees(params.max_speed / params.radius)
self.transition_angle = params.delta * self.arc_omega / (np.pi * params.max_speed)
self.arc_omega = np.degrees(params.speed / params.radius)
self.transition_angle = params.delta * self.arc_omega / (np.pi * params.speed)
self.arc_angle = params.angle - 2 * self.transition_angle
self.arc_length = params.max_speed * self.arc_angle / self.arc_omega
self.arc_length = params.speed * self.arc_angle / self.arc_omega
self.length = 2 * params.delta + self.arc_length

def get_omega(self,p,speed):
Expand All @@ -123,7 +123,7 @@ def __init__(self):
def setup(self, params : TurnParameters):
self.params = params
radius = 4.0*params.delta/(np.pi*np.radians(params.angle))
self.arc_omega = np.degrees(params.max_speed / radius)
self.arc_omega = np.degrees(params.speed / radius)
self.length = 2 * params.delta


Expand Down
1 change: 0 additions & 1 deletion profilers.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ def setup(self, params : TurnParameters):
self.arc_angle = params.angle - 2 * self.transition_angle
self.arc_length = self.params.speed * self.arc_angle / self.arc_omega
self.length = 2 * params.delta + self.arc_length
print(self.arc_length)

def get_omega(self,p):
phase = 1
Expand Down
8 changes: 4 additions & 4 deletions pyturnprofile.ui
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ p, li { white-space: pre-wrap; }
</widget>
</item>
<item row="7" column="1">
<widget class="QSpinBox" name="slipSpinBox">
<widget class="QSpinBox" name="gripSpinBox">
<property name="toolTip">
<string extracomment="Slip angle constant (deg/g)"/>
</property>
Expand Down Expand Up @@ -472,9 +472,9 @@ p, li { white-space: pre-wrap; }
</spacer>
</item>
<item row="7" column="0">
<widget class="QLabel" name="lblSlip">
<widget class="QLabel" name="lblGrip">
<property name="text">
<string>Slip</string>
<string>Grip</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
Expand Down Expand Up @@ -653,7 +653,7 @@ p, li { white-space: pre-wrap; }
<string>Turn Summary</string>
</property>
</widget>
<widget class="PGWidget" name="mpl_widget" native="true">
<widget class="PGWidget" name="pg_widget" native="true">
<property name="geometry">
<rect>
<x>10</x>
Expand Down
5 changes: 2 additions & 3 deletions trajectory.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# File Created: Thursday, 5th January 2023 2:10:17 pm
# Author: Peter Harrison
# -----
# Last Modified: Saturday, 7th January 2023 11:05:43 pm
# Last Modified: Sunday, 8th January 2023 3:24:48 pm
# -----
# Copyright 2022 - 2023 Peter Harrison, Micromouseonline
# -----
Expand Down Expand Up @@ -160,8 +160,6 @@ def beta_dot(omega,beta, speed):
b_dot = -(np.radians(omega) + self.k_grip * np.radians(beta) / speed)
return np.degrees(b_dot)

self.theta_actual[0] = self.start_angle
# print(self.speed, self.k_grip, self.k_grip/self.speed)
for i in range(len(self.time)):
if i > 0:
omega = self.omega_ideal[i-1]
Expand All @@ -173,6 +171,7 @@ def beta_dot(omega,beta, speed):

x = self.start_x
y = self.start_y
self.theta_actual[0] = self.theta_ideal[0]
for i,angle in enumerate(self.theta_actual):
self.x_actual[i] = x
self.y_actual[i] = y
Expand Down
6 changes: 3 additions & 3 deletions ui_pyturnprofile.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,9 @@ def setupUi(self, MainWindow):
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(10, 460, 131, 16))
self.label.setObjectName("label")
self.mpl_widget = PGWidget(self.centralwidget)
self.mpl_widget.setGeometry(QtCore.QRect(10, 30, 401, 401))
self.mpl_widget.setObjectName("mpl_widget")
self.pg_widget = PGWidget(self.centralwidget)
self.pg_widget.setGeometry(QtCore.QRect(10, 30, 401, 401))
self.pg_widget.setObjectName("pg_widget")
MainWindow.setCentralWidget(self.centralwidget)

self.retranslateUi(MainWindow)
Expand Down

0 comments on commit c559cf9

Please sign in to comment.