Created
May 11, 2020 04:14
-
-
Save gftabor/9b5875a50e51f333e59f5a3106b3fd3e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
""" | |
Created on Sun May 10 21:50:41 2020 | |
@author: tabor | |
""" | |
import numpy as np | |
import matplotlib.pyplot as plt | |
def speed(w1,w2): | |
x_direction_speed = max(abs(w1[0]),abs(w2[0])) | |
y_direction_speed = max(abs(w1[1]),abs(w2[1])) | |
return np.sqrt(x_direction_speed**2+y_direction_speed**2) | |
#given wheel configuration run it in every possible direction to find its fastest | |
def testAllDirections(w1,w2): | |
speeds = [] | |
for deg in range(360): | |
theta = np.deg2rad(deg) | |
c, s = np.cos(theta), np.sin(theta) | |
R = np.array(((c, -s), (s, c))) | |
new_w1 = np.dot(R,w1) | |
new_w2 = np.dot(R,w2) | |
speeds.append(speed(new_w1,new_w2)) | |
return np.max(speeds) | |
print(speed([1,0],[1,0])) | |
print(speed([1,0],[0,1])) | |
angles = np.linspace(-90,90,200) | |
maxSpeeds = [] | |
for theta in angles: | |
w1 = np.array([np.cos(np.deg2rad(theta)), np.sin(np.deg2rad(theta))]) | |
w2 = np.array([np.cos(np.deg2rad(-theta)), np.sin(np.deg2rad(-theta))]) | |
maxSpeeds.append(testAllDirections(w1,w2)) | |
plt.plot(angles,maxSpeeds) | |
print(angles[np.argmax(maxSpeeds)]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment