Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
motor-primitives-in-steering-simulation/templates.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
57 lines (44 sloc)
1.78 KB
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
import numpy as np | |
import matplotlib.pyplot as plt | |
# SHAPE FUNCTIONS -------------------------------------------------- | |
def gaussian(x, mu, sigma, amp): | |
return (np.radians(amp))*(np.exp(-np.power(x - mu, 2.) / (2 * np.power(sigma, 2.)))) | |
def sigmoid(x,shift,amp,k): | |
return ((np.radians(amp))/(1 + np.exp(k*(-x +shift)))) | |
def straight(x,slope,b): | |
return (slope*x+b) | |
# PLOT FUNCTION SHAPES ----------------------------------------------- | |
def bellcurve_vis(time, amp): | |
x_val = np.arange(0, time, 0.01) | |
path, = plt.plot(x_val, gaussian(x_val, 5, 2, amp)) | |
plt.grid(True, which='both') | |
plt.axhline(y=0, color='k') | |
plt.xlabel('time') | |
plt.ylabel('steering angle (in degrees)') | |
plt.title('Bell Curve to Represent Steering Profile') | |
bellcurve_vis.xdata = path.get_xdata() | |
bellcurve_vis.ydata = path.get_ydata() | |
plt.show() | |
def straight_vis(time): | |
plt.hlines(y = 0, xmin = 1, xmax = time, label = "black line") | |
plt.grid(True, which='both') | |
plt.axhline(y=0, color='k') | |
plt.xlabel('time') | |
plt.ylabel('steering angle (in degrees)') | |
plt.title('Line to Represent Steering Profile') | |
straight_vis.xdata = np.arange(0,time,0.1) | |
straight_vis.ydata = np.full(np.size(straight_vis.xdata),0) | |
plt.show() | |
def sigmoid_vis(time,amp,shift,slope): | |
x = np.arange(0, time, 0.1) | |
z = sigmoid(x,shift,amp,slope) | |
path, = plt.plot(x, z) | |
plt.grid(True, which='both') | |
plt.axhline(y=0, color='k') | |
plt.xlabel('time') | |
plt.ylabel('steering angle (in degrees)') | |
plt.title('S Curve to Represent Steering Profile') | |
sigmoid_vis.xdata = path.get_xdata() | |
sigmoid_vis.ydata = path.get_ydata() | |
plt.show() | |
# TEST CODE ------------------------------------------------------- | |